From bfaba288427e80e7941e49c4264ba8f6cd6d97d1 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Fri, 15 Mar 2019 11:35:51 +0000 Subject: Fix buildbots hidden_api_test Target buildbots set /system to be the runtime module root because they are running without an apex. The test assumes that /system dex files are assigned to the application domain but here they get assigned to the core-platform domain. Adjust the domain setting logic to check if the runtime module root is distict from the android root (as a proxy for 'is running with apex'). If not (as is the case with the buildbots), skip checks against apex locations. Test: m test-art-target-gtest-hidden_api_test Change-Id: Iff3890ec69cb04a1e4ed5bc2a3b5c652ada05f36 --- runtime/hidden_api_test.cc | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'runtime/hidden_api_test.cc') diff --git a/runtime/hidden_api_test.cc b/runtime/hidden_api_test.cc index be6407963b..70fafe6587 100644 --- a/runtime/hidden_api_test.cc +++ b/runtime/hidden_api_test.cc @@ -17,6 +17,7 @@ #include "hidden_api.h" #include +#include #include "base/file_utils.h" #include "base/sdk_version.h" @@ -431,20 +432,25 @@ static bool LoadDexFiles(const std::string& path, static bool CheckAllDexFilesInDomain(ObjPtr loader, const std::vector>& dex_files, - hiddenapi::Domain expected_domain) + hiddenapi::Domain expected_domain, + /* out */ std::string* error_msg) REQUIRES_SHARED(Locks::mutator_lock_) { for (const auto& dex_file : dex_files) { hiddenapi::AccessContext context(loader, dex_file.get()); if (context.GetDomain() != expected_domain) { - LOG(ERROR) << dex_file->GetLocation() << ": access context domain does not match " + std::stringstream ss; + ss << dex_file->GetLocation() << ": access context domain does not match " << "(expected=" << static_cast(expected_domain) << ", actual=" << static_cast(context.GetDomain()) << ")"; + *error_msg = ss.str(); return false; } if (dex_file->GetHiddenapiDomain() != expected_domain) { - LOG(ERROR) << dex_file->GetLocation() << ": dex file domain does not match " + std::stringstream ss; + ss << dex_file->GetLocation() << ": dex file domain does not match " << "(expected=" << static_cast(expected_domain) << ", actual=" << static_cast(dex_file->GetHiddenapiDomain()) << ")"; + *error_msg = ss.str(); return false; } } @@ -466,7 +472,10 @@ TEST_F(HiddenApiTest, DexDomain_DataDir) { ASSERT_TRUE(LoadDexFiles(data_location_path, soa, &dex_files, &class_loader, &error_msg)) << error_msg; ASSERT_GE(dex_files.size(), 1u); - ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, dex_files, hiddenapi::Domain::kApplication)); + ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, + dex_files, + hiddenapi::Domain::kApplication, + &error_msg)) << error_msg; dex_files.clear(); ASSERT_EQ(0, remove(data_location_path.c_str())); @@ -486,7 +495,10 @@ TEST_F(HiddenApiTest, DexDomain_SystemDir) { ASSERT_TRUE(LoadDexFiles(system_location_path, soa, &dex_files, &class_loader, &error_msg)) << error_msg; ASSERT_GE(dex_files.size(), 1u); - ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, dex_files, hiddenapi::Domain::kApplication)); + ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, + dex_files, + hiddenapi::Domain::kApplication, + &error_msg)) << error_msg; dex_files.clear(); ASSERT_EQ(0, remove(system_location_path.c_str())); @@ -510,7 +522,10 @@ TEST_F(HiddenApiTest, DexDomain_SystemFrameworkDir) { &class_loader, &error_msg)) << error_msg; ASSERT_GE(dex_files.size(), 1u); - ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, dex_files, hiddenapi::Domain::kPlatform)); + ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, + dex_files, + hiddenapi::Domain::kPlatform, + &error_msg)) << error_msg; dex_files.clear(); ASSERT_EQ(0, remove(system_framework_location_path.c_str())); @@ -531,7 +546,10 @@ TEST_F(HiddenApiTest, DexDomain_DataDir_MultiDex) { ASSERT_TRUE(LoadDexFiles(data_multi_location_path, soa, &dex_files, &class_loader, &error_msg)) << error_msg; ASSERT_GE(dex_files.size(), 1u); - ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, dex_files, hiddenapi::Domain::kApplication)); + ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, + dex_files, + hiddenapi::Domain::kApplication, + &error_msg)) << error_msg; dex_files.clear(); ASSERT_EQ(0, remove(data_multi_location_path.c_str())); @@ -553,7 +571,10 @@ TEST_F(HiddenApiTest, DexDomain_SystemDir_MultiDex) { ASSERT_TRUE(LoadDexFiles(system_multi_location_path, soa, &dex_files, &class_loader, &error_msg)) << error_msg; ASSERT_GT(dex_files.size(), 1u); - ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, dex_files, hiddenapi::Domain::kApplication)); + ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, + dex_files, + hiddenapi::Domain::kApplication, + &error_msg)) << error_msg; dex_files.clear(); ASSERT_EQ(0, remove(system_multi_location_path.c_str())); @@ -579,7 +600,10 @@ TEST_F(HiddenApiTest, DexDomain_SystemFrameworkDir_MultiDex) { &class_loader, &error_msg)) << error_msg; ASSERT_GT(dex_files.size(), 1u); - ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, dex_files, hiddenapi::Domain::kPlatform)); + ASSERT_TRUE(CheckAllDexFilesInDomain(class_loader, + dex_files, + hiddenapi::Domain::kPlatform, + &error_msg)) << error_msg; dex_files.clear(); ASSERT_EQ(0, remove(system_framework_multi_location_path.c_str())); -- cgit v1.2.3-59-g8ed1b