📄 test.c
字号:
/*
* test.c
* Simple test driver
*
* Just add your test name and address to the table...
*
* Special commands:
* ? Print out test table
* all Run all tests in table
*/
#define _TEST_C_
#include "windows.h"
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "hwdefs.h"
#include "testvars.h"
#include "t_sdram.h"
#include "t_mmio.h"
#include "tmmanapi.h"
/* disable some tests for release */
#define FULL_SUITE 0
/*
* Test table
*/
typedef struct
{
int (*func)(void) ;
char *name ;
char *desc ;
} TEST_TBL ;
TEST_TBL test_tbl[] =
{
{t_sdram_addr,
"sdram_addr",
"test sdram with address @ address"},
{t_sdram_walk0,
"sdram_walk0",
"test sdram with walking zeroes"},
{t_sdram_walk1,
"sdram_walk1",
"test sdram with walking ones"},
{t_mmio_display,
"mmio_display",
"display mmio registers"},
/*
TRC9703227 commented since the register values have changed now
and no one has time to update these tests
*/
/*
{t_mmio_walk1,
"mmio_walk1",
"test mmio with walking ones"},
{t_mmio_walk0,
"mmio_walk0",
"test mmio with walking zeroes"},
{t_mmio_read,
"mmio_read",
"read/verify mmio registers initial value"},
*/
} ;
#define TEST_TBL_SIZE (sizeof(test_tbl)/sizeof(TEST_TBL))
#define TEST_TBL_PASSING_SIZE 5
/*
* Local functions
*/
void test_help(void) ;
int test_run(TEST_TBL *, int) ;
/*
* Test driver entry point
*/
void
TaskTest(
int argc,
char *argv[],
int32 *_sdram_mapped_base,
int32 _sdram_physical_base,
int32 *_mmio_mapped_base,
int32 _mmio_physical_base,
int32 _sdram_len )
{
TEST_TBL *tblp ;
int count ;
char *test_name ;
printf("\n") ;
if (argc < 1)
{
printf("need a test name\n") ;
return;
}
test_name = argv[0] ;
/*
* Pass data to tests in globals
* (yuck! but makes test coding easier)
*/
test_argc = argc ;
test_argv = argv ;
mmio_virt_base = _mmio_mapped_base ;
mmio_phys_base = _mmio_physical_base ;
sdram_virt_base = _sdram_mapped_base ;
sdram_phys_base = _sdram_physical_base ;
sdram_len = _sdram_len ;
/*
* Check for help command
*/
if (strcmp(test_name, "?") == 0)
{
test_help() ;
return ;
}
/*
* Check for all command
*/
if (strcmp(test_name, "all") == 0)
{
test_run(test_tbl, TEST_TBL_SIZE) ;
return ;
}
/*
* Check for passing command
*/
if (strcmp(test_name, "passing") == 0)
{
test_run(test_tbl, TEST_TBL_PASSING_SIZE) ;
return ;
}
/*
* Check for command in table
*/
tblp = test_tbl ;
count = TEST_TBL_SIZE ;
while (count-- != 0)
{
if (strcmp(test_name, tblp->name) == 0)
{
test_run(tblp, 1 ) ;
return ;
}
tblp++ ;
}
printf("test not found '%s', type 'hosttest ?' to see list of tests\n", test_name) ;
}
/*
* Print out list of tests
*/
void
test_help()
{
TEST_TBL *tblp ;
int count ;
static char *fmt = " %-20s %s\n" ;
printf("tests available are:\n") ;
printf(fmt, "?", "print this message") ;
printf(fmt, "all", "run all tests") ;
printf(fmt, "passing", "run passing tests") ;
tblp = test_tbl ;
count = TEST_TBL_SIZE ;
while (count-- != 0)
{
printf(fmt, tblp->name, tblp->desc) ;
tblp++ ;
}
}
/*
* Run tests (single or multiple)
*/
int
test_run(
TEST_TBL *tblp,
int size
)
{
time_t time_start ;
time_t time_end ;
time_t time_elapsed ;
time_t all_start ;
time_t all_end ;
time_t all_elapsed ;
int errors ;
int all_errors ;
int count ;
unsigned long IterationCount;
IterationCount = GetPrivateProfileInt (
"Device.0", "IterationCount", 1, "tmman.ini" );
all_start = time(NULL) ;
count = size ;
all_errors = 0 ;
while (count-- != 0)
{
while( IterationCount-- != 0 )
{
time_start = time(NULL) ;
errors = tblp->func() ;
time_end = time(NULL) ;
time_elapsed = time_end - time_start ;
if (errors != 0)
{
printf("%s failed, %d secs\n", tblp->name, time_elapsed) ;
}
else
{
printf("%s passed, %d secs\n", tblp->name, time_elapsed) ;
}
}
all_errors += errors ;
tblp++ ;
}
all_end = time(NULL) ;
all_elapsed = all_end - all_start ;
if (size != 1)
{
if (all_errors != 0)
{
printf("overall status: failed, %d secs\n", all_elapsed) ;
}
else
{
printf("overall status: passed, %d secs\n", all_elapsed) ;
}
}
return all_errors ;
}
void main( int argc, char*argv[] )
{
UInt32 DSPHandle;
tmmanDSPInfo DSPInfo;
tmmanDSPOpen ( 0, &DSPHandle );
tmmanDSPGetInfo ( DSPHandle, &DSPInfo );
TaskTest (
argc - 1 , &argv[1],
(int32*) DSPInfo.SDRAM.MappedAddress,
DSPInfo.SDRAM.PhysicalAddress,
(int32 *) DSPInfo.MMIO.MappedAddress,
DSPInfo.MMIO.PhysicalAddress,
DSPInfo.SDRAM.Size );
tmmanDSPClose ( DSPHandle );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -