📄 cg6test.c
字号:
static char version[] = "Version 1.1";static char sccsid[] = "@(#)cg6test.c 1.1 7/30/92 Copyright 1988 Sun Micro";#include "cg6test.h"#include <machine/param.h>#ifdef DELAY#undef DELAY#define DELAY(xxx) { register int i=xxx; while (i--); }#endif DELAY#define DEV_NOT_OPEN 3#define RED_FAILED 4 #define GREEN_FAILED 5 #define BLUE_FAILED 6 #define FRAME_BUFFER_ERROR 7#define SIGBUS_ERROR 8#define SIGSEGV_ERROR 9#define SCREEN_NOT_OPEN 10#define CORRUPT_CG_LOWER_RT_A 12#define CORRUPT_CG_UPPER_LT_A 13#define CORRUPT_CG_LOWER_RT_B 14#define CORRUPT_CG_UPPER_LT_B 15#define SYNC_ERROR 19#define END_ERROR 20#include <sundiag_rpcnums.h> /* sundiag routines */#include <sdrtns.h>#define DEVICE "/dev/cgsix0"static unsigned char tred[256], tgrn[256], tblu[256];unsigned char red1[256], grn1[256], blu1[256];static unsigned char red2[256], grn2[256], blu2[256];static int rootfd, devtopfd;int testing_secondary_buffer;Pixrect *prfd, *sprfd;struct screen new_screen;int width, height, depth;unsigned int tmpplane;int cleanup_ioctl = FALSE;int tmpfbc, fbc_rev, tmptec, tec_fbc_test_flag;int dblflag, typeflag, lockflag;struct pixrect *mexp, *mobs;#define SINGLEHEAD 0x0#define DUALHEAD 0x1#define DBLBUF 0x2#define DBLBUF2HEAD 0x3 /* DUALHEAD | DBLBUF */#define read_lego_fbc(addr) (*(addr))#define write_lego_fbc(addr, datum) ((*(addr)) = (datum))#define read_lego_tec(addr) (*(addr))#define write_lego_tec(addr, datum) ((*(addr)) = (datum))/* LOCALS */static int simulate_error, return_code;static char msg[80];static int dummy(){return(FALSE);}char *routine_msg="Routine ";char *test_usage_msg= "[D=device name]";char *program_name;main(argc, argv) int argc; char *argv[];{ int tmpsim, probecode; u_long *fbc_base; extern int process_test_args(); extern buserr(); extern int routine_usage(); struct fbtype fb_type; struct fbgattr fb_gattr; unsigned int planes = 0xff;#ifdef FBIOGXINFO struct cg6_info cinfo;#endif FBIOGXINFO int tmpfd; program_name = argv[0]; test_name = argv[0]; device_name = DEVICE; fbc_rev = 0; testing_secondary_buffer = FALSE; func_name = "main"; TRACE_IN typeflag = 0; lockflag = 0; dblflag= FALSE; tec_fbc_test_flag=FALSE; simulate_error = 0; prfd = (Pixrect *) 0; /* begin Sundiag test */test_init(argc, argv, process_test_args, routine_usage, test_usage_msg); /* * initialize the mem pixrect */ prfd = pr_open(device_name); if (prfd <= 0) { pr_close(prfd); test_end(); } fb_gattr.real_type = 10; if ((tmpfd=open(device_name, O_RDONLY)) != -1) { ioctl(tmpfd, FBIOGATTR, &fb_gattr); close (tmpfd); }/* if (fb_gattr.real_type == FBTYPE_SUNFAST_COLOR ) {* if ( strcmp("/dev/cgsix0",device_name) == 0) {* device_name = "/dev/fb";** }** }*/ enable_vid(device_name); /* enable video, mainly for 2nd/3rd cg6's */ fbc_base = (u_long *) cg6_d(prfd)->cg6_fbc; fbc_rev = read_lego_fbc( fbc_base ) & 0x0f00000 ;#ifdef FBIOGXINFO/* printf("fbc_rev = 0x%x\n",fbc_rev); */ if((tmpfd=open(device_name, O_RDONLY)) == -1) printf("\nopen failed"); else { if( ioctl(tmpfd, FBIOGXINFO, &cinfo)>=0) { if((cinfo.vmsize==4)&&(cinfo.hdb_capable)) dblflag=TRUE; } close (tmpfd); }#endif FBIOGXINFO lock_desktop(device_name); lockflag=TRUE; width = prfd->pr_width; height = prfd->pr_height; depth = prfd->pr_depth; pr_getattributes(prfd, &tmpplane); pr_getcolormap(prfd, 0, 256, tred, tgrn, tblu); /* enable all planes */ planes = 0xff; pr_putattributes(prfd, &planes); initmem(); test_tec(); test_fbc(); tmpsim = simulate_error; if ( (simulate_error == CORRUPT_CG_LOWER_RT_B) || (simulate_error == CORRUPT_CG_UPPER_LT_B) ) { simulate_error = 0; } clear_screen(); testframebuffer(); simulate_error = tmpsim; testfb_to_fb(); test_blits(); test_lines(); test_polygons(); init_cmapnfb( red1, grn1, blu1); DELAY(10000); testcolormap(); clear_screen(); test_sine(); pr_putcolormap(prfd, 0, 256, tred, tgrn, tblu); clear_screen();#ifdef FBIOGXINFO if( dblflag == TRUE ) dbuf();#endif FBIOGXINFO pr_putcolormap(prfd, 0, 256, tred, tgrn, tblu); clear_screen(); clean_up(); if (!exec_by_sundiag) printf ("end of test.\n");done: test_end(); }process_test_args(argv, arrcount)char *argv[];int arrcount;{ func_name = "process_test_args"; TRACE_IN if (strncmp(argv[arrcount], "D=", 2) == 0) { device_name = argv[arrcount]+2; TRACE_OUT return(TRUE); } else return(FALSE);}routine_usage(){ func_name = "routine_usage"; TRACE_IN (void)send_message(SKIP_ERROR, CONSOLE, routine_msg, test_name); TRACE_OUT}struct pixrect *mexp, *mobs;unsigned int *ptr1, *ptr2, *mexphead, *mobshead;initmem(){ register struct mprp_data *mprd; /* * we set up the pixrect */ mexp = mem_create (width, height, depth); if (mexp <= 0) syserror(-SCREEN_NOT_OPEN, "mexp"); mobs = mem_create (width, height, depth); if (mobs <= 0) syserror(-SCREEN_NOT_OPEN, "mobs"); /* * set up where data begins in mem pixrects * mexphead = start of mexp. * mobshead = start of mobs. */ mprd = (struct mprp_data *) mexp->pr_data; mexphead = (unsigned int *) mprd->mpr.md_image; mprd = (struct mprp_data *) mobs->pr_data; mobshead = (unsigned int *) mprd->mpr.md_image; return (0);}testframebuffer(){ static char *framename[] = { "fb screen 1", "fb screen 2", "fb screen 3", "fb screen 4", "fb screen 5", "fb screen 6", "fb screen 7", "fb screen 8", }; int i, knt; int x, y, tw, th; unsigned int value; int num; func_name = "testframebuffer"; TRACE_IN /* * Roy G. Biv test * this test is basically a walking 1's type test. * a specific color signifies one of eight bits. */ /* * load the color map with appropriate values */ for (i = 0; i <= 255; i++) { red1[i] = 0; grn1[i] = 0; blu1[i] = 0; } red1[0] = 0; grn1[0] = 0; blu1[0] = 0; /* black */ red1[255] = 0xFF; grn1[255] = 0xFF; blu1[255] = 0xFF; /* white */ red1[1] = 0xFF; grn1[1] = 0; blu1[1] = 0; /* red */ red1[2] = 255; grn1[2] = 128; blu1[2] = 0; /* orange */ red1[4] = 255; grn1[4] = 255; blu1[4] = 0; /* yellow */ red1[8] = 0; grn1[8] = 0xFF; blu1[8] = 0xFF; /* cyan */ red1[0x10] = 0; grn1[0x10] = 0xFF; blu1[0x10] = 0; /* green */ red1[0x20] = 0; grn1[0x20] = 0; blu1[0x20] = 0xFF; /* blue */ red1[0x40] = 255; grn1[0x40] = 183; blu1[0x40] = 183; /* pink */ red1[0x80] = 255; grn1[0x80] = 0; blu1[0x80] = 255; /* violet */ pr_putcolormap(prfd, 0, 256, red1, grn1, blu1); /* each rop will should have only a single bit * set to 1. */ width = prfd->pr_width; height = prfd->pr_height; depth = prfd->pr_depth; num = 0; tw = width / depth; th = height; y = 0; for (i = 1; i <= 0x80; i <<= 1) { x = 0; value = i; for (knt = 0; knt < 8; knt++) { ropsend(x,y,tw, th, value); x += tw; if (value == 0x80) value = 0x1; else value <<= 1; } /* * corrupt to test if set. */ if ( (simulate_error == CORRUPT_CG_LOWER_RT_A) || (simulate_error == CORRUPT_CG_LOWER_RT_B) ) { pr_put(prfd, 1150, 898, 0x3); printf("corrupted 1150, 898\n"); } if ( (simulate_error == CORRUPT_CG_UPPER_LT_A) || (simulate_error == CORRUPT_CG_UPPER_LT_B) ) { pr_put(prfd, 1, 1, 0x3); printf("corrupted 1, 1\n"); } /* * read whats in the CG into mobs. */ pr_rop(mobs,0, 0, width, height,PIX_SRC,prfd,0,0); ropcheck(0,0,width, height,framename[num]); num++; } TRACE_OUT return (0);}/* send rop to CG and to expected */ropsend (x, y, w, h, color)int x, y, w, h, color;{ /* * we rop into the frame buffer and again * into the control memory. * it is ok to rop into memory without locking because it * is done into memory, not a common fb. * */ pr_rop(prfd,x, y, w, h,PIX_SRC|PIX_COLOR(color),0,0,0); pr_rop(mexp,x, y, w, h,PIX_SRC|PIX_COLOR(color),0,0,0); return (0);}ropcheck(x, y, w, h, testname)int x, y, w, h;char *testname;{ int i; int endpt; int tx, ty, tmp; ptr1 = (unsigned int *) mexphead; ptr2 = (unsigned int *) mobshead; i = y * width + x; for (; i < w * h/ sizeof (ptr1) ; i++) { if (*ptr1 != *ptr2 || simulate_error == FRAME_BUFFER_ERROR) { tmp = i*sizeof (ptr1); tx = tmp % width; ty = ( tmp - tx ) / width; sprintf(msg, "CG6 %s failure, x pos = %d, y pos = %d, exp = 0x%x, actual = 0x%x.", testname, tx, ty, *ptr1, *ptr2); errorprint(-FRAME_BUFFER_ERROR, msg); } ++ptr1; ++ptr2; } check_input(); return (0);}#define BLACK 0x0#define WHITE 0x1#define RED 0x55#define GREEN 0xAA#define BLUE 0x33#define YELLOW 0xCC#define CYAN 0x66#define VIOLET 0x99clear_screen(){ func_name = "clear_screen"; TRACE_IN pr_rop(prfd,0,0,width,height, PIX_SRC|PIX_COLOR(BLACK), 0,0,0); if(mobs>0) pr_rop(mobs,0, 0, width, height, PIX_SRC | PIX_COLOR(0), 0,0,0); if(mexp>0) pr_rop(mexp,0, 0, width, height, PIX_SRC | PIX_COLOR(0), 0,0,0); TRACE_OUT return(0);}testfb_to_fb(){ int i; int w, h, x1, y1, x2, y2, x3, y3, x4, y4; func_name= "testfb_to_fb"; TRACE_IN clear_screen(); /* * load the color map with appropriate values */ for (i = 0; i <= 255; i++) { red1[i] = 0; grn1[i] = 0; blu1[i] = 0; } red1[0] = 0; grn1[0] = 0; blu1[0] = 0; /* black */ red1[255] = 0xFF; grn1[255] = 0xFF; blu1[255] = 0xFF; /* white */ red1[RED] = 0xFF; grn1[RED] = 0; blu1[RED] = 0; /* red */ red1[GREEN] = 0; grn1[GREEN] = 0xFF; blu1[GREEN] = 0; /* green */ red1[BLUE] = 0; grn1[BLUE] = 0; blu1[BLUE] = 0xFF; /* blue */ red1[YELLOW] = 255; grn1[YELLOW] = 255; blu1[YELLOW] = 0; /* yellow */ red1[CYAN] = 0; grn1[CYAN] = 0xFF; blu1[CYAN] = 0xFF; /* cyan */ red1[VIOLET] = 255; grn1[VIOLET] = 0; blu1[VIOLET] = 255; /* violet */ pr_putcolormap(prfd, 0, 256, red1, grn1, blu1); w = 300; h = 300; /* upper left corner */ x1 = 0; y1 = 0; /* lower right corner */ x2 = width - 300; y2 = height - 300; /* upper right corner */ x3 = width - 300; y3 = 0; /* lower left corner */ x4 = 0; y4 = height - 300; /* bit blit of CYAN */ pr_rop(prfd, x1, y1, w, h, PIX_SRC|PIX_COLOR(CYAN), 0,0,0); pr_rop(prfd, x2, y2, w, h, PIX_SRC,prfd,x1,y1); pr_rop(prfd, x3, y3, w, h, PIX_SRC,prfd,x2,y2); pr_rop(prfd, x4, y4, w, h, PIX_SRC,prfd,x3,y3); /* read and place into observed */ pr_rop(mobs,0, 0, width, height, PIX_SRC,prfd,0,0); /* rop whats expected into expected */ pr_rop(mexp, 0, 0, width, height, PIX_SRC|PIX_COLOR(BLACK), 0,0,0); pr_rop(mexp, x1, y1, w, h, PIX_SRC|PIX_COLOR(CYAN), 0,0,0); pr_rop(mexp, x2, y2, w, h, PIX_SRC,prfd,x1,y1); pr_rop(mexp, x3, y3, w, h, PIX_SRC,prfd,x2,y2); pr_rop(mexp, x4, y4, w, h, PIX_SRC,prfd,x3,y3); ropcheck(0, 0, width, height, "fb to fb"); /* now we xor the whole frame buffer */ pr_rop(prfd,0,0,width,height, PIX_SRC ^ PIX_DST | PIX_COLOR(VIOLET), 0,0,0); /* rop frame buffer into observed */ pr_rop(mobs,0,0,width,height, PIX_SRC, prfd,0,0); /* rop data into expected */ pr_rop(mexp,0,0,width,height, PIX_SRC ^ PIX_DST | PIX_COLOR(VIOLET), 0,0,0); ropcheck(0,0,width,height, "xor src to fb"); TRACE_OUT return(0);}test_blits(){ int w, h, x1, y1, x2, y2, x3, y3, x4, y4; x1 = 0; y1 = 0; x2 = 300; y2 = 300; w = 250; h = 250; clear_screen(); /* bit blit of CYAN */ pr_rop(prfd, x1, y1, w, h, PIX_SRC|PIX_COLOR(CYAN), 0,0,0); pr_rop(prfd, x2, y2, w, h, PIX_SRC,prfd,x1,y1); return(0);}init_cmapnfb(red1, grn1, blu1)unsigned char red1[256], grn1[256], blu1[256];{ int i, j, k, x, y, tw, th; clear_screen(); /* * put squares into the frame buffer */ if ( (width == 1152) && (height == 900) ) { tw = 72; th = 56; } else { tw = width / 16; th = height / 16; } k = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -