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" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | namespace verifier { |
| 29 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 30 | class MethodVerifierTest : public CommonRuntimeTest { |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 31 | protected: |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 32 | void VerifyClass(const std::string& descriptor) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 33 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 34 | ASSERT_TRUE(descriptor != NULL); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 35 | mirror::Class* klass = class_linker_->FindSystemClass(Thread::Current(), descriptor.c_str()); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 36 | |
| 37 | // Verify the class |
| 38 | std::string error_msg; |
Ian Rogers | ee39a10 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 39 | ASSERT_TRUE(MethodVerifier::VerifyClass(klass, true, &error_msg) == MethodVerifier::kNoFailure) |
| 40 | << error_msg; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 43 | void VerifyDexFile(const DexFile* dex) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 44 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 45 | ASSERT_TRUE(dex != NULL); |
| 46 | |
| 47 | // Verify all the classes defined in this file |
| 48 | for (size_t i = 0; i < dex->NumClassDefs(); i++) { |
| 49 | const DexFile::ClassDef& class_def = dex->GetClassDef(i); |
| 50 | const char* descriptor = dex->GetClassDescriptor(class_def); |
| 51 | VerifyClass(descriptor); |
| 52 | } |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | TEST_F(MethodVerifierTest, LibCore) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 57 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 58 | VerifyDexFile(java_lang_dex_file_); |
| 59 | } |
| 60 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 61 | } // namespace verifier |
| 62 | } // namespace art |