Search
lxdream.org :: lxdream/test/sh4/testsh4.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testsh4.c
changeset 399:23e51a2b4f99
prev396:0738dbc01d95
next404:c5ed3c8642a2
author nkeynes
date Thu Sep 20 08:34:23 2007 +0000 (15 years ago)
permissions -rw-r--r--
last change Add tests for TAS.B
view annotate diff log raw
     1 #include <stdio.h>
     3 int total_tests = 0;
     4 int total_fails = 0;
     6 int test_print_result( char *testname, int failed, int total )
     7 {
     8     fprintf( stdout, "%s: %d/%d tests passed\n", testname, total-failed, total );
     9     total_tests += total;
    10     total_fails += failed;
    11     return failed;
    12 }
    14 void test_print_failure( char *testname, int number, char *message )
    15 {
    16     if( message == NULL ) {
    17 	fprintf( stderr, "%s: Test %d failed!\n", testname, number );
    18     } else {
    19 	fprintf( stderr, "%s: Test %d failed: %s\n", testname, number, message );
    20     }
    21 }
    23 extern unsigned int interrupt_pc;
    24 extern unsigned int interrupt_count;
    26 int assert_exception_caught( char *testname, int number, unsigned int expectedpc ) 
    27 {
    28     if( interrupt_count == 0 ) {
    29 	fprintf( stderr, "%s: Test %d failed: Expected exception not delivered\n",
    30 		 testname, number );
    31 	return 1;
    32     } else if( interrupt_count != 1 ) {
    33 	fprintf( stderr, "%s: Test %d failed: Expected exception delivered %d times!\n",
    34 		 testname, number, interrupt_count );
    35 	return 1;
    36     } else if( interrupt_pc != expectedpc ) {
    37 	fprintf( stderr, "%s: Test %d failed: Expected exception at PC %08X, but was %08X\n",
    38 		 testname, number, expectedpc, interrupt_pc );
    39 	return 1;
    40     } else {
    41 	return 0;
    42     }
    43 }
    45 int main()
    46 {
    47     fprintf( stdout, "Instruction tests...\n" );
    48     install_interrupt_handler();
    49     test_add();
    50     test_addc();
    51     test_addv();
    52     test_and();
    53     test_andi();
    54     test_bf(); 
    55     test_bt();
    56     test_cmp();
    57     test_cmpstr();
    58     test_div0();
    59     test_div1();
    60     test_float();
    61     test_fmov();
    62     test_ftrc();
    63     test_mac();
    64     test_rot();
    65     test_shl();
    66     test_shld();
    67     test_sub();
    68     test_subc();
    69     test_tas();
    70     test_xtrct();
    71     fprintf( stdout, "--> %d/%d instruction tests passed (%d%%)\n\n",
    72 	     total_tests-total_fails, total_tests, 
    73 	     ((total_tests-total_fails)*100)/total_tests );
    75     fprintf( stdout, "Exception tests...\n" );
    76     test_slot_illegal();
    77     test_undefined();
    78     remove_interrupt_handler();
    80     fprintf( stdout, "Total: %d/%d tests passed (%d%%)\n", total_tests-total_fails,
    81 	     total_tests, ((total_tests-total_fails)*100)/total_tests );
    82 }
.