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