From 1a509c8effc938ba3da0f90ad83abb124b296386 Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Mon, 24 Jul 2017 16:51:21 -0700 Subject: Be prepared to handle empty class loader contexts When executing run-tests we can hit an empty class loader contexts if the compilation sources are passed with "-cp" and later removed from the context. Be prepared for such case and assume a PathClassLoader context. Bug: 63977059 Test: ./art/test/run-test --host --optimizing --dev test-art-host Change-Id: Id0fa853b2407e358592f89766adb5dad19137289 --- runtime/class_loader_context_test.cc | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'runtime/class_loader_context_test.cc') diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc index 1b46f67215..e60f61cc11 100644 --- a/runtime/class_loader_context_test.cc +++ b/runtime/class_loader_context_test.cc @@ -162,6 +162,19 @@ class ClassLoaderContextTest : public CommonRuntimeTest { } }; +TEST_F(ClassLoaderContextTest, ParseValidEmptyContext) { + std::unique_ptr context = ClassLoaderContext::Create(""); + // An empty context should create a single empty PathClassLoader. + VerifyContextSize(context.get(), 1); + VerifyClassLoaderPCL(context.get(), 0, ""); +} + +TEST_F(ClassLoaderContextTest, ParseValidSharedLibraryContext) { + std::unique_ptr context = ClassLoaderContext::Create("&"); + // An shared library context should have no class loader in the chain. + VerifyContextSize(context.get(), 0); +} + TEST_F(ClassLoaderContextTest, ParseValidContextPCL) { std::unique_ptr context = ClassLoaderContext::Create("PCL[a.dex]"); @@ -313,6 +326,34 @@ TEST_F(ClassLoaderContextTest, CreateClassLoaderWithEmptyContext) { soa.Decode(WellKnownClasses::java_lang_BootClassLoader)); } +TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSharedLibraryContext) { + std::unique_ptr context = ClassLoaderContext::Create("&"); + + ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, "")); + + std::vector> compilation_sources = OpenTestDexFiles("MultiDex"); + + std::vector compilation_sources_raw = + MakeNonOwningPointerVector(compilation_sources); + jobject jclass_loader = context->CreateClassLoader(compilation_sources_raw); + ASSERT_TRUE(jclass_loader != nullptr); + + ScopedObjectAccess soa(Thread::Current()); + + StackHandleScope<1> hs(soa.Self()); + Handle class_loader = hs.NewHandle( + soa.Decode(jclass_loader)); + + // A shared library context should create a single PathClassLoader with only the compilation + // sources. + VerifyClassLoaderDexFiles(soa, + class_loader, + WellKnownClasses::dalvik_system_PathClassLoader, + compilation_sources_raw); + ASSERT_TRUE(class_loader->GetParent()->GetClass() == + soa.Decode(WellKnownClasses::java_lang_BootClassLoader)); +} + TEST_F(ClassLoaderContextTest, CreateClassLoaderWithComplexChain) { // Setup the context. std::vector> classpath_dex_a = OpenTestDexFiles("ForClassLoaderA"); -- cgit v1.2.3-59-g8ed1b