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 Thu Jan 31 09:35:01 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Update release notes for 0.8.3
view annotate diff log raw
     1 #include "lib.h"
     3 void fwrite_dump( FILE *f, char *buf, int length)
     4 {
     5     int i,j;
     6     for( i=0; i<length; i+=16 ) {
     7 	fprintf( f, "%08X: ", i );
     8         for( j=0; j<16 && i+j < length; j+=4 ) {
     9 	    unsigned int val = *((volatile unsigned int *)(buf+i+j));
    10 	    fprintf( f, "%02X %02X %02X %02X  ", val&0xFF, (val>>8)&0xFF, (val>>16)&0xFF, (val>>24)&0xFF );
    11         }
    12         for( ;j<16; j+= 4 ) {
    13             fprintf( f, "             " );
    14         }
    15 	for( j=0; j<16 && i+j < length; j++ ) {
    16 	    fprintf( f, "%c", isprint(buf[i+j]) ? buf[i+j] : '.' );
    17 	}
    18 	fprintf( f, "\n");
    19     }
    20 }
    22 void fwrite_diff( FILE *f,  char *a, int a_length, char *b, int b_length )
    23 {
    24     int i;
    25     fprintf( f, "Expected %d bytes:\n", a_length );
    26     fwrite_dump( f, a, a_length );
    27     fprintf( f, "but was %d bytes =>\n", b_length );
    28     fwrite_dump( f, b, b_length );
    29 }
    31 void fwrite_diff32( FILE *f, char *a, int a_length, char *b, int b_length )
    32 {
    33     int i,j, k;
    34     int length = a_length > b_length ? a_length : b_length;
    35     fprintf( f, "Expected %d bytes, was %d bytes =>\n", a_length, b_length );
    37     for( i=0; i<length; i+=16 ) {
    38 	for( k=0; k<32 && i+k < length; k+=4 ) {
    39 	    if( i+k >= a_length || i+k >= b_length ||
    40 		*((volatile unsigned int *)(a+i+k)) != *((volatile unsigned int *)(b+i+k)) ) {
    41 		break;
    42 	    }
    43 	}
    44 	if( k != 32 && i+k != length ) {
    45 	    fprintf( f, "%08X: ", i );
    46 	    for( j=0; j<16 && i+j < a_length; j+=4 ) {
    47 		fprintf( f, "%08X ", *((volatile unsigned int *)(a+i+j)) );
    48 	    }
    50 	    for(; j<16; j+=4 ) {
    51 		fprintf( f, "         " );
    52 	    }
    54 	    fprintf( f, "| " );
    55 	    for( j=0; j<16 && i+j < b_length; j+=4 ) {
    56 		fprintf( f, "%08X ", *((volatile unsigned int *)(b+i+j)) );
    57 	    }
    59 	    fprintf( f, "\n");
    60 	}
    61     }
    62 }
.