David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 17 | // Test is in compiler, as it uses compiler related code. |
| 18 | #include "verifier/verifier_deps.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 19 | |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 20 | #include "art_method-inl.h" |
David Sehr | 9c4a015 | 2018-04-05 12:23:54 -0700 | [diff] [blame] | 21 | #include "base/indenter.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 22 | #include "class_linker.h" |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 23 | #include "common_compiler_test.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 24 | #include "compiler_callbacks.h" |
Mathieu Chartier | c8c8d5f | 2018-05-22 11:56:14 -0700 | [diff] [blame] | 25 | #include "dex/class_accessor-inl.h" |
| 26 | #include "dex/class_iterator.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 27 | #include "dex/dex_file-inl.h" |
| 28 | #include "dex/dex_file_types.h" |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 29 | #include "dex/verification_results.h" |
| 30 | #include "dex/verified_method.h" |
Andreas Gampe | d482e73 | 2017-04-24 17:59:09 -0700 | [diff] [blame] | 31 | #include "driver/compiler_driver-inl.h" |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 32 | #include "driver/compiler_options.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 33 | #include "handle_scope-inl.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 34 | #include "mirror/class_loader.h" |
| 35 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 36 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | 6d7abbd | 2017-04-24 13:19:09 -0700 | [diff] [blame] | 37 | #include "thread.h" |
Mathieu Chartier | 93764b8 | 2017-07-17 14:51:53 -0700 | [diff] [blame] | 38 | #include "utils/atomic_dex_ref_map-inl.h" |
Andreas Gampe | 6d7abbd | 2017-04-24 13:19:09 -0700 | [diff] [blame] | 39 | #include "verifier/method_verifier-inl.h" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 40 | |
| 41 | namespace art { |
| 42 | namespace verifier { |
| 43 | |
| 44 | class VerifierDepsCompilerCallbacks : public CompilerCallbacks { |
| 45 | public: |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 46 | VerifierDepsCompilerCallbacks() |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 47 | : CompilerCallbacks(CompilerCallbacks::CallbackMode::kCompileApp), |
| 48 | deps_(nullptr) {} |
| 49 | |
| 50 | void MethodVerified(verifier::MethodVerifier* verifier ATTRIBUTE_UNUSED) OVERRIDE {} |
| 51 | void ClassRejected(ClassReference ref ATTRIBUTE_UNUSED) OVERRIDE {} |
| 52 | bool IsRelocationPossible() OVERRIDE { return false; } |
| 53 | |
| 54 | verifier::VerifierDeps* GetVerifierDeps() const OVERRIDE { return deps_; } |
| 55 | void SetVerifierDeps(verifier::VerifierDeps* deps) { deps_ = deps; } |
| 56 | |
| 57 | private: |
| 58 | verifier::VerifierDeps* deps_; |
| 59 | }; |
| 60 | |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 61 | class VerifierDepsTest : public CommonCompilerTest { |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 62 | public: |
| 63 | void SetUpRuntimeOptions(RuntimeOptions* options) { |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 64 | CommonCompilerTest::SetUpRuntimeOptions(options); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 65 | callbacks_.reset(new VerifierDepsCompilerCallbacks()); |
| 66 | } |
| 67 | |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 68 | ObjPtr<mirror::Class> FindClassByName(ScopedObjectAccess& soa, const std::string& name) |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 69 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 70 | StackHandleScope<1> hs(soa.Self()); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 71 | Handle<mirror::ClassLoader> class_loader_handle( |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 72 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_))); |
| 73 | ObjPtr<mirror::Class> klass = |
| 74 | class_linker_->FindClass(soa.Self(), name.c_str(), class_loader_handle); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 75 | if (klass == nullptr) { |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 76 | DCHECK(soa.Self()->IsExceptionPending()); |
| 77 | soa.Self()->ClearException(); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 78 | } |
| 79 | return klass; |
| 80 | } |
| 81 | |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 82 | void SetupCompilerDriver() { |
| 83 | compiler_options_->boot_image_ = false; |
| 84 | compiler_driver_->InitializeThreadPools(); |
| 85 | } |
| 86 | |
| 87 | void VerifyWithCompilerDriver(verifier::VerifierDeps* deps) { |
| 88 | TimingLogger timings("Verify", false, false); |
| 89 | // The compiler driver handles the verifier deps in the callbacks, so |
| 90 | // remove what this class did for unit testing. |
Mathieu Chartier | 72041a0 | 2017-07-14 18:23:25 -0700 | [diff] [blame] | 91 | if (deps == nullptr) { |
| 92 | // Create some verifier deps by default if they are not already specified. |
| 93 | deps = new verifier::VerifierDeps(dex_files_); |
| 94 | verifier_deps_.reset(deps); |
| 95 | } |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 96 | callbacks_->SetVerifierDeps(deps); |
| 97 | compiler_driver_->Verify(class_loader_, dex_files_, &timings); |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 98 | callbacks_->SetVerifierDeps(nullptr); |
Nicolas Geoffray | 1d0ae3f | 2016-12-06 13:40:16 +0000 | [diff] [blame] | 99 | // Clear entries in the verification results to avoid hitting a DCHECK that |
| 100 | // we always succeed inserting a new entry after verifying. |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 101 | AtomicDexRefMap<MethodReference, const VerifiedMethod*>* map = |
Nicolas Geoffray | 1d0ae3f | 2016-12-06 13:40:16 +0000 | [diff] [blame] | 102 | &compiler_driver_->GetVerificationResults()->atomic_verified_methods_; |
Mathieu Chartier | 93764b8 | 2017-07-17 14:51:53 -0700 | [diff] [blame] | 103 | map->Visit([](const DexFileReference& ref ATTRIBUTE_UNUSED, const VerifiedMethod* method) { |
Nicolas Geoffray | 1d0ae3f | 2016-12-06 13:40:16 +0000 | [diff] [blame] | 104 | delete method; |
| 105 | }); |
| 106 | map->ClearEntries(); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 107 | } |
| 108 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 109 | void SetVerifierDeps(const std::vector<const DexFile*>& dex_files) { |
| 110 | verifier_deps_.reset(new verifier::VerifierDeps(dex_files)); |
| 111 | VerifierDepsCompilerCallbacks* callbacks = |
| 112 | reinterpret_cast<VerifierDepsCompilerCallbacks*>(callbacks_.get()); |
| 113 | callbacks->SetVerifierDeps(verifier_deps_.get()); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 116 | void LoadDexFile(ScopedObjectAccess& soa, const char* name1, const char* name2 = nullptr) |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 117 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 118 | class_loader_ = (name2 == nullptr) ? LoadDex(name1) : LoadMultiDex(name1, name2); |
| 119 | dex_files_ = GetDexFiles(class_loader_); |
| 120 | primary_dex_file_ = dex_files_.front(); |
| 121 | |
| 122 | SetVerifierDeps(dex_files_); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 123 | StackHandleScope<1> hs(soa.Self()); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 124 | Handle<mirror::ClassLoader> loader = |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 125 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_)); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 126 | for (const DexFile* dex_file : dex_files_) { |
| 127 | class_linker_->RegisterDexFile(*dex_file, loader.Get()); |
| 128 | } |
Nicolas Geoffray | 1d0ae3f | 2016-12-06 13:40:16 +0000 | [diff] [blame] | 129 | for (const DexFile* dex_file : dex_files_) { |
| 130 | compiler_driver_->GetVerificationResults()->AddDexFile(dex_file); |
| 131 | } |
Mathieu Chartier | 72041a0 | 2017-07-14 18:23:25 -0700 | [diff] [blame] | 132 | compiler_driver_->SetDexFilesForOatFile(dex_files_); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 135 | void LoadDexFile(ScopedObjectAccess& soa) REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 136 | LoadDexFile(soa, "VerifierDeps"); |
| 137 | CHECK_EQ(dex_files_.size(), 1u); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 138 | klass_Main_ = FindClassByName(soa, "LMain;"); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 139 | CHECK(klass_Main_ != nullptr); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | bool VerifyMethod(const std::string& method_name) { |
| 143 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 144 | LoadDexFile(soa); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 145 | |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 146 | StackHandleScope<2> hs(soa.Self()); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 147 | Handle<mirror::ClassLoader> class_loader_handle( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 148 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_))); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 149 | Handle<mirror::DexCache> dex_cache_handle(hs.NewHandle(klass_Main_->GetDexCache())); |
| 150 | |
| 151 | const DexFile::ClassDef* class_def = klass_Main_->GetClassDef(); |
Mathieu Chartier | c8c8d5f | 2018-05-22 11:56:14 -0700 | [diff] [blame] | 152 | ClassAccessor accessor(*primary_dex_file_, *class_def); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 153 | |
Mathieu Chartier | c8c8d5f | 2018-05-22 11:56:14 -0700 | [diff] [blame] | 154 | bool has_failures = true; |
| 155 | bool found_method = false; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 156 | |
Mathieu Chartier | 0d896bd | 2018-05-25 00:20:27 -0700 | [diff] [blame] | 157 | for (const ClassAccessor::Method& method : accessor.GetMethods()) { |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 158 | ArtMethod* resolved_method = |
| 159 | class_linker_->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( |
Mathieu Chartier | c8c8d5f | 2018-05-22 11:56:14 -0700 | [diff] [blame] | 160 | method.GetIndex(), |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 161 | dex_cache_handle, |
| 162 | class_loader_handle, |
Vladimir Marko | 8901119 | 2017-12-11 13:45:05 +0000 | [diff] [blame] | 163 | /* referrer */ nullptr, |
Mathieu Chartier | c8c8d5f | 2018-05-22 11:56:14 -0700 | [diff] [blame] | 164 | method.GetInvokeType(class_def->access_flags_)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 165 | CHECK(resolved_method != nullptr); |
| 166 | if (method_name == resolved_method->GetName()) { |
Mathieu Chartier | c8c8d5f | 2018-05-22 11:56:14 -0700 | [diff] [blame] | 167 | soa.Self()->SetVerifierDeps(callbacks_->GetVerifierDeps()); |
| 168 | MethodVerifier verifier(soa.Self(), |
| 169 | primary_dex_file_, |
| 170 | dex_cache_handle, |
| 171 | class_loader_handle, |
| 172 | *class_def, |
| 173 | method.GetCodeItem(), |
| 174 | method.GetIndex(), |
| 175 | resolved_method, |
| 176 | method.GetAccessFlags(), |
| 177 | true /* can_load_classes */, |
| 178 | true /* allow_soft_failures */, |
| 179 | true /* need_precise_constants */, |
| 180 | false /* verify to dump */, |
| 181 | true /* allow_thread_suspension */); |
| 182 | verifier.Verify(); |
| 183 | soa.Self()->SetVerifierDeps(nullptr); |
| 184 | has_failures = verifier.HasFailures(); |
| 185 | found_method = true; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 186 | } |
Mathieu Chartier | 0d896bd | 2018-05-25 00:20:27 -0700 | [diff] [blame] | 187 | } |
Mathieu Chartier | c8c8d5f | 2018-05-22 11:56:14 -0700 | [diff] [blame] | 188 | CHECK(found_method) << "Expected to find method " << method_name; |
| 189 | return !has_failures; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 192 | void VerifyDexFile(const char* multidex = nullptr) { |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 193 | { |
| 194 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 195 | LoadDexFile(soa, "VerifierDeps", multidex); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 196 | } |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 197 | SetupCompilerDriver(); |
| 198 | VerifyWithCompilerDriver(/* verifier_deps */ nullptr); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 199 | } |
| 200 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 201 | bool TestAssignabilityRecording(const std::string& dst, |
| 202 | const std::string& src, |
| 203 | bool is_strict, |
| 204 | bool is_assignable) { |
| 205 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 206 | LoadDexFile(soa); |
| 207 | StackHandleScope<1> hs(soa.Self()); |
| 208 | Handle<mirror::Class> klass_dst = hs.NewHandle(FindClassByName(soa, dst)); |
Nicolas Geoffray | bdb540d | 2017-04-19 13:50:34 +0100 | [diff] [blame] | 209 | DCHECK(klass_dst != nullptr) << dst; |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 210 | ObjPtr<mirror::Class> klass_src = FindClassByName(soa, src); |
Nicolas Geoffray | bdb540d | 2017-04-19 13:50:34 +0100 | [diff] [blame] | 211 | DCHECK(klass_src != nullptr) << src; |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 212 | verifier_deps_->AddAssignability(*primary_dex_file_, |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 213 | klass_dst.Get(), |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 214 | klass_src, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 215 | is_strict, |
| 216 | is_assignable); |
| 217 | return true; |
| 218 | } |
| 219 | |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 220 | // Check that the status of classes in `class_loader_` match the |
| 221 | // expected status in `deps`. |
| 222 | void VerifyClassStatus(const verifier::VerifierDeps& deps) { |
| 223 | ScopedObjectAccess soa(Thread::Current()); |
| 224 | StackHandleScope<2> hs(soa.Self()); |
| 225 | Handle<mirror::ClassLoader> class_loader_handle( |
| 226 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_))); |
| 227 | MutableHandle<mirror::Class> cls(hs.NewHandle<mirror::Class>(nullptr)); |
| 228 | for (const DexFile* dex_file : dex_files_) { |
Mathieu Chartier | bf755fe | 2017-08-01 13:42:56 -0700 | [diff] [blame] | 229 | const std::set<dex::TypeIndex>& unverified_classes = deps.GetUnverifiedClasses(*dex_file); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 230 | for (uint32_t i = 0; i < dex_file->NumClassDefs(); ++i) { |
| 231 | const DexFile::ClassDef& class_def = dex_file->GetClassDef(i); |
| 232 | const char* descriptor = dex_file->GetClassDescriptor(class_def); |
| 233 | cls.Assign(class_linker_->FindClass(soa.Self(), descriptor, class_loader_handle)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 234 | if (cls == nullptr) { |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 235 | CHECK(soa.Self()->IsExceptionPending()); |
| 236 | soa.Self()->ClearException(); |
Andreas Gampe | bb30d5d | 2018-04-23 09:59:25 -0700 | [diff] [blame] | 237 | } else if (&cls->GetDexFile() != dex_file) { |
| 238 | // Ignore classes from different dex files. |
Mathieu Chartier | bf755fe | 2017-08-01 13:42:56 -0700 | [diff] [blame] | 239 | } else if (unverified_classes.find(class_def.class_idx_) == unverified_classes.end()) { |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 240 | ASSERT_EQ(cls->GetStatus(), ClassStatus::kVerified); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 241 | } else { |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 242 | ASSERT_LT(cls->GetStatus(), ClassStatus::kVerified); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 248 | bool HasUnverifiedClass(const std::string& cls) { |
Nicolas Geoffray | 7cc3ae5 | 2017-03-07 14:33:37 +0000 | [diff] [blame] | 249 | return HasUnverifiedClass(cls, *primary_dex_file_); |
| 250 | } |
| 251 | |
| 252 | bool HasUnverifiedClass(const std::string& cls, const DexFile& dex_file) { |
| 253 | const DexFile::TypeId* type_id = dex_file.FindTypeId(cls.c_str()); |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 254 | DCHECK(type_id != nullptr); |
Nicolas Geoffray | 7cc3ae5 | 2017-03-07 14:33:37 +0000 | [diff] [blame] | 255 | dex::TypeIndex index = dex_file.GetIndexForTypeId(*type_id); |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 256 | for (const auto& dex_dep : verifier_deps_->dex_deps_) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 257 | for (dex::TypeIndex entry : dex_dep.second->unverified_classes_) { |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 258 | if (index == entry) { |
| 259 | return true; |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | return false; |
| 264 | } |
| 265 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 266 | // Iterates over all assignability records and tries to find an entry which |
| 267 | // matches the expected destination/source pair. |
| 268 | bool HasAssignable(const std::string& expected_destination, |
| 269 | const std::string& expected_source, |
| 270 | bool expected_is_assignable) { |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 271 | for (auto& dex_dep : verifier_deps_->dex_deps_) { |
| 272 | const DexFile& dex_file = *dex_dep.first; |
| 273 | auto& storage = expected_is_assignable ? dex_dep.second->assignable_types_ |
| 274 | : dex_dep.second->unassignable_types_; |
| 275 | for (auto& entry : storage) { |
| 276 | std::string actual_destination = |
| 277 | verifier_deps_->GetStringFromId(dex_file, entry.GetDestination()); |
| 278 | std::string actual_source = verifier_deps_->GetStringFromId(dex_file, entry.GetSource()); |
| 279 | if ((expected_destination == actual_destination) && (expected_source == actual_source)) { |
| 280 | return true; |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | // Iterates over all class resolution records, finds an entry which matches |
| 288 | // the given class descriptor and tests its properties. |
| 289 | bool HasClass(const std::string& expected_klass, |
| 290 | bool expected_resolved, |
| 291 | const std::string& expected_access_flags = "") { |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 292 | for (auto& dex_dep : verifier_deps_->dex_deps_) { |
| 293 | for (auto& entry : dex_dep.second->classes_) { |
| 294 | if (expected_resolved != entry.IsResolved()) { |
| 295 | continue; |
| 296 | } |
| 297 | |
| 298 | std::string actual_klass = dex_dep.first->StringByTypeIdx(entry.GetDexTypeIndex()); |
| 299 | if (expected_klass != actual_klass) { |
| 300 | continue; |
| 301 | } |
| 302 | |
| 303 | if (expected_resolved) { |
| 304 | // Test access flags. Note that PrettyJavaAccessFlags always appends |
| 305 | // a space after the modifiers. Add it to the expected access flags. |
| 306 | std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags()); |
| 307 | if (expected_access_flags + " " != actual_access_flags) { |
| 308 | continue; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | return true; |
| 313 | } |
| 314 | } |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | // Iterates over all field resolution records, finds an entry which matches |
| 319 | // the given field class+name+type and tests its properties. |
| 320 | bool HasField(const std::string& expected_klass, |
| 321 | const std::string& expected_name, |
| 322 | const std::string& expected_type, |
| 323 | bool expected_resolved, |
| 324 | const std::string& expected_access_flags = "", |
| 325 | const std::string& expected_decl_klass = "") { |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 326 | for (auto& dex_dep : verifier_deps_->dex_deps_) { |
| 327 | for (auto& entry : dex_dep.second->fields_) { |
| 328 | if (expected_resolved != entry.IsResolved()) { |
| 329 | continue; |
| 330 | } |
| 331 | |
| 332 | const DexFile::FieldId& field_id = dex_dep.first->GetFieldId(entry.GetDexFieldIndex()); |
| 333 | |
| 334 | std::string actual_klass = dex_dep.first->StringByTypeIdx(field_id.class_idx_); |
| 335 | if (expected_klass != actual_klass) { |
| 336 | continue; |
| 337 | } |
| 338 | |
| 339 | std::string actual_name = dex_dep.first->StringDataByIdx(field_id.name_idx_); |
| 340 | if (expected_name != actual_name) { |
| 341 | continue; |
| 342 | } |
| 343 | |
| 344 | std::string actual_type = dex_dep.first->StringByTypeIdx(field_id.type_idx_); |
| 345 | if (expected_type != actual_type) { |
| 346 | continue; |
| 347 | } |
| 348 | |
| 349 | if (expected_resolved) { |
| 350 | // Test access flags. Note that PrettyJavaAccessFlags always appends |
| 351 | // a space after the modifiers. Add it to the expected access flags. |
| 352 | std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags()); |
| 353 | if (expected_access_flags + " " != actual_access_flags) { |
| 354 | continue; |
| 355 | } |
| 356 | |
| 357 | std::string actual_decl_klass = verifier_deps_->GetStringFromId( |
| 358 | *dex_dep.first, entry.GetDeclaringClassIndex()); |
| 359 | if (expected_decl_klass != actual_decl_klass) { |
| 360 | continue; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | return true; |
| 365 | } |
| 366 | } |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | // Iterates over all method resolution records, finds an entry which matches |
| 371 | // the given field kind+class+name+signature and tests its properties. |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 372 | bool HasMethod(const std::string& expected_klass, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 373 | const std::string& expected_name, |
| 374 | const std::string& expected_signature, |
| 375 | bool expected_resolved, |
| 376 | const std::string& expected_access_flags = "", |
| 377 | const std::string& expected_decl_klass = "") { |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 378 | for (auto& dex_dep : verifier_deps_->dex_deps_) { |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 379 | for (const VerifierDeps::MethodResolution& entry : dex_dep.second->methods_) { |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 380 | if (expected_resolved != entry.IsResolved()) { |
| 381 | continue; |
| 382 | } |
| 383 | |
| 384 | const DexFile::MethodId& method_id = dex_dep.first->GetMethodId(entry.GetDexMethodIndex()); |
| 385 | |
| 386 | std::string actual_klass = dex_dep.first->StringByTypeIdx(method_id.class_idx_); |
| 387 | if (expected_klass != actual_klass) { |
| 388 | continue; |
| 389 | } |
| 390 | |
| 391 | std::string actual_name = dex_dep.first->StringDataByIdx(method_id.name_idx_); |
| 392 | if (expected_name != actual_name) { |
| 393 | continue; |
| 394 | } |
| 395 | |
| 396 | std::string actual_signature = dex_dep.first->GetMethodSignature(method_id).ToString(); |
| 397 | if (expected_signature != actual_signature) { |
| 398 | continue; |
| 399 | } |
| 400 | |
| 401 | if (expected_resolved) { |
| 402 | // Test access flags. Note that PrettyJavaAccessFlags always appends |
| 403 | // a space after the modifiers. Add it to the expected access flags. |
| 404 | std::string actual_access_flags = PrettyJavaAccessFlags(entry.GetAccessFlags()); |
| 405 | if (expected_access_flags + " " != actual_access_flags) { |
| 406 | continue; |
| 407 | } |
| 408 | |
| 409 | std::string actual_decl_klass = verifier_deps_->GetStringFromId( |
| 410 | *dex_dep.first, entry.GetDeclaringClassIndex()); |
| 411 | if (expected_decl_klass != actual_decl_klass) { |
| 412 | continue; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | return true; |
| 417 | } |
| 418 | } |
| 419 | return false; |
| 420 | } |
| 421 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 422 | size_t NumberOfCompiledDexFiles() { |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 423 | return verifier_deps_->dex_deps_.size(); |
| 424 | } |
| 425 | |
| 426 | size_t HasEachKindOfRecord() { |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 427 | bool has_strings = false; |
| 428 | bool has_assignability = false; |
| 429 | bool has_classes = false; |
| 430 | bool has_fields = false; |
| 431 | bool has_methods = false; |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 432 | bool has_unverified_classes = false; |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 433 | |
| 434 | for (auto& entry : verifier_deps_->dex_deps_) { |
| 435 | has_strings |= !entry.second->strings_.empty(); |
| 436 | has_assignability |= !entry.second->assignable_types_.empty(); |
| 437 | has_assignability |= !entry.second->unassignable_types_.empty(); |
| 438 | has_classes |= !entry.second->classes_.empty(); |
| 439 | has_fields |= !entry.second->fields_.empty(); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 440 | has_methods |= !entry.second->methods_.empty(); |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 441 | has_unverified_classes |= !entry.second->unverified_classes_.empty(); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 442 | } |
| 443 | |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 444 | return has_strings && |
| 445 | has_assignability && |
| 446 | has_classes && |
| 447 | has_fields && |
| 448 | has_methods && |
| 449 | has_unverified_classes; |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 450 | } |
| 451 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 452 | std::unique_ptr<verifier::VerifierDeps> verifier_deps_; |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 453 | std::vector<const DexFile*> dex_files_; |
| 454 | const DexFile* primary_dex_file_; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 455 | jobject class_loader_; |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 456 | ObjPtr<mirror::Class> klass_Main_; |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | TEST_F(VerifierDepsTest, StringToId) { |
| 460 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 461 | LoadDexFile(soa); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 462 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 463 | dex::StringIndex id_Main1 = verifier_deps_->GetIdFromString(*primary_dex_file_, "LMain;"); |
| 464 | ASSERT_LT(id_Main1.index_, primary_dex_file_->NumStringIds()); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 465 | ASSERT_EQ("LMain;", verifier_deps_->GetStringFromId(*primary_dex_file_, id_Main1)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 466 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 467 | dex::StringIndex id_Main2 = verifier_deps_->GetIdFromString(*primary_dex_file_, "LMain;"); |
| 468 | ASSERT_LT(id_Main2.index_, primary_dex_file_->NumStringIds()); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 469 | ASSERT_EQ("LMain;", verifier_deps_->GetStringFromId(*primary_dex_file_, id_Main2)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 470 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 471 | dex::StringIndex id_Lorem1 = verifier_deps_->GetIdFromString(*primary_dex_file_, "Lorem ipsum"); |
| 472 | ASSERT_GE(id_Lorem1.index_, primary_dex_file_->NumStringIds()); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 473 | ASSERT_EQ("Lorem ipsum", verifier_deps_->GetStringFromId(*primary_dex_file_, id_Lorem1)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 474 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 475 | dex::StringIndex id_Lorem2 = verifier_deps_->GetIdFromString(*primary_dex_file_, "Lorem ipsum"); |
| 476 | ASSERT_GE(id_Lorem2.index_, primary_dex_file_->NumStringIds()); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 477 | ASSERT_EQ("Lorem ipsum", verifier_deps_->GetStringFromId(*primary_dex_file_, id_Lorem2)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 478 | |
| 479 | ASSERT_EQ(id_Main1, id_Main2); |
| 480 | ASSERT_EQ(id_Lorem1, id_Lorem2); |
| 481 | ASSERT_NE(id_Main1, id_Lorem1); |
| 482 | } |
| 483 | |
| 484 | TEST_F(VerifierDepsTest, Assignable_BothInBoot) { |
| 485 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/TimeZone;", |
| 486 | /* src */ "Ljava/util/SimpleTimeZone;", |
| 487 | /* is_strict */ true, |
| 488 | /* is_assignable */ true)); |
| 489 | ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true)); |
| 490 | } |
| 491 | |
| 492 | TEST_F(VerifierDepsTest, Assignable_DestinationInBoot1) { |
| 493 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/net/Socket;", |
| 494 | /* src */ "LMySSLSocket;", |
| 495 | /* is_strict */ true, |
| 496 | /* is_assignable */ true)); |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 497 | ASSERT_TRUE(HasAssignable("Ljava/net/Socket;", "Ljavax/net/ssl/SSLSocket;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | TEST_F(VerifierDepsTest, Assignable_DestinationInBoot2) { |
| 501 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/TimeZone;", |
| 502 | /* src */ "LMySimpleTimeZone;", |
| 503 | /* is_strict */ true, |
| 504 | /* is_assignable */ true)); |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 505 | ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | TEST_F(VerifierDepsTest, Assignable_DestinationInBoot3) { |
| 509 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/util/Collection;", |
| 510 | /* src */ "LMyThreadSet;", |
| 511 | /* is_strict */ true, |
| 512 | /* is_assignable */ true)); |
Nicolas Geoffray | 0e2fe0f | 2016-12-21 16:54:52 +0000 | [diff] [blame] | 513 | ASSERT_TRUE(HasAssignable("Ljava/util/Collection;", "Ljava/util/Set;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | TEST_F(VerifierDepsTest, Assignable_BothArrays_Resolved) { |
| 517 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[[Ljava/util/TimeZone;", |
| 518 | /* src */ "[[Ljava/util/SimpleTimeZone;", |
| 519 | /* is_strict */ true, |
| 520 | /* is_assignable */ true)); |
| 521 | // If the component types of both arrays are resolved, we optimize the list of |
| 522 | // dependencies by recording a dependency on the component types. |
| 523 | ASSERT_FALSE(HasAssignable("[[Ljava/util/TimeZone;", "[[Ljava/util/SimpleTimeZone;", true)); |
| 524 | ASSERT_FALSE(HasAssignable("[Ljava/util/TimeZone;", "[Ljava/util/SimpleTimeZone;", true)); |
| 525 | ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true)); |
| 526 | } |
| 527 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 528 | TEST_F(VerifierDepsTest, NotAssignable_BothInBoot) { |
| 529 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;", |
| 530 | /* src */ "Ljava/util/SimpleTimeZone;", |
| 531 | /* is_strict */ true, |
| 532 | /* is_assignable */ false)); |
| 533 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/util/SimpleTimeZone;", false)); |
| 534 | } |
| 535 | |
| 536 | TEST_F(VerifierDepsTest, NotAssignable_DestinationInBoot1) { |
| 537 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;", |
| 538 | /* src */ "LMySSLSocket;", |
| 539 | /* is_strict */ true, |
| 540 | /* is_assignable */ false)); |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 541 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljavax/net/ssl/SSLSocket;", false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | TEST_F(VerifierDepsTest, NotAssignable_DestinationInBoot2) { |
| 545 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;", |
| 546 | /* src */ "LMySimpleTimeZone;", |
| 547 | /* is_strict */ true, |
| 548 | /* is_assignable */ false)); |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 549 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/util/SimpleTimeZone;", false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | TEST_F(VerifierDepsTest, NotAssignable_BothArrays) { |
| 553 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[Ljava/lang/Exception;", |
| 554 | /* src */ "[Ljava/util/SimpleTimeZone;", |
| 555 | /* is_strict */ true, |
| 556 | /* is_assignable */ false)); |
| 557 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/util/SimpleTimeZone;", false)); |
| 558 | } |
| 559 | |
| 560 | TEST_F(VerifierDepsTest, ArgumentType_ResolvedClass) { |
| 561 | ASSERT_TRUE(VerifyMethod("ArgumentType_ResolvedClass")); |
| 562 | ASSERT_TRUE(HasClass("Ljava/lang/Thread;", true, "public")); |
| 563 | } |
| 564 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 565 | TEST_F(VerifierDepsTest, ArgumentType_UnresolvedClass) { |
| 566 | ASSERT_TRUE(VerifyMethod("ArgumentType_UnresolvedClass")); |
| 567 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 568 | } |
| 569 | |
| 570 | TEST_F(VerifierDepsTest, ArgumentType_UnresolvedSuper) { |
| 571 | ASSERT_TRUE(VerifyMethod("ArgumentType_UnresolvedSuper")); |
| 572 | ASSERT_TRUE(HasClass("LMySetWithUnresolvedSuper;", false)); |
| 573 | } |
| 574 | |
| 575 | TEST_F(VerifierDepsTest, ReturnType_Reference) { |
| 576 | ASSERT_TRUE(VerifyMethod("ReturnType_Reference")); |
| 577 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/lang/IllegalStateException;", true)); |
| 578 | } |
| 579 | |
| 580 | TEST_F(VerifierDepsTest, ReturnType_Array) { |
| 581 | ASSERT_FALSE(VerifyMethod("ReturnType_Array")); |
| 582 | ASSERT_TRUE(HasAssignable("Ljava/lang/Integer;", "Ljava/lang/IllegalStateException;", false)); |
| 583 | } |
| 584 | |
| 585 | TEST_F(VerifierDepsTest, InvokeArgumentType) { |
| 586 | ASSERT_TRUE(VerifyMethod("InvokeArgumentType")); |
| 587 | ASSERT_TRUE(HasClass("Ljava/text/SimpleDateFormat;", true, "public")); |
| 588 | ASSERT_TRUE(HasClass("Ljava/util/SimpleTimeZone;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 589 | ASSERT_TRUE(HasMethod("Ljava/text/SimpleDateFormat;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 590 | "setTimeZone", |
| 591 | "(Ljava/util/TimeZone;)V", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 592 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 593 | "public", |
| 594 | "Ljava/text/DateFormat;")); |
| 595 | ASSERT_TRUE(HasAssignable("Ljava/util/TimeZone;", "Ljava/util/SimpleTimeZone;", true)); |
| 596 | } |
| 597 | |
| 598 | TEST_F(VerifierDepsTest, MergeTypes_RegisterLines) { |
| 599 | ASSERT_TRUE(VerifyMethod("MergeTypes_RegisterLines")); |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 600 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/net/SocketTimeoutException;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 601 | ASSERT_TRUE(HasAssignable( |
| 602 | "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true)); |
| 603 | } |
| 604 | |
| 605 | TEST_F(VerifierDepsTest, MergeTypes_IfInstanceOf) { |
| 606 | ASSERT_TRUE(VerifyMethod("MergeTypes_IfInstanceOf")); |
| 607 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/net/SocketTimeoutException;", true)); |
| 608 | ASSERT_TRUE(HasAssignable( |
| 609 | "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true)); |
| 610 | ASSERT_TRUE(HasAssignable("Ljava/net/SocketTimeoutException;", "Ljava/lang/Exception;", false)); |
| 611 | } |
| 612 | |
| 613 | TEST_F(VerifierDepsTest, MergeTypes_Unresolved) { |
| 614 | ASSERT_TRUE(VerifyMethod("MergeTypes_Unresolved")); |
| 615 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "Ljava/net/SocketTimeoutException;", true)); |
| 616 | ASSERT_TRUE(HasAssignable( |
| 617 | "Ljava/lang/Exception;", "Ljava/util/concurrent/TimeoutException;", true)); |
| 618 | } |
| 619 | |
| 620 | TEST_F(VerifierDepsTest, ConstClass_Resolved) { |
| 621 | ASSERT_TRUE(VerifyMethod("ConstClass_Resolved")); |
| 622 | ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public")); |
| 623 | } |
| 624 | |
| 625 | TEST_F(VerifierDepsTest, ConstClass_Unresolved) { |
Andreas Gampe | 629be51 | 2017-08-25 17:09:32 -0700 | [diff] [blame] | 626 | ASSERT_FALSE(VerifyMethod("ConstClass_Unresolved")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 627 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 628 | } |
| 629 | |
| 630 | TEST_F(VerifierDepsTest, CheckCast_Resolved) { |
| 631 | ASSERT_TRUE(VerifyMethod("CheckCast_Resolved")); |
| 632 | ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public")); |
| 633 | } |
| 634 | |
| 635 | TEST_F(VerifierDepsTest, CheckCast_Unresolved) { |
Andreas Gampe | 629be51 | 2017-08-25 17:09:32 -0700 | [diff] [blame] | 636 | ASSERT_FALSE(VerifyMethod("CheckCast_Unresolved")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 637 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 638 | } |
| 639 | |
| 640 | TEST_F(VerifierDepsTest, InstanceOf_Resolved) { |
| 641 | ASSERT_TRUE(VerifyMethod("InstanceOf_Resolved")); |
| 642 | ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public")); |
| 643 | } |
| 644 | |
| 645 | TEST_F(VerifierDepsTest, InstanceOf_Unresolved) { |
Andreas Gampe | 629be51 | 2017-08-25 17:09:32 -0700 | [diff] [blame] | 646 | ASSERT_FALSE(VerifyMethod("InstanceOf_Unresolved")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 647 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 648 | } |
| 649 | |
| 650 | TEST_F(VerifierDepsTest, NewInstance_Resolved) { |
| 651 | ASSERT_TRUE(VerifyMethod("NewInstance_Resolved")); |
| 652 | ASSERT_TRUE(HasClass("Ljava/lang/IllegalStateException;", true, "public")); |
| 653 | } |
| 654 | |
| 655 | TEST_F(VerifierDepsTest, NewInstance_Unresolved) { |
Andreas Gampe | 629be51 | 2017-08-25 17:09:32 -0700 | [diff] [blame] | 656 | ASSERT_FALSE(VerifyMethod("NewInstance_Unresolved")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 657 | ASSERT_TRUE(HasClass("LUnresolvedClass;", false)); |
| 658 | } |
| 659 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 660 | TEST_F(VerifierDepsTest, NewArray_Unresolved) { |
Andreas Gampe | 629be51 | 2017-08-25 17:09:32 -0700 | [diff] [blame] | 661 | ASSERT_FALSE(VerifyMethod("NewArray_Unresolved")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 662 | ASSERT_TRUE(HasClass("[LUnresolvedClass;", false)); |
| 663 | } |
| 664 | |
| 665 | TEST_F(VerifierDepsTest, Throw) { |
| 666 | ASSERT_TRUE(VerifyMethod("Throw")); |
| 667 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/lang/IllegalStateException;", true)); |
| 668 | } |
| 669 | |
| 670 | TEST_F(VerifierDepsTest, MoveException_Resolved) { |
| 671 | ASSERT_TRUE(VerifyMethod("MoveException_Resolved")); |
| 672 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
| 673 | ASSERT_TRUE(HasClass("Ljava/net/SocketTimeoutException;", true, "public")); |
| 674 | ASSERT_TRUE(HasClass("Ljava/util/zip/ZipException;", true, "public")); |
| 675 | |
| 676 | // Testing that all exception types are assignable to Throwable. |
| 677 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/io/InterruptedIOException;", true)); |
| 678 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/net/SocketTimeoutException;", true)); |
| 679 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/util/zip/ZipException;", true)); |
| 680 | |
| 681 | // Testing that the merge type is assignable to Throwable. |
| 682 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/io/IOException;", true)); |
| 683 | |
| 684 | // Merging of exception types. |
| 685 | ASSERT_TRUE(HasAssignable("Ljava/io/IOException;", "Ljava/io/InterruptedIOException;", true)); |
| 686 | ASSERT_TRUE(HasAssignable("Ljava/io/IOException;", "Ljava/util/zip/ZipException;", true)); |
| 687 | ASSERT_TRUE(HasAssignable( |
| 688 | "Ljava/io/InterruptedIOException;", "Ljava/net/SocketTimeoutException;", true)); |
| 689 | } |
| 690 | |
| 691 | TEST_F(VerifierDepsTest, MoveException_Unresolved) { |
| 692 | ASSERT_FALSE(VerifyMethod("MoveException_Unresolved")); |
| 693 | ASSERT_TRUE(HasClass("LUnresolvedException;", false)); |
| 694 | } |
| 695 | |
| 696 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInReferenced) { |
| 697 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInReferenced")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 698 | ASSERT_TRUE(HasClass("Ljava/lang/System;", true, "public")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 699 | ASSERT_TRUE(HasField("Ljava/lang/System;", |
| 700 | "out", |
| 701 | "Ljava/io/PrintStream;", |
| 702 | true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 703 | "public static", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 704 | "Ljava/lang/System;")); |
| 705 | } |
| 706 | |
| 707 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInSuperclass1) { |
| 708 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInSuperclass1")); |
| 709 | ASSERT_TRUE(HasClass("Ljava/util/SimpleTimeZone;", true, "public")); |
| 710 | ASSERT_TRUE(HasField( |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 711 | "Ljava/util/SimpleTimeZone;", "LONG", "I", true, "public static", "Ljava/util/TimeZone;")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInSuperclass2) { |
| 715 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInSuperclass2")); |
| 716 | ASSERT_TRUE(HasField( |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 717 | "LMySimpleTimeZone;", "SHORT", "I", true, "public static", "Ljava/util/TimeZone;")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface1) { |
| 721 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface1")); |
| 722 | ASSERT_TRUE(HasClass("Ljavax/xml/transform/dom/DOMResult;", true, "public")); |
| 723 | ASSERT_TRUE(HasField("Ljavax/xml/transform/dom/DOMResult;", |
| 724 | "PI_ENABLE_OUTPUT_ESCAPING", |
| 725 | "Ljava/lang/String;", |
| 726 | true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 727 | "public static", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 728 | "Ljavax/xml/transform/Result;")); |
| 729 | } |
| 730 | |
| 731 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface2) { |
| 732 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface2")); |
| 733 | ASSERT_TRUE(HasField("LMyDOMResult;", |
| 734 | "PI_ENABLE_OUTPUT_ESCAPING", |
| 735 | "Ljava/lang/String;", |
| 736 | true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 737 | "public static", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 738 | "Ljavax/xml/transform/Result;")); |
| 739 | } |
| 740 | |
| 741 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface3) { |
| 742 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface3")); |
| 743 | ASSERT_TRUE(HasField("LMyResult;", |
| 744 | "PI_ENABLE_OUTPUT_ESCAPING", |
| 745 | "Ljava/lang/String;", |
| 746 | true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 747 | "public static", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 748 | "Ljavax/xml/transform/Result;")); |
| 749 | } |
| 750 | |
| 751 | TEST_F(VerifierDepsTest, StaticField_Resolved_DeclaredInInterface4) { |
| 752 | ASSERT_TRUE(VerifyMethod("StaticField_Resolved_DeclaredInInterface4")); |
| 753 | ASSERT_TRUE(HasField("LMyDocument;", |
| 754 | "ELEMENT_NODE", |
| 755 | "S", |
| 756 | true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 757 | "public static", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 758 | "Lorg/w3c/dom/Node;")); |
| 759 | } |
| 760 | |
| 761 | TEST_F(VerifierDepsTest, StaticField_Unresolved_ReferrerInBoot) { |
| 762 | ASSERT_TRUE(VerifyMethod("StaticField_Unresolved_ReferrerInBoot")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 763 | ASSERT_TRUE(HasClass("Ljava/util/TimeZone;", true, "public")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 764 | ASSERT_TRUE(HasField("Ljava/util/TimeZone;", "x", "I", false)); |
| 765 | } |
| 766 | |
| 767 | TEST_F(VerifierDepsTest, StaticField_Unresolved_ReferrerInDex) { |
| 768 | ASSERT_TRUE(VerifyMethod("StaticField_Unresolved_ReferrerInDex")); |
| 769 | ASSERT_TRUE(HasField("LMyThreadSet;", "x", "I", false)); |
| 770 | } |
| 771 | |
| 772 | TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInReferenced) { |
| 773 | ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInReferenced")); |
| 774 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
| 775 | ASSERT_TRUE(HasField("Ljava/io/InterruptedIOException;", |
| 776 | "bytesTransferred", |
| 777 | "I", |
| 778 | true, |
| 779 | "public", |
| 780 | "Ljava/io/InterruptedIOException;")); |
| 781 | ASSERT_TRUE(HasAssignable( |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 782 | "Ljava/io/InterruptedIOException;", "Ljava/net/SocketTimeoutException;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInSuperclass1) { |
| 786 | ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInSuperclass1")); |
| 787 | ASSERT_TRUE(HasClass("Ljava/net/SocketTimeoutException;", true, "public")); |
| 788 | ASSERT_TRUE(HasField("Ljava/net/SocketTimeoutException;", |
| 789 | "bytesTransferred", |
| 790 | "I", |
| 791 | true, |
| 792 | "public", |
| 793 | "Ljava/io/InterruptedIOException;")); |
| 794 | ASSERT_TRUE(HasAssignable( |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 795 | "Ljava/io/InterruptedIOException;", "Ljava/net/SocketTimeoutException;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | TEST_F(VerifierDepsTest, InstanceField_Resolved_DeclaredInSuperclass2) { |
| 799 | ASSERT_TRUE(VerifyMethod("InstanceField_Resolved_DeclaredInSuperclass2")); |
| 800 | ASSERT_TRUE(HasField("LMySocketTimeoutException;", |
| 801 | "bytesTransferred", |
| 802 | "I", |
| 803 | true, |
| 804 | "public", |
| 805 | "Ljava/io/InterruptedIOException;")); |
| 806 | ASSERT_TRUE(HasAssignable( |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 807 | "Ljava/io/InterruptedIOException;", "Ljava/net/SocketTimeoutException;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | TEST_F(VerifierDepsTest, InstanceField_Unresolved_ReferrerInBoot) { |
| 811 | ASSERT_TRUE(VerifyMethod("InstanceField_Unresolved_ReferrerInBoot")); |
| 812 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
| 813 | ASSERT_TRUE(HasField("Ljava/io/InterruptedIOException;", "x", "I", false)); |
| 814 | } |
| 815 | |
| 816 | TEST_F(VerifierDepsTest, InstanceField_Unresolved_ReferrerInDex) { |
| 817 | ASSERT_TRUE(VerifyMethod("InstanceField_Unresolved_ReferrerInDex")); |
| 818 | ASSERT_TRUE(HasField("LMyThreadSet;", "x", "I", false)); |
| 819 | } |
| 820 | |
| 821 | TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInReferenced) { |
| 822 | ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInReferenced")); |
| 823 | ASSERT_TRUE(HasClass("Ljava/net/Socket;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 824 | ASSERT_TRUE(HasMethod("Ljava/net/Socket;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 825 | "setSocketImplFactory", |
| 826 | "(Ljava/net/SocketImplFactory;)V", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 827 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 828 | "public static", |
| 829 | "Ljava/net/Socket;")); |
| 830 | } |
| 831 | |
| 832 | TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInSuperclass1) { |
| 833 | ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInSuperclass1")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 834 | ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 835 | ASSERT_TRUE(HasMethod("Ljavax/net/ssl/SSLSocket;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 836 | "setSocketImplFactory", |
| 837 | "(Ljava/net/SocketImplFactory;)V", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 838 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 839 | "public static", |
| 840 | "Ljava/net/Socket;")); |
| 841 | } |
| 842 | |
| 843 | TEST_F(VerifierDepsTest, InvokeStatic_Resolved_DeclaredInSuperclass2) { |
| 844 | ASSERT_TRUE(VerifyMethod("InvokeStatic_Resolved_DeclaredInSuperclass2")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 845 | ASSERT_TRUE(HasMethod("LMySSLSocket;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 846 | "setSocketImplFactory", |
| 847 | "(Ljava/net/SocketImplFactory;)V", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 848 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 849 | "public static", |
| 850 | "Ljava/net/Socket;")); |
| 851 | } |
| 852 | |
| 853 | TEST_F(VerifierDepsTest, InvokeStatic_DeclaredInInterface1) { |
| 854 | ASSERT_TRUE(VerifyMethod("InvokeStatic_DeclaredInInterface1")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 855 | ASSERT_TRUE(HasClass("Ljava/util/Map$Entry;", true, "public interface")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 856 | ASSERT_TRUE(HasMethod("Ljava/util/Map$Entry;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 857 | "comparingByKey", |
| 858 | "()Ljava/util/Comparator;", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 859 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 860 | "public static", |
| 861 | "Ljava/util/Map$Entry;")); |
| 862 | } |
| 863 | |
| 864 | TEST_F(VerifierDepsTest, InvokeStatic_DeclaredInInterface2) { |
| 865 | ASSERT_FALSE(VerifyMethod("InvokeStatic_DeclaredInInterface2")); |
| 866 | ASSERT_TRUE(HasClass("Ljava/util/AbstractMap$SimpleEntry;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 867 | ASSERT_TRUE(HasMethod("Ljava/util/AbstractMap$SimpleEntry;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 868 | "comparingByKey", |
| 869 | "()Ljava/util/Comparator;", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 870 | /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | TEST_F(VerifierDepsTest, InvokeStatic_Unresolved1) { |
| 874 | ASSERT_FALSE(VerifyMethod("InvokeStatic_Unresolved1")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 875 | ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 876 | ASSERT_TRUE(HasMethod("Ljavax/net/ssl/SSLSocket;", |
| 877 | "x", |
| 878 | "()V", |
| 879 | /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | TEST_F(VerifierDepsTest, InvokeStatic_Unresolved2) { |
| 883 | ASSERT_FALSE(VerifyMethod("InvokeStatic_Unresolved2")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 884 | ASSERT_TRUE(HasMethod("LMySSLSocket;", |
| 885 | "x", |
| 886 | "()V", |
| 887 | /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInReferenced) { |
| 891 | ASSERT_TRUE(VerifyMethod("InvokeDirect_Resolved_DeclaredInReferenced")); |
| 892 | ASSERT_TRUE(HasClass("Ljava/net/Socket;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 893 | ASSERT_TRUE(HasMethod("Ljava/net/Socket;", |
| 894 | "<init>", |
| 895 | "()V", |
| 896 | /* expect_resolved */ true, |
| 897 | "public", |
| 898 | "Ljava/net/Socket;")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInSuperclass1) { |
| 902 | ASSERT_FALSE(VerifyMethod("InvokeDirect_Resolved_DeclaredInSuperclass1")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 903 | ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 904 | ASSERT_TRUE(HasMethod("Ljavax/net/ssl/SSLSocket;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 905 | "checkOldImpl", |
| 906 | "()V", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 907 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 908 | "private", |
| 909 | "Ljava/net/Socket;")); |
| 910 | } |
| 911 | |
| 912 | TEST_F(VerifierDepsTest, InvokeDirect_Resolved_DeclaredInSuperclass2) { |
| 913 | ASSERT_FALSE(VerifyMethod("InvokeDirect_Resolved_DeclaredInSuperclass2")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 914 | ASSERT_TRUE(HasMethod("LMySSLSocket;", |
| 915 | "checkOldImpl", |
| 916 | "()V", |
| 917 | /* expect_resolved */ true, |
| 918 | "private", |
| 919 | "Ljava/net/Socket;")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | TEST_F(VerifierDepsTest, InvokeDirect_Unresolved1) { |
| 923 | ASSERT_FALSE(VerifyMethod("InvokeDirect_Unresolved1")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 924 | ASSERT_TRUE(HasClass("Ljavax/net/ssl/SSLSocket;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 925 | ASSERT_TRUE(HasMethod("Ljavax/net/ssl/SSLSocket;", |
| 926 | "x", |
| 927 | "()V", |
| 928 | /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | TEST_F(VerifierDepsTest, InvokeDirect_Unresolved2) { |
| 932 | ASSERT_FALSE(VerifyMethod("InvokeDirect_Unresolved2")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 933 | ASSERT_TRUE(HasMethod("LMySSLSocket;", |
| 934 | "x", |
| 935 | "()V", |
| 936 | /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInReferenced) { |
| 940 | ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInReferenced")); |
| 941 | ASSERT_TRUE(HasClass("Ljava/lang/Throwable;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 942 | ASSERT_TRUE(HasMethod("Ljava/lang/Throwable;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 943 | "getMessage", |
| 944 | "()Ljava/lang/String;", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 945 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 946 | "public", |
| 947 | "Ljava/lang/Throwable;")); |
| 948 | // Type dependency on `this` argument. |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 949 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/net/SocketTimeoutException;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperclass1) { |
| 953 | ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperclass1")); |
| 954 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 955 | ASSERT_TRUE(HasMethod("Ljava/io/InterruptedIOException;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 956 | "getMessage", |
| 957 | "()Ljava/lang/String;", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 958 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 959 | "public", |
| 960 | "Ljava/lang/Throwable;")); |
| 961 | // Type dependency on `this` argument. |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 962 | ASSERT_TRUE(HasAssignable("Ljava/lang/Throwable;", "Ljava/net/SocketTimeoutException;", true)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperclass2) { |
| 966 | ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperclass2")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 967 | ASSERT_TRUE(HasMethod("LMySocketTimeoutException;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 968 | "getMessage", |
| 969 | "()Ljava/lang/String;", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 970 | /* expect_resolved */ true, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 971 | "public", |
| 972 | "Ljava/lang/Throwable;")); |
| 973 | } |
| 974 | |
| 975 | TEST_F(VerifierDepsTest, InvokeVirtual_Resolved_DeclaredInSuperinterface) { |
| 976 | ASSERT_TRUE(VerifyMethod("InvokeVirtual_Resolved_DeclaredInSuperinterface")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 977 | ASSERT_TRUE(HasMethod("LMyThreadSet;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 978 | "size", |
| 979 | "()I", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 980 | /* expect_resolved */ true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 981 | "public", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 982 | "Ljava/util/Set;")); |
| 983 | } |
| 984 | |
| 985 | TEST_F(VerifierDepsTest, InvokeVirtual_Unresolved1) { |
| 986 | ASSERT_FALSE(VerifyMethod("InvokeVirtual_Unresolved1")); |
| 987 | ASSERT_TRUE(HasClass("Ljava/io/InterruptedIOException;", true, "public")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 988 | ASSERT_TRUE(HasMethod("Ljava/io/InterruptedIOException;", |
| 989 | "x", |
| 990 | "()V", |
| 991 | /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | TEST_F(VerifierDepsTest, InvokeVirtual_Unresolved2) { |
| 995 | ASSERT_FALSE(VerifyMethod("InvokeVirtual_Unresolved2")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 996 | ASSERT_TRUE(HasMethod("LMySocketTimeoutException;", |
| 997 | "x", |
| 998 | "()V", |
| 999 | /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInReferenced) { |
| 1003 | ASSERT_TRUE(VerifyMethod("InvokeInterface_Resolved_DeclaredInReferenced")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1004 | ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public interface")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1005 | ASSERT_TRUE(HasMethod("Ljava/lang/Runnable;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1006 | "run", |
| 1007 | "()V", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1008 | /* expect_resolved */ true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1009 | "public", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1010 | "Ljava/lang/Runnable;")); |
| 1011 | } |
| 1012 | |
| 1013 | TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperclass) { |
| 1014 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperclass")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1015 | // TODO: Maybe we should not record dependency if the invoke type does not match the lookup type. |
| 1016 | ASSERT_TRUE(HasMethod("LMyThread;", |
| 1017 | "join", |
| 1018 | "()V", |
| 1019 | /* expect_resolved */ true, |
| 1020 | "public", |
| 1021 | "Ljava/lang/Thread;")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperinterface1) { |
| 1025 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperinterface1")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1026 | // TODO: Maybe we should not record dependency if the invoke type does not match the lookup type. |
| 1027 | ASSERT_TRUE(HasMethod("LMyThreadSet;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1028 | "run", |
| 1029 | "()V", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1030 | /* expect_resolved */ true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1031 | "public", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1032 | "Ljava/lang/Thread;")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | TEST_F(VerifierDepsTest, InvokeInterface_Resolved_DeclaredInSuperinterface2) { |
| 1036 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Resolved_DeclaredInSuperinterface2")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1037 | ASSERT_TRUE(HasMethod("LMyThreadSet;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1038 | "isEmpty", |
| 1039 | "()Z", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1040 | /* expect_resolved */ true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1041 | "public", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1042 | "Ljava/util/Set;")); |
| 1043 | } |
| 1044 | |
| 1045 | TEST_F(VerifierDepsTest, InvokeInterface_Unresolved1) { |
| 1046 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Unresolved1")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1047 | ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public interface")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1048 | ASSERT_TRUE(HasMethod("Ljava/lang/Runnable;", |
| 1049 | "x", |
| 1050 | "()V", |
| 1051 | /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | TEST_F(VerifierDepsTest, InvokeInterface_Unresolved2) { |
| 1055 | ASSERT_FALSE(VerifyMethod("InvokeInterface_Unresolved2")); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1056 | ASSERT_TRUE(HasMethod("LMyThreadSet;", "x", "()V", /* expect_resolved */ false)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | TEST_F(VerifierDepsTest, InvokeSuper_ThisAssignable) { |
| 1060 | ASSERT_TRUE(VerifyMethod("InvokeSuper_ThisAssignable")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1061 | ASSERT_TRUE(HasClass("Ljava/lang/Runnable;", true, "public interface")); |
Nicolas Geoffray | 0e2fe0f | 2016-12-21 16:54:52 +0000 | [diff] [blame] | 1062 | ASSERT_TRUE(HasAssignable("Ljava/lang/Runnable;", "Ljava/lang/Thread;", true)); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1063 | ASSERT_TRUE(HasMethod("Ljava/lang/Runnable;", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1064 | "run", |
| 1065 | "()V", |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1066 | /* expect_resolved */ true, |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1067 | "public", |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1068 | "Ljava/lang/Runnable;")); |
| 1069 | } |
| 1070 | |
| 1071 | TEST_F(VerifierDepsTest, InvokeSuper_ThisNotAssignable) { |
| 1072 | ASSERT_FALSE(VerifyMethod("InvokeSuper_ThisNotAssignable")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1073 | ASSERT_TRUE(HasClass("Ljava/lang/Integer;", true, "public")); |
Nicolas Geoffray | 119e846 | 2016-12-21 10:29:43 +0000 | [diff] [blame] | 1074 | ASSERT_TRUE(HasAssignable("Ljava/lang/Integer;", "Ljava/lang/Thread;", false)); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1075 | ASSERT_TRUE(HasMethod("Ljava/lang/Integer;", |
| 1076 | "intValue", "()I", |
| 1077 | /* expect_resolved */ true, |
| 1078 | "public", "Ljava/lang/Integer;")); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1079 | } |
| 1080 | |
Nicolas Geoffray | 0f1cb17 | 2017-01-05 15:23:19 +0000 | [diff] [blame] | 1081 | TEST_F(VerifierDepsTest, ArgumentType_ResolvedReferenceArray) { |
| 1082 | ASSERT_TRUE(VerifyMethod("ArgumentType_ResolvedReferenceArray")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1083 | ASSERT_TRUE(HasClass("[Ljava/lang/Thread;", true, "public")); |
Nicolas Geoffray | 0f1cb17 | 2017-01-05 15:23:19 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | TEST_F(VerifierDepsTest, NewArray_Resolved) { |
| 1087 | ASSERT_TRUE(VerifyMethod("NewArray_Resolved")); |
Nicolas Geoffray | 6e54f78 | 2017-03-08 15:27:09 +0000 | [diff] [blame] | 1088 | ASSERT_TRUE(HasClass("[Ljava/lang/IllegalStateException;", true, "public")); |
Nicolas Geoffray | 0f1cb17 | 2017-01-05 15:23:19 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 1091 | TEST_F(VerifierDepsTest, EncodeDecode) { |
| 1092 | VerifyDexFile(); |
| 1093 | |
| 1094 | ASSERT_EQ(1u, NumberOfCompiledDexFiles()); |
| 1095 | ASSERT_TRUE(HasEachKindOfRecord()); |
| 1096 | |
| 1097 | std::vector<uint8_t> buffer; |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 1098 | verifier_deps_->Encode(dex_files_, &buffer); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 1099 | ASSERT_FALSE(buffer.empty()); |
| 1100 | |
Nicolas Geoffray | e70dd56 | 2016-10-30 21:03:35 +0000 | [diff] [blame] | 1101 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 1102 | ASSERT_TRUE(verifier_deps_->Equals(decoded_deps)); |
| 1103 | } |
| 1104 | |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 1105 | TEST_F(VerifierDepsTest, EncodeDecodeMulti) { |
| 1106 | VerifyDexFile("MultiDex"); |
| 1107 | |
| 1108 | ASSERT_GT(NumberOfCompiledDexFiles(), 1u); |
| 1109 | std::vector<uint8_t> buffer; |
| 1110 | verifier_deps_->Encode(dex_files_, &buffer); |
| 1111 | ASSERT_FALSE(buffer.empty()); |
| 1112 | |
| 1113 | // Create new DexFile, to mess with std::map order: the verifier deps used |
| 1114 | // to iterate over the map, which doesn't guarantee insertion order. We fixed |
| 1115 | // this by passing the expected order when encoding/decoding. |
| 1116 | std::vector<std::unique_ptr<const DexFile>> first_dex_files = OpenTestDexFiles("VerifierDeps"); |
| 1117 | std::vector<std::unique_ptr<const DexFile>> second_dex_files = OpenTestDexFiles("MultiDex"); |
| 1118 | std::vector<const DexFile*> dex_files; |
| 1119 | for (auto& dex_file : first_dex_files) { |
| 1120 | dex_files.push_back(dex_file.get()); |
| 1121 | } |
| 1122 | for (auto& dex_file : second_dex_files) { |
| 1123 | dex_files.push_back(dex_file.get()); |
| 1124 | } |
| 1125 | |
| 1126 | // Dump the new verifier deps to ensure it can properly read the data. |
Nicolas Geoffray | e70dd56 | 2016-10-30 21:03:35 +0000 | [diff] [blame] | 1127 | VerifierDeps decoded_deps(dex_files, ArrayRef<const uint8_t>(buffer)); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 1128 | std::ostringstream stream; |
| 1129 | VariableIndentationOutputStream os(&stream); |
| 1130 | decoded_deps.Dump(&os); |
| 1131 | } |
| 1132 | |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 1133 | TEST_F(VerifierDepsTest, UnverifiedClasses) { |
| 1134 | VerifyDexFile(); |
| 1135 | ASSERT_FALSE(HasUnverifiedClass("LMyThread;")); |
| 1136 | // Test that a class with a soft failure is recorded. |
| 1137 | ASSERT_TRUE(HasUnverifiedClass("LMain;")); |
| 1138 | // Test that a class with hard failure is recorded. |
| 1139 | ASSERT_TRUE(HasUnverifiedClass("LMyVerificationFailure;")); |
| 1140 | // Test that a class with unresolved super is recorded. |
Nicolas Geoffray | 7cc3ae5 | 2017-03-07 14:33:37 +0000 | [diff] [blame] | 1141 | ASSERT_TRUE(HasUnverifiedClass("LMyClassWithNoSuper;")); |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 1142 | // Test that a class with unresolved super and hard failure is recorded. |
| 1143 | ASSERT_TRUE(HasUnverifiedClass("LMyClassWithNoSuperButFailures;")); |
| 1144 | } |
| 1145 | |
Mathieu Chartier | bf755fe | 2017-08-01 13:42:56 -0700 | [diff] [blame] | 1146 | TEST_F(VerifierDepsTest, UnverifiedOrder) { |
| 1147 | ScopedObjectAccess soa(Thread::Current()); |
| 1148 | jobject loader = LoadDex("VerifierDeps"); |
| 1149 | std::vector<const DexFile*> dex_files = GetDexFiles(loader); |
| 1150 | ASSERT_GT(dex_files.size(), 0u); |
| 1151 | const DexFile* dex_file = dex_files[0]; |
| 1152 | VerifierDeps deps1(dex_files); |
| 1153 | Thread* const self = Thread::Current(); |
| 1154 | ASSERT_TRUE(self->GetVerifierDeps() == nullptr); |
| 1155 | self->SetVerifierDeps(&deps1); |
| 1156 | deps1.MaybeRecordVerificationStatus(*dex_file, |
| 1157 | dex::TypeIndex(0), |
| 1158 | verifier::FailureKind::kHardFailure); |
| 1159 | deps1.MaybeRecordVerificationStatus(*dex_file, |
| 1160 | dex::TypeIndex(1), |
| 1161 | verifier::FailureKind::kHardFailure); |
| 1162 | VerifierDeps deps2(dex_files); |
| 1163 | self->SetVerifierDeps(nullptr); |
| 1164 | self->SetVerifierDeps(&deps2); |
| 1165 | deps2.MaybeRecordVerificationStatus(*dex_file, |
| 1166 | dex::TypeIndex(1), |
| 1167 | verifier::FailureKind::kHardFailure); |
| 1168 | deps2.MaybeRecordVerificationStatus(*dex_file, |
| 1169 | dex::TypeIndex(0), |
| 1170 | verifier::FailureKind::kHardFailure); |
| 1171 | self->SetVerifierDeps(nullptr); |
| 1172 | std::vector<uint8_t> buffer1; |
| 1173 | deps1.Encode(dex_files, &buffer1); |
| 1174 | std::vector<uint8_t> buffer2; |
| 1175 | deps2.Encode(dex_files, &buffer2); |
| 1176 | EXPECT_EQ(buffer1, buffer2); |
| 1177 | } |
| 1178 | |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1179 | TEST_F(VerifierDepsTest, VerifyDeps) { |
| 1180 | VerifyDexFile(); |
| 1181 | |
| 1182 | ASSERT_EQ(1u, NumberOfCompiledDexFiles()); |
| 1183 | ASSERT_TRUE(HasEachKindOfRecord()); |
| 1184 | |
| 1185 | // When validating, we create a new class loader, as |
| 1186 | // the existing `class_loader_` may contain erroneous classes, |
| 1187 | // that ClassLinker::FindClass won't return. |
| 1188 | |
| 1189 | ScopedObjectAccess soa(Thread::Current()); |
| 1190 | StackHandleScope<1> hs(soa.Self()); |
| 1191 | MutableHandle<mirror::ClassLoader> new_class_loader(hs.NewHandle<mirror::ClassLoader>(nullptr)); |
| 1192 | { |
| 1193 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1194 | ASSERT_TRUE(verifier_deps_->ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | std::vector<uint8_t> buffer; |
| 1198 | verifier_deps_->Encode(dex_files_, &buffer); |
| 1199 | ASSERT_FALSE(buffer.empty()); |
| 1200 | |
| 1201 | { |
| 1202 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1203 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1204 | ASSERT_TRUE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | // Fiddle with the dependencies to make sure we catch any change and fail to verify. |
| 1208 | |
| 1209 | { |
| 1210 | // Mess up with the assignable_types. |
| 1211 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1212 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1213 | deps->assignable_types_.insert(*deps->unassignable_types_.begin()); |
| 1214 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1215 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | { |
| 1219 | // Mess up with the unassignable_types. |
| 1220 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1221 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1222 | deps->unassignable_types_.insert(*deps->assignable_types_.begin()); |
| 1223 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1224 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | // Mess up with classes. |
| 1228 | { |
| 1229 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1230 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1231 | bool found = false; |
| 1232 | for (const auto& entry : deps->classes_) { |
| 1233 | if (entry.IsResolved()) { |
| 1234 | deps->classes_.insert(VerifierDeps::ClassResolution( |
| 1235 | entry.GetDexTypeIndex(), VerifierDeps::kUnresolvedMarker)); |
| 1236 | found = true; |
| 1237 | break; |
| 1238 | } |
| 1239 | } |
| 1240 | ASSERT_TRUE(found); |
| 1241 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1242 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | { |
| 1246 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1247 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1248 | bool found = false; |
| 1249 | for (const auto& entry : deps->classes_) { |
| 1250 | if (!entry.IsResolved()) { |
| 1251 | deps->classes_.insert(VerifierDeps::ClassResolution( |
| 1252 | entry.GetDexTypeIndex(), VerifierDeps::kUnresolvedMarker - 1)); |
| 1253 | found = true; |
| 1254 | break; |
| 1255 | } |
| 1256 | } |
| 1257 | ASSERT_TRUE(found); |
| 1258 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1259 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | { |
| 1263 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1264 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1265 | bool found = false; |
| 1266 | for (const auto& entry : deps->classes_) { |
| 1267 | if (entry.IsResolved()) { |
| 1268 | deps->classes_.insert(VerifierDeps::ClassResolution( |
| 1269 | entry.GetDexTypeIndex(), entry.GetAccessFlags() - 1)); |
| 1270 | found = true; |
| 1271 | break; |
| 1272 | } |
| 1273 | } |
| 1274 | ASSERT_TRUE(found); |
| 1275 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1276 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | // Mess up with fields. |
| 1280 | { |
| 1281 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1282 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1283 | bool found = false; |
| 1284 | for (const auto& entry : deps->fields_) { |
| 1285 | if (entry.IsResolved()) { |
| 1286 | deps->fields_.insert(VerifierDeps::FieldResolution(entry.GetDexFieldIndex(), |
| 1287 | VerifierDeps::kUnresolvedMarker, |
| 1288 | entry.GetDeclaringClassIndex())); |
| 1289 | found = true; |
| 1290 | break; |
| 1291 | } |
| 1292 | } |
| 1293 | ASSERT_TRUE(found); |
| 1294 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1295 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | { |
| 1299 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1300 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1301 | bool found = false; |
| 1302 | for (const auto& entry : deps->fields_) { |
| 1303 | if (!entry.IsResolved()) { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1304 | constexpr dex::StringIndex kStringIndexZero(0); // We know there is a class there. |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1305 | deps->fields_.insert(VerifierDeps::FieldResolution(0 /* we know there is a field there */, |
| 1306 | VerifierDeps::kUnresolvedMarker - 1, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1307 | kStringIndexZero)); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1308 | found = true; |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | ASSERT_TRUE(found); |
| 1313 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1314 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | { |
| 1318 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1319 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1320 | bool found = false; |
| 1321 | for (const auto& entry : deps->fields_) { |
| 1322 | if (entry.IsResolved()) { |
| 1323 | deps->fields_.insert(VerifierDeps::FieldResolution(entry.GetDexFieldIndex(), |
| 1324 | entry.GetAccessFlags() - 1, |
| 1325 | entry.GetDeclaringClassIndex())); |
| 1326 | found = true; |
| 1327 | break; |
| 1328 | } |
| 1329 | } |
| 1330 | ASSERT_TRUE(found); |
| 1331 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1332 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | { |
| 1336 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1337 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1338 | bool found = false; |
| 1339 | for (const auto& entry : deps->fields_) { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1340 | constexpr dex::StringIndex kNewTypeIndex(0); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1341 | if (entry.GetDeclaringClassIndex() != kNewTypeIndex) { |
| 1342 | deps->fields_.insert(VerifierDeps::FieldResolution(entry.GetDexFieldIndex(), |
| 1343 | entry.GetAccessFlags(), |
| 1344 | kNewTypeIndex)); |
| 1345 | found = true; |
| 1346 | break; |
| 1347 | } |
| 1348 | } |
| 1349 | ASSERT_TRUE(found); |
| 1350 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1351 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | // Mess up with methods. |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1355 | { |
| 1356 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1357 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1358 | bool found = false; |
| 1359 | std::set<VerifierDeps::MethodResolution>* methods = &deps->methods_; |
| 1360 | for (const auto& entry : *methods) { |
| 1361 | if (entry.IsResolved()) { |
| 1362 | methods->insert(VerifierDeps::MethodResolution(entry.GetDexMethodIndex(), |
| 1363 | VerifierDeps::kUnresolvedMarker, |
| 1364 | entry.GetDeclaringClassIndex())); |
| 1365 | found = true; |
| 1366 | break; |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1367 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1368 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1369 | ASSERT_TRUE(found); |
| 1370 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
| 1371 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
| 1372 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1373 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1374 | { |
| 1375 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1376 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1377 | bool found = false; |
| 1378 | std::set<VerifierDeps::MethodResolution>* methods = &deps->methods_; |
| 1379 | for (const auto& entry : *methods) { |
| 1380 | if (!entry.IsResolved()) { |
| 1381 | constexpr dex::StringIndex kStringIndexZero(0); // We know there is a class there. |
| 1382 | methods->insert(VerifierDeps::MethodResolution(0 /* we know there is a method there */, |
| 1383 | VerifierDeps::kUnresolvedMarker - 1, |
| 1384 | kStringIndexZero)); |
| 1385 | found = true; |
| 1386 | break; |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1387 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1388 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1389 | ASSERT_TRUE(found); |
| 1390 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
| 1391 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
| 1392 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1393 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1394 | { |
| 1395 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1396 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1397 | bool found = false; |
| 1398 | std::set<VerifierDeps::MethodResolution>* methods = &deps->methods_; |
| 1399 | for (const auto& entry : *methods) { |
| 1400 | if (entry.IsResolved()) { |
| 1401 | methods->insert(VerifierDeps::MethodResolution(entry.GetDexMethodIndex(), |
| 1402 | entry.GetAccessFlags() - 1, |
| 1403 | entry.GetDeclaringClassIndex())); |
| 1404 | found = true; |
| 1405 | break; |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1406 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1407 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1408 | ASSERT_TRUE(found); |
| 1409 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
| 1410 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
| 1411 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1412 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1413 | { |
| 1414 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1415 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1416 | bool found = false; |
| 1417 | std::set<VerifierDeps::MethodResolution>* methods = &deps->methods_; |
| 1418 | for (const auto& entry : *methods) { |
| 1419 | constexpr dex::StringIndex kNewTypeIndex(0); |
| 1420 | if (entry.IsResolved() && entry.GetDeclaringClassIndex() != kNewTypeIndex) { |
| 1421 | methods->insert(VerifierDeps::MethodResolution(entry.GetDexMethodIndex(), |
| 1422 | entry.GetAccessFlags(), |
| 1423 | kNewTypeIndex)); |
| 1424 | found = true; |
| 1425 | break; |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1426 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1427 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1428 | ASSERT_TRUE(found); |
| 1429 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
| 1430 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | TEST_F(VerifierDepsTest, CompilerDriver) { |
| 1435 | SetupCompilerDriver(); |
| 1436 | |
| 1437 | // Test both multi-dex and single-dex configuration. |
| 1438 | for (const char* multi : { "MultiDex", static_cast<const char*>(nullptr) }) { |
| 1439 | // Test that the compiler driver behaves as expected when the dependencies |
| 1440 | // verify and when they don't verify. |
| 1441 | for (bool verify_failure : { false, true }) { |
| 1442 | { |
| 1443 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 1444 | LoadDexFile(soa, "VerifierDeps", multi); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1445 | } |
| 1446 | VerifyWithCompilerDriver(/* verifier_deps */ nullptr); |
| 1447 | |
| 1448 | std::vector<uint8_t> buffer; |
| 1449 | verifier_deps_->Encode(dex_files_, &buffer); |
| 1450 | |
| 1451 | { |
| 1452 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | a8bba7d | 2018-05-30 15:18:48 +0100 | [diff] [blame] | 1453 | LoadDexFile(soa, "VerifierDeps", multi); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1454 | } |
| 1455 | verifier::VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1456 | if (verify_failure) { |
| 1457 | // Just taint the decoded VerifierDeps with one invalid entry. |
| 1458 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1459 | bool found = false; |
| 1460 | for (const auto& entry : deps->classes_) { |
| 1461 | if (entry.IsResolved()) { |
| 1462 | deps->classes_.insert(VerifierDeps::ClassResolution( |
| 1463 | entry.GetDexTypeIndex(), VerifierDeps::kUnresolvedMarker)); |
| 1464 | found = true; |
| 1465 | break; |
| 1466 | } |
| 1467 | } |
| 1468 | ASSERT_TRUE(found); |
| 1469 | } |
| 1470 | VerifyWithCompilerDriver(&decoded_deps); |
| 1471 | |
| 1472 | if (verify_failure) { |
| 1473 | ASSERT_FALSE(verifier_deps_ == nullptr); |
| 1474 | ASSERT_FALSE(verifier_deps_->Equals(decoded_deps)); |
| 1475 | } else { |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1476 | VerifyClassStatus(decoded_deps); |
| 1477 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | } |
| 1481 | |
Nicolas Geoffray | 7cc3ae5 | 2017-03-07 14:33:37 +0000 | [diff] [blame] | 1482 | TEST_F(VerifierDepsTest, MultiDexVerification) { |
| 1483 | VerifyDexFile("VerifierDepsMulti"); |
| 1484 | ASSERT_EQ(NumberOfCompiledDexFiles(), 2u); |
| 1485 | |
| 1486 | ASSERT_TRUE(HasUnverifiedClass("LMySoftVerificationFailure;", *dex_files_[1])); |
| 1487 | ASSERT_TRUE(HasUnverifiedClass("LMySub1SoftVerificationFailure;", *dex_files_[0])); |
| 1488 | ASSERT_TRUE(HasUnverifiedClass("LMySub2SoftVerificationFailure;", *dex_files_[0])); |
| 1489 | |
| 1490 | std::vector<uint8_t> buffer; |
| 1491 | verifier_deps_->Encode(dex_files_, &buffer); |
| 1492 | ASSERT_FALSE(buffer.empty()); |
| 1493 | } |
| 1494 | |
Nicolas Geoffray | fc38e91 | 2017-03-16 16:51:59 +0000 | [diff] [blame] | 1495 | TEST_F(VerifierDepsTest, NotAssignable_InterfaceWithClassInBoot) { |
| 1496 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;", |
| 1497 | /* src */ "LIface;", |
| 1498 | /* is_strict */ true, |
| 1499 | /* is_assignable */ false)); |
| 1500 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LIface;", false)); |
| 1501 | } |
| 1502 | |
Nicolas Geoffray | bdb540d | 2017-04-19 13:50:34 +0100 | [diff] [blame] | 1503 | TEST_F(VerifierDepsTest, Assignable_Arrays) { |
| 1504 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[LIface;", |
| 1505 | /* src */ "[LMyClassExtendingInterface;", |
| 1506 | /* is_strict */ false, |
| 1507 | /* is_assignable */ true)); |
| 1508 | ASSERT_FALSE(HasAssignable( |
| 1509 | "LIface;", "LMyClassExtendingInterface;", /* expected_is_assignable */ true)); |
| 1510 | ASSERT_FALSE(HasAssignable( |
| 1511 | "LIface;", "LMyClassExtendingInterface;", /* expected_is_assignable */ false)); |
| 1512 | } |
| 1513 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1514 | } // namespace verifier |
| 1515 | } // namespace art |