filename | test/sh4/testsh4.c |
changeset | 976:e57a25d9eb7d |
prev | 823:8a592668322f |
next | 1083:34895c8bab20 |
author | nkeynes |
date | Tue Mar 24 11:15:57 2009 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Add preliminary implementation of the GDB remote debugging server - attaches to either or both the SH4 and ARM |
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 fprintf( stderr, "Fail" );
18 fprintf( stderr, testname );
20 if( message == NULL ) {
21 fprintf( stderr, "%s: Test %d failed!\n", testname, number );
22 } else {
23 fprintf( stderr, "%s: Test %d failed: %s\n", testname, number, message );
24 }
25 }
27 extern unsigned int interrupt_pc;
28 extern unsigned int interrupt_count;
30 int assert_exception_caught( char *testname, int number, unsigned int expectedpc )
31 {
32 if( interrupt_count == 0 ) {
33 fprintf( stderr, "%s: Test %d failed: Expected exception not delivered\n",
34 testname, number );
35 return 1;
36 } else if( interrupt_count != 1 ) {
37 fprintf( stderr, "%s: Test %d failed: Expected exception delivered %d times!\n",
38 testname, number, interrupt_count );
39 return 1;
40 } else if( interrupt_pc != expectedpc ) {
41 fprintf( stderr, "%s: Test %d failed: Expected exception at PC %08X, but was %08X\n",
42 testname, number, expectedpc, interrupt_pc );
43 return 1;
44 } else {
45 return 0;
46 }
47 }
49 int assert_tlb_exception_caught( char *testname, int number, unsigned int expectedpc,
50 unsigned int vpn )
51 {
52 if( assert_exception_caught(testname, number, expectedpc) == 1 ) {
53 return 1;
54 }
56 unsigned int pteh = long_read(0xFF000000);
57 if( (pteh & 0xFFFFFC00) != (vpn & 0xFFFFFC00) ) {
58 fprintf(stderr, "%s: Test %d failed: Expected PTEH.VPN = %08X, but was %08X\n",
59 testname, number, (vpn>>10), (pteh>>10) );
60 return 1;
61 }
63 unsigned int tea = long_read(0xFF00000C);
64 if( tea != vpn ) {
65 fprintf(stderr, "%s: Test %d failed: Expected TEA = %08X, but was %08X\n",
66 testname, number, vpn, tea );
67 return 1;
68 }
69 return 0;
70 }
72 int main()
73 {
74 fprintf( stdout, "Instruction tests...\n" );
75 install_interrupt_handler();
76 test_add();
77 test_addc();
78 test_addv();
79 test_and();
80 test_andi();
81 test_bf();
82 test_bt();
83 test_bsr();
84 test_cmp();
85 test_cmpstr();
86 test_div0();
87 test_div1();
88 test_float();
89 test_fmov();
90 test_ftrc();
91 test_ldc();
92 test_mac();
93 test_rot();
94 test_shl();
95 test_shld();
96 test_sub();
97 test_subc();
98 test_trapa();
99 test_tas();
100 test_xtrct();
101 fprintf( stdout, "--> %d/%d instruction tests passed (%d%%)\n\n",
102 total_tests-total_fails, total_tests,
103 ((total_tests-total_fails)*100)/total_tests );
105 fprintf( stdout, "Exception tests...\n" );
106 test_slot_illegal();
107 test_undefined();
108 test_tlb();
109 test_vmexit();
110 remove_interrupt_handler();
112 fprintf( stdout, "Total: %d/%d tests passed (%d%%)\n", total_tests-total_fails,
113 total_tests, ((total_tests-total_fails)*100)/total_tests );
114 return total_fails;
115 }
.