From 7ee34a1eeba20c1b438f7bcad75adba65dd2a840 Mon Sep 17 00:00:00 2001 From: Evgeny Astigeevich Date: Tue, 10 Dec 2019 11:36:33 +0000 Subject: Add OptimizingUnitTestHelper::GraphChecker methods GraphChecker should be always used in gtests where it is possible. Currently only ImprovedOptimizingUnitTest allows unit tests to use GraphChecker. Unit tests based on OptimizingUnitTest cannot use this functionality. Another issue is that GraphChecker has reference type information checks which unit tests cannot satisfy. The CL resolves the issues by: * Adding a public GraphChecker::SetRefTypeInfoCheckEnabled. * Adding a private OptimizingUnitTestHelper::CheckGraph(HGraph* graph, bool check_ref_type_info). * Adding a public OptimizingUnitTestHelper::CheckGraph(graph) to perform all checks. * Adding a public OptimizingUnitTestHelper::CheckGraphSkipRefTypeInfoChecks(graph) to perform all checks but reference type information checks. * Updating ImprovedOptimizingUnitTest::CheckGraph to use OptimizingUnitTestHelper::CheckGraph. To demonstrate how the new API can be used, unit tests for the Load-Store-Analysis pass are updated. Test: test.py --host --optimizing --jit --gtest Test: test.py --target --optimizing --jit Test: run-gtests.sh Change-Id: I7ca0983e66d9904073f0d711b3de96cccfe42746 --- compiler/optimizing/optimizing_unit_test.h | 36 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'compiler/optimizing/optimizing_unit_test.h') diff --git a/compiler/optimizing/optimizing_unit_test.h b/compiler/optimizing/optimizing_unit_test.h index 01571267e2..eb262bc123 100644 --- a/compiler/optimizing/optimizing_unit_test.h +++ b/compiler/optimizing/optimizing_unit_test.h @@ -180,7 +180,29 @@ class OptimizingUnitTestHelper { } } + // Run GraphChecker with all checks. + // + // Return: the status whether the run is successful. + bool CheckGraph(HGraph* graph) { + return CheckGraph(graph, /*check_ref_type_info=*/true); + } + + // Run GraphChecker with all checks except reference type information checks. + // + // Return: the status whether the run is successful. + bool CheckGraphSkipRefTypeInfoChecks(HGraph* graph) { + return CheckGraph(graph, /*check_ref_type_info=*/false); + } + private: + bool CheckGraph(HGraph* graph, bool check_ref_type_info) { + GraphChecker checker(graph); + checker.SetRefTypeInfoCheckEnabled(check_ref_type_info); + checker.Run(); + checker.Dump(std::cerr); + return checker.IsValid(); + } + std::vector> dex_files_; std::unique_ptr pool_and_allocator_; std::unique_ptr handles_; @@ -223,15 +245,11 @@ class ImprovedOptimizingUnitTest : public OptimizingUnitTest { } bool CheckGraph() { - GraphChecker checker(graph_); - checker.Run(); - if (!checker.IsValid()) { - for (const std::string& error : checker.GetErrors()) { - std::cout << error << std::endl; - } - return false; - } - return true; + return OptimizingUnitTestHelper::CheckGraph(graph_); + } + + bool CheckGraphSkipRefTypeInfoChecks() { + return OptimizingUnitTestHelper::CheckGraphSkipRefTypeInfoChecks(graph_); } HEnvironment* ManuallyBuildEnvFor(HInstruction* instruction, -- cgit v1.2.3-59-g8ed1b