📄 mono.c
字号:
/* * video_test() opens the particular device (e.g., /dev/bwtwo0), mmaps it * to this process' address space, and then calls the functions that * actually test the frame buffer. * * argument: size - size of frame buffer, in bytes. */video_test(size) int size;{ caddr_t mmap(); unsigned char *fb_addr;/* fb's address in this process' address space */ int fd; /* file descriptor for frame buffer device */ unsigned seed; /* seed for random data test */ if ((fd = open(fbname, O_RDWR)) < 0) fb_send_message(1, ERROR, e_open_msg, fbname); if ((fb_addr = (unsigned char *)mmap((caddr_t)0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)0)) == (unsigned char *)-1) { fb_send_message(2, ERROR, e_mmap_msg, errmsg(errno)); } fb_send_message(0, VERBOSE, v_fbaddr_msg, fb_addr); fill(fb_addr, size, 0x33); check(fb_addr, size, 0x33); fill(fb_addr, size, 0x55); check(fb_addr, size, 0x55); for (seed = 1; seed < size; seed = seed + (size/10)) randomtest((unsigned long *)fb_addr, size, seed); addrtest(fb_addr, size); laddrtest((unsigned long *)fb_addr, size); stripetest(fb_addr, size);}/* * check_input() checks if the user has typed a CTRL-C on the keyboard, * meaning the test should be aborted. */check_input(){# ifdef OL /* if ( XCheckIFEvent() ).. */# else int arg; if (needs_clean_up) { (void)ioctl(gfx_fd, FIONREAD, &arg); if (arg != 0) { (void)input_readevent(gfx_fd, &event); if (event_id(&event) == 0x03) /* CTRL-C */ finish(); } }# endif OL}/* * fill() writes a constant pattern into the frame buffer. * * arguments: * base - base address of frame buffer. * size - number of bytes in frame buffer. * pattern - a constant pattern (8 bits). */fill(base, size, pattern) unsigned char *base; int size; u_char pattern;{ int i; for (i = 0; i < size; i++) *base++ = pattern; check_input();}/* * check() reads from the frame buffer and compares each location with a * constant pattern. When a miscompare is found, the error message * is displayed and the test aborted (via send_message). * * arguments: * base - base address of frame buffer. * size - number of bytes in frame buffer. * pattern - a constant pattern (8 bits). */check(base, size, pattern) unsigned char *base; int size; u_char pattern;{ int i; u_char value; unsigned char *addr = base; for (i = 0; i < size; i++, addr++) { if ((value = *addr) != pattern) fb_send_message(1, ERROR, e_const_msg, addr-base, pattern, value); } check_input();}/* * addrtest() fills each (byte) location of the frame buffer with the lower * 8 bits of its address. After writing to entire frame buffer, addrtest() * then reads and compares the data. If an error is found, the message is * displayed and the test terminates (via send_message). * * arguments: * base - base address of frame buffer. * size - number of bytes in frame buffer. */addrtest(base, size) unsigned char *base; int size;{ int i; unsigned char *addr = base; u_char obs_value; for (i = 0; i < size; i++, addr++) *addr = (u_char)addr; check_input(); for (addr = base, i = 0; i < size; i++, addr++) { if ((obs_value = *addr) != (u_char)addr) fb_send_message(1, ERROR, e_addr_msg, addr-base, obs_value, (u_char)addr); }}/* * laddrtest() fills each (word) location of the frame buffer with * its 32-bit address. After writing to entire frame buffer, laddrtest() * then reads and compares the data. If an error is found, the message is * displayed and the test terminates (via send_message). * * arguments: * base - base address of frame buffer. * size - number of bytes in frame buffer. */laddrtest(base, size) unsigned long *base; int size; /* frame buffer size, in bytes */{ int i; unsigned long *addr = base; unsigned long obs_value; for (i = 0; i < size/(sizeof(long)); i++, addr++) *addr = (unsigned long)addr; check_input(); for (addr = base, i = 0; i < size/(sizeof(long)); i++, addr++) { if ((obs_value = *addr) != (unsigned long)addr) fb_send_message(1, ERROR, e_laddr_msg, addr-base, obs_value, addr); }}/* * randomtest() fills each (word) location of the frame buffer with a random * number. The random numbers are generated using the seed argument. * This is only pseudo-random as the numbers are the same ones generated * for each seed. Since this is the case, we can go back and compare * what was written to what we expect. If a miscompare is found, the * error message is displayed and the test terminates (via send_message). * * arguments: * base - base address of frame buffer. * size - number of bytes in frame buffer. * seed - seed to generate random numbers. */randomtest(base, size, seed) unsigned long *base; int size; /* frame buffer size, in bytes */ unsigned seed; /* seed for random() function */{ long random(); char *initstate(); static long state1[32] = {3}; int i; unsigned long *addr = base; unsigned long obs_value, exp_value; (void)initstate(seed, (char *)state1, 128); /* set up random sequence */ for (i = 0; i < size/(sizeof(long)); i++) *addr++ = (unsigned long)(random()); check_input(); addr = base; /* reset addr to base of fb for checking */ (void)initstate(seed, (char *)state1, 128); for (i = 0; i < size/(sizeof(long)); i++) { if ((obs_value = *addr++) != (exp_value = (unsigned long)random())) fb_send_message(1, ERROR, e_rand_msg, addr-base, obs_value, exp_value); }}/* * stripetest() writes an approximately stripe pattern to the frame buffer. * First 0's are written to every other j bytes until end of frame buffer. * Then the bytes that were skipped will be filled in with 0xff's (black) * until end of frame buffer memory. Then the bytes are read back and * compared to the expected pattern. If successful, then we double the * size of j and start writing to memory again. * * arguments: * base - base address of frame buffer. * size - number of bytes in frame buffer. * */stripetest(base, size) unsigned char *base; int size;{ unsigned char pat = 0; unsigned char obs = 0; /* observed pattern */ unsigned char *addr = base; int j, k, l, m; for (j = 1; j < size; j *= 2) { /* double the bytes written each time */ for (k = 0; k < 2; k++, pat = ~pat) { for (addr = base + (j * k), l = size/(j * sizeof(unsigned char)*2); l != 0; l--, addr += j) { for (m = j; m != 0; m--, addr++) *addr = pat; } } check_input(); for (k = 0; k < 2; k++, pat = ~pat) { for (addr = base + (j * k), l = size/(j * sizeof(unsigned char)*2); l != 0; l--, addr += j) { for (m = j; m != 0; m--, addr++) { if ((obs = *addr) != pat) fb_send_message(1, ERROR, e_stripe_msg, addr-base, pat, obs); } } } }}clean_up(){# ifdef OL# else struct sgttyb ttybuf; if (needs_clean_up) { /* restore the input characteristics */ (void)ioctl(0, TIOCGETP, &ttybuf); ttybuf.sg_flags &= ~CBREAK; ttybuf.sg_flags |= ECHO; (void)ioctl(0, TIOCSETP, &ttybuf); (void)win_grabio(gfx_fd); /* to restore the screen(!!!) */ (void)win_releaseio(gfx_fd); (void)win_setms(gfx_fd, &s); /* reconnect the mouse */ (void)close(gfx_fd); } else if ((testing_fb == FALSE) && (screen != NULL)) (void)pr_rop(screen,0,0,screen->pr_size.x, screen->pr_size.y, PIX_SRC|PIX_COLOR(0xff), (Pixrect *)0,0,0); /* clear the screen before exit */# endif OL}process_mono_args(argv, arrcount)char *argv[];int arrcount;{ if (strncmp(argv[arrcount], "/dev/", 5) == 0) { fbname = argv[arrcount]; return (TRUE); } return (FALSE);}routine_usage(){ send_message(0, CONSOLE, routine_msg);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -