Search
lxdream.org :: lxdream/test/sh4/testsh4.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testsh4.c
changeset 228:70adc8ffa8d1
prev226:0eeeb25447d3
next231:a9e61a96a885
author nkeynes
date Mon Sep 25 11:13:56 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Commit BF tests and initial exception handler
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@225
     8
    fprintf( stderr, "%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@228
    47
    install_interrupt_handler();
nkeynes@225
    48
    test_add();
nkeynes@226
    49
    test_addc();
nkeynes@226
    50
    test_addv();
nkeynes@226
    51
    test_and();
nkeynes@226
    52
    test_andi();
nkeynes@228
    53
    test_bf(); 
nkeynes@228
    54
    remove_interrupt_handler();
nkeynes@226
    55
nkeynes@226
    56
    fprintf( stderr, "Total: %d/%d tests passed (%d%%)\n", total_tests-total_fails,
nkeynes@226
    57
	     total_tests, ((total_tests-total_fails)*100)/total_tests );
nkeynes@225
    58
}
.