2 * $Id: testta.c,v 1.3 2006-08-04 01:38:30 nkeynes Exp $
4 * Tile Accelerator test cases
6 * Copyright (c) 2006 Nathan Keynes.
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.
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.
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
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 };
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 )
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 );
60 memcpy( expect, expected_block->data, expected_block->length );
62 if( expected_block->length <= length-4 ) {
63 *((unsigned int *)&expect[expected_block->length]) = 0xF0000000;
68 int tilematrix_block_compare( test_data_block_t expected_block, char *tile_ptrs[], int tile_type, int offset )
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 );
77 int test_ta( test_data_t test_case )
80 unsigned int *p = DMA_ALIGN(buf);
81 unsigned int *data = p;
83 int checkedTile[5] = {0,0,0,0,0};
86 char *result = (char *)(PVR_VRAM_BASE+OBJ_START);
87 char *tilematrix = (char *)(PVR_VRAM_BASE+TILE_START+TILE_LENGTH);
92 memset( PVR_VRAM_BASE, MEM_FILL, 0x00090000 );
93 test_data_block_t config_data = get_test_data( test_case, "config" );
94 struct ta_config *config = &default_ta_config;
95 if( config_data != NULL ) {
96 if( config_data->length != sizeof(struct ta_config) ) {
97 fprintf( stderr, "Invalid config data length %d - aborting test %s\n",
98 config_data->length, test_case->test_name );
101 config = (struct ta_config *)config_data->data;
104 for( i=0; i<5; i++ ) {
105 tile_sizes[i] = TILE_SIZE(config,i);
107 hsegs = (config->grid_size & 0xFFFF)+1;
108 vsegs = (config->grid_size >> 16) + 1;
109 tile_ptrs[0] = tilematrix;
110 tile_ptrs[1] = tile_ptrs[0] + (hsegs*vsegs*tile_sizes[0]);
111 tile_ptrs[2] = tile_ptrs[1] + (hsegs*vsegs*tile_sizes[1]);
112 tile_ptrs[3] = tile_ptrs[2] + (hsegs*vsegs*tile_sizes[2]);
113 tile_ptrs[4] = tile_ptrs[3] + (hsegs*vsegs*tile_sizes[3]);
116 test_data_block_t input = get_test_data(test_case, "input");
117 test_data_block_t output = get_test_data(test_case, "output");
118 test_data_block_t error = get_test_data(test_case, "error");
119 if( input == NULL || output == NULL ) {
120 fprintf( stderr, "Skipping test case '%s': data incomplete\n", test_case->test_name );
124 if( pvr_dma_write( 0x10000000, input->data, input->length, 0 ) == -1 ) {
128 if( error != NULL ) {
129 for( i=0; i<error->length; i++ ) {
130 if( asic_wait( error->data[i] ) == -1 ) {
131 fprintf( stderr, "Test %s: failed (Timeout waiting for error event %d)\n",
132 test_case->test_name, error->data[i] );
139 for( i=0; i<MAX_DATA_BLOCKS; i++ ) {
140 test_data_block_t data = &test_case->item[i];
141 int tile, x, y, offset;
142 if( data->name != NULL ) {
143 int result = sscanf( data->name, "tile %d %dx%d", &tile, &x, &y );
146 } else if( result != 3 ) {
150 offset = x + (y * hsegs);
152 if( checkedTile[tile] == 0 ) {
153 if( asic_wait( tile_events[tile] ) == -1 ) {
154 fprintf( stderr, "Test %s: failed (Timeout waiting for %s done event)\n",
155 test_case->test_name, tile_names[tile] );
162 if( tilematrix_block_compare( data, tile_ptrs, tile, offset ) != 0 ) {
163 fprintf( stderr, "Test %s: Failed (%s matrix %dx%d). ",
164 test_case->test_name, tile_names[tile], x, y );
165 fwrite_diff32( stderr, data->data, data->length,
166 tile_ptrs[tile] + (tile_sizes[tile]*offset), tile_sizes[tile] );
169 checkedTile[tile] = 1;
174 test_data_block_t plist = get_test_data(test_case, "plist" );
175 if( plist != NULL ) {
176 unsigned int plist_posn, plist_end;
177 if( config->ta_cfg & 0x00100000 ) { /* Descending */
178 plist_posn = pvr_get_plist_posn(); //+ tile_sizes[0];
179 plist_end = config->plist_start;
181 plist_posn = config->plist_start;
182 plist_end = pvr_get_plist_posn() + tile_sizes[0];
184 char *plist_data = (char *)(PVR_VRAM_BASE + plist_posn);
185 if( test_block_compare( plist, plist_data, plist_end-plist_posn ) != 0 ) {
186 fprintf( stderr, "Test %s: Failed (Plist buffer)", test_case->test_name );
187 fwrite_diff32( stderr, plist->data, plist->length, (char *)plist_data,
188 plist_end - plist_posn );
191 char block[tile_sizes[0]];
192 memset( block, MEM_FILL, tile_sizes[0] );
193 if( memcmp( block, plist_data - tile_sizes[0], tile_sizes[0] ) != 0 ) {
194 fprintf( stderr, "Test %s: Failed (Plist buffer)", test_case->test_name );
195 fwrite_diff32( stderr, block, tile_sizes[0], plist_data - tile_sizes[0],
202 int result_length = pvr_get_objbuf_size();
203 if( test_block_compare( output, result, result_length ) != 0 ) {
204 fprintf( stderr, "Test %s: Failed (Vertex buffer). ", test_case->test_name );
205 fwrite_diff32( stderr, output->data, output->length, result, result_length );
210 for( i=0; i<5; i++ ) {
211 if( checkedTile[i] == 0 ) {
212 if( tilematrix_block_compare( NULL, tile_ptrs, i, 0 ) != 0 ) {
213 fprintf( stderr, "Test %s: Failed (%s matrix). ", test_case->test_name, tile_names[i] );
214 fprintf( stderr, "Expected empty buffer at %08X, but was =>\n",
215 (unsigned int)(tile_ptrs[i]) );
216 fwrite_dump( stderr, tile_ptrs[i], tile_sizes[i] );
217 // fwrite_dump( stderr, tile_ptrs[i] - 128, 256 );
223 if( error == NULL ) {
224 if( asic_check(EVENT_TA_ERROR) || asic_check(EVENT_PVR_PRIM_ALLOC_FAIL) ||
225 asic_check(EVENT_PVR_MATRIX_ALLOC_FAIL) || asic_check(EVENT_PVR_BAD_INPUT) ) {
226 fprintf( stderr, "Test %s: Failed (unexpected error events)\n", test_case->test_name );
235 fprintf( stdout, "Test %s: OK\n", test_case->test_name );
239 int main( int argc, char *argv[] )
242 int test_failures = 0;
243 test_data_t test_data = load_test_dataset(stdin);
244 test_data_t test_case = test_data;
249 while( test_case != NULL ) {
251 int result = test_ta(test_case);
255 test_case = test_case->next;
257 free_test_dataset(test_data);
258 if( test_failures != 0 ) {
259 fprintf( stderr, "%d/%d test failures!\n", test_failures, test_cases );
262 fprintf( stderr, "%d tests OK\n", test_cases );
.