diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/422-type-conversion/src/Main.java | 71 | ||||
| -rw-r--r-- | test/425-invoke-super/expected.txt | 1 | ||||
| -rw-r--r-- | test/425-invoke-super/src/Main.java | 2 | ||||
| -rw-r--r-- | test/800-smali/expected.txt | 1 | ||||
| -rw-r--r-- | test/800-smali/smali/b_17978759.smali | 28 | ||||
| -rw-r--r-- | test/800-smali/src/Main.java | 80 | ||||
| -rwxr-xr-x | test/run-test | 18 |
7 files changed, 156 insertions, 45 deletions
diff --git a/test/422-type-conversion/src/Main.java b/test/422-type-conversion/src/Main.java index 88b45280ac..0bf958541b 100644 --- a/test/422-type-conversion/src/Main.java +++ b/test/422-type-conversion/src/Main.java @@ -24,6 +24,12 @@ public class Main { } } + public static void assertShortEquals(short expected, short result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + public static void assertIntEquals(int expected, int result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); @@ -39,23 +45,32 @@ public class Main { public static void assertCharEquals(char expected, char result) { if (expected != result) { // Values are cast to int to display numeric values instead of - // (Unicode) characters. + // (UTF-16 encoded) characters. throw new Error("Expected: " + (int)expected + ", found: " + (int)result); } } public static void main(String[] args) { + // Generate, compile and check int-to-long Dex instructions. byteToLong(); shortToLong(); intToLong(); charToLong(); + // Generate, compile and check long-to-int Dex instructions. longToInt(); + // Generate, compile and check int-to-byte Dex instructions. shortToByte(); intToByte(); charToByte(); + // Generate, compile and check int-to-short Dex instructions. + byteToShort(); + intToShort(); + charToShort(); + + // Generate, compile and check int-to-char Dex instructions. byteToChar(); shortToChar(); intToChar(); @@ -100,10 +115,6 @@ public class Main { assertLongEquals(51L, $opt$CharToLong((char)51)); assertLongEquals(32767L, $opt$CharToLong((char)32767)); // 2^15 - 1 assertLongEquals(65535L, $opt$CharToLong((char)65535)); // 2^16 - 1 - - assertLongEquals(0L, $opt$CharToLong('\u0000')); - assertLongEquals(65535L, $opt$CharToLong('\uFFFF')); // 2^16 - 1 - assertLongEquals(65535L, $opt$CharToLong((char)-1)); assertLongEquals(65485L, $opt$CharToLong((char)-51)); assertLongEquals(32769L, $opt$CharToLong((char)-32767)); // -(2^15 - 1) @@ -175,10 +186,6 @@ public class Main { assertByteEquals((byte)-128, $opt$CharToByte((char)128)); // 2^7 assertByteEquals((byte)-1, $opt$CharToByte((char)32767)); // 2^15 - 1 assertByteEquals((byte)-1, $opt$CharToByte((char)65535)); // 2^16 - 1 - - assertByteEquals((byte)0, $opt$CharToByte('\u0000')); - assertByteEquals((byte)-1, $opt$CharToByte('\uFFFF')); // 2^16 - 1 - assertByteEquals((byte)-1, $opt$CharToByte((char)-1)); assertByteEquals((byte)-51, $opt$CharToByte((char)-51)); assertByteEquals((byte)-127, $opt$CharToByte((char)-127)); // -(2^7 - 1) @@ -186,6 +193,47 @@ public class Main { assertByteEquals((byte)127, $opt$CharToByte((char)-129)); // -(2^7 + 1) } + private static void byteToShort() { + assertShortEquals((short)1, $opt$ByteToShort((byte)1)); + assertShortEquals((short)0, $opt$ByteToShort((byte)0)); + assertShortEquals((short)-1, $opt$ByteToShort((byte)-1)); + assertShortEquals((short)51, $opt$ByteToShort((byte)51)); + assertShortEquals((short)-51, $opt$ByteToShort((byte)-51)); + assertShortEquals((short)127, $opt$ByteToShort((byte)127)); // 2^7 - 1 + assertShortEquals((short)-127, $opt$ByteToShort((byte)-127)); // -(2^7 - 1) + assertShortEquals((short)-128, $opt$ByteToShort((byte)-128)); // -(2^7) + } + + private static void intToShort() { + assertShortEquals((short)1, $opt$IntToShort(1)); + assertShortEquals((short)0, $opt$IntToShort(0)); + assertShortEquals((short)-1, $opt$IntToShort(-1)); + assertShortEquals((short)51, $opt$IntToShort(51)); + assertShortEquals((short)-51, $opt$IntToShort(-51)); + assertShortEquals((short)32767, $opt$IntToShort(32767)); // 2^15 - 1 + assertShortEquals((short)-32767, $opt$IntToShort(-32767)); // -(2^15 - 1) + assertShortEquals((short)-32768, $opt$IntToShort(-32768)); // -(2^15) + assertShortEquals((short)-32768, $opt$IntToShort(32768)); // 2^15 + assertShortEquals((short)32767, $opt$IntToShort(-32769)); // -(2^15 + 1) + assertShortEquals((short)-1, $opt$IntToShort(2147483647)); // 2^31 - 1 + assertShortEquals((short)0, $opt$IntToShort(-2147483648)); // -(2^31) + } + + private static void charToShort() { + assertShortEquals((short)1, $opt$CharToShort((char)1)); + assertShortEquals((short)0, $opt$CharToShort((char)0)); + assertShortEquals((short)51, $opt$CharToShort((char)51)); + assertShortEquals((short)32767, $opt$CharToShort((char)32767)); // 2^15 - 1 + assertShortEquals((short)-32768, $opt$CharToShort((char)32768)); // 2^15 + assertShortEquals((short)-32767, $opt$CharToShort((char)32769)); // 2^15 + assertShortEquals((short)-1, $opt$CharToShort((char)65535)); // 2^16 - 1 + assertShortEquals((short)-1, $opt$CharToShort((char)-1)); + assertShortEquals((short)-51, $opt$CharToShort((char)-51)); + assertShortEquals((short)-32767, $opt$CharToShort((char)-32767)); // -(2^15 - 1) + assertShortEquals((short)-32768, $opt$CharToShort((char)-32768)); // -(2^15) + assertShortEquals((short)32767, $opt$CharToShort((char)-32769)); // -(2^15 + 1) + } + private static void byteToChar() { assertCharEquals((char)1, $opt$ByteToChar((byte)1)); assertCharEquals((char)0, $opt$ByteToChar((byte)0)); @@ -242,6 +290,11 @@ public class Main { static byte $opt$IntToByte(int a){ return (byte)a; } static byte $opt$CharToByte(char a){ return (byte)a; } + // These methods produce int-to-short Dex instructions. + static short $opt$ByteToShort(byte a){ return (short)a; } + static short $opt$IntToShort(int a){ return (short)a; } + static short $opt$CharToShort(char a){ return (short)a; } + // These methods produce int-to-char Dex instructions. static char $opt$ByteToChar(byte a){ return (char)a; } static char $opt$ShortToChar(short a){ return (char)a; } diff --git a/test/425-invoke-super/expected.txt b/test/425-invoke-super/expected.txt index e69de29bb2..f7f6ae4911 100644 --- a/test/425-invoke-super/expected.txt +++ b/test/425-invoke-super/expected.txt @@ -0,0 +1 @@ +Test started diff --git a/test/425-invoke-super/src/Main.java b/test/425-invoke-super/src/Main.java index 1fb62d0871..f3166fd35b 100644 --- a/test/425-invoke-super/src/Main.java +++ b/test/425-invoke-super/src/Main.java @@ -39,6 +39,8 @@ public class Main { } public static void main(String[] args) throws Exception { + // Workaround for b/18051191. + System.out.println("Test started"); assertEquals(1, new B().$opt$bar()); assertEquals(1, new C().$opt$bar()); assertEquals(1, new D().$opt$bar()); diff --git a/test/800-smali/expected.txt b/test/800-smali/expected.txt index 3e3955b106..f766b0a6cf 100644 --- a/test/800-smali/expected.txt +++ b/test/800-smali/expected.txt @@ -1,4 +1,5 @@ b/17790197 +b/17978759 FloatBadArgReg negLong Done! diff --git a/test/800-smali/smali/b_17978759.smali b/test/800-smali/smali/b_17978759.smali new file mode 100644 index 0000000000..07bcae5bb4 --- /dev/null +++ b/test/800-smali/smali/b_17978759.smali @@ -0,0 +1,28 @@ +.class public LB17978759; +.super Ljava/lang/Object; + + .method public constructor <init>()V + .registers 1 + invoke-direct {p0}, Ljava/lang/Object;-><init>()V + return-void + .end method + + .method public test()V + .registers 2 + + move-object v0, p0 + # v0 and p0 alias + monitor-enter p0 + # monitor-enter on p0 + monitor-exit v0 + # monitor-exit on v0, however, verifier doesn't track this and so this is + # a warning. Verifier will still think p0 is locked. + + move-object v0, p0 + # v0 will now appear locked. + monitor-enter v0 + # Attempt to lock v0 twice is a verifier failure. + monitor-exit v0 + + return-void + .end method diff --git a/test/800-smali/src/Main.java b/test/800-smali/src/Main.java index 87549d9fdb..014edc0fa4 100644 --- a/test/800-smali/src/Main.java +++ b/test/800-smali/src/Main.java @@ -15,6 +15,7 @@ */ import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.LinkedList; import java.util.List; @@ -49,6 +50,7 @@ public class Main { testCases = new LinkedList<TestCase>(); testCases.add(new TestCase("b/17790197", "B17790197", "getInt", null, null, 100)); + testCases.add(new TestCase("b/17978759", "B17978759", "test", null, new VerifyError(), null)); testCases.add(new TestCase("FloatBadArgReg", "FloatBadArgReg", "getInt", new Object[]{100}, null, 100)); testCases.add(new TestCase("negLong", "negLong", "negLong", null, null, 122142L)); @@ -66,47 +68,59 @@ public class Main { } private void runTest(TestCase tc) throws Exception { - Class<?> c = Class.forName(tc.testClass); - - Method[] methods = c.getDeclaredMethods(); - - // For simplicity we assume that test methods are not overloaded. So searching by name - // will give us the method we need to run. - Method method = null; - for (Method m : methods) { - if (m.getName().equals(tc.testMethodName)) { - method = m; - break; - } - } - - if (method == null) { - throw new IllegalArgumentException("Could not find test method " + tc.testMethodName + - " in class " + tc.testClass + " for test " + tc.testName); - } - Exception errorReturn = null; try { - Object retValue = method.invoke(null, tc.values); - if (tc.expectedException != null) { - errorReturn = new IllegalStateException("Expected an exception in test " + - tc.testName); + Class<?> c = Class.forName(tc.testClass); + + Method[] methods = c.getDeclaredMethods(); + + // For simplicity we assume that test methods are not overloaded. So searching by name + // will give us the method we need to run. + Method method = null; + for (Method m : methods) { + if (m.getName().equals(tc.testMethodName)) { + method = m; + break; + } } - if (tc.expectedReturn == null && retValue != null) { - errorReturn = new IllegalStateException("Expected a null result in test " + - tc.testName); - } else if (tc.expectedReturn != null && - (retValue == null || !tc.expectedReturn.equals(retValue))) { - errorReturn = new IllegalStateException("Expected return " + tc.expectedReturn + - ", but got " + retValue); + + if (method == null) { + errorReturn = new IllegalArgumentException("Could not find test method " + + tc.testMethodName + " in class " + + tc.testClass + " for test " + + tc.testName); + } else { + Object retValue; + if (Modifier.isStatic(method.getModifiers())) { + retValue = method.invoke(null, tc.values); + } else { + retValue = method.invoke(method.getDeclaringClass().newInstance(), tc.values); + } + if (tc.expectedException != null) { + errorReturn = new IllegalStateException("Expected an exception in test " + + tc.testName); + } + if (tc.expectedReturn == null && retValue != null) { + errorReturn = new IllegalStateException("Expected a null result in test " + + tc.testName); + } else if (tc.expectedReturn != null && + (retValue == null || !tc.expectedReturn.equals(retValue))) { + errorReturn = new IllegalStateException("Expected return " + + tc.expectedReturn + + ", but got " + retValue); + } else { + // Expected result, do nothing. + } } - } catch (Exception exc) { + } catch (Throwable exc) { if (tc.expectedException == null) { errorReturn = new IllegalStateException("Did not expect exception", exc); } else if (!tc.expectedException.getClass().equals(exc.getClass())) { errorReturn = new IllegalStateException("Expected " + - tc.expectedException.getClass().getName() + - ", but got " + exc.getClass(), exc); + tc.expectedException.getClass().getName() + + ", but got " + exc.getClass(), exc); + } else { + // Expected exception, do nothing. } } finally { if (errorReturn != null) { diff --git a/test/run-test b/test/run-test index b43668d0e8..843714b949 100755 --- a/test/run-test +++ b/test/run-test @@ -501,6 +501,8 @@ if ! ulimit -S "$file_size_limit"; then fi good="no" +good_build="yes" +good_run="yes" if [ "$dev_mode" = "yes" ]; then "./${build}" 2>&1 build_exit="$?" @@ -548,7 +550,15 @@ else if [ "$build_exit" = '0' ]; then echo "${test_dir}: running..." 1>&2 "./${run}" $run_args "$@" >"$output" 2>&1 + run_exit="$?" + if [ "$run_exit" != "0" ]; then + echo "run exit status: $run_exit" 1>&2 + good_run="no" + else + good_run="yes" + fi else + good_build="no" cp "$build_output" "$output" echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output" echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output" @@ -561,9 +571,11 @@ else fi ./$check_cmd "$expected" "$output" if [ "$?" = "0" ]; then - # output == expected - good="yes" - echo "${test_dir}: succeeded!" 1>&2 + if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then + # output == expected + good="yes" + echo "${test_dir}: succeeded!" 1>&2 + fi fi fi |