diff options
author | Nicolas Geoffray <ngeoffray@google.com> | 2014-07-22 10:48:00 +0100 |
---|---|---|
committer | Nicolas Geoffray <ngeoffray@google.com> | 2014-08-13 18:01:51 +0100 |
commit | 4fcdc94d22a4608e355aa8df36240181149d10e8 (patch) | |
tree | cb600df7e9b585720c03a08b10509151aa96d5dd /test | |
parent | b66252112d45fd24eab85122fa8902afd1324542 (diff) | |
download | art-4fcdc94d22a4608e355aa8df36240181149d10e8.tar.gz art-4fcdc94d22a4608e355aa8df36240181149d10e8.tar.bz2 art-4fcdc94d22a4608e355aa8df36240181149d10e8.zip |
Execute an application even when dex2oat crashes.
Bug: 17000769
Change-Id: Iffeb582862a5e794b6c7364c7ec2368cfd0f2214
Diffstat (limited to 'test')
-rw-r--r-- | test/116-nodex2oat/expected.txt | 6 | ||||
-rw-r--r-- | test/116-nodex2oat/info.txt | 1 | ||||
-rw-r--r-- | test/116-nodex2oat/nodex2oat.cc | 45 | ||||
-rwxr-xr-x | test/116-nodex2oat/run | 30 | ||||
-rw-r--r-- | test/116-nodex2oat/src/Main.java | 36 | ||||
-rw-r--r-- | test/Android.libarttest.mk | 3 |
6 files changed, 120 insertions, 1 deletions
diff --git a/test/116-nodex2oat/expected.txt b/test/116-nodex2oat/expected.txt new file mode 100644 index 0000000000..05b1c2f387 --- /dev/null +++ b/test/116-nodex2oat/expected.txt @@ -0,0 +1,6 @@ +Run -Xnodex2oat +Has oat is false, is dex2oat enabled is false. +Run -Xdex2oat +Has oat is true, is dex2oat enabled is true. +Run default +Has oat is true, is dex2oat enabled is true. diff --git a/test/116-nodex2oat/info.txt b/test/116-nodex2oat/info.txt new file mode 100644 index 0000000000..f063d9f12e --- /dev/null +++ b/test/116-nodex2oat/info.txt @@ -0,0 +1 @@ +Test that disables dex2oat'ing the application. diff --git a/test/116-nodex2oat/nodex2oat.cc b/test/116-nodex2oat/nodex2oat.cc new file mode 100644 index 0000000000..4326db0e54 --- /dev/null +++ b/test/116-nodex2oat/nodex2oat.cc @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "class_linker.h" +#include "dex_file-inl.h" +#include "mirror/class-inl.h" +#include "scoped_thread_state_change.h" +#include "thread.h" + +namespace art { + +class NoDex2OatTest { + public: + static bool hasOat(jclass cls) { + ScopedObjectAccess soa(Thread::Current()); + mirror::Class* klass = soa.Decode<mirror::Class*>(cls); + const DexFile& dex_file = klass->GetDexFile(); + const OatFile* oat_file = + Runtime::Current()->GetClassLinker()->FindOpenedOatFileForDexFile(dex_file); + return oat_file != nullptr; + } +}; + +extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasOat(JNIEnv*, jclass cls) { + return NoDex2OatTest::hasOat(cls); +} + +extern "C" JNIEXPORT jboolean JNICALL Java_Main_isDex2OatEnabled(JNIEnv*, jclass cls) { + return Runtime::Current()->IsDex2OatEnabled(); +} + +} // namespace art diff --git a/test/116-nodex2oat/run b/test/116-nodex2oat/run new file mode 100755 index 0000000000..5ffeecdbb1 --- /dev/null +++ b/test/116-nodex2oat/run @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Copyright (C) 2014 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Remove prebuild from the flags, this test is for testing not having oat files. +flags="${@/--prebuild/}" + +# Make sure we can run without an oat file, +echo "Run -Xnodex2oat" +${RUN} ${flags} --runtime-option -Xnodex2oat + +# Make sure we can run with the oat file. +echo "Run -Xdex2oat" +${RUN} ${flags} --runtime-option -Xdex2oat + +# Make sure we can run with the default settings. +echo "Run default" +${RUN} ${flags} diff --git a/test/116-nodex2oat/src/Main.java b/test/116-nodex2oat/src/Main.java new file mode 100644 index 0000000000..37ac9d5b78 --- /dev/null +++ b/test/116-nodex2oat/src/Main.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class Main { + public static void main(String[] args) { + System.out.println( + "Has oat is " + hasOat() + ", is dex2oat enabled is " + isDex2OatEnabled() + "."); + + if (hasOat() && !isDex2OatEnabled()) { + throw new Error("Application with dex2oat disabled runs with an oat file"); + } else if (!hasOat() && isDex2OatEnabled()) { + throw new Error("Application with dex2oat enabled runs without an oat file"); + } + } + + static { + System.loadLibrary("arttest"); + } + + private native static boolean hasOat(); + + private native static boolean isDex2OatEnabled(); +} diff --git a/test/Android.libarttest.mk b/test/Android.libarttest.mk index f3563a4af0..3871b28ec1 100644 --- a/test/Android.libarttest.mk +++ b/test/Android.libarttest.mk @@ -23,7 +23,8 @@ LIBARTTEST_COMMON_SRC_FILES := \ 004-SignalTest/signaltest.cc \ 004-ReferenceMap/stack_walk_refmap_jni.cc \ 004-StackWalk/stack_walk_jni.cc \ - 004-UnsafeTest/unsafe_test.cc + 004-UnsafeTest/unsafe_test.cc \ + 116-nodex2oat/nodex2oat.cc ART_TARGET_LIBARTTEST_$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_TARGET_TEST_OUT)/$(TARGET_ARCH)/libarttest.so ifdef TARGET_2ND_ARCH |