Search
lxdream.org :: lxdream/test/sh4/testsh4.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testsh4.c
changeset 1192:ba3df0bf2c23
prev1083:34895c8bab20
author nkeynes
date Fri Aug 24 08:53:50 2012 +1000 (11 years ago)
permissions -rw-r--r--
last change Move the generated prologue/epilogue code out into a common entry stub
(reduces space requirements) and pre-save all saved registers. Change
FASTCALL to use 3 regs instead of 2 since we can now keep everything in
regs.
view annotate diff log raw
     1 #include <stdio.h>
     2 #include "../lib.h"
     4 int total_tests = 0;
     5 int total_fails = 0;
     7 void test_print_float_error( int expect, int actual )
     8 {
     9     fprintf( stderr, "Error: expected 0x%08x but was 0x%08x\n", expect, actual );
    10 }
    12 int test_print_result( char *testname, int failed, int total )
    13 {
    14     fprintf( stdout, "%s: %d/%d tests passed\n", testname, total-failed, total );
    15     total_tests += total;
    16     total_fails += failed;
    17     return failed;
    18 }
    20 void test_print_failure( char *testname, int number, char *message )
    21 {
    22     if( message == NULL ) {
    23 	fprintf( stderr, "%s: Test %d failed!\n", testname, number );
    24     } else {
    25 	fprintf( stderr, "%s: Test %d failed: %s\n", testname, number, message );
    26     }
    27 }
    29 extern unsigned int interrupt_pc;
    30 extern unsigned int interrupt_count;
    32 int assert_exception_caught( char *testname, int number, unsigned int expectedpc ) 
    33 {
    34     if( interrupt_count == 0 ) {
    35 	fprintf( stderr, "%s: Test %d failed: Expected exception not delivered\n",
    36 		 testname, number );
    37 	return 1;
    38     } else if( interrupt_count != 1 ) {
    39 	fprintf( stderr, "%s: Test %d failed: Expected exception delivered %d times!\n",
    40 		 testname, number, interrupt_count );
    41 	return 1;
    42     } else if( interrupt_pc != expectedpc ) {
    43 	fprintf( stderr, "%s: Test %d failed: Expected exception at PC %08X, but was %08X\n",
    44 		 testname, number, expectedpc, interrupt_pc );
    45 	return 1;
    46     } else {
    47 	return 0;
    48     }
    49 }
    51 int assert_tlb_exception_caught( char *testname, int number, unsigned int expectedpc,
    52 				 unsigned int vpn )
    53 {
    54     if( assert_exception_caught(testname, number, expectedpc) == 1 ) {
    55 	return 1;
    56     }
    58     unsigned int pteh = long_read(0xFF000000);
    59     if( (pteh & 0xFFFFFC00) != (vpn & 0xFFFFFC00) ) {
    60 	fprintf(stderr, "%s: Test %d failed: Expected PTEH.VPN = %08X, but was %08X\n",
    61 		testname, number, (vpn>>10), (pteh>>10) );
    62 	return 1;
    63     }
    65     unsigned int tea = long_read(0xFF00000C);
    66     if( tea != vpn ) {
    67 	fprintf(stderr, "%s: Test %d failed: Expected TEA = %08X, but was %08X\n",
    68 		testname, number, vpn, tea );
    69 	return 1;
    70     }
    71     return 0;
    72 }
    74 int main()
    75 {
    76     fprintf( stdout, "Instruction tests...\n" );
    77     install_interrupt_handler();
    78     test_add();
    79     test_addc();
    80     test_addv();
    81     test_and();
    82     test_andi();
    83     test_bf(); 
    84     test_bt();
    85     test_bsr();
    86     test_cmp();
    87     test_cmpstr();
    88     test_div0();
    89     test_div1();
    90     test_float();
    91     test_fsrra();
    92     test_fmov();
    93     test_ftrc();
    94     test_ldc();
    95     test_mac();
    96     test_rot();
    97     test_shl();
    98     test_shld();
    99     test_sub();
   100     test_subc();
   101     test_subv();
   102     test_trapa();
   103     test_tas();
   104     test_xtrct();
   105     fprintf( stdout, "--> %d/%d instruction tests passed (%d%%)\n\n",
   106 	     total_tests-total_fails, total_tests, 
   107 	     ((total_tests-total_fails)*100)/total_tests );
   109     fprintf( stdout, "Exception tests...\n" );
   110     test_slot_illegal();
   111     test_undefined();
   112     test_tlb();
   113     test_vmexit();
   114     remove_interrupt_handler();
   116     fprintf( stdout, "Total: %d/%d tests passed (%d%%)\n", total_tests-total_fails,
   117 	     total_tests, ((total_tests-total_fails)*100)/total_tests );
   118     return total_fails;
   119 }
.