diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/454-get-vreg/expected.txt | 0 | ||||
-rw-r--r-- | test/454-get-vreg/get_vreg_jni.cc | 122 | ||||
-rw-r--r-- | test/454-get-vreg/info.txt | 1 | ||||
-rw-r--r-- | test/454-get-vreg/src/Main.java | 53 | ||||
-rw-r--r-- | test/455-set-vreg/expected.txt | 0 | ||||
-rw-r--r-- | test/455-set-vreg/info.txt | 1 | ||||
-rw-r--r-- | test/455-set-vreg/set_vreg_jni.cc | 95 | ||||
-rw-r--r-- | test/455-set-vreg/src/Main.java | 73 | ||||
-rw-r--r-- | test/Android.libarttest.mk | 4 | ||||
-rwxr-xr-x | test/etc/run-test-jar | 2 |
10 files changed, 349 insertions, 2 deletions
diff --git a/test/454-get-vreg/expected.txt b/test/454-get-vreg/expected.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/454-get-vreg/expected.txt diff --git a/test/454-get-vreg/get_vreg_jni.cc b/test/454-get-vreg/get_vreg_jni.cc new file mode 100644 index 0000000000..937d2fee76 --- /dev/null +++ b/test/454-get-vreg/get_vreg_jni.cc @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2015 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 "arch/context.h" +#include "jni.h" +#include "mirror/art_method-inl.h" +#include "scoped_thread_state_change.h" +#include "stack.h" +#include "thread.h" + +namespace art { + +namespace { + +class TestVisitor : public StackVisitor { + public: + TestVisitor(Thread* thread, Context* context, mirror::Object* this_value) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) + : StackVisitor(thread, context), this_value_(this_value), found_method_index_(0) {} + + bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + mirror::ArtMethod* m = GetMethod(); + std::string m_name(m->GetName()); + + if (m_name.compare("testSimpleVReg") == 0) { + found_method_index_ = 1; + uint32_t value = 0; + + CHECK(GetVReg(m, 0, kIntVReg, &value)); + CHECK_EQ(value, 42u); + + bool success = GetVReg(m, 1, kIntVReg, &value); + if (m->IsOptimized(sizeof(void*))) CHECK(!success); + + success = GetVReg(m, 2, kIntVReg, &value); + if (m->IsOptimized(sizeof(void*))) CHECK(!success); + + CHECK(GetVReg(m, 3, kReferenceVReg, &value)); + CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_); + + CHECK(GetVReg(m, 4, kIntVReg, &value)); + CHECK_EQ(value, 1u); + + CHECK(GetVReg(m, 5, kFloatVReg, &value)); + uint32_t cast = bit_cast<float, uint32_t>(1.0f); + CHECK_EQ(value, cast); + + CHECK(GetVReg(m, 6, kIntVReg, &value)); + CHECK_EQ(value, 2u); + + CHECK(GetVReg(m, 7, kIntVReg, &value)); + CHECK_EQ(value, true); + + CHECK(GetVReg(m, 8, kIntVReg, &value)); + CHECK_EQ(value, 3u); + + CHECK(GetVReg(m, 9, kIntVReg, &value)); + CHECK_EQ(value, static_cast<uint32_t>('c')); + } else if (m_name.compare("testPairVReg") == 0) { + found_method_index_ = 2; + uint64_t value = 0; + CHECK(GetVRegPair(m, 0, kLongLoVReg, kLongHiVReg, &value)); + CHECK_EQ(value, 42u); + + bool success = GetVRegPair(m, 2, kLongLoVReg, kLongHiVReg, &value); + if (m->IsOptimized(sizeof(void*))) CHECK(!success); + + success = GetVRegPair(m, 4, kLongLoVReg, kLongHiVReg, &value); + if (m->IsOptimized(sizeof(void*))) CHECK(!success); + + uint32_t value32 = 0; + CHECK(GetVReg(m, 6, kReferenceVReg, &value32)); + CHECK_EQ(reinterpret_cast<mirror::Object*>(value32), this_value_); + + CHECK(GetVRegPair(m, 7, kLongLoVReg, kLongHiVReg, &value)); + CHECK_EQ(static_cast<int64_t>(value), std::numeric_limits<int64_t>::min()); + + CHECK(GetVRegPair(m, 9, kLongLoVReg, kLongHiVReg, &value)); + CHECK_EQ(static_cast<int64_t>(value), std::numeric_limits<int64_t>::max()); + + CHECK(GetVRegPair(m, 11, kLongLoVReg, kLongHiVReg, &value)); + CHECK_EQ(value, 0u); + + CHECK(GetVRegPair(m, 13, kDoubleLoVReg, kDoubleHiVReg, &value)); + uint64_t cast = bit_cast<double, uint64_t>(2.0); + CHECK_EQ(value, cast); + } + + return true; + } + + mirror::Object* this_value_; + + // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg + // have been found and tested. + jint found_method_index_; +}; + +extern "C" JNIEXPORT jint JNICALL Java_Main_doNativeCall(JNIEnv*, jobject value) { + ScopedObjectAccess soa(Thread::Current()); + std::unique_ptr<Context> context(Context::Create()); + TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object*>(value)); + visitor.WalkStack(); + return visitor.found_method_index_; +} + +} // namespace + +} // namespace art diff --git a/test/454-get-vreg/info.txt b/test/454-get-vreg/info.txt new file mode 100644 index 0000000000..20df0b5129 --- /dev/null +++ b/test/454-get-vreg/info.txt @@ -0,0 +1 @@ +Tests for inspecting DEX registers in a Java method. diff --git a/test/454-get-vreg/src/Main.java b/test/454-get-vreg/src/Main.java new file mode 100644 index 0000000000..df07d441a8 --- /dev/null +++ b/test/454-get-vreg/src/Main.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2015 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 Main() { + } + + int testSimpleVReg(int a, float f, short s, boolean z, byte b, char c) { + int e = doCall(); + int g = doNativeCall(); + return e + g; + } + + long testPairVReg(long a, long b, long c, double e) { + long f = doCall(); + long g = doNativeCall(); + return f + g; + } + + native int doNativeCall(); + + int doCall() { + return 42; + } + + static { + System.loadLibrary("arttest"); + } + + public static void main(String[] args) { + Main rm = new Main(); + if (rm.testSimpleVReg(1, 1.0f, (short)2, true, (byte)3, 'c') != 43) { + throw new Error("Expected 43"); + } + + if (rm.testPairVReg(Long.MIN_VALUE, Long.MAX_VALUE, 0, 2.0) != 44) { + throw new Error("Expected 44"); + } + } +} diff --git a/test/455-set-vreg/expected.txt b/test/455-set-vreg/expected.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/455-set-vreg/expected.txt diff --git a/test/455-set-vreg/info.txt b/test/455-set-vreg/info.txt new file mode 100644 index 0000000000..e8c57b579c --- /dev/null +++ b/test/455-set-vreg/info.txt @@ -0,0 +1 @@ +Tests for setting DEX registers in a Java method. diff --git a/test/455-set-vreg/set_vreg_jni.cc b/test/455-set-vreg/set_vreg_jni.cc new file mode 100644 index 0000000000..24d783264d --- /dev/null +++ b/test/455-set-vreg/set_vreg_jni.cc @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2015 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 "arch/context.h" +#include "jni.h" +#include "mirror/art_method-inl.h" +#include "scoped_thread_state_change.h" +#include "stack.h" +#include "thread.h" + +namespace art { + +namespace { + +class TestVisitor : public StackVisitor { + public: + TestVisitor(Thread* thread, Context* context, mirror::Object* this_value) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) + : StackVisitor(thread, context), this_value_(this_value) {} + + bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + mirror::ArtMethod* m = GetMethod(); + std::string m_name(m->GetName()); + + if (m_name.compare("testIntVReg") == 0) { + uint32_t value = 0; + CHECK(GetVReg(m, 1, kReferenceVReg, &value)); + CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_); + + CHECK(SetVReg(m, 2, 5, kIntVReg)); + CHECK(SetVReg(m, 3, 4, kIntVReg)); + CHECK(SetVReg(m, 4, 3, kIntVReg)); + CHECK(SetVReg(m, 5, 2, kIntVReg)); + CHECK(SetVReg(m, 6, 1, kIntVReg)); + } else if (m_name.compare("testLongVReg") == 0) { + uint32_t value = 0; + CHECK(GetVReg(m, 3, kReferenceVReg, &value)); + CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_); + + CHECK(SetVRegPair(m, 4, std::numeric_limits<int64_t>::max(), kLongLoVReg, kLongHiVReg)); + CHECK(SetVRegPair(m, 6, 4, kLongLoVReg, kLongHiVReg)); + CHECK(SetVRegPair(m, 8, 3, kLongLoVReg, kLongHiVReg)); + CHECK(SetVRegPair(m, 10, 2, kLongLoVReg, kLongHiVReg)); + CHECK(SetVRegPair(m, 12, 1, kLongLoVReg, kLongHiVReg)); + } else if (m_name.compare("testFloatVReg") == 0) { + uint32_t value = 0; + CHECK(GetVReg(m, 1, kReferenceVReg, &value)); + CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_); + + CHECK(SetVReg(m, 2, bit_cast<float, uint32_t>(5.0f), kFloatVReg)); + CHECK(SetVReg(m, 3, bit_cast<float, uint32_t>(4.0f), kFloatVReg)); + CHECK(SetVReg(m, 4, bit_cast<float, uint32_t>(3.0f), kFloatVReg)); + CHECK(SetVReg(m, 5, bit_cast<float, uint32_t>(2.0f), kFloatVReg)); + CHECK(SetVReg(m, 6, bit_cast<float, uint32_t>(1.0f), kFloatVReg)); + } else if (m_name.compare("testDoubleVReg") == 0) { + uint32_t value = 0; + CHECK(GetVReg(m, 3, kReferenceVReg, &value)); + CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_); + + CHECK(SetVRegPair(m, 4, bit_cast<double, uint64_t>(5.0), kDoubleLoVReg, kDoubleHiVReg)); + CHECK(SetVRegPair(m, 6, bit_cast<double, uint64_t>(4.0), kDoubleLoVReg, kDoubleHiVReg)); + CHECK(SetVRegPair(m, 8, bit_cast<double, uint64_t>(3.0), kDoubleLoVReg, kDoubleHiVReg)); + CHECK(SetVRegPair(m, 10, bit_cast<double, uint64_t>(2.0), kDoubleLoVReg, kDoubleHiVReg)); + CHECK(SetVRegPair(m, 12, bit_cast<double, uint64_t>(1.0), kDoubleLoVReg, kDoubleHiVReg)); + } + + return true; + } + + mirror::Object* this_value_; +}; + +extern "C" JNIEXPORT void JNICALL Java_Main_doNativeCallSetVReg(JNIEnv*, jobject value) { + ScopedObjectAccess soa(Thread::Current()); + std::unique_ptr<Context> context(Context::Create()); + TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object*>(value)); + visitor.WalkStack(); +} + +} // namespace + +} // namespace art diff --git a/test/455-set-vreg/src/Main.java b/test/455-set-vreg/src/Main.java new file mode 100644 index 0000000000..2172d9212d --- /dev/null +++ b/test/455-set-vreg/src/Main.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2015 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 Main() { + } + + int testIntVReg(int a, int b, int c, int d, int e) { + doNativeCallSetVReg(); + return a - b - c - d - e; + } + + long testLongVReg(long a, long b, long c, long d, long e) { + doNativeCallSetVReg(); + return a - b - c - d - e; + } + + float testFloatVReg(float a, float b, float c, float d, float e) { + doNativeCallSetVReg(); + return a - b - c - d - e; + } + + double testDoubleVReg(double a, double b, double c, double d, double e) { + doNativeCallSetVReg(); + return a - b - c - d - e; + } + + native void doNativeCallSetVReg(); + + static { + System.loadLibrary("arttest"); + } + + public static void main(String[] args) { + Main rm = new Main(); + int intExpected = 5 - 4 - 3 - 2 - 1; + int intResult = rm.testIntVReg(0, 0, 0, 0, 0); + if (intResult != intExpected) { + throw new Error("Expected " + intExpected + ", got " + intResult); + } + + long longExpected = Long.MAX_VALUE - 4 - 3 - 2 - 1; + long longResult = rm.testLongVReg(0, 0, 0, 0, 0); + if (longResult != longExpected) { + throw new Error("Expected " + longExpected + ", got " + longResult); + } + + float floatExpected = 5.0f - 4.0f - 3.0f - 2.0f - 1.0f; + float floatResult = rm.testFloatVReg(0.0f, 0.0f, 0.0f, 0.0f, 0.0f); + if (floatResult != floatExpected) { + throw new Error("Expected " + floatExpected + ", got " + floatResult); + } + + double doubleExpected = 5.0 - 4.0 - 3.0 - 2.0 - 1.0; + double doubleResult = rm.testDoubleVReg(0.0, 0.0, 0.0, 0.0, 0.0); + if (doubleResult != doubleExpected) { + throw new Error("Expected " + doubleExpected + ", got " + doubleResult); + } + } +} diff --git a/test/Android.libarttest.mk b/test/Android.libarttest.mk index e64df5c32a..75c5d72f18 100644 --- a/test/Android.libarttest.mk +++ b/test/Android.libarttest.mk @@ -27,7 +27,9 @@ LIBARTTEST_COMMON_SRC_FILES := \ 051-thread/thread_test.cc \ 116-nodex2oat/nodex2oat.cc \ 117-nopatchoat/nopatchoat.cc \ - 118-noimage-dex2oat/noimage-dex2oat.cc + 118-noimage-dex2oat/noimage-dex2oat.cc \ + 454-get-vreg/get_vreg_jni.cc \ + 455-set-vreg/set_vreg_jni.cc ART_TARGET_LIBARTTEST_$(ART_PHONY_TEST_TARGET_SUFFIX) += $(ART_TARGET_TEST_OUT)/$(TARGET_ARCH)/libarttest.so ifdef TARGET_2ND_ARCH diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar index ee40ee8310..7a2ad1c321 100755 --- a/test/etc/run-test-jar +++ b/test/etc/run-test-jar @@ -361,8 +361,8 @@ if [ "$HOST" = "n" ]; then export ANDROID_DATA=$DEX_LOCATION && \ export DEX_LOCATION=$DEX_LOCATION && \ export ANDROID_ROOT=$ANDROID_ROOT && \ - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \ $mkdir_cmdline && \ + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \ $dex2oat_cmdline && \ $dalvikvm_cmdline" |