diff options
-rw-r--r-- | build/Android.gtest.mk | 18 | ||||
-rw-r--r-- | build/art.go | 9 | ||||
-rw-r--r-- | build/makevars.go | 27 | ||||
-rw-r--r-- | compiler/utils/assembler_test.h | 1 | ||||
-rw-r--r-- | libartbase/base/common_art_test.cc | 73 | ||||
-rw-r--r-- | libnativeloader/Android.bp | 13 | ||||
-rw-r--r-- | test/Android.bp | 5 |
7 files changed, 90 insertions, 56 deletions
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk index 21199dac33..a71ce41c50 100644 --- a/build/Android.gtest.mk +++ b/build/Android.gtest.mk @@ -25,12 +25,13 @@ my_files := $(ART_TESTCASES_CONTENT) # Manually add system libraries that we need to run the host ART tools. my_files += \ - $(foreach lib, \ - libbacktrace libbase libc++ libicu_jni liblog libsigchain libunwindstack libziparchive, \ - $(call intermediates-dir-for,SHARED_LIBRARIES,$(lib),HOST)/$(lib).so:lib64/$(lib).so) \ - $(foreach lib, \ - libcrypto libz, \ - $(call intermediates-dir-for,SHARED_LIBRARIES,$(lib),HOST)/$(lib).so:lib64/$(lib)-host.so) + $(foreach lib, libbacktrace libbase libc++ libicu_jni liblog libsigchain libunwindstack \ + libziparchive libjavacore libandroidio libopenjdkd, \ + $(call intermediates-dir-for,SHARED_LIBRARIES,$(lib),HOST)/$(lib).so:lib64/$(lib).so \ + $(call intermediates-dir-for,SHARED_LIBRARIES,$(lib),HOST,,2ND)/$(lib).so:lib/$(lib).so) \ + $(foreach lib, libcrypto libz libicuuc libicui18n libandroidicu libexpat, \ + $(call intermediates-dir-for,SHARED_LIBRARIES,$(lib),HOST)/$(lib).so:lib64/$(lib)-host.so \ + $(call intermediates-dir-for,SHARED_LIBRARIES,$(lib),HOST,,2ND)/$(lib).so:lib/$(lib)-host.so) # Add apex directories for art, conscrypt and i18n. my_files += $(foreach infix,_ _VDEX_,$(foreach suffix,$(HOST_ARCH) $(HOST_2ND_ARCH), \ @@ -39,7 +40,8 @@ my_files += \ $(foreach jar,$(CORE_IMG_JARS),\ $(HOST_OUT_JAVA_LIBRARIES)/$(jar)-hostdex.jar:apex/com.android.art/javalib/$(jar).jar) \ $(HOST_OUT_JAVA_LIBRARIES)/conscrypt-hostdex.jar:apex/com.android.conscrypt/javalib/conscrypt.jar\ - $(HOST_OUT_JAVA_LIBRARIES)/core-icu4j-hostdex.jar:apex/com.android.i18n/javalib/core-icu4j.jar + $(HOST_OUT_JAVA_LIBRARIES)/core-icu4j-hostdex.jar:apex/com.android.i18n/javalib/core-icu4j.jar \ + $(HOST_OUT)/com.android.i18n/etc/icu/icudt66l.dat:com.android.i18n/etc/icu/icudt66l.dat # Create dummy module that will copy all the data files into testcases directory. # For now, this copies everything to "out/host/linux-x86/" subdirectory, since it @@ -51,7 +53,7 @@ LOCAL_MODULE_TAGS := tests LOCAL_MODULE_CLASS := NATIVE_TESTS LOCAL_MODULE_SUFFIX := .txt LOCAL_COMPATIBILITY_SUITE := general-tests -LOCAL_COMPATIBILITY_SUPPORT_FILES := \ +LOCAL_COMPATIBILITY_SUPPORT_FILES := $(ART_TESTCASES_PREBUILT_CONTENT) \ $(foreach f,$(my_files),$(call word-colon,1,$f):out/host/linux-x86/$(call word-colon,2,$f)) include $(BUILD_SYSTEM)/base_rules.mk diff --git a/build/art.go b/build/art.go index 8deea23098..af2a5deb54 100644 --- a/build/art.go +++ b/build/art.go @@ -291,10 +291,11 @@ func addTestcasesFile(ctx android.InstallHookContext) { defer artTestMutex.Unlock() if ctx.Os().Class == android.Host { - path := ctx.Path().ToMakePath().String() - parts := strings.Split(path, "/") - // Keep last two parts of the path (e.g. bin/dex2oat). - testcasesContent[strings.Join(parts[len(parts)-2:], "/")] = path + src := ctx.SrcPath().String() + path := strings.Split(ctx.Path().ToMakePath().String(), "/") + // Keep last two parts of the install path (e.g. bin/dex2oat). + dst := strings.Join(path[len(path)-2:], "/") + testcasesContent[dst] = src } } diff --git a/build/makevars.go b/build/makevars.go index 6e66966bf5..22ef205c86 100644 --- a/build/makevars.go +++ b/build/makevars.go @@ -15,18 +15,22 @@ package art import ( + "path/filepath" "sort" "strings" "android/soong/android" + "android/soong/cc/config" ) var ( - pctx = android.NewPackageContext("android/soong/art") + pctx = android.NewPackageContext("android/soong/art") + prebuiltToolsForTests = []string{"as", "addr2line", "objdump"} ) func init() { android.RegisterMakeVarsProvider(pctx, makeVarsProvider) + pctx.Import("android/soong/cc/config") } func makeVarsProvider(ctx android.MakeVarsContext) { @@ -52,4 +56,25 @@ func makeVarsProvider(ctx android.MakeVarsContext) { copy_cmds = append(copy_cmds, testcasesContent[key]+":"+key) } ctx.Strict("ART_TESTCASES_CONTENT", strings.Join(copy_cmds, " ")) + + // Add prebuilt tools. + copy_cmds = []string{} + for _, cmd := range prebuiltToolsForTests { + target := ctx.Config().Targets[android.BuildOs][0] + toolchain := config.FindToolchain(target.Os, target.Arch) + gccRoot, gccTriple := toolchain.GccRoot(), toolchain.GccTriple() + eval := func(path ...string) string { + result, err := ctx.Eval(filepath.Join(path...)) + if err != nil { + panic(err) + } + return result + } + src := eval(gccRoot, "bin", gccTriple+"-"+cmd) + // Different tests use different paths, so we need to copy to two locations. + // TODO: Unify the test code so that this is no longer necessary. + copy_cmds = append(copy_cmds, src+":"+eval(gccRoot, "bin", gccTriple+"-"+cmd)) + copy_cmds = append(copy_cmds, src+":"+eval(gccRoot, gccTriple, "bin", cmd)) + } + ctx.Strict("ART_TESTCASES_PREBUILT_CONTENT", strings.Join(copy_cmds, " ")) } diff --git a/compiler/utils/assembler_test.h b/compiler/utils/assembler_test.h index 9e23d11116..268befba3b 100644 --- a/compiler/utils/assembler_test.h +++ b/compiler/utils/assembler_test.h @@ -738,6 +738,7 @@ class AssemblerTest : public testing::Test { AssemblerTest() {} void SetUp() override { + CommonArtTest::SetUpAndroidRootEnvVars(); allocator_.reset(new ArenaAllocator(&pool_)); assembler_.reset(CreateAssembler(allocator_.get())); test_helper_.reset( diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc index 2497e77e75..e327832a7b 100644 --- a/libartbase/base/common_art_test.cc +++ b/libartbase/base/common_art_test.cc @@ -141,53 +141,40 @@ void ScratchFile::Unlink() { void CommonArtTestImpl::SetUpAndroidRootEnvVars() { if (IsHost()) { - // Make sure that ANDROID_BUILD_TOP is set. If not, set it from CWD. - const char* android_build_top_from_env = getenv("ANDROID_BUILD_TOP"); - if (android_build_top_from_env == nullptr) { - // Not set by build server, so default to current directory. - char* cwd = getcwd(nullptr, 0); - setenv("ANDROID_BUILD_TOP", cwd, 1); - free(cwd); - android_build_top_from_env = getenv("ANDROID_BUILD_TOP"); - } - - const char* android_host_out_from_env = getenv("ANDROID_HOST_OUT"); - if (android_host_out_from_env == nullptr) { - // Not set by build server, so default to the usual value of - // ANDROID_HOST_OUT. - std::string android_host_out; -#if defined(__linux__) - // Fallback - android_host_out = std::string(android_build_top_from_env) + "/out/host/linux-x86"; - // Look at how we were invoked - std::string argv; - if (android::base::ReadFileToString("/proc/self/cmdline", &argv)) { - // /proc/self/cmdline is the programs 'argv' with elements delimited by '\0'. - std::string cmdpath(argv.substr(0, argv.find('\0'))); - std::filesystem::path path(cmdpath); - // If the path is relative then prepend the android_build_top_from_env to it - if (path.is_relative()) { - path = std::filesystem::path(android_build_top_from_env).append(cmdpath); - DCHECK(path.is_absolute()) << path; - } - // Walk up until we find the linux-x86 directory or we hit the root directory. - while (path.has_parent_path() && path.parent_path() != path && - path.filename() != std::filesystem::path("linux-x86")) { - path = path.parent_path(); - } - // If we found a linux-x86 directory path is now android_host_out + // Look at how we were invoked to extract reasonable default paths. + std::string argv; + if (android::base::ReadFileToString("/proc/self/cmdline", &argv)) { + // /proc/self/cmdline is the programs 'argv' with elements delimited by '\0'. + std::filesystem::path path(argv.substr(0, argv.find('\0'))); + path = std::filesystem::absolute(path); + // Walk up until we find the one of the well-known directories. + for (; path.parent_path() != path; path = path.parent_path()) { + // We are running tests from out/host/linux-x86 on developer machine. if (path.filename() == std::filesystem::path("linux-x86")) { - android_host_out = path.string(); + char* cwd = getcwd(nullptr, 0); + setenv("ANDROID_BUILD_TOP", cwd, /*overwrite=*/ 0); // No-op if already set. + free(cwd); + setenv("ANDROID_HOST_OUT", path.c_str(), /*overwrite=*/ 0); // No-op if already set. + break; + } + // We are running tests from testcases (extracted from zip) on tradefed. + if (path.filename() == std::filesystem::path("testcases")) { + path.append("art_common"); + bool ok = chdir(path.c_str()) == 0; + CHECK(ok); + setenv("ANDROID_BUILD_TOP", path.c_str(), /*overwrite=*/ 0); // No-op if already set. + path.append("out/host/linux-x86"); + setenv("ANDROID_HOST_OUT", path.c_str(), /*overwrite=*/ 0); // No-op if already set. + break; } } -#elif defined(__APPLE__) - android_host_out = std::string(android_build_top_from_env) + "/out/host/darwin-x86"; -#else -#error unsupported OS -#endif - setenv("ANDROID_HOST_OUT", android_host_out.c_str(), 1); - android_host_out_from_env = getenv("ANDROID_HOST_OUT"); } + const char* android_build_top_from_env = getenv("ANDROID_BUILD_TOP"); + DCHECK(android_build_top_from_env != nullptr); + DCHECK(std::filesystem::exists(android_build_top_from_env)) << android_build_top_from_env; + const char* android_host_out_from_env = getenv("ANDROID_HOST_OUT"); + DCHECK(android_host_out_from_env != nullptr); + DCHECK(std::filesystem::exists(android_host_out_from_env)) << android_host_out_from_env; // Environment variable ANDROID_ROOT is set on the device, but not // necessarily on the host. diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp index 5f29b4d626..33a2c8f483 100644 --- a/libnativeloader/Android.bp +++ b/libnativeloader/Android.bp @@ -35,6 +35,19 @@ art_cc_library { "libbase", ], target: { + // Library search path needed for running host tests remotely (from testcases directory). + linux_glibc_x86: { + ldflags: [ + "-Wl,-rpath,$ORIGIN/../art_common/out/host/linux-x86/lib", + "-Wl,--enable-new-dtags", + ], + }, + linux_glibc_x86_64: { + ldflags: [ + "-Wl,-rpath,$ORIGIN/../art_common/out/host/linux-x86/lib64", + "-Wl,--enable-new-dtags", + ], + }, android: { srcs: [ "library_namespaces.cpp", diff --git a/test/Android.bp b/test/Android.bp index 62b2153991..81f5f4157a 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -54,6 +54,11 @@ art_cc_defaults { "art_defaults", ], + test_suites: ["general-tests"], + test_options: { + test_suite_tag: ["art-host-gtest"], + }, + shared_libs: [ "libartd", "libartd-disassembler", |