?? tests.c
字號:
#ifndef lintstatic char sccsid[] = "@(#)tests.c 1.1 92/07/30 Copyright Sun Micro";#endif/* * Copyright (c) 1987 by Sun Microsystems, Inc. */#include "sundiag.h"#include <sys/fcntl.h>#include <sys/ioctl.h>#include <sys/file.h>#include <sys/param.h>#include <sys/stat.h>#include <sys/wait.h>#include <sys/resource.h>#include <signal.h>#include <sun/fbio.h>#include <vfork.h>#include "../../lib/include/libonline.h"#include "../../lib/include/probe_sundiag.h"#include "struct.h"#include "procs.h"#include "sundiag_ats.h"#include "sundiag_msg.h"#ifndef sun386#include <sys/mtio.h>#else#include "mtio.h"#endif#define MAX_ARG 17 /* max. # of arg's for child + 2 */#define GROUP_COL 1 /* group toggle starting column */#define SEL_COL 4 /* test select toggle starting column */#define OPT_COL 32 /* option panel item starting column */#define FB_WAIT 30/* seconds to be wait before restart the frame buffer tests */struct test_info *tests[MAXTESTS]; /* test's data base */int exist_tests=0; /* total # of existing tests */char *cpuname; /* CPU type of the tested machine */char *vmem_waittime[] = {"0","5","10","15","30","60","90","random"};int vmem_wait=0; /* vmem wait time counter */int fb_delay=0; /* # of seconds to be delayed between fb tests */char *sp_src= "0,1,3,5,8,9,b,d"; /* default ALM loopback source */char *sp_des= "7,2,4,6,f,a,c,e"; /* default ALM loopback destination */char *sp2_src= "0,2,4,6,8,a,c,e"; /* default ALM2 loopback source */char *sp2_des= "1,3,5,7,9,b,d,f"; /* default ALM2 loopback destination */char *scsisp_src= "0,2"; /* default SCSI serial port loopback source */char *scsisp_des= "1,3";/* default SCSI serial port loopback destination */char *sunlink_src[]= /* default SunLink loopback source */ {"0,2","4,6","8,10","12,14"};char *sunlink_des[]= /* default SunLink loopback destination */ {"1,3","5,7","9,11","13,15"};char *bpp_mode[] = {"fast", "medium", "extended"};char *lpvi_mode[] = {"fast", "medium", "extended"};char *lpvi_image[] = {"default", "57fonts", "u_image"};char *lpvi_resolution[] = {"400", "300"};Frame option_frame=NULL; /* used to keep the frame of the option popup */int taac=0; /* flag for whether a taac board or not */int zebra=0; /* flag for whether a zebra board or not */FILE *conf_fp;extern select_test(); /* forward external declaration */extern Panel init_opt_panel(); /* declared in option.c */extern frame_destroy_proc(); /* declared in panelprocs.c */extern char *malloc();extern char *strtok();extern char *strcpy();extern char *strcat();extern char *sprintf();extern char *mktemp();extern FILE *fopen();extern char *getenv();extern multi_tests(); /* forward declaration */extern Pixrect *pr_open();extern Pixrect *start_button, *reset_button; /* defined in panel.c */extern char *remotehost;extern int config_file_only; /* defined in sundiag.c */char toni_msg[82];static char *child_arg[MAX_ARG]; /* argument array of pointers */static int start_row=7; /* beginning row of the test selection items */static int ipcs=0; /* keep # of IPC's */static int gp2=0; /* flag for whether there is GP2 board */static int cg2=0; /* flag for whether there is CG2 board */static int cg4=0; /* flag for whether there is CG4 board */static int cg5=0; /* flag for whether there is CG5 board */static int cg12=0; /* flag for whether there is CG12 board */ static int gttest=0; /* flag for whether there is GT board */static int ibis=0; /* flag for whether there is IBIS board */static int fb_inuse=0; /* flag to tell whether frame buffer is in use */static int fb_id= -1; /* to keep track of who is using the fb */static int dcp_kernel[4]={0,0,0,0}; /* dcp kernel(ucode) been loaded? */static int mcp_flag[8]={0,0,0,0,0,0,0,0}; /* up to 8 mcp boards in a machine */static int net_flag=0; /* only run one nettest at a time */static int next_net=0; /* only run one nettest at a time */static int last_group; /* the group id of lastly-run test *//****************************************************************************** * check_dblbuf(), returns TRUE if the frame device is double buffered. * * This code was extracted from cg5test.c. * * Note: this function(checking double frame buffer) should be moved to probe.* ******************************************************************************/static int check_dblbuf(){ Pixrect *prfd; struct fbtype fb_type; int tmpfd; /* first test for console type */ if ((tmpfd=open("/dev/fb", O_RDONLY)) != -1) { (void)ioctl(tmpfd, FBIOGTYPE, &fb_type); (void)close(tmpfd); } else return(FALSE); /* check if cg driver is there */ if (access("/dev/cgtwo0", 0) == 0) { /* first check if going through gp2 */ if (fb_type.fb_type == FBTYPE_SUN2GP ) { if (access("/dev/gpone0a", 0) == 0) { if ((prfd=pr_open("/dev/gpone0a")) == (Pixrect *)0) return(FALSE); } else return(FALSE); } else if (fb_type.fb_type == FBTYPE_SUN2COLOR) { if ((prfd=pr_open("/dev/fb")) == (Pixrect *)0) return(FALSE); } else { if ((prfd=pr_open("/dev/cgtwo0")) == (Pixrect *)0) return(FALSE); } /* We have a device. Check for single or double buffer */ (void)pr_dbl_set(prfd, PR_DBL_WRITE, PR_DBL_B, 0); (void)pr_put(prfd, 0, 0, 0x55); (void)pr_dbl_set(prfd, PR_DBL_WRITE, PR_DBL_A, 0); (void)pr_put(prfd, 0, 0, 0xAA); (void)pr_dbl_set(prfd, PR_DBL_READ, PR_DBL_B, 0); if (pr_get(prfd, 0, 0) == 0x55) { (void)pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A, PR_DBL_READ, PR_DBL_A, PR_DBL_WRITE, PR_DBL_BOTH, 0); (void)pr_destroy(prfd); return(TRUE); } else (void)pr_dbl_set(prfd, PR_DBL_DISPLAY, PR_DBL_A, PR_DBL_READ, PR_DBL_A, PR_DBL_WRITE, PR_DBL_BOTH, 0); (void)pr_destroy(prfd); } return(FALSE);}/****************************************************************************** * check_probe() checks the device name againt the test data base to determine* * which test should be run on this device. * * Input: dev_ptr, the info. regarding the found device. * * Output: the test no; -1 if no test supports this device. * ******************************************************************************/static int check_probe(dev_ptr)struct found_dev *dev_ptr;{ int i; if (dev_ptr->unit > 0) /* if 2nd(and higher) device */ { if (strcmp(dev_ptr->device_name, "ie") == 0) return(ENET2); /* at most 2 ethernet boards!! */ if (strcmp(dev_ptr->device_name, "zs") == 0) { if (dev_ptr->unit == 2) /* zs3 is dummy */ return(CPU_SP1); /* ttyc and ttyd */ else if (dev_ptr->unit == 4) /* zs5 is dummy */ return(SCSISP2); else return(-1); /* not implemented yet */ } } for (i=0; i != TEST_NO; ++i) if (strcmp(dev_ptr->device_name, tests_base[i].devname) == 0) { if (i == GP) /* check whether it is CG2 */ { if (dev_ptr->u_tag.uval.devinfo.status == 2) return(GP2); } else if (i == COLOR2) /* check whether it's double buffered */ { if (check_dblbuf()) return(COLOR5); } else if (i == FPA) /* check for fpa-3x board */ { if (dev_ptr->u_tag.uval.devinfo.status == FPA3X_EXIST) return(FPA3X); } else if (i == FPUTEST) { if (dev_ptr->u_tag.uval.devinfo.status == FPU2_EXIST) return(FPU2); } return(i); } return(-1);}/****************************************************************************** * make_test() creates a test information data structure to be inserted into * * the tests[]. * * Input: test_no, test number; unit, device unit number. * * Output: a pointer to created data structure. * ******************************************************************************/static struct test_info *make_test(test_no, unit)int test_no; /* test no(index to tests_base[]) */int unit; /* device unit number */{ struct test_info *tmp; if (unit != 0) /* if multiple devices */ { if (tests_base[test_no].unit == -1) /* devices with single unit, but with a non-zero UNIX device number */ { tests_base[test_no].unit = unit; /* change the unit number here */ return(&tests_base[test_no]); } tmp = (struct test_info *)malloc(sizeof(struct test_info)); bcopy((char *)(&tests_base[test_no]), (char *)tmp, sizeof(struct test_info)); tmp->unit = unit; tmp->devname = malloc((unsigned)strlen(tmp->devname)+5); (void)strcpy(tmp->devname, tests_base[test_no].devname); } else tmp = &tests_base[test_no]; return(tmp);}/****************************************************************************** * build_user_test(), appends the user-defined tests at the end of the test * * data structure, tests[]. * * Input: global test data structure, tests[]. * * Output: None, but the test data structure, tests[], will be modified. * ******************************************************************************/build_user_tests(){ FILE *user_fp; int i, k; struct test_info *tmp; char buff[82], *temp; char *param[21]; /* max. to 20 tokens(plus one to store NULL) */ char *delimit; if ((user_fp=fopen(USER_FILE, "r")) == NULL) return; k = 0; /* initialize the user-defined test number */ while (fgets(buff, 81, user_fp) != NULL) { if (buff[0] == '#') continue; /* skip comment */ i = 0; delimit = ",\n"; if ((temp=strtok(buff, delimit)) != NULL) { do { param[i++] = temp; /* parse out the tokens */ if (i == 2) delimit = "\n"; /* ignore the comma from here */ } while ((temp=strtok((char *)NULL, delimit)) != NULL && i < 20); param[i] = NULL; } if (i < 2) continue; /* format error, skipped for now */ tmp = (struct test_info *)malloc(sizeof(struct test_info)); (void)bcopy((char *)(&tests_base[USER]), (char *)tmp, sizeof(struct test_info)); temp = malloc((unsigned)strlen(tmp->devname)+5); (void)sprintf(temp, "%s%d", tmp->devname, k); tmp->devname = temp; /* get the device name, userx */ temp = malloc((unsigned)strlen(param[0])+5); (void)strcpy(temp, param[0]); /* get the label */ tmp->label = temp; temp = malloc((unsigned)strlen(param[1])+2); (void)strcpy(temp, param[1]); /* get the testname */ while (*temp == ' ' || *temp == '\t') ++temp; /* skip white spaces */ tmp->testname = temp; if (i > 2) /* there are command tails */ { temp = malloc((unsigned)strlen(param[2])+2); (void)strcpy(temp, param[2]); /* ignore the rest of parameters */ tmp->env = temp; } tests[exist_tests++] = tmp; ++k; } (void)fclose(user_fp);}/****************************************************************************** * Initilaize the test's data base according to whatever the probing routine * * discovered. * * Input: f_dev_ptr, pointer to the table of information regarding the * * "found" device(built by probing routine). * * Output: None. * * * * Note: The found devices will also be sorted by the group. * ******************************************************************************/init_tests(f_dev_ptr)struct f_devs *f_dev_ptr; /* info. of found devices */{ int i, j, k, temp, test_no; char *tmp, buff[82]; struct found_dev *dev_ptr; struct test_info *tmp_tests[MAXTESTS]; /* temporary array */ int already_log=0; last_group = ngroups - 1; if (!ats_nohost || config_file_only == TRUE) if ((conf_fp=fopen(conf_file, "w")) == NULL) { (void)fprintf(stderr, "Sundiag: Can't open %s", conf_file); sundiag_exit(1); } cpuname = malloc((unsigned)strlen(f_dev_ptr->cpuname)+2); (void)strcpy(cpuname, f_dev_ptr->cpuname); if (!ats_nohost || config_file_only == TRUE) (void)fprintf(conf_fp, "cpu \"%s\"\n", cpuname); exist_tests = f_dev_ptr->num; dev_ptr = f_dev_ptr->found_dev; for (i=0, j= -1; i < exist_tests; ++i) { if ((test_no=check_probe(dev_ptr)) != -1) { tmp_tests[++j] = make_test(test_no, dev_ptr->unit); /* copy the device information into test's data base */ tmp_tests[j]->conf = (struct u_tag *)malloc(sizeof(struct u_tag)); bcopy((char *)(&(dev_ptr->u_tag)), (char *)(tmp_tests[j]->conf), sizeof(struct u_tag)); if (dev_ptr->u_tag.utype == DISK_DEV) { tmp = malloc((unsigned)strlen(dev_ptr->u_tag.uval.diskinfo.ctlr)+2); (void)strcpy(tmp, dev_ptr->u_tag.uval.diskinfo.ctlr); tmp_tests[j]->conf->uval.diskinfo.ctlr = tmp; } else if (dev_ptr->u_tag.utype == TAPE_DEV) { tmp = malloc((unsigned)strlen(dev_ptr->u_tag.uval.tapeinfo.ctlr)+2); (void)strcpy(tmp, dev_ptr->u_tag.uval.tapeinfo.ctlr); tmp_tests[j]->conf->uval.tapeinfo.ctlr = tmp; } switch (tmp_tests[j]->id) { case AUDIO: if ( dev_ptr->u_tag.uval.devinfo.status == 1 ) { tmp_tests[j]->type = 2; tmp_tests[j]->enable = DISABLE; tmp_tests[j]->data = (caddr_t)0x40; tmp_tests[j]->testname = "audbri"; tmp_tests[j]->special = (caddr_t)0; } break; case PMEM: case VMEM: temp = dev_ptr->u_tag.uval.meminfo.amt/1024; if (dev_ptr->u_tag.uval.meminfo.amt%1024 > 0) ++temp; tmp_tests[j]->conf->uval.meminfo.amt = temp; /* save it */ if (!ats_nohost || config_file_only == TRUE) { (void)fprintf(conf_fp, "%s\t%d MB\n", tmp_tests[j]->devname, temp); already_log = 1; } break; case SCSIDISK1: case XYDISK1: case XDDISK1: case IPIDISK1: case IDDISK1: case SFDISK1: case OBFDISK1: temp = dev_ptr->u_tag.uval.diskinfo.amt; /* in the unit of MB */ if (!ats_nohost || config_file_only == TRUE) { if (tmp_tests[j]->id != IDDISK1) (void)fprintf(conf_fp, "%s%d\t%d MB\n", tmp_tests[j]->devname, tmp_tests[j]->unit, temp); else (void)fprintf(conf_fp, "%s%03x\t%d MB\n", tmp_tests[j]->devname, tmp_tests[j]->unit, temp); already_log = 1; } /* Make sure the default rawtest option runs only one copy */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -