Search
lxdream.org :: lxdream/test/sh4/testsh4.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testsh4.c
changeset 822:6e0536758465
prev808:da414654f3fa
next823:8a592668322f
author nkeynes
date Sat Aug 23 12:08:01 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Mask off SR correctly when writing to it - this turns out to be important
in some cases
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_ldcsr();
    89     test_mac();
    90     test_rot();
    91     test_shl();
    92     test_shld();
    93     test_sub();
    94     test_subc();
    95     test_trapa();
    96     test_tas();
    97     test_xtrct();
    98     fprintf( stdout, "--> %d/%d instruction tests passed (%d%%)\n\n",
    99 	     total_tests-total_fails, total_tests, 
   100 	     ((total_tests-total_fails)*100)/total_tests );
   102     fprintf( stdout, "Exception tests...\n" );
   103     test_slot_illegal();
   104     test_undefined();
   105     test_tlb();
   106     test_vmexit();
   107     remove_interrupt_handler();
   109     fprintf( stdout, "Total: %d/%d tests passed (%d%%)\n", total_tests-total_fails,
   110 	     total_tests, ((total_tests-total_fails)*100)/total_tests );
   111     return total_fails;
   112 }
.