Search
lxdream.org :: lxdream/test/lib.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/lib.c
changeset 190:f7653df5e832
prev185:6755a04c447f
author nkeynes
date Fri Aug 18 09:33:19 2006 +0000 (16 years ago)
permissions -rw-r--r--
last change Initial rendering tests (no support for result comparison yet)
file annotate diff log raw
nkeynes@185
     1
#include "lib.h"
nkeynes@185
     2
nkeynes@185
     3
void fwrite_dump( FILE *f, char *buf, int length)
nkeynes@185
     4
{
nkeynes@185
     5
    int i,j;
nkeynes@185
     6
    for( i=0; i<length; i+=16 ) {
nkeynes@185
     7
	fprintf( f, "%08X: ", i );
nkeynes@185
     8
        for( j=0; j<16 && i+j < length; j+=4 ) {
nkeynes@185
     9
	    unsigned int val = *((volatile unsigned int *)(buf+i+j));
nkeynes@185
    10
	    fprintf( f, "%02X %02X %02X %02X  ", val&0xFF, (val>>8)&0xFF, (val>>16)&0xFF, (val>>24)&0xFF );
nkeynes@185
    11
        }
nkeynes@185
    12
        for( ;j<16; j+= 4 ) {
nkeynes@185
    13
            fprintf( f, "             " );
nkeynes@185
    14
        }
nkeynes@185
    15
	for( j=0; j<16 && i+j < length; j++ ) {
nkeynes@185
    16
	    fprintf( f, "%c", isprint(buf[i+j]) ? buf[i+j] : '.' );
nkeynes@185
    17
	}
nkeynes@185
    18
	fprintf( f, "\n");
nkeynes@185
    19
    }
nkeynes@185
    20
}
nkeynes@190
    21
nkeynes@190
    22
void fwrite_diff( FILE *f,  char *a, int a_length, char *b, int b_length )
nkeynes@190
    23
{
nkeynes@190
    24
    int i;
nkeynes@190
    25
    fprintf( f, "Expected %d bytes:\n", a_length );
nkeynes@190
    26
    fwrite_dump( f, a, a_length );
nkeynes@190
    27
    fprintf( f, "but was %d bytes =>\n", b_length );
nkeynes@190
    28
    fwrite_dump( f, b, b_length );
nkeynes@190
    29
}
nkeynes@190
    30
nkeynes@190
    31
void fwrite_diff32( FILE *f, char *a, int a_length, char *b, int b_length )
nkeynes@190
    32
{
nkeynes@190
    33
    int i,j, k;
nkeynes@190
    34
    int length = a_length > b_length ? a_length : b_length;
nkeynes@190
    35
    fprintf( f, "Expected %d bytes, was %d bytes =>\n", a_length, b_length );
nkeynes@190
    36
    
nkeynes@190
    37
    for( i=0; i<length; i+=16 ) {
nkeynes@190
    38
	for( k=0; k<32 && i+k < length; k+=4 ) {
nkeynes@190
    39
	    if( i+k >= a_length || i+k >= b_length ||
nkeynes@190
    40
		*((volatile unsigned int *)(a+i+k)) != *((volatile unsigned int *)(b+i+k)) ) {
nkeynes@190
    41
		break;
nkeynes@190
    42
	    }
nkeynes@190
    43
	}
nkeynes@190
    44
	if( k != 32 && i+k != length ) {
nkeynes@190
    45
	    fprintf( f, "%08X: ", i );
nkeynes@190
    46
	    for( j=0; j<16 && i+j < a_length; j+=4 ) {
nkeynes@190
    47
		fprintf( f, "%08X ", *((volatile unsigned int *)(a+i+j)) );
nkeynes@190
    48
	    }
nkeynes@190
    49
	    
nkeynes@190
    50
	    for(; j<16; j+=4 ) {
nkeynes@190
    51
		fprintf( f, "         " );
nkeynes@190
    52
	    }
nkeynes@190
    53
	    
nkeynes@190
    54
	    fprintf( f, "| " );
nkeynes@190
    55
	    for( j=0; j<16 && i+j < b_length; j+=4 ) {
nkeynes@190
    56
		fprintf( f, "%08X ", *((volatile unsigned int *)(b+i+j)) );
nkeynes@190
    57
	    }
nkeynes@190
    58
nkeynes@190
    59
	    fprintf( f, "\n");
nkeynes@190
    60
	}
nkeynes@190
    61
    }
nkeynes@190
    62
}
.