filename | test/sh4/testsh4.c |
changeset | 1083:34895c8bab20 |
prev | 976:e57a25d9eb7d |
next | 1192:ba3df0bf2c23 |
author | nkeynes |
date | Wed Dec 02 10:36:49 2009 +1000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Add missing SUBV instruction to the emulation core (translation core is ok), along with test cases. Thanks to D. Jeff Dionne for pointing this out. |
view | annotate | diff | log | raw |
1 #include <stdio.h>
2 #include "../lib.h"
4 int total_tests = 0;
5 int total_fails = 0;
7 int test_print_result( char *testname, int failed, int total )
8 {
9 fprintf( stdout, "%s: %d/%d tests passed\n", testname, total-failed, total );
10 total_tests += total;
11 total_fails += failed;
12 return failed;
13 }
15 void test_print_failure( char *testname, int number, char *message )
16 {
17 if( message == NULL ) {
18 fprintf( stderr, "%s: Test %d failed!\n", testname, number );
19 } else {
20 fprintf( stderr, "%s: Test %d failed: %s\n", testname, number, message );
21 }
22 }
24 extern unsigned int interrupt_pc;
25 extern unsigned int interrupt_count;
27 int assert_exception_caught( char *testname, int number, unsigned int expectedpc )
28 {
29 if( interrupt_count == 0 ) {
30 fprintf( stderr, "%s: Test %d failed: Expected exception not delivered\n",
31 testname, number );
32 return 1;
33 } else if( interrupt_count != 1 ) {
34 fprintf( stderr, "%s: Test %d failed: Expected exception delivered %d times!\n",
35 testname, number, interrupt_count );
36 return 1;
37 } else if( interrupt_pc != expectedpc ) {
38 fprintf( stderr, "%s: Test %d failed: Expected exception at PC %08X, but was %08X\n",
39 testname, number, expectedpc, interrupt_pc );
40 return 1;
41 } else {
42 return 0;
43 }
44 }
46 int assert_tlb_exception_caught( char *testname, int number, unsigned int expectedpc,
47 unsigned int vpn )
48 {
49 if( assert_exception_caught(testname, number, expectedpc) == 1 ) {
50 return 1;
51 }
53 unsigned int pteh = long_read(0xFF000000);
54 if( (pteh & 0xFFFFFC00) != (vpn & 0xFFFFFC00) ) {
55 fprintf(stderr, "%s: Test %d failed: Expected PTEH.VPN = %08X, but was %08X\n",
56 testname, number, (vpn>>10), (pteh>>10) );
57 return 1;
58 }
60 unsigned int tea = long_read(0xFF00000C);
61 if( tea != vpn ) {
62 fprintf(stderr, "%s: Test %d failed: Expected TEA = %08X, but was %08X\n",
63 testname, number, vpn, tea );
64 return 1;
65 }
66 return 0;
67 }
69 int main()
70 {
71 fprintf( stdout, "Instruction tests...\n" );
72 install_interrupt_handler();
73 test_add();
74 test_addc();
75 test_addv();
76 test_and();
77 test_andi();
78 test_bf();
79 test_bt();
80 test_bsr();
81 test_cmp();
82 test_cmpstr();
83 test_div0();
84 test_div1();
85 test_float();
86 test_fmov();
87 test_ftrc();
88 test_ldc();
89 test_mac();
90 test_rot();
91 test_shl();
92 test_shld();
93 test_sub();
94 test_subc();
95 test_subv();
96 test_trapa();
97 test_tas();
98 test_xtrct();
99 fprintf( stdout, "--> %d/%d instruction tests passed (%d%%)\n\n",
100 total_tests-total_fails, total_tests,
101 ((total_tests-total_fails)*100)/total_tests );
103 fprintf( stdout, "Exception tests...\n" );
104 test_slot_illegal();
105 test_undefined();
106 test_tlb();
107 test_vmexit();
108 remove_interrupt_handler();
110 fprintf( stdout, "Total: %d/%d tests passed (%d%%)\n", total_tests-total_fails,
111 total_tests, ((total_tests-total_fails)*100)/total_tests );
112 return total_fails;
113 }
.