Search
lxdream.org :: lxdream/test/sh4/testsh4.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testsh4.c
changeset 555:309c97260912
prev533:9764673fd4a5
next808:da414654f3fa
author nkeynes
date Tue Jan 15 20:50:23 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Merged lxdream-mmu r570:596 to trunk
file annotate diff log raw
nkeynes@225
     1
#include <stdio.h>
nkeynes@555
     2
#include "../lib.h"
nkeynes@225
     3
nkeynes@226
     4
int total_tests = 0;
nkeynes@226
     5
int total_fails = 0;
nkeynes@226
     6
nkeynes@225
     7
int test_print_result( char *testname, int failed, int total )
nkeynes@225
     8
{
nkeynes@231
     9
    fprintf( stdout, "%s: %d/%d tests passed\n", testname, total-failed, total );
nkeynes@226
    10
    total_tests += total;
nkeynes@226
    11
    total_fails += failed;
nkeynes@225
    12
    return failed;
nkeynes@225
    13
}
nkeynes@225
    14
nkeynes@226
    15
void test_print_failure( char *testname, int number, char *message )
nkeynes@225
    16
{
nkeynes@226
    17
    if( message == NULL ) {
nkeynes@226
    18
	fprintf( stderr, "%s: Test %d failed!\n", testname, number );
nkeynes@226
    19
    } else {
nkeynes@226
    20
	fprintf( stderr, "%s: Test %d failed: %s\n", testname, number, message );
nkeynes@226
    21
    }
nkeynes@225
    22
}
nkeynes@225
    23
nkeynes@228
    24
extern unsigned int interrupt_pc;
nkeynes@228
    25
extern unsigned int interrupt_count;
nkeynes@228
    26
nkeynes@228
    27
int assert_exception_caught( char *testname, int number, unsigned int expectedpc ) 
nkeynes@228
    28
{
nkeynes@228
    29
    if( interrupt_count == 0 ) {
nkeynes@228
    30
	fprintf( stderr, "%s: Test %d failed: Expected exception not delivered\n",
nkeynes@228
    31
		 testname, number );
nkeynes@228
    32
	return 1;
nkeynes@228
    33
    } else if( interrupt_count != 1 ) {
nkeynes@228
    34
	fprintf( stderr, "%s: Test %d failed: Expected exception delivered %d times!\n",
nkeynes@228
    35
		 testname, number, interrupt_count );
nkeynes@228
    36
	return 1;
nkeynes@228
    37
    } else if( interrupt_pc != expectedpc ) {
nkeynes@228
    38
	fprintf( stderr, "%s: Test %d failed: Expected exception at PC %08X, but was %08X\n",
nkeynes@228
    39
		 testname, number, expectedpc, interrupt_pc );
nkeynes@228
    40
	return 1;
nkeynes@228
    41
    } else {
nkeynes@228
    42
	return 0;
nkeynes@228
    43
    }
nkeynes@228
    44
}
nkeynes@228
    45
nkeynes@555
    46
int assert_tlb_exception_caught( char *testname, int number, unsigned int expectedpc,
nkeynes@555
    47
				 unsigned int vpn )
nkeynes@555
    48
{
nkeynes@555
    49
    if( assert_exception_caught(testname, number, expectedpc) == 1 ) {
nkeynes@555
    50
	return 1;
nkeynes@555
    51
    }
nkeynes@555
    52
    
nkeynes@555
    53
    unsigned int pteh = long_read(0xFF000000);
nkeynes@555
    54
    if( (pteh & 0xFFFFFC00) != (vpn & 0xFFFFFC00) ) {
nkeynes@555
    55
	fprintf(stderr, "%s: Test %d failed: Expected PTEH.VPN = %08X, but was %08X\n",
nkeynes@555
    56
		testname, number, (vpn>>10), (pteh>>10) );
nkeynes@555
    57
	return 1;
nkeynes@555
    58
    }
nkeynes@555
    59
nkeynes@555
    60
    unsigned int tea = long_read(0xFF00000C);
nkeynes@555
    61
    if( tea != vpn ) {
nkeynes@555
    62
	fprintf(stderr, "%s: Test %d failed: Expected TEA = %08X, but was %08X\n",
nkeynes@555
    63
		testname, number, vpn, tea );
nkeynes@555
    64
	return 1;
nkeynes@555
    65
    }
nkeynes@555
    66
    return 0;
nkeynes@555
    67
}
nkeynes@555
    68
nkeynes@225
    69
int main()
nkeynes@225
    70
{
nkeynes@231
    71
    fprintf( stdout, "Instruction tests...\n" );
nkeynes@228
    72
    install_interrupt_handler();
nkeynes@225
    73
    test_add();
nkeynes@226
    74
    test_addc();
nkeynes@226
    75
    test_addv();
nkeynes@226
    76
    test_and();
nkeynes@226
    77
    test_andi();
nkeynes@228
    78
    test_bf(); 
nkeynes@231
    79
    test_bt();
nkeynes@404
    80
    test_bsr();
nkeynes@231
    81
    test_cmp();
nkeynes@364
    82
    test_cmpstr();
nkeynes@364
    83
    test_div0();
nkeynes@384
    84
    test_div1();
nkeynes@357
    85
    test_float();
nkeynes@358
    86
    test_fmov();
nkeynes@357
    87
    test_ftrc();
nkeynes@358
    88
    test_mac();
nkeynes@396
    89
    test_rot();
nkeynes@396
    90
    test_shl();
nkeynes@364
    91
    test_shld();
nkeynes@393
    92
    test_sub();
nkeynes@393
    93
    test_subc();
nkeynes@533
    94
    test_trapa();
nkeynes@399
    95
    test_tas();
nkeynes@393
    96
    test_xtrct();
nkeynes@231
    97
    fprintf( stdout, "--> %d/%d instruction tests passed (%d%%)\n\n",
nkeynes@231
    98
	     total_tests-total_fails, total_tests, 
nkeynes@231
    99
	     ((total_tests-total_fails)*100)/total_tests );
nkeynes@231
   100
nkeynes@231
   101
    fprintf( stdout, "Exception tests...\n" );
nkeynes@231
   102
    test_slot_illegal();
nkeynes@233
   103
    test_undefined();
nkeynes@555
   104
    test_tlb();
nkeynes@228
   105
    remove_interrupt_handler();
nkeynes@226
   106
nkeynes@231
   107
    fprintf( stdout, "Total: %d/%d tests passed (%d%%)\n", total_tests-total_fails,
nkeynes@226
   108
	     total_tests, ((total_tests-total_fails)*100)/total_tests );
nkeynes@522
   109
    return total_fails;
nkeynes@225
   110
}
.