From 7adeda8592f44039ea475dda778ac20d2ed72a0a Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Mon, 25 Jul 2016 08:27:35 -0700 Subject: [PATCH] Revert "Revert "ART: Add dex2oat swap usage test"" Now correctly ignores the target (but with enough infrastructure to introduce this some day). This reverts commit ec743ffd47ac9d3c10a449926d78c2eb51e5208e. Bug: 29259363 Test: m test-art-host-gtest-dex2oat_test Test: m test-art-target-gtest-dex2oat_test (shamu) Change-Id: I11b4e755bc8cb1e2eea29cd006e8df67df632c00 --- build/Android.gtest.mk | 2 +- dex2oat/dex2oat_test.cc | 137 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 130 insertions(+), 9 deletions(-) diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk index cc96cf0a9..7f8fa8e39 100644 --- a/build/Android.gtest.mk +++ b/build/Android.gtest.mk @@ -71,7 +71,7 @@ ART_GTEST_class_linker_test_DEX_DEPS := Interfaces MultiDex MyClass Nested Stati ART_GTEST_compiler_driver_test_DEX_DEPS := AbstractMethod StaticLeafMethods ProfileTestMultiDex ART_GTEST_dex_cache_test_DEX_DEPS := Main ART_GTEST_dex_file_test_DEX_DEPS := GetMethodSignature Main Nested -ART_GTEST_dex2oat_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS) +ART_GTEST_dex2oat_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS) Statics ART_GTEST_exception_test_DEX_DEPS := ExceptionHandle ART_GTEST_instrumentation_test_DEX_DEPS := Instrumentation ART_GTEST_jni_compiler_test_DEX_DEPS := MyClassNatives diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc index 93351e9f2..c076b5aea 100644 --- a/dex2oat/dex2oat_test.cc +++ b/dex2oat/dex2oat_test.cc @@ -14,9 +14,10 @@ * limitations under the License. */ +#include +#include #include #include -#include #include "common_runtime_test.h" @@ -207,7 +208,7 @@ class Dex2oatSwapTest : public Dex2oatTest { std::string dex_location = GetScratchDir() + "/Dex2OatSwapTest.jar"; std::string odex_location = GetOdexDir() + "/Dex2OatSwapTest.odex"; - Copy(GetDexSrc1(), dex_location); + Copy(GetTestDexFileName(), dex_location); std::vector copy(extra_args); @@ -226,7 +227,11 @@ class Dex2oatSwapTest : public Dex2oatTest { CheckResult(expect_use); } - void CheckResult(bool expect_use) { + virtual std::string GetTestDexFileName() { + return GetDexSrc1(); + } + + virtual void CheckResult(bool expect_use) { if (kIsTargetBuild) { CheckTargetResult(expect_use); } else { @@ -234,13 +239,13 @@ class Dex2oatSwapTest : public Dex2oatTest { } } - void CheckTargetResult(bool expect_use ATTRIBUTE_UNUSED) { + virtual void CheckTargetResult(bool expect_use ATTRIBUTE_UNUSED) { // TODO: Ignore for now, as we won't capture any output (it goes to the logcat). We may do // something for variants with file descriptor where we can control the lifetime of // the swap file and thus take a look at it. } - void CheckHostResult(bool expect_use) { + virtual void CheckHostResult(bool expect_use) { if (!kIsTargetBuild) { if (expect_use) { EXPECT_NE(output_.find("Large app, accepted running with swap."), std::string::npos) @@ -253,7 +258,7 @@ class Dex2oatSwapTest : public Dex2oatTest { } // Check whether the dex2oat run was really successful. - void CheckValidity() { + virtual void CheckValidity() { if (kIsTargetBuild) { CheckTargetValidity(); } else { @@ -261,14 +266,14 @@ class Dex2oatSwapTest : public Dex2oatTest { } } - void CheckTargetValidity() { + virtual void CheckTargetValidity() { // TODO: Ignore for now, as we won't capture any output (it goes to the logcat). We may do // something for variants with file descriptor where we can control the lifetime of // the swap file and thus take a look at it. } // On the host, we can get the dex2oat output. Here, look for "dex2oat took." - void CheckHostValidity() { + virtual void CheckHostValidity() { EXPECT_NE(output_.find("dex2oat took"), std::string::npos) << output_; } }; @@ -297,6 +302,122 @@ TEST_F(Dex2oatSwapTest, DoUseSwapSingleSmall) { { "--swap-dex-size-threshold=0", "--swap-dex-count-threshold=0" }); } +class Dex2oatSwapUseTest : public Dex2oatSwapTest { + protected: + void CheckHostResult(bool expect_use) OVERRIDE { + if (!kIsTargetBuild) { + if (expect_use) { + EXPECT_NE(output_.find("Large app, accepted running with swap."), std::string::npos) + << output_; + } else { + EXPECT_EQ(output_.find("Large app, accepted running with swap."), std::string::npos) + << output_; + } + } + } + + std::string GetTestDexFileName() OVERRIDE { + // Use Statics as it has a handful of functions. + return CommonRuntimeTest::GetTestDexFileName("Statics"); + } + + void GrabResult1() { + if (!kIsTargetBuild) { + native_alloc_1_ = ParseNativeAlloc(); + swap_1_ = ParseSwap(false /* expected */); + } else { + native_alloc_1_ = std::numeric_limits::max(); + swap_1_ = 0; + } + } + + void GrabResult2() { + if (!kIsTargetBuild) { + native_alloc_2_ = ParseNativeAlloc(); + swap_2_ = ParseSwap(true /* expected */); + } else { + native_alloc_2_ = 0; + swap_2_ = std::numeric_limits::max(); + } + } + + private: + size_t ParseNativeAlloc() { + std::regex native_alloc_regex("dex2oat took.*native alloc=[^ ]+ \\(([0-9]+)B\\)"); + std::smatch native_alloc_match; + bool found = std::regex_search(output_, native_alloc_match, native_alloc_regex); + if (!found) { + EXPECT_TRUE(found); + return 0; + } + if (native_alloc_match.size() != 2U) { + EXPECT_EQ(native_alloc_match.size(), 2U); + return 0; + } + + std::istringstream stream(native_alloc_match[1].str()); + size_t value; + stream >> value; + + return value; + } + + size_t ParseSwap(bool expected) { + std::regex swap_regex("dex2oat took[^\\n]+swap=[^ ]+ \\(([0-9]+)B\\)"); + std::smatch swap_match; + bool found = std::regex_search(output_, swap_match, swap_regex); + if (found != expected) { + EXPECT_EQ(expected, found); + return 0; + } + + if (!found) { + return 0; + } + + if (swap_match.size() != 2U) { + EXPECT_EQ(swap_match.size(), 2U); + return 0; + } + + std::istringstream stream(swap_match[1].str()); + size_t value; + stream >> value; + + return value; + } + + protected: + size_t native_alloc_1_; + size_t native_alloc_2_; + + size_t swap_1_; + size_t swap_2_; +}; + +TEST_F(Dex2oatSwapUseTest, CheckSwapUsage) { + RunTest(false /* use_fd */, + false /* expect_use */); + GrabResult1(); + std::string output_1 = output_; + + output_ = ""; + + RunTest(false /* use_fd */, + true /* expect_use */, + { "--swap-dex-size-threshold=0", "--swap-dex-count-threshold=0" }); + GrabResult2(); + std::string output_2 = output_; + + if (native_alloc_2_ >= native_alloc_1_ || swap_1_ >= swap_2_) { + EXPECT_LT(native_alloc_2_, native_alloc_1_); + EXPECT_LT(swap_1_, swap_2_); + + LOG(ERROR) << output_1; + LOG(ERROR) << output_2; + } +} + class Dex2oatVeryLargeTest : public Dex2oatTest { protected: void CheckFilter(CompilerFilter::Filter input ATTRIBUTE_UNUSED, -- 2.11.0