⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 run_test.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
字号:
/*
	run_test.c

	Main program for running tests.
	
	cmdline_loop, cmdline_ask, cmdline_pause_on_error have been conditioned
	( usually by "parse()" ).

*/

#include <stdtypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <string.h>
#include <conio.h>
#include <time.h>

/* non-standard includes... */
#include <lib.h>
#include <clib1.h>
#include <amcclib.h>
#include <main.h>
#include <nvram.h>
#include <typedefs.h>
#include <mailbox.h>

#include <hp.h>
#include <mini_api.h>


extern struct _hp hp;
extern UINT8 boot_nvram[];
extern struct _chip chip_uut, chip_control;
extern CHAR errstring[], infostring[];
extern int use_hp, test_has_info_did_not_run, skip_test;
extern VUINT32 control;
extern int cmdline_loop, cmdline_ask, cmdline_pause_on_error;
extern int cmdline_exit_on_error, cmdline_quiet, skiptest[]; 
extern int cmdline_only, exit_program;
extern int version_uut, clock_rate_pci, clock_rate_addon; 

/* ****************************************	*/
/*               Local Stuff...            	*/
/* ****************************************	*/
static int showerr( void );
static void	show_info( void );
static UINT8 config_space_uut[PCI_CONFIG_SIZE];

#define CHECKPCI if ( status != PCI_SUCCESSFUL )  \
			{									\
				pci_bios_fail(status);			\
				return showerr();		\
			}

#define CHECKNV	if ( status != NVRAM_OK )	\
			{							\
				nvfail(status);			\
				return showerr();		\
			}

int run_tests( struct _test *tests, struct _test_count *tcnt )
/*
	Run a set of tests.

	Return: TRUE if all ran OK, else FALSE (errstring printed).

	Note: cmdline_only = 0 means run all tests
						<> means run test cmdline_only - 1
*/
{
	// define mask that we want to save from control reg...
	// 23:20 (type)  13:8 (waits 13:11 = FIFO)
	#define CONTROL_MASK 0x00F03FFFL
	UINT32 saveptcr, save_control;
	int i, mods, result, loop_failed, status, max_test_number;
	CHAR c;

		for( max_test_number = 0; ; max_test_number++ )
			if ( tests[max_test_number+1].testptr == NULL )  break;
		if ( cmdline_only > (max_test_number + 1) )
		{
			fprintf( stderr, "Max test number allowed is %x.\n", max_test_number );
			exit(1);
		}

		loop_failed = FALSE;
		for( i=0; tests[i].testptr != NULL; i++ )
		{
			if ( exit_program ) exit(0);

			if ( cmdline_only != 0 )
			{
				if ( i != (cmdline_only - 1) )  continue;
			}

			else
			{
				// running all tests...
				if( !tests[i].testflag )  continue;	// skip test?
				if( skiptest[i] )
				{
					if ( !cmdline_quiet ) 
						printf( "Skipping test %2.2x - %s.\n", i, tests[i].testname );
					continue;		// skip test?
				}

				if ( cmdline_ask )
				{
					printf( "Run test %2.2x -  %s ? ", i, tests[i].testname );
					c = getch();
					printf( "\n" );
					if ( c == ESC ) exit(0);
					if ( (c != 'Y') && (c != 'y') ) continue;
				}
			}

			if ( !cmdline_quiet ) printf( "Running test %2.2x - %s.\n", \
				i, tests[i].testname );

			// reset flags and strings...
			errstring[0] = '\0';
			infostring[0] = '\0';
			result = TRUE; 						/* no error */
			test_has_info_did_not_run = FALSE;	// used by test to indicate info ONLY

			mailbox_clear_all( );				// clear all mailbox stuff
			// save commonly-changed PTCR and region types
			saveptcr = region_read32( &chip_uut, 0, PTCR );
			save_control = control;				// region type bits,...
			mods = tests[i].testptr( 1 );		// call test asking what it
												// modifies
			if ( mods & AMCC_TEST_REQUIRES_RECONFIG )
			{
				// save config...
				status = pciReadBuf( chip_uut.bus, chip_uut.device, \
					config_space_uut, PCI_CONFIG_SIZE );
				CHECKPCI
			}

			// clear prefetched data to avoid prefetched address bug...
			// (test may have left prefetched data)
			if 	( 	(version_uut < 1) && (clock_rate_pci != clock_rate_addon) )
				reset_uut_fifo();

			result = tests[i].testptr( 0 );		// run test

			if ( !result )
			{
				tcnt->fail++; loop_failed = TRUE;
				printf( "Test %2.2x - %s failed.\n", i, tests[i].testname );
				showerr();
				printf( "Configuration at failure...\n" );
				show_info();
			}
			else if ( test_has_info_did_not_run )
				tcnt->info++;
			else
				tcnt->pass++;

			if ( mods & AMCC_TEST_REQUIRES_RECONFIG )
			{
				// set chip back to what it was so we can at least see opregs...
				if ( !reset_uut(0) )
					return showerr();
				status = restore_uut_config( config_space_uut );
				CHECKPCI
			}

			// more than config portion of nvram was changed ?...
			if ( mods & AMCC_TEST_MOD_NVRAM )
			{
				printf( "Restoring nvRAM modified during test..." );
				status = nvram_write( boot_nvram, 0, \
					NVRAM_SIZE_BYTES, chip_uut.reg[0].base, \
					chip_uut.type );
				printf( "\n" );
				CHECKNV
			}

			if ( mods & AMCC_TEST_REQUIRES_RECONFIG )
			{
				// restore config portion of NVRAM and reset/re-configure...
				status = nvram_write( &boot_nvram[NVRAM_CONFIG_OFFSET], \
					NVRAM_CONFIG_OFFSET, NVRAM_CONFIG_SIZE, chip_uut.reg[0].base, \
					chip_uut.type );
				CHECKNV
				// restore everything now that nvRAM is correct...
				if ( !reset_uut(0) )
					return showerr();
				status = restore_uut_config( config_space_uut );
				CHECKPCI
			}

			if ( result && !test_has_info_did_not_run && !cmdline_quiet )
				printf( "Passed.\n" );

			if ( !cmdline_quiet )
			{
				// infostring may have info even though test passed
				if ( infostring[0] != '\0' )
					printf( infostring );
				if ( !cmdline_loop )
					if ( pcontinue() == ESC )  return TRUE;
			}

			if ( result )
			{
				// restore original values including region type and waits...
				region_write32( &chip_uut, 0, PTCR, saveptcr );
				bset_control_reg( save_control & CONTROL_MASK );
				bclr_control_reg( (~save_control & CONTROL_MASK) );
			}

			else	// if ( !result )
			{
				if ( cmdline_exit_on_error ) 
					exit(1);
				if ( cmdline_pause_on_error )
					if ( pcontinue() == ESC ) exit(1);
				return FALSE;
			}


		}	/* each test */

		if ( loop_failed ) tcnt->loop_fail++;
		else tcnt->loop_pass++;

	return TRUE;
}


static int showerr( void )
{
	if ( use_hp )  hp_close();
	printf( errstring );
	return FALSE;
}


static void	show_info( void )
{
	time_t t;

  	time(&t);
	printf( show_passthru_configuration() );
  	printf( "%s", ctime(&t));
	printf( "Control reg value = %8.8lx. Status reg = %4.4x.\n", \
		control, read_status_register() );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -