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