blob: a5895e6dbf51b1cefc9eff2c4927d6acecbba25b [file] [log] [blame]
Ian Rogers776ac1f2012-04-13 23:36:36 -07001/*
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 Carlstroma1ce1fe2014-02-24 23:23:58 -080017#include "method_verifier.h"
18
Ian Rogers776ac1f2012-04-13 23:36:36 -070019#include <stdio.h>
Ian Rogers700a4022014-05-19 16:49:03 -070020#include <memory>
Ian Rogers776ac1f2012-04-13 23:36:36 -070021
Mingyao Yang98d1cc82014-05-15 17:02:16 -070022#include "class_linker-inl.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080023#include "common_runtime_test.h"
Ian Rogers776ac1f2012-04-13 23:36:36 -070024#include "dex_file.h"
Ian Rogerse63db272014-07-15 15:36:11 -070025#include "scoped_thread_state_change.h"
Ian Rogers776ac1f2012-04-13 23:36:36 -070026
27namespace art {
28namespace verifier {
29
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080030class MethodVerifierTest : public CommonRuntimeTest {
Ian Rogers776ac1f2012-04-13 23:36:36 -070031 protected:
Ian Rogers00f7d0e2012-07-19 15:28:27 -070032 void VerifyClass(const std::string& descriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -070033 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers776ac1f2012-04-13 23:36:36 -070034 ASSERT_TRUE(descriptor != NULL);
Ian Rogers98379392014-02-24 16:53:16 -080035 mirror::Class* klass = class_linker_->FindSystemClass(Thread::Current(), descriptor.c_str());
Ian Rogers776ac1f2012-04-13 23:36:36 -070036
37 // Verify the class
38 std::string error_msg;
Ian Rogersee39a102013-09-19 02:56:49 -070039 ASSERT_TRUE(MethodVerifier::VerifyClass(klass, true, &error_msg) == MethodVerifier::kNoFailure)
40 << error_msg;
Ian Rogers776ac1f2012-04-13 23:36:36 -070041 }
42
Ian Rogers00f7d0e2012-07-19 15:28:27 -070043 void VerifyDexFile(const DexFile* dex)
Ian Rogersb726dcb2012-09-05 08:57:23 -070044 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers776ac1f2012-04-13 23:36:36 -070045 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
56TEST_F(MethodVerifierTest, LibCore) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070057 ScopedObjectAccess soa(Thread::Current());
Ian Rogers776ac1f2012-04-13 23:36:36 -070058 VerifyDexFile(java_lang_dex_file_);
59}
60
Ian Rogers776ac1f2012-04-13 23:36:36 -070061} // namespace verifier
62} // namespace art