Search
lxdream.org :: lxdream/test/testta.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/testta.c
changeset 212:8b77a7e6b6f0
prev193:31151fcc3cb7
next561:533f6b478071
author nkeynes
date Tue Sep 11 01:05:05 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change If a render buffer can't be obtained, skip the render
view annotate diff log raw
     1 /**
     2  * $Id: testta.c,v 1.4 2006-08-18 09:32:32 nkeynes Exp $
     3  * 
     4  * Tile Accelerator test cases 
     5  *
     6  * Copyright (c) 2006 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include <stdio.h>
    20 #include "testdata.h"
    21 #include "pvr.h"
    22 #include "lib.h"
    23 #include "asic.h"
    25 #define DMA_ALIGN(x)   ((void *)((((unsigned int)(x))+0x1F)&0xFFFFFFE0))
    27 #define OBJ_START 0x00010000
    28 #define OBJ_LENGTH 0x00010000
    29 #define TILE_START 0x00060000
    30 #define TILE_LENGTH 0x00010000
    32 #define MEM_FILL 0xFE
    34 int ta_tile_sizes[4] = { 0, 32, 64, 128 };
    36 #define TILE_SIZE(cfg, tile) ta_tile_sizes[((((cfg->ta_cfg) >> (4*tile))&0x03))]
    38 struct ta_config default_ta_config = { 0x00111111, GRID_SIZE(640,480), OBJ_START,
    39 				       OBJ_START+OBJ_LENGTH, TILE_START+TILE_LENGTH,
    40 				       TILE_START, TILE_START+TILE_LENGTH };
    43 int tile_sizes[5];
    44 int tile_events[5] = { EVENT_PVR_OPAQUE_DONE, EVENT_PVR_OPAQUEMOD_DONE,
    45 		       EVENT_PVR_TRANS_DONE, EVENT_PVR_TRANSMOD_DONE,
    46 		       EVENT_PVR_PUNCHOUT_DONE };
    47 char *tile_names[5] = { "Opaque", "Opaque Mod", "Trans", "Trans Mod", "Punch Out" };
    49 #define FLOAT(p) *((float *)(p))
    51 void make_expected_buffer( test_data_block_t expected_block, char *expect, int length )
    52 {
    53     memset( expect, MEM_FILL,length );
    55     if( expected_block != NULL ) {
    56 	if( expected_block->length > length ) {
    57 	    fprintf( stderr, "Test data error: expected tile length is %d, but tile size is only %d\n", expected_block->length, length );
    58 	    return;
    59 	}
    60 	memcpy( expect, expected_block->data, expected_block->length );
    62 	if( expected_block->length <= length-4 ) {
    63 	    *((unsigned int *)&expect[expected_block->length]) = 0xF0000000;
    64 	}
    65     }
    66 }
    68 int tilematrix_block_compare( test_data_block_t expected_block, char *tile_ptrs[], int tile_type, int offset )
    69 {
    70     int tile_size = tile_sizes[tile_type];
    71     char expect[tile_size];
    73     make_expected_buffer(expected_block, expect, tile_size);
    74     return memcmp( expect, tile_ptrs[tile_type]+(offset*tile_sizes[tile_type]), tile_size );
    75 }
    77 /**
    78  * Copy from vram, wrapping appropriately 
    79  */
    80 int memcpy_from_vram( char *dest, char *src, int len ) 
    81 {
    82     while( len > 0 ) {
    83 	*dest++ = *src++;
    84 	src = (char *)( ((unsigned int)src) & 0xFF7FFFFF );
    85 	len--;
    86     }
    87 }
    89 int test_ta( test_data_t test_case )
    90 {
    91     char buf[1024];
    92     unsigned int *p = DMA_ALIGN(buf);
    93     unsigned int *data = p;
    94     int haveFailure = 0;
    95     int checkedTile[5] = {0,0,0,0,0};
    96     int i;
    97     int hsegs,vsegs;
    98     char *tile_ptrs[5];
   100     asic_clear();
   102     memset( PVR_VRAM_BASE, MEM_FILL,  0x00090000 );
   103     test_data_block_t config_data = get_test_data( test_case, "config" );
   104     struct ta_config *config = &default_ta_config;
   105     if( config_data != NULL ) {
   106 	if( config_data->length != sizeof(struct ta_config) ) {
   107 	    fprintf( stderr, "Invalid config data length %d - aborting test %s\n",
   108 		     config_data->length, test_case->test_name );
   109 	    return -1;
   110 	}
   111 	config = (struct ta_config *)config_data->data;
   112     }
   113     char *result = (char *)(PVR_VRAM_BASE+config->obj_start);
   114     char *tilematrix = (char *)(PVR_VRAM_BASE+config->tile_start);
   116     ta_init(config);
   117     for( i=0; i<5; i++ ) {
   118 	tile_sizes[i] = TILE_SIZE(config,i);
   119     }
   120     hsegs = (config->grid_size & 0xFFFF)+1;
   121     vsegs = (config->grid_size >> 16) + 1;
   122     tile_ptrs[0] = tilematrix;
   123     tile_ptrs[1] = tile_ptrs[0] + (hsegs*vsegs*tile_sizes[0]);
   124     tile_ptrs[2] = tile_ptrs[1] + (hsegs*vsegs*tile_sizes[1]);
   125     tile_ptrs[3] = tile_ptrs[2] + (hsegs*vsegs*tile_sizes[2]);
   126     tile_ptrs[4] = tile_ptrs[3] + (hsegs*vsegs*tile_sizes[3]);
   129     test_data_block_t input = get_test_data(test_case, "input");
   130     test_data_block_t input2 = get_test_data(test_case, "input2");
   131     test_data_block_t output = get_test_data(test_case, "output");
   132     test_data_block_t error = get_test_data(test_case, "error");
   133     if( input == NULL || output == NULL ) {
   134 	fprintf( stderr, "Skipping test case '%s': data incomplete\n", test_case->test_name );
   135 	return -1;
   136     }
   138     if( pvr_dma_write( 0x10000000, input->data, input->length, 0 ) == -1 ) {
   139 	return -1;
   140     }
   142     if( input2 != NULL ) {
   143 	ta_reinit();
   144 	pvr_dma_write( 0x10000000, input2->data, input2->length, 0 );
   145     }
   148     if( error != NULL ) {
   149 	for( i=0; i<error->length; i++ ) {
   150 	    if( asic_wait( error->data[i] ) == -1 ) {
   151 		fprintf( stderr, "Test %s: failed (Timeout waiting for error event %d)\n",
   152 			 test_case->test_name, error->data[i] );
   153 		asic_dump( stderr );
   154 		return -1;
   155 	    }
   156 	}
   157     }
   159     for( i=0; i<MAX_DATA_BLOCKS; i++ ) {
   160 	test_data_block_t data = &test_case->item[i];
   161 	int tile, x, y, offset;
   162 	if( data->name != NULL ) {
   163 	    int result = sscanf( data->name, "tile %d %dx%d", &tile, &x, &y );
   164 	    if( result == 1 ) {
   165 		x = y = 0;
   166 	    } else if( result != 3 ) {
   167 		continue;
   168 	    }
   169 	    tile--;
   170 	    offset = x + (y * hsegs);
   172 	    if( checkedTile[tile] == 0 ) {
   173 		if( asic_wait( tile_events[tile] ) == -1 ) {
   174 		    fprintf( stderr, "Test %s: failed (Timeout waiting for %s done event)\n", 
   175 			     test_case->test_name, tile_names[tile] );
   176 		    ta_dump_regs();
   177 		    asic_dump( stderr );
   178 		    haveFailure = 1;
   179 		}
   180 	    }
   182 	    if( tilematrix_block_compare( data, tile_ptrs, tile, offset ) != 0 ) {
   183 		fprintf( stderr, "Test %s: Failed (%s matrix %dx%d). ", 
   184 			 test_case->test_name, tile_names[tile], x, y );
   185 		fwrite_diff32( stderr, data->data, data->length, 
   186 			       tile_ptrs[tile] + (tile_sizes[tile]*offset), tile_sizes[tile] );
   187 		haveFailure = 1;
   188 	    }
   189 	    checkedTile[tile] = 1;
   190 	}
   191     }
   193     /* Overflow */
   194     test_data_block_t plist = get_test_data(test_case, "plist" );
   195     if( plist != NULL ) {
   196 	unsigned int plist_posn, plist_end;
   197 	if( config->ta_cfg & 0x00100000 ) { /* Descending */
   198 	    plist_posn = pvr_get_plist_posn(); //+ tile_sizes[0];
   199 	    plist_end = config->plist_start;
   200 	} else {
   201 	    plist_posn = config->plist_start;
   202 	    plist_end = pvr_get_plist_posn() + tile_sizes[0];
   203 	}
   204 	char *plist_data = (char *)(PVR_VRAM_BASE + plist_posn);
   205 	if( test_block_compare( plist, plist_data, plist_end-plist_posn ) != 0 ) {
   206 	    fprintf( stderr, "Test %s: Failed (Plist buffer)", test_case->test_name );
   207 	    fwrite_diff32( stderr, plist->data, plist->length, (char *)plist_data, 
   208 			   plist_end - plist_posn );
   209 	    haveFailure = 1;
   210 	}
   211 	char block[tile_sizes[0]];
   212 	memset( block, MEM_FILL, tile_sizes[0] );
   213 	if( memcmp( block, plist_data - tile_sizes[0], tile_sizes[0] ) != 0 ) {
   214 	    fprintf( stderr, "Test %s: Failed (Plist buffer)", test_case->test_name );
   215 	    fwrite_diff32( stderr, block, tile_sizes[0], plist_data - tile_sizes[0],
   216 			   tile_sizes[0]);
   217 	    haveFailure = 1;
   218 	}
   219     }
   221     /* Vertex buffer */
   222     int result_length = pvr_get_objbuf_size();
   223     char tmp[result_length];
   224     memcpy_from_vram( tmp, result, result_length );
   225     if( test_block_compare( output, tmp, result_length ) != 0 ) {
   226 	fprintf( stderr, "Test %s: Failed (Vertex buffer). ", test_case->test_name );
   227 	fwrite_diff32( stderr, output->data, output->length, tmp, result_length );
   228 	haveFailure = 1;
   229     }
   232     for( i=0; i<5; i++ ) {
   233 	if( checkedTile[i] == 0 ) {
   234 	    if( tilematrix_block_compare( NULL, tile_ptrs, i, 0 ) != 0 ) {
   235 		fprintf( stderr, "Test %s: Failed (%s matrix). ", test_case->test_name, tile_names[i] );
   236                 fprintf( stderr, "Expected empty buffer at %08X, but was =>\n", 
   237 			 (unsigned int)(tile_ptrs[i]) );
   238 		fwrite_dump( stderr, tile_ptrs[i], tile_sizes[i] );
   239 		//		fwrite_dump( stderr, tile_ptrs[i] - 128, 256 );
   241 	    }
   242 	}
   243     }
   245     if( error == NULL ) {
   246 	if( asic_check(EVENT_TA_ERROR) || asic_check(EVENT_PVR_PRIM_ALLOC_FAIL) ||
   247 	    asic_check(EVENT_PVR_MATRIX_ALLOC_FAIL) || asic_check(EVENT_PVR_BAD_INPUT) ) {
   248 	    fprintf( stderr, "Test %s: Failed (unexpected error events)\n", test_case->test_name );
   249 	    asic_dump( stderr );
   250 	    haveFailure = 1;
   251 	}
   252     }
   254     if( haveFailure )
   255 	return -1;
   257     fprintf( stdout, "Test %s: OK\n", test_case->test_name );
   258     return 0;
   259 }
   261 int main( int argc, char *argv[] ) 
   262 {
   263     int test_cases = 0;
   264     int test_failures = 0;
   265     test_data_t test_data = load_test_dataset(stdin);
   266     test_data_t test_case = test_data;
   268     asic_mask_all();
   269     pvr_init();
   271     while( test_case != NULL ) {
   272 	test_cases++;
   273 	int result = test_ta(test_case);
   274 	if( result != 0 ) {
   275 	    test_failures++;
   276 	}
   277 	test_case = test_case->next;
   278     }
   279     free_test_dataset(test_data);
   280     if( test_failures != 0 ) {
   281 	fprintf( stderr, "%d/%d test failures!\n", test_failures, test_cases );
   282 	return 1;
   283     } else {
   284 	fprintf( stderr, "%d tests OK\n", test_cases );
   285 	return 0;
   286     }
   287 }
.