Search
lxdream.org :: lxdream/test/testdata.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/testdata.c
changeset 190:f7653df5e832
prev185:6755a04c447f
next263:6f641270b2aa
author nkeynes
date Wed Aug 02 04:13:15 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Add many more TA test cases (a couple of corner cases aren't 100% correct
yet, TBA)
Add new test "testregs" to check register masks (currently just PVR registers)
file annotate diff log raw
1.1 --- a/test/testdata.c Tue Jul 11 01:35:27 2006 +0000
1.2 +++ b/test/testdata.c Wed Aug 02 04:13:15 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: testdata.c,v 1.1 2006-07-11 01:35:23 nkeynes Exp $
1.6 + * $Id: testdata.c,v 1.2 2006-08-02 04:13:15 nkeynes Exp $
1.7 *
1.8 * Test data loader.
1.9 *
1.10 @@ -99,7 +99,8 @@
1.11 if( end != NULL )
1.12 *end = '\0';
1.13 current_size = DEFAULT_SIZE;
1.14 - test_data_t test = calloc(current_size, 1);
1.15 + test_data_t test = malloc(current_size);
1.16 + memset( test, 0, current_size );
1.17
1.18 dataptr = (char *)(test+1);
1.19 test->next = NULL;
1.20 @@ -120,9 +121,10 @@
1.21 if( equals != NULL ) {
1.22 char *block_name = line;
1.23 int len;
1.24 - *equals-- = '\0';
1.25 - while( isspace(*equals) )
1.26 - *equals-- = '\0';
1.27 + char *p = equals;
1.28 + *p-- = '\0';
1.29 + while( isspace(*p) )
1.30 + *p-- = '\0';
1.31 len = strlen(line)+1;
1.32 if( dataptr + len > current_end ) {
1.33 current_end += current_size;
1.34 @@ -137,50 +139,56 @@
1.35 dataptr = ALIGN_32(dataptr+len);
1.36 current->item[current_block].data = dataptr;
1.37 current->item[current_block].length = 0;
1.38 - } else {
1.39 - /* Data */
1.40 - if( current == NULL || current_block == -1 )
1.41 - continue;
1.42 - char *p = strtok(line, "\t\r\n ");
1.43 - while( p != NULL ) {
1.44 - if( dataptr + 8 > current_end ) {
1.45 - current_end += current_size;
1.46 - current_size *= 2;
1.47 - current = realloc(current, current_size );
1.48 - if( last != NULL )
1.49 - last->next = current;
1.50 +
1.51 + line = equals+1;
1.52 + while( isspace(*line) )
1.53 + line++;
1.54 + }
1.55 +
1.56 + /* Data */
1.57 + if( current == NULL || current_block == -1 )
1.58 + continue;
1.59 + char *p = strtok(line, "\t\r\n ");
1.60 + while( p != NULL ) {
1.61 + if( dataptr + 8 > current_end ) {
1.62 + int old_size = current_size;
1.63 + current_end += current_size;
1.64 + current_size *= 2;
1.65 + current = realloc(current, current_size );
1.66 + memset( current + old_size, 0, old_size );
1.67 + if( last != NULL )
1.68 + last->next = current;
1.69 + }
1.70 + int len = strlen(p);
1.71 + int datalen = 0;
1.72 + char *dot = strchr(p, '.');
1.73 + if( dot != NULL ) { /* FP */
1.74 + if( p[len-1] == 'L' ) { /* Ending in L */
1.75 + p[len-1] = '\0';
1.76 + double d = strtod(p, NULL);
1.77 + *((double *)dataptr) = d;
1.78 + datalen = 8;
1.79 + } else {
1.80 + float f = (float)strtod(p,NULL);
1.81 + *((float *)dataptr) = f;
1.82 + datalen = 4;
1.83 }
1.84 - int len = strlen(p);
1.85 - int datalen = 0;
1.86 - char *dot = strchr(p, '.');
1.87 - if( dot != NULL ) { /* FP */
1.88 - if( p[len-1] == 'L' ) { /* Ending in L */
1.89 - p[len-1] = '\0';
1.90 - double d = strtod(p, NULL);
1.91 - *((double *)dataptr) = d;
1.92 - datalen = 8;
1.93 - } else {
1.94 - float f = (float)strtod(p,NULL);
1.95 - *((float *)dataptr) = f;
1.96 - datalen = 4;
1.97 - }
1.98 - } else {
1.99 - unsigned long value = strtoul(p, NULL, 16);
1.100 - if( len == 8 ) {
1.101 - *((unsigned int *)dataptr) = value;
1.102 - datalen = 4;
1.103 - } else if( len == 4 ) {
1.104 - *((unsigned short *)dataptr) = value;
1.105 - datalen = 2;
1.106 - } else if( len == 2 ) {
1.107 - *((unsigned char *)dataptr) = value;
1.108 - datalen = 1;
1.109 - }
1.110 + } else {
1.111 + unsigned long value = strtoul(p, NULL, 16);
1.112 + if( len == 8 ) {
1.113 + *((unsigned int *)dataptr) = value;
1.114 + datalen = 4;
1.115 + } else if( len == 4 ) {
1.116 + *((unsigned short *)dataptr) = value;
1.117 + datalen = 2;
1.118 + } else if( len == 2 ) {
1.119 + *((unsigned char *)dataptr) = value;
1.120 + datalen = 1;
1.121 }
1.122 - dataptr += datalen;
1.123 - current->item[current_block].length += datalen;
1.124 - p = strtok(NULL, "\t\r\n ");
1.125 }
1.126 + dataptr += datalen;
1.127 + current->item[current_block].length += datalen;
1.128 + p = strtok(NULL, "\t\r\n ");
1.129 }
1.130 }
1.131 }
.