Search
lxdream.org :: lxdream/test/sh4/testsh4.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testsh4.c
changeset 357:3592a10b3242
prev233:f8333b94f503
next358:65043a8f5785
author nkeynes
date Tue Feb 13 08:34:27 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Add tests for FLOAT and FTRC
Comment out user-mode exception test (broken)
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@231
    56
    test_cmp();
nkeynes@357
    57
    test_float();
nkeynes@357
    58
    test_ftrc();
nkeynes@231
    59
    fprintf( stdout, "--> %d/%d instruction tests passed (%d%%)\n\n",
nkeynes@231
    60
	     total_tests-total_fails, total_tests, 
nkeynes@231
    61
	     ((total_tests-total_fails)*100)/total_tests );
nkeynes@231
    62
nkeynes@231
    63
    fprintf( stdout, "Exception tests...\n" );
nkeynes@231
    64
    test_slot_illegal();
nkeynes@233
    65
    test_undefined();
nkeynes@228
    66
    remove_interrupt_handler();
nkeynes@226
    67
nkeynes@231
    68
    fprintf( stdout, "Total: %d/%d tests passed (%d%%)\n", total_tests-total_fails,
nkeynes@226
    69
	     total_tests, ((total_tests-total_fails)*100)/total_tests );
nkeynes@225
    70
}
.