diff options
-rw-r--r-- | runtime/arch/arch_test.cc | 7 | ||||
-rw-r--r-- | runtime/common_runtime_test.cc | 30 | ||||
-rw-r--r-- | runtime/common_runtime_test.h | 4 | ||||
-rw-r--r-- | runtime/entrypoints/quick/quick_trampoline_entrypoints_test.cc | 7 | ||||
-rw-r--r-- | runtime/parsed_options_test.cc | 38 |
5 files changed, 72 insertions, 14 deletions
diff --git a/runtime/arch/arch_test.cc b/runtime/arch/arch_test.cc index d6ba304bd1..1680bbda1e 100644 --- a/runtime/arch/arch_test.cc +++ b/runtime/arch/arch_test.cc @@ -30,6 +30,13 @@ class ArchTest : public CommonRuntimeTest { options->push_back(std::make_pair("imageinstructionset", "x86_64")); } + // Do not do any of the finalization. We don't want to run any code, we don't need the heap + // prepared, it actually will be a problem with setting the instruction set to x86_64 in + // SetUpRuntimeOptions. + void FinalizeSetup() OVERRIDE { + ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet()); + } + static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size) NO_THREAD_SAFETY_ANALYSIS { Runtime* const runtime = Runtime::Current(); diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc index 2f9bbbd76d..403dd4c0df 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -333,6 +333,19 @@ void CommonRuntimeTest::SetUp() { class_linker_ = runtime_->GetClassLinker(); class_linker_->FixupDexCaches(runtime_->GetResolutionMethod()); + // Runtime::Create acquired the mutator_lock_ that is normally given away when we + // Runtime::Start, give it away now and then switch to a more managable ScopedObjectAccess. + Thread::Current()->TransitionFromRunnableToSuspended(kNative); + + // Get the boot class path from the runtime so it can be used in tests. + boot_class_path_ = class_linker_->GetBootClassPath(); + ASSERT_FALSE(boot_class_path_.empty()); + java_lang_dex_file_ = boot_class_path_[0]; + + FinalizeSetup(); +} + +void CommonRuntimeTest::FinalizeSetup() { // Initialize maps for unstarted runtime. This needs to be here, as running clinits needs this // set up. if (!unstarted_initialized_) { @@ -340,14 +353,10 @@ void CommonRuntimeTest::SetUp() { unstarted_initialized_ = true; } - class_linker_->RunRootClinits(); - boot_class_path_ = class_linker_->GetBootClassPath(); - java_lang_dex_file_ = boot_class_path_[0]; - - - // Runtime::Create acquired the mutator_lock_ that is normally given away when we - // Runtime::Start, give it away now and then switch to a more managable ScopedObjectAccess. - Thread::Current()->TransitionFromRunnableToSuspended(kNative); + { + ScopedObjectAccess soa(Thread::Current()); + class_linker_->RunRootClinits(); + } // We're back in native, take the opportunity to initialize well known classes. WellKnownClasses::Init(Thread::Current()->GetJniEnv()); @@ -358,11 +367,6 @@ void CommonRuntimeTest::SetUp() { runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption before the test // Reduce timinig-dependent flakiness in OOME behavior (eg StubTest.AllocObject). runtime_->GetHeap()->SetMinIntervalHomogeneousSpaceCompactionByOom(0U); - - // Get the boot class path from the runtime so it can be used in tests. - boot_class_path_ = class_linker_->GetBootClassPath(); - ASSERT_FALSE(boot_class_path_.empty()); - java_lang_dex_file_ = boot_class_path_[0]; } void CommonRuntimeTest::ClearDirectory(const char* dirpath) { diff --git a/runtime/common_runtime_test.h b/runtime/common_runtime_test.h index 672bd7173d..8d9e6281c0 100644 --- a/runtime/common_runtime_test.h +++ b/runtime/common_runtime_test.h @@ -114,6 +114,10 @@ class CommonRuntimeTest : public testing::Test { // Called after the runtime is created. virtual void PostRuntimeCreate() {} + // Called to finish up runtime creation and filling test fields. By default runs root + // initializers, initialize well-known classes, and creates the heap thread pool. + virtual void FinalizeSetup(); + // Gets the path of the specified dex file for host or target. static std::string GetDexFileName(const std::string& jar_prefix); diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints_test.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints_test.cc index 4e8591339c..01e22a4a7d 100644 --- a/runtime/entrypoints/quick/quick_trampoline_entrypoints_test.cc +++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints_test.cc @@ -31,6 +31,13 @@ class QuickTrampolineEntrypointsTest : public CommonRuntimeTest { options->push_back(std::make_pair("imageinstructionset", "x86_64")); } + // Do not do any of the finalization. We don't want to run any code, we don't need the heap + // prepared, it actually will be a problem with setting the instruction set to x86_64 in + // SetUpRuntimeOptions. + void FinalizeSetup() OVERRIDE { + ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet()); + } + static ArtMethod* CreateCalleeSaveMethod(InstructionSet isa, Runtime::CalleeSaveType type) NO_THREAD_SAFETY_ANALYSIS { Runtime* r = Runtime::Current(); diff --git a/runtime/parsed_options_test.cc b/runtime/parsed_options_test.cc index b2240cb6a6..5b90c6adad 100644 --- a/runtime/parsed_options_test.cc +++ b/runtime/parsed_options_test.cc @@ -18,6 +18,8 @@ #include <memory> +#include "arch/instruction_set.h" +#include "base/stringprintf.h" #include "common_runtime_test.h" namespace art { @@ -123,6 +125,40 @@ TEST_F(ParsedOptionsTest, ParsedOptionsGc) { EXPECT_TRUE(map.Exists(Opt::GcOption)); XGcOption xgc = map.GetOrDefault(Opt::GcOption); - EXPECT_EQ(gc::kCollectorTypeMC, xgc.collector_type_);} + EXPECT_EQ(gc::kCollectorTypeMC, xgc.collector_type_); +} + +TEST_F(ParsedOptionsTest, ParsedOptionsInstructionSet) { + using Opt = RuntimeArgumentMap; + + { + // Nothing set, should be kRuntimeISA. + RuntimeOptions options; + RuntimeArgumentMap map; + bool parsed = ParsedOptions::Parse(options, false, &map); + ASSERT_TRUE(parsed); + InstructionSet isa = map.GetOrDefault(Opt::ImageInstructionSet); + EXPECT_EQ(kRuntimeISA, isa); + } + + const char* isa_strings[] = { "arm", "arm64", "x86", "x86_64", "mips", "mips64" }; + InstructionSet ISAs[] = { InstructionSet::kArm, + InstructionSet::kArm64, + InstructionSet::kX86, + InstructionSet::kX86_64, + InstructionSet::kMips, + InstructionSet::kMips64 }; + static_assert(arraysize(isa_strings) == arraysize(ISAs), "Need same amount."); + + for (size_t i = 0; i < arraysize(isa_strings); ++i) { + RuntimeOptions options; + options.push_back(std::make_pair("imageinstructionset", isa_strings[i])); + RuntimeArgumentMap map; + bool parsed = ParsedOptions::Parse(options, false, &map); + ASSERT_TRUE(parsed); + InstructionSet isa = map.GetOrDefault(Opt::ImageInstructionSet); + EXPECT_EQ(ISAs[i], isa); + } +} } // namespace art |