Search
lxdream.org :: lxdream/src/test/testxlt.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/test/testxlt.c
changeset 515:5e5bb1dd369e
prev363:7d0bab24016c
next561:533f6b478071
author nkeynes
date Thu Nov 15 08:17:17 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Fix compilation of the unit tests
file annotate diff log raw
nkeynes@363
     1
#include <assert.h>
nkeynes@363
     2
#include "sh4/xltcache.h"
nkeynes@363
     3
#include "dreamcast.h"
nkeynes@363
     4
nkeynes@363
     5
extern xlat_cache_block_t xlat_new_cache;
nkeynes@363
     6
extern xlat_cache_block_t xlat_new_cache_ptr;
nkeynes@363
     7
extern xlat_cache_block_t xlat_temp_cache;
nkeynes@363
     8
extern xlat_cache_block_t xlat_temp_cache_ptr;
nkeynes@363
     9
nkeynes@363
    10
/**
nkeynes@363
    11
 * Test initial allocations from the new cache
nkeynes@363
    12
 */
nkeynes@363
    13
void test_initial()
nkeynes@363
    14
{
nkeynes@363
    15
    int i;
nkeynes@363
    16
    xlat_cache_block_t block = xlat_start_block( 0x0C008000 );
nkeynes@363
    17
    assert( block->active == 1 );
nkeynes@363
    18
    assert( block->size == XLAT_NEW_CACHE_SIZE - (2*sizeof(struct xlat_cache_block)) );
nkeynes@363
    19
    memset( block->code, 0xB5, 8192 );
nkeynes@515
    20
    xlat_commit_block( 8192, 100 );
nkeynes@363
    21
    assert( block->active == 1 );
nkeynes@363
    22
    assert( block->size == 8192 );
nkeynes@363
    23
    
nkeynes@363
    24
    int size = XLAT_NEW_CACHE_SIZE - (4*sizeof(struct xlat_cache_block)) - 8192 - 4096;
nkeynes@363
    25
    xlat_cache_block_t block2 = xlat_start_block( 0x0C009000 );
nkeynes@363
    26
    assert( block2->active == 1 );
nkeynes@363
    27
    assert( block2->size == XLAT_NEW_CACHE_SIZE - (3*sizeof(struct xlat_cache_block)) - 8192 );
nkeynes@363
    28
    memset( block2->code, 0x6D, size );
nkeynes@515
    29
    xlat_commit_block( size, 200 );
nkeynes@363
    30
    assert( block2->active == 1 );
nkeynes@363
    31
    assert( block2->size == size );
nkeynes@363
    32
    
nkeynes@363
    33
    void *addr = xlat_get_code( 0x0C008000 );
nkeynes@363
    34
    assert( addr == &block->code );
nkeynes@363
    35
    addr = xlat_get_code( 0x0C009000 );
nkeynes@363
    36
    assert( addr == &block2->code );
nkeynes@363
    37
    addr = xlat_get_code( 0x0C008002 );
nkeynes@363
    38
    assert( addr == NULL );
nkeynes@363
    39
    
nkeynes@363
    40
    xlat_cache_block_t block3 = xlat_start_block( 0x0D009800 );
nkeynes@363
    41
    assert( block3->active == 1 );
nkeynes@363
    42
    assert( block3->size == 4096 );
nkeynes@363
    43
    memset( block3->code, 0x9C, 4096 );
nkeynes@515
    44
    xlat_cache_block_t block3a = xlat_extend_block(8192);
nkeynes@363
    45
    assert( block3a != block3 );
nkeynes@363
    46
    assert( block3a == block );
nkeynes@363
    47
    assert( block3a->active == 1 );
nkeynes@363
    48
    assert( block3a->size = 8192 );
nkeynes@363
    49
    assert( block3->active == 0 );
nkeynes@363
    50
    assert( block3->size == 4096 );
nkeynes@363
    51
    for( i=0; i<4096; i++ ) {
nkeynes@363
    52
	assert( block3a->code[i] == 0x9C );
nkeynes@363
    53
    }
nkeynes@363
    54
    for( i=4096; i<8192; i++ ) {
nkeynes@363
    55
	assert( block3a->code[i] == 0xB5 );
nkeynes@363
    56
    }
nkeynes@515
    57
    xlat_commit_block(6142, 432);
nkeynes@363
    58
    addr = xlat_get_code( 0x0D009800 );
nkeynes@363
    59
    assert( addr == &block3a->code );
nkeynes@363
    60
    /* check promoted block in temp cache */
nkeynes@363
    61
    addr = xlat_get_code( 0x0C008000 );
nkeynes@363
    62
    assert( addr == &xlat_temp_cache->code );
nkeynes@363
    63
    assert( xlat_temp_cache->active == 1 );
nkeynes@363
    64
    assert( xlat_temp_cache->size == 8192 );
nkeynes@363
    65
    for( i=0; i<8192; i++ ) {
nkeynes@363
    66
	assert( xlat_temp_cache->code[i] == 0xB5 );
nkeynes@363
    67
    }
nkeynes@363
    68
}
nkeynes@363
    69
nkeynes@363
    70
int main()
nkeynes@363
    71
{
nkeynes@363
    72
    xlat_cache_init();
nkeynes@363
    73
    xlat_check_integrity();
nkeynes@363
    74
    
nkeynes@363
    75
    test_initial();
nkeynes@363
    76
    return 0;
nkeynes@363
    77
}
.