3 #define TEST(cond) test(#cond, (cond), __LINE__)
4 #define TODO() test("TODO: Implement", false, __LINE__)
8 static int s_i, s_i1, s_i2;
9 static float s_f, s_f1, s_f2;
10 static char s_c, s_c1;
11 static short s_s, s_s1;
12 static long s_l, s_l1, s_l2;
13 static double s_d, s_d1, s_d2;
16 static final char[] s_ca = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
17 static char[] s_ca2 = { '0', '1', '2' };
18 static String s_as0 = "s0", s_as1 = "s1", s_as2 = "s2";
19 static Object s_a0 = s_as0, s_a1 = s_as1, s_a2 = s_as2;
20 static Object[] s_aa = { s_a0, s_a1, s_a2 };
21 static Object[] s_aa2 = { null, null, null };
22 static byte[] s_bya = { 10, 11, 12, 13, 14, 15 };
23 static byte[] s_bya2 = { 0, 1, 2, 3};
24 static byte s_by, s_by1;
25 static short[] s_sa2 = { 0, 1, 2, 3};
26 static short[] s_sa = { 10, 11, 12, 13, 14, 15 };
27 static int[] s_ia2 = { 0, 1, 2, 3 };
28 static int[] s_ia = { 10, 11, 12, 13, 14, 15 };
30 static class members {
40 static class exception extends Exception {
47 static char s_cm() { return s_c; }
48 static short s_sm() { return s_s; }
49 static int s_im() { return s_i; }
50 static long s_lm() { return s_l; }
51 static Object s_am() { return s_a; }
52 static float s_fm() { return s_f; }
53 static double s_dm() { return s_d; }
55 static int s_testsOk = 0, s_testsFailure = 0;
57 static void test(String description, boolean success, int line) {
62 System.out.println(code + description + " (at line " + line + ")");
70 static void summary() {
73 (s_testsOk + s_testsFailure) + " tests, OK: " +
74 s_testsOk + ", FAILURE: " + s_testsFailure + "."
78 static void test_ICONST() {
90 TEST(s_i == 0x7fffffff);
91 TEST(s_i != 0x7ffffffe);
94 TEST(s_i == 0xffffffff);
95 TEST(s_i != 0x7fffffff);
98 static void test_FCONST() {
100 // load some float constant
108 static void test_INEG() {
116 // negate corner (-) value
120 TEST(s_i == 0x7fffffff);
123 static void test_INT2CHAR() {
131 TEST(s_c == (char)-1);
134 TEST(s_c == (char)-3);
137 static void test_IADD() {
154 static void test_IADDCONST() {
156 // valid (+) immediate
168 // valid (-) immediate
174 // big (+) immediate (datasegment)
178 TEST(s_i == 1001983);
180 // big (-) immediate (datasegment)
184 TEST(s_i == -20000000);
188 static void test_ISUB() {
190 // substract 2 (+) values
195 TEST(s_i == -9421338);
197 // substract 2 (-) values
202 TEST(s_i == 9421338);
205 static void test_ISUBCONST() {
207 // substract valid immediate
213 // substract big (+) immediate (datasegment)
217 TEST(s_i == -9421338);
225 // substract big (-) immediate (datasegment)
229 TEST(s_i == 9421338);
232 static void test_IMULCONST() {
244 TEST(s_i == 2000000);
246 // big immediate (datasegment)
250 TEST(s_i == 2000000);
253 static void test_IDIV() {
265 static void test_IREM() {
272 static void test_FMUL() {
276 TEST(s_f == 113.37f);
279 static void test_DMUL() {
284 System.out.println(s_d);
287 static void test_FDIV() {
291 TEST(s_f == 1.1337f);
294 static void test_DDIV() {
301 static void test_FSUB() {
305 TEST(s_f == 1.1007f);
308 static void test_DSUB() {
315 static void test_FADD() {
319 TEST(s_f == 1.1337f);
322 static void test_DADD() {
329 static void test_I2F() {
332 TEST(s_f == 1234567.0f);
338 static void test_I2D() {
342 static void test_F2I() {
351 static void test_FCMP() {
353 // tests FCMPL and FCMPG
358 // With ecj, FCMPG is generated for < and reverse !
372 s_b = (s_f2 == s_f1);
376 s_b = (s_f2 == s_f1);
380 // This might not work with compilers other than ecj
383 s_b = (s_f1 < s_f2); // this generates FCMPG with NaN -> GT
386 s_b = (s_f1 > s_f2); // this generates FCMPL whith NAN -> LT
389 s_b = (s_f1 == s_f2); // this generates FCMPXX with NAN -> XX
394 s_f1 = Float.NEGATIVE_INFINITY;
395 s_f2 = Float.POSITIVE_INFINITY;
401 s_b = (s_f1 == s_f2);
404 s_f1 = Float.NEGATIVE_INFINITY;
411 s_b = (s_f1 == s_f2);
415 s_f2 = Float.POSITIVE_INFINITY;
421 s_b = (s_f1 == s_f2);
425 static void test_ARRAYLENGTH() {
426 TEST(s_ca.length == 10);
427 TEST(s_ca.length != 11);
430 static void test_CALOAD() {
435 static void test_BALOAD() {
440 static void test_SALOAD() {
445 static void test_IALOAD() {
450 static void test_AALOAD() {
456 static void test_CASTORE() {
462 static void test_BASTORE() {
469 static void test_SASTORE() {
470 s_s1 = (short)0xbcde;
473 TEST(s_s == (short)0xbcde);
476 static void test_IASTORE() {
480 TEST(s_i == 0xbcde1234);
483 static void test_AASTORE() {
489 static void test_GETPUTSTATIC() {
505 s_l1 = 0x987AABBCCDDl;
507 TEST(s_l == 0x987AABBCCDDl);
518 static void test_IF_LXX_LCMPXX() {
519 // the tests generated are the negated tests
524 # define LTEST(val1, op, val2, expect) \
526 s_i = (s_l op val2 ? YES : NO); \
527 TEST(s_i == expect); \
530 s_i = (s_l1 op s_l2 ? YES : NO); \
535 LTEST(0xffABCDl, <, 0xffABCDl, NO);
536 LTEST(0xffABCDl, <=, 0xffABCDl, YES);
537 LTEST(0xffABCDl, >, 0xffABCDl, NO);
538 LTEST(0xffABCDl, >=, 0xffABCDl, YES);
539 LTEST(0xffABCDl, ==, 0xffABCDl, YES);
540 LTEST(0xffABCDl, !=, 0xffABCDl, NO);
542 LTEST(0xffABCDl, <, 0xfffABCDl, YES);
543 LTEST(0xffABCDl, <=, 0xfffABCDl, YES);
544 LTEST(0xffABCDl, >, 0xfffABCDl, NO);
545 LTEST(0xffABCDl, >=, 0xfffABCDl, NO);
546 LTEST(0xffABCDl, ==, 0xfffABCDl, NO);
547 LTEST(0xffABCDl, !=, 0xfffABCDl, YES);
549 LTEST(0xffABCDl, <, 0xfABCDl, NO);
550 LTEST(0xffABCDl, <=, 0xfABCDl, NO);
551 LTEST(0xffABCDl, >, 0xfABCDl, YES);
552 LTEST(0xffABCDl, >=, 0xfABCDl, YES);
553 LTEST(0xffABCDl, ==, 0xfABCDl, NO);
554 LTEST(0xffABCDl, !=, 0xfABCDl, YES);
558 LTEST(0xffAABBCCDDl, <, 0xffAABBCCDDl, NO);
559 LTEST(0xffAABBCCDDl, <=, 0xffAABBCCDDl, YES);
560 LTEST(0xffAABBCCDDl, >, 0xffAABBCCDDl, NO);
561 LTEST(0xffAABBCCDDl, >=, 0xffAABBCCDDl, YES);
562 LTEST(0xffAABBCCDDl, ==, 0xffAABBCCDDl, YES);
563 LTEST(0xffAABBCCDDl, !=, 0xffAABBCCDDl, NO);
565 LTEST(0xffAABBCCDDl, <, 0xfffAABBCCDDl, YES);
566 LTEST(0xffAABBCCDDl, <=, 0xfffAABBCCDDl, YES);
567 LTEST(0xffAABBCCDDl, >, 0xfffAABBCCDDl, NO);
568 LTEST(0xffAABBCCDDl, >=, 0xfffAABBCCDDl, NO);
569 LTEST(0xffAABBCCDDl, ==, 0xfffAABBCCDDl, NO);
570 LTEST(0xffAABBCCDDl, !=, 0xfffAABBCCDDl, YES);
572 LTEST(0xffAABBCCDDl, <, 0xfAABBCCDDl, NO);
573 LTEST(0xffAABBCCDDl, <=, 0xfAABBCCDDl, NO);
574 LTEST(0xffAABBCCDDl, >, 0xfAABBCCDDl, YES);
575 LTEST(0xffAABBCCDDl, >=, 0xfAABBCCDDl, YES);
576 LTEST(0xffAABBCCDDl, ==, 0xfAABBCCDDl, NO);
577 LTEST(0xffAABBCCDDl, !=, 0xfAABBCCDDl, YES);
579 // Greater in absolute value is negative
581 LTEST(0xffABCDl, <, -0xfffABCDl, NO);
582 LTEST(0xffABCDl, <=, -0xfffABCDl, NO);
583 LTEST(0xffABCDl, >, -0xfffABCDl, YES);
584 LTEST(0xffABCDl, >=, -0xfffABCDl, YES);
585 LTEST(0xffABCDl, ==, -0xfffABCDl, NO);
586 LTEST(0xffABCDl, !=, -0xfffABCDl, YES);
588 LTEST(-0xffABCDl, <, 0xfABCDl, YES);
589 LTEST(-0xffABCDl, <=, 0xfABCDl, YES);
590 LTEST(-0xffABCDl, >, 0xfABCDl, NO);
591 LTEST(-0xffABCDl, >=, 0xfABCDl, NO);
592 LTEST(-0xffABCDl, ==, 0xfABCDl, NO);
593 LTEST(-0xffABCDl, !=, 0xfABCDl, YES);
600 static void test_GETPUTFIELD() {
601 members m = new members();
618 s_l1 = 0x987AABBCCDDl;
620 TEST(m.l == 0x987AABBCCDDl);
631 static void doThrow(int line) throws exception {
632 throw new exception(line);
635 static void test_ATHROW() {
638 /* Propagate line in java source with exception.
639 * Then compare with line provided by exception stack trace.
644 throw new exception(s_i + 2);
645 } catch (exception e) {
648 //TEST(e.line == e.getStackTrace()[0].getLineNumber());
650 TEST(s_b); /* exception catched ? */
653 static void test_IFNULL() {
657 static void test_IFNONNULL() {
661 static void test_IFXX_ICMPXX() {
664 # define ITEST(val1, op, val2, expect) \
666 s_i = (s_i1 op val2 ? YES: NO); \
667 TEST(s_i == expect); \
670 s_i = (s_i1 op s_i2 ? YES: NO); \
673 ITEST(0xffABCD, <, 0xffABCD, NO);
674 ITEST(0xffABCD, <=, 0xffABCD, YES);
675 ITEST(0xffABCD, >, 0xffABCD, NO);
676 ITEST(0xffABCD, >=, 0xffABCD, YES);
677 ITEST(0xffABCD, ==, 0xffABCD, YES);
678 ITEST(0xffABCD, !=, 0xffABCD, NO);
680 ITEST(0xffABCD, <, 0xfffABCD, YES);
681 ITEST(0xffABCD, <=, 0xfffABCD, YES);
682 ITEST(0xffABCD, >, 0xfffABCD, NO);
683 ITEST(0xffABCD, >=, 0xfffABCD, NO);
684 ITEST(0xffABCD, ==, 0xfffABCD, NO);
685 ITEST(0xffABCD, !=, 0xfffABCD, YES);
687 ITEST(0xffABCD, <, 0xfABCD, NO);
688 ITEST(0xffABCD, <=, 0xfABCD, NO);
689 ITEST(0xffABCD, >, 0xfABCD, YES);
690 ITEST(0xffABCD, >=, 0xfABCD, YES);
691 ITEST(0xffABCD, ==, 0xfABCD, NO);
692 ITEST(0xffABCD, !=, 0xfABCD, YES);
694 // Greater in absolute value is negative
696 ITEST(0xffABCD, <, -0xfffABCD, NO);
697 ITEST(0xffABCD, <=, -0xfffABCD, NO);
698 ITEST(0xffABCD, >, -0xfffABCD, YES);
699 ITEST(0xffABCD, >=, -0xfffABCD, YES);
700 ITEST(0xffABCD, ==, -0xfffABCD, NO);
701 ITEST(0xffABCD, !=, -0xfffABCD, YES);
703 ITEST(-0xffABCD, <, 0xfABCD, YES);
704 ITEST(-0xffABCD, <=, 0xfABCD, YES);
705 ITEST(-0xffABCD, >, 0xfABCD, NO);
706 ITEST(-0xffABCD, >=, 0xfABCD, NO);
707 ITEST(-0xffABCD, ==, 0xfABCD, NO);
708 ITEST(-0xffABCD, !=, 0xfABCD, YES);
715 static void test_IF_ACMPXX() {
716 s_i = (s_a1 == s_a1 ? 10 : 20);
718 s_i = (s_a1 != s_a1 ? 10 : 20);
720 s_i = (s_a1 == s_a2 ? 10 : 20);
722 s_i = (s_a1 != s_a2 ? 10 : 20);
726 static void test_XRETURN() {
727 # define RTEST(type, value) \
729 s_##type##1 = s_##type##m(); \
730 TEST(s_##type##1 == value);
734 RTEST(i, 0xFFEEDDCC);
735 RTEST(l, 0xAABBCCDD11223344l);
743 static interface i1 { };
744 static interface i2 { };
745 static interface i3 extends i2 { };
746 static interface i4 extends i3 { };
747 static interface i5 { };
749 static class c2 extends c1 implements i1 { };
750 static class c3 extends c2 implements i4 { };
753 static void test_INSTANCEOF() {
755 TEST(x instanceof i1);
756 TEST(x instanceof i2);
757 TEST(x instanceof i3);
758 TEST(x instanceof i4);
759 TEST(! (x instanceof i5));
760 TEST(! (x instanceof java.lang.Runnable));
761 TEST(x instanceof c1);
762 TEST(x instanceof c2);
763 TEST(x instanceof c3);
764 TEST(! (x instanceof c4));
765 TEST(! (x instanceof java.lang.String));
766 TEST(x instanceof java.lang.Object);
769 static void test_CHECKCAST() {
772 # define TESTCAST(klass, res) \
775 klass y = (klass)x; \
776 } catch (ClassCastException e) { \
786 TESTCAST(java.lang.Runnable, false);
791 TESTCAST(java.lang.String, false);
792 TESTCAST(java.lang.Object, true);
798 static void test_emit_exception_stubs() {
802 } catch (ArrayIndexOutOfBoundsException e) {
809 } catch (ArrayIndexOutOfBoundsException e) {
815 static void test_IAND() {
819 TEST(s_i == 0x0c080400);
821 static void test_IOR() {
825 TEST(s_i == 0x1a2b3c5d);
827 static void test_IXOR() {
831 TEST(s_i == 0xff002400);
833 // xor swapping algorithm
842 TEST(s_i2 == 0xa75bced8);
843 TEST(s_i1 == 0x1458aa56);
846 static void main(String[] args) {
869 test_IF_LXX_LCMPXX();
878 test_emit_exception_stubs();