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" |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 26 | #include "dex_file.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. |
| 90 | verifier_deps_.reset(nullptr); |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 91 | callbacks_->SetVerifierDeps(deps); |
| 92 | compiler_driver_->Verify(class_loader_, dex_files_, &timings); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 93 | // The compiler driver may have updated the VerifierDeps in the callback object. |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 94 | if (callbacks_->GetVerifierDeps() != deps) { |
| 95 | verifier_deps_.reset(callbacks_->GetVerifierDeps()); |
| 96 | } |
| 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 | 93764b8 | 2017-07-17 14:51:53 -0700 | [diff] [blame] | 100 | AtomicDexRefMap<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 | } |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 131 | } |
| 132 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 133 | void LoadDexFile(ScopedObjectAccess* soa) REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 134 | LoadDexFile(soa, "VerifierDeps"); |
| 135 | CHECK_EQ(dex_files_.size(), 1u); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 136 | klass_Main_ = FindClassByName("LMain;", soa); |
| 137 | CHECK(klass_Main_ != nullptr); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | bool VerifyMethod(const std::string& method_name) { |
| 141 | ScopedObjectAccess soa(Thread::Current()); |
| 142 | LoadDexFile(&soa); |
| 143 | |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 144 | StackHandleScope<2> hs(soa.Self()); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 145 | Handle<mirror::ClassLoader> class_loader_handle( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 146 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_))); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 147 | Handle<mirror::DexCache> dex_cache_handle(hs.NewHandle(klass_Main_->GetDexCache())); |
| 148 | |
| 149 | const DexFile::ClassDef* class_def = klass_Main_->GetClassDef(); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 150 | const uint8_t* class_data = primary_dex_file_->GetClassData(*class_def); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 151 | CHECK(class_data != nullptr); |
| 152 | |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 153 | ClassDataItemIterator it(*primary_dex_file_, class_data); |
Mathieu Chartier | e17cf24 | 2017-06-19 11:05:51 -0700 | [diff] [blame] | 154 | it.SkipAllFields(); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 155 | |
| 156 | ArtMethod* method = nullptr; |
| 157 | while (it.HasNextDirectMethod()) { |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 158 | ArtMethod* resolved_method = |
| 159 | class_linker_->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( |
| 160 | *primary_dex_file_, |
| 161 | it.GetMemberIndex(), |
| 162 | dex_cache_handle, |
| 163 | class_loader_handle, |
| 164 | nullptr, |
| 165 | it.GetMethodInvokeType(*class_def)); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 166 | CHECK(resolved_method != nullptr); |
| 167 | if (method_name == resolved_method->GetName()) { |
| 168 | method = resolved_method; |
| 169 | break; |
| 170 | } |
| 171 | it.Next(); |
| 172 | } |
| 173 | CHECK(method != nullptr); |
| 174 | |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 175 | Thread::Current()->SetVerifierDeps(callbacks_->GetVerifierDeps()); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 176 | MethodVerifier verifier(Thread::Current(), |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 177 | primary_dex_file_, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 178 | dex_cache_handle, |
| 179 | class_loader_handle, |
| 180 | *class_def, |
| 181 | it.GetMethodCodeItem(), |
| 182 | it.GetMemberIndex(), |
| 183 | method, |
| 184 | it.GetMethodAccessFlags(), |
| 185 | true /* can_load_classes */, |
| 186 | true /* allow_soft_failures */, |
| 187 | true /* need_precise_constants */, |
| 188 | false /* verify to dump */, |
| 189 | true /* allow_thread_suspension */); |
| 190 | verifier.Verify(); |
Nicolas Geoffray | 340dafa | 2016-11-18 16:03:10 +0000 | [diff] [blame] | 191 | Thread::Current()->SetVerifierDeps(nullptr); |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 192 | return !verifier.HasFailures(); |
| 193 | } |
| 194 | |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 195 | void VerifyDexFile(const char* multidex = nullptr) { |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 196 | { |
| 197 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 198 | LoadDexFile(&soa, "VerifierDeps", multidex); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 199 | } |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 200 | SetupCompilerDriver(); |
| 201 | VerifyWithCompilerDriver(/* verifier_deps */ nullptr); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 202 | } |
| 203 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 204 | bool TestAssignabilityRecording(const std::string& dst, |
| 205 | const std::string& src, |
| 206 | bool is_strict, |
| 207 | bool is_assignable) { |
| 208 | ScopedObjectAccess soa(Thread::Current()); |
| 209 | LoadDexFile(&soa); |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 210 | mirror::Class* klass_dst = FindClassByName(dst, &soa); |
Nicolas Geoffray | bdb540d | 2017-04-19 13:50:34 +0100 | [diff] [blame] | 211 | DCHECK(klass_dst != nullptr) << dst; |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 212 | mirror::Class* klass_src = FindClassByName(src, &soa); |
Nicolas Geoffray | bdb540d | 2017-04-19 13:50:34 +0100 | [diff] [blame] | 213 | DCHECK(klass_src != nullptr) << src; |
Nicolas Geoffray | d01f60c | 2016-10-28 14:45:48 +0100 | [diff] [blame] | 214 | verifier_deps_->AddAssignability(*primary_dex_file_, |
David Brazdil | 6f82fbd | 2016-09-14 11:55:26 +0100 | [diff] [blame] | 215 | klass_dst, |
| 216 | klass_src, |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 217 | is_strict, |
| 218 | is_assignable); |
| 219 | return true; |
| 220 | } |
| 221 | |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 222 | // Check that the status of classes in `class_loader_` match the |
| 223 | // expected status in `deps`. |
| 224 | void VerifyClassStatus(const verifier::VerifierDeps& deps) { |
| 225 | ScopedObjectAccess soa(Thread::Current()); |
| 226 | StackHandleScope<2> hs(soa.Self()); |
| 227 | Handle<mirror::ClassLoader> class_loader_handle( |
| 228 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader_))); |
| 229 | MutableHandle<mirror::Class> cls(hs.NewHandle<mirror::Class>(nullptr)); |
| 230 | for (const DexFile* dex_file : dex_files_) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 231 | const std::vector<dex::TypeIndex>& unverified_classes = deps.GetUnverifiedClasses(*dex_file); |
| 232 | std::set<dex::TypeIndex> set(unverified_classes.begin(), unverified_classes.end()); |
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(); |
| 240 | } else if (set.find(class_def.class_idx_) == set.end()) { |
| 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) { |
| 627 | ASSERT_TRUE(VerifyMethod("ConstClass_Unresolved")); |
| 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) { |
| 637 | ASSERT_TRUE(VerifyMethod("CheckCast_Unresolved")); |
| 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) { |
| 647 | ASSERT_TRUE(VerifyMethod("InstanceOf_Unresolved")); |
| 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) { |
| 657 | ASSERT_TRUE(VerifyMethod("NewInstance_Unresolved")); |
| 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) { |
| 662 | ASSERT_TRUE(VerifyMethod("NewArray_Unresolved")); |
| 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 | |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1147 | TEST_F(VerifierDepsTest, VerifyDeps) { |
| 1148 | VerifyDexFile(); |
| 1149 | |
| 1150 | ASSERT_EQ(1u, NumberOfCompiledDexFiles()); |
| 1151 | ASSERT_TRUE(HasEachKindOfRecord()); |
| 1152 | |
| 1153 | // When validating, we create a new class loader, as |
| 1154 | // the existing `class_loader_` may contain erroneous classes, |
| 1155 | // that ClassLinker::FindClass won't return. |
| 1156 | |
| 1157 | ScopedObjectAccess soa(Thread::Current()); |
| 1158 | StackHandleScope<1> hs(soa.Self()); |
| 1159 | MutableHandle<mirror::ClassLoader> new_class_loader(hs.NewHandle<mirror::ClassLoader>(nullptr)); |
| 1160 | { |
| 1161 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1162 | ASSERT_TRUE(verifier_deps_->ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | std::vector<uint8_t> buffer; |
| 1166 | verifier_deps_->Encode(dex_files_, &buffer); |
| 1167 | ASSERT_FALSE(buffer.empty()); |
| 1168 | |
| 1169 | { |
| 1170 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1171 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1172 | ASSERT_TRUE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | // Fiddle with the dependencies to make sure we catch any change and fail to verify. |
| 1176 | |
| 1177 | { |
| 1178 | // Mess up with the assignable_types. |
| 1179 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1180 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1181 | deps->assignable_types_.insert(*deps->unassignable_types_.begin()); |
| 1182 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1183 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | { |
| 1187 | // Mess up with the unassignable_types. |
| 1188 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1189 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1190 | deps->unassignable_types_.insert(*deps->assignable_types_.begin()); |
| 1191 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1192 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | // Mess up with classes. |
| 1196 | { |
| 1197 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1198 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1199 | bool found = false; |
| 1200 | for (const auto& entry : deps->classes_) { |
| 1201 | if (entry.IsResolved()) { |
| 1202 | deps->classes_.insert(VerifierDeps::ClassResolution( |
| 1203 | entry.GetDexTypeIndex(), VerifierDeps::kUnresolvedMarker)); |
| 1204 | found = true; |
| 1205 | break; |
| 1206 | } |
| 1207 | } |
| 1208 | ASSERT_TRUE(found); |
| 1209 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1210 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | { |
| 1214 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1215 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1216 | bool found = false; |
| 1217 | for (const auto& entry : deps->classes_) { |
| 1218 | if (!entry.IsResolved()) { |
| 1219 | deps->classes_.insert(VerifierDeps::ClassResolution( |
| 1220 | entry.GetDexTypeIndex(), VerifierDeps::kUnresolvedMarker - 1)); |
| 1221 | found = true; |
| 1222 | break; |
| 1223 | } |
| 1224 | } |
| 1225 | ASSERT_TRUE(found); |
| 1226 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1227 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | { |
| 1231 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1232 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1233 | bool found = false; |
| 1234 | for (const auto& entry : deps->classes_) { |
| 1235 | if (entry.IsResolved()) { |
| 1236 | deps->classes_.insert(VerifierDeps::ClassResolution( |
| 1237 | entry.GetDexTypeIndex(), entry.GetAccessFlags() - 1)); |
| 1238 | found = true; |
| 1239 | break; |
| 1240 | } |
| 1241 | } |
| 1242 | ASSERT_TRUE(found); |
| 1243 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1244 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | // Mess up with fields. |
| 1248 | { |
| 1249 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1250 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1251 | bool found = false; |
| 1252 | for (const auto& entry : deps->fields_) { |
| 1253 | if (entry.IsResolved()) { |
| 1254 | deps->fields_.insert(VerifierDeps::FieldResolution(entry.GetDexFieldIndex(), |
| 1255 | VerifierDeps::kUnresolvedMarker, |
| 1256 | entry.GetDeclaringClassIndex())); |
| 1257 | found = true; |
| 1258 | break; |
| 1259 | } |
| 1260 | } |
| 1261 | ASSERT_TRUE(found); |
| 1262 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1263 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | { |
| 1267 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1268 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1269 | bool found = false; |
| 1270 | for (const auto& entry : deps->fields_) { |
| 1271 | if (!entry.IsResolved()) { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1272 | constexpr dex::StringIndex kStringIndexZero(0); // We know there is a class there. |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1273 | deps->fields_.insert(VerifierDeps::FieldResolution(0 /* we know there is a field there */, |
| 1274 | VerifierDeps::kUnresolvedMarker - 1, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1275 | kStringIndexZero)); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1276 | found = true; |
| 1277 | break; |
| 1278 | } |
| 1279 | } |
| 1280 | ASSERT_TRUE(found); |
| 1281 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1282 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | { |
| 1286 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1287 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1288 | bool found = false; |
| 1289 | for (const auto& entry : deps->fields_) { |
| 1290 | if (entry.IsResolved()) { |
| 1291 | deps->fields_.insert(VerifierDeps::FieldResolution(entry.GetDexFieldIndex(), |
| 1292 | entry.GetAccessFlags() - 1, |
| 1293 | entry.GetDeclaringClassIndex())); |
| 1294 | found = true; |
| 1295 | break; |
| 1296 | } |
| 1297 | } |
| 1298 | ASSERT_TRUE(found); |
| 1299 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1300 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | { |
| 1304 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1305 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1306 | bool found = false; |
| 1307 | for (const auto& entry : deps->fields_) { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1308 | constexpr dex::StringIndex kNewTypeIndex(0); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1309 | if (entry.GetDeclaringClassIndex() != kNewTypeIndex) { |
| 1310 | deps->fields_.insert(VerifierDeps::FieldResolution(entry.GetDexFieldIndex(), |
| 1311 | entry.GetAccessFlags(), |
| 1312 | kNewTypeIndex)); |
| 1313 | found = true; |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
| 1317 | ASSERT_TRUE(found); |
| 1318 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1319 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | // Mess up with methods. |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1323 | { |
| 1324 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1325 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1326 | bool found = false; |
| 1327 | std::set<VerifierDeps::MethodResolution>* methods = &deps->methods_; |
| 1328 | for (const auto& entry : *methods) { |
| 1329 | if (entry.IsResolved()) { |
| 1330 | methods->insert(VerifierDeps::MethodResolution(entry.GetDexMethodIndex(), |
| 1331 | VerifierDeps::kUnresolvedMarker, |
| 1332 | entry.GetDeclaringClassIndex())); |
| 1333 | found = true; |
| 1334 | break; |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1335 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1336 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1337 | ASSERT_TRUE(found); |
| 1338 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
| 1339 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
| 1340 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1341 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1342 | { |
| 1343 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1344 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1345 | bool found = false; |
| 1346 | std::set<VerifierDeps::MethodResolution>* methods = &deps->methods_; |
| 1347 | for (const auto& entry : *methods) { |
| 1348 | if (!entry.IsResolved()) { |
| 1349 | constexpr dex::StringIndex kStringIndexZero(0); // We know there is a class there. |
| 1350 | methods->insert(VerifierDeps::MethodResolution(0 /* we know there is a method there */, |
| 1351 | VerifierDeps::kUnresolvedMarker - 1, |
| 1352 | kStringIndexZero)); |
| 1353 | found = true; |
| 1354 | break; |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1355 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1356 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1357 | ASSERT_TRUE(found); |
| 1358 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
| 1359 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
| 1360 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1361 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1362 | { |
| 1363 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1364 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1365 | bool found = false; |
| 1366 | std::set<VerifierDeps::MethodResolution>* methods = &deps->methods_; |
| 1367 | for (const auto& entry : *methods) { |
| 1368 | if (entry.IsResolved()) { |
| 1369 | methods->insert(VerifierDeps::MethodResolution(entry.GetDexMethodIndex(), |
| 1370 | entry.GetAccessFlags() - 1, |
| 1371 | entry.GetDeclaringClassIndex())); |
| 1372 | found = true; |
| 1373 | break; |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1374 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1375 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1376 | ASSERT_TRUE(found); |
| 1377 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
| 1378 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
| 1379 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1380 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1381 | { |
| 1382 | VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1383 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1384 | bool found = false; |
| 1385 | std::set<VerifierDeps::MethodResolution>* methods = &deps->methods_; |
| 1386 | for (const auto& entry : *methods) { |
| 1387 | constexpr dex::StringIndex kNewTypeIndex(0); |
| 1388 | if (entry.IsResolved() && entry.GetDeclaringClassIndex() != kNewTypeIndex) { |
| 1389 | methods->insert(VerifierDeps::MethodResolution(entry.GetDexMethodIndex(), |
| 1390 | entry.GetAccessFlags(), |
| 1391 | kNewTypeIndex)); |
| 1392 | found = true; |
| 1393 | break; |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1394 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1395 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1396 | ASSERT_TRUE(found); |
| 1397 | new_class_loader.Assign(soa.Decode<mirror::ClassLoader>(LoadDex("VerifierDeps"))); |
| 1398 | ASSERT_FALSE(decoded_deps.ValidateDependencies(new_class_loader, soa.Self())); |
Nicolas Geoffray | 6bb7f1b | 2016-11-03 10:52:49 +0000 | [diff] [blame] | 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | TEST_F(VerifierDepsTest, CompilerDriver) { |
| 1403 | SetupCompilerDriver(); |
| 1404 | |
| 1405 | // Test both multi-dex and single-dex configuration. |
| 1406 | for (const char* multi : { "MultiDex", static_cast<const char*>(nullptr) }) { |
| 1407 | // Test that the compiler driver behaves as expected when the dependencies |
| 1408 | // verify and when they don't verify. |
| 1409 | for (bool verify_failure : { false, true }) { |
| 1410 | { |
| 1411 | ScopedObjectAccess soa(Thread::Current()); |
| 1412 | LoadDexFile(&soa, "VerifierDeps", multi); |
| 1413 | } |
| 1414 | VerifyWithCompilerDriver(/* verifier_deps */ nullptr); |
| 1415 | |
| 1416 | std::vector<uint8_t> buffer; |
| 1417 | verifier_deps_->Encode(dex_files_, &buffer); |
| 1418 | |
| 1419 | { |
| 1420 | ScopedObjectAccess soa(Thread::Current()); |
| 1421 | LoadDexFile(&soa, "VerifierDeps", multi); |
| 1422 | } |
| 1423 | verifier::VerifierDeps decoded_deps(dex_files_, ArrayRef<const uint8_t>(buffer)); |
| 1424 | if (verify_failure) { |
| 1425 | // Just taint the decoded VerifierDeps with one invalid entry. |
| 1426 | VerifierDeps::DexFileDeps* deps = decoded_deps.GetDexFileDeps(*primary_dex_file_); |
| 1427 | bool found = false; |
| 1428 | for (const auto& entry : deps->classes_) { |
| 1429 | if (entry.IsResolved()) { |
| 1430 | deps->classes_.insert(VerifierDeps::ClassResolution( |
| 1431 | entry.GetDexTypeIndex(), VerifierDeps::kUnresolvedMarker)); |
| 1432 | found = true; |
| 1433 | break; |
| 1434 | } |
| 1435 | } |
| 1436 | ASSERT_TRUE(found); |
| 1437 | } |
| 1438 | VerifyWithCompilerDriver(&decoded_deps); |
| 1439 | |
| 1440 | if (verify_failure) { |
| 1441 | ASSERT_FALSE(verifier_deps_ == nullptr); |
| 1442 | ASSERT_FALSE(verifier_deps_->Equals(decoded_deps)); |
| 1443 | } else { |
| 1444 | ASSERT_TRUE(verifier_deps_ == nullptr); |
| 1445 | VerifyClassStatus(decoded_deps); |
| 1446 | } |
Nicolas Geoffray | 8904b6f | 2016-10-28 19:50:34 +0100 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | } |
| 1450 | |
Nicolas Geoffray | 7cc3ae5 | 2017-03-07 14:33:37 +0000 | [diff] [blame] | 1451 | TEST_F(VerifierDepsTest, MultiDexVerification) { |
| 1452 | VerifyDexFile("VerifierDepsMulti"); |
| 1453 | ASSERT_EQ(NumberOfCompiledDexFiles(), 2u); |
| 1454 | |
| 1455 | ASSERT_TRUE(HasUnverifiedClass("LMySoftVerificationFailure;", *dex_files_[1])); |
| 1456 | ASSERT_TRUE(HasUnverifiedClass("LMySub1SoftVerificationFailure;", *dex_files_[0])); |
| 1457 | ASSERT_TRUE(HasUnverifiedClass("LMySub2SoftVerificationFailure;", *dex_files_[0])); |
| 1458 | |
| 1459 | std::vector<uint8_t> buffer; |
| 1460 | verifier_deps_->Encode(dex_files_, &buffer); |
| 1461 | ASSERT_FALSE(buffer.empty()); |
| 1462 | } |
| 1463 | |
Nicolas Geoffray | fc38e91 | 2017-03-16 16:51:59 +0000 | [diff] [blame] | 1464 | TEST_F(VerifierDepsTest, NotAssignable_InterfaceWithClassInBoot) { |
| 1465 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "Ljava/lang/Exception;", |
| 1466 | /* src */ "LIface;", |
| 1467 | /* is_strict */ true, |
| 1468 | /* is_assignable */ false)); |
| 1469 | ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LIface;", false)); |
| 1470 | } |
| 1471 | |
Nicolas Geoffray | bdb540d | 2017-04-19 13:50:34 +0100 | [diff] [blame] | 1472 | TEST_F(VerifierDepsTest, Assignable_Arrays) { |
| 1473 | ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[LIface;", |
| 1474 | /* src */ "[LMyClassExtendingInterface;", |
| 1475 | /* is_strict */ false, |
| 1476 | /* is_assignable */ true)); |
| 1477 | ASSERT_FALSE(HasAssignable( |
| 1478 | "LIface;", "LMyClassExtendingInterface;", /* expected_is_assignable */ true)); |
| 1479 | ASSERT_FALSE(HasAssignable( |
| 1480 | "LIface;", "LMyClassExtendingInterface;", /* expected_is_assignable */ false)); |
| 1481 | } |
| 1482 | |
David Brazdil | ca3c8c3 | 2016-09-06 14:04:48 +0100 | [diff] [blame] | 1483 | } // namespace verifier |
| 1484 | } // namespace art |