Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 17 | #include "method_verifier.h" |
| 18 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 19 | #include <stdio.h> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 20 | #include <memory> |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 21 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 22 | #include "class_linker-inl.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 23 | #include "common_runtime_test.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 24 | #include "dex_file.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 25 | #include "scoped_thread_state_change.h" |
Andreas Gampe | 5fd66d0 | 2016-09-12 20:22:19 -0700 | [diff] [blame^] | 26 | #include "verifier_log_mode.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | namespace verifier { |
| 30 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 31 | class MethodVerifierTest : public CommonRuntimeTest { |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 32 | protected: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 33 | void VerifyClass(const std::string& descriptor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 34 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 35 | ASSERT_TRUE(descriptor != nullptr); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 36 | Thread* self = Thread::Current(); |
| 37 | mirror::Class* klass = class_linker_->FindSystemClass(self, descriptor.c_str()); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 38 | |
| 39 | // Verify the class |
| 40 | std::string error_msg; |
Andreas Gampe | 5fd66d0 | 2016-09-12 20:22:19 -0700 | [diff] [blame^] | 41 | MethodVerifier::FailureKind failure = MethodVerifier::VerifyClass( |
| 42 | self, klass, nullptr, true, HardFailLogMode::kLogWarning, &error_msg); |
Andreas Gampe | 7fe3023 | 2016-03-25 16:58:00 -0700 | [diff] [blame] | 43 | ASSERT_TRUE(failure == MethodVerifier::kNoFailure) << error_msg; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 46 | void VerifyDexFile(const DexFile& dex) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 47 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 48 | // Verify all the classes defined in this file |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 49 | for (size_t i = 0; i < dex.NumClassDefs(); i++) { |
| 50 | const DexFile::ClassDef& class_def = dex.GetClassDef(i); |
| 51 | const char* descriptor = dex.GetClassDescriptor(class_def); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 52 | VerifyClass(descriptor); |
| 53 | } |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | TEST_F(MethodVerifierTest, LibCore) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 58 | ScopedObjectAccess soa(Thread::Current()); |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 59 | ASSERT_TRUE(java_lang_dex_file_ != nullptr); |
| 60 | VerifyDexFile(*java_lang_dex_file_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 63 | } // namespace verifier |
| 64 | } // namespace art |