Adding get long regression test for jdk.internal.misc.Unsafe
Test: art/test/testrunner/testrunner.py -t 2236-JdkUnsafeGetLong-regression
Bug: 190470684
Change-Id: I500618ed7fa914420db7aceff8da622969857667
diff --git a/test/2236-JdkUnsafeGetLong-regression/Android.bp b/test/2236-JdkUnsafeGetLong-regression/Android.bp
new file mode 100644
index 0000000..403cab8
--- /dev/null
+++ b/test/2236-JdkUnsafeGetLong-regression/Android.bp
@@ -0,0 +1,40 @@
+// Generated by `regen-test-files`. Do not edit manually.
+
+// Build rules for ART run-test `2236-JdkUnsafeGetLong-regression`.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "art_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["art_license"],
+}
+
+// Test's Dex code.
+java_test {
+ name: "art-run-test-2236-JdkUnsafeGetLong-regression",
+ defaults: ["art-run-test-defaults"],
+ test_config_template: ":art-run-test-target-template",
+ srcs: ["src/**/*.java"],
+ data: [
+ ":art-run-test-2236-JdkUnsafeGetLong-regression-expected-stdout",
+ ":art-run-test-2236-JdkUnsafeGetLong-regression-expected-stderr",
+ ],
+}
+
+// Test's expected standard output.
+genrule {
+ name: "art-run-test-2236-JdkUnsafeGetLong-regression-expected-stdout",
+ out: ["art-run-test-2236-JdkUnsafeGetLong-regression-expected-stdout.txt"],
+ srcs: ["expected-stdout.txt"],
+ cmd: "cp -f $(in) $(out)",
+}
+
+// Test's expected standard error.
+genrule {
+ name: "art-run-test-2236-JdkUnsafeGetLong-regression-expected-stderr",
+ out: ["art-run-test-2236-JdkUnsafeGetLong-regression-expected-stderr.txt"],
+ srcs: ["expected-stderr.txt"],
+ cmd: "cp -f $(in) $(out)",
+}
diff --git a/test/2236-JdkUnsafeGetLong-regression/expected-stderr.txt b/test/2236-JdkUnsafeGetLong-regression/expected-stderr.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/2236-JdkUnsafeGetLong-regression/expected-stderr.txt
diff --git a/test/2236-JdkUnsafeGetLong-regression/expected-stdout.txt b/test/2236-JdkUnsafeGetLong-regression/expected-stdout.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/2236-JdkUnsafeGetLong-regression/expected-stdout.txt
diff --git a/test/2236-JdkUnsafeGetLong-regression/info.txt b/test/2236-JdkUnsafeGetLong-regression/info.txt
new file mode 100644
index 0000000..05d5f27
--- /dev/null
+++ b/test/2236-JdkUnsafeGetLong-regression/info.txt
@@ -0,0 +1,2 @@
+Regression test for jdk.internal.misc.Unsafe.getLong's intrinsic's locations
+not handled properly. Copied from 555-UnsafeGetLong-regression.
diff --git a/test/2236-JdkUnsafeGetLong-regression/src/Main.java b/test/2236-JdkUnsafeGetLong-regression/src/Main.java
new file mode 100644
index 0000000..674b73e
--- /dev/null
+++ b/test/2236-JdkUnsafeGetLong-regression/src/Main.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+import java.lang.reflect.Field;
+import jdk.internal.misc.Unsafe;
+
+public class Main {
+ private static void assertLongEquals(long expected, long result) {
+ if (expected != result) {
+ throw new Error("Expected: " + expected + ", found: " + result);
+ }
+ }
+
+ private static Unsafe getUnsafe() throws Exception {
+ Class<?> unsafeClass = Class.forName("jdk.internal.misc.Unsafe");
+ Field f = unsafeClass.getDeclaredField("theUnsafe");
+ f.setAccessible(true);
+ return (Unsafe) f.get(null);
+ }
+
+ public static void main(String[] args) throws Exception {
+ Unsafe unsafe = getUnsafe();
+
+ testUnsafeGetLong(unsafe);
+ }
+
+ public static void testUnsafeGetLong(Unsafe unsafe) throws Exception {
+ TestClass test = new TestClass();
+ Field longField = TestClass.class.getDeclaredField("longVar");
+ long lvar = unsafe.objectFieldOffset(longField);
+ lvar = unsafe.getLong(test, lvar);
+ assertLongEquals(1122334455667788L, lvar);
+ }
+
+ private static class TestClass {
+ public long longVar = 1122334455667788L;
+ }
+}
diff --git a/test/knownfailures.json b/test/knownfailures.json
index e7ed208..76b02c3 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -1437,7 +1437,8 @@
"description": ["Out of memory"]
},
{
- "tests": ["2235-JdkUnsafeTest"],
+ "tests": ["2235-JdkUnsafeTest",
+ "2236-JdkUnsafeGetLong-regression"],
"variant": "jvm",
"bug": "b/195387473",
"description": ["Depends on using language level 11."]