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