📄 test-xnet.c
字号:
{(15 * HZ), (60 * HZ)}, /* T1 15-60 seconds */ {(3 * 60 * HZ), (3 * 60 * HZ)}, /* T2 3 minutes */ {(2 * 60 * HZ), (2 * 60 * HZ)}, /* T3 2 minutes */ {(5 * 60 * HZ), (15 * 60 * HZ)}, /* T4 5-15 minutes */ {(5 * 60 * HZ), (15 * 60 * HZ)}, /* T5 5-15 minutes */ {(10 * HZ), (32 * HZ)}, /* T6 10-32 seconds (specified in Q.118) */ {(20 * HZ), (30 * HZ)}, /* T7 20-30 seconds */ {(10 * HZ), (15 * HZ)}, /* T8 10-15 seconds */ {(2 * 60 * HZ), (4 * 60 * HZ)}, /* T9 2-4 minutes (specified in Q.118) */ {(4 * HZ), (6 * HZ)}, /* T10 4-6 seconds */ {(15 * HZ), (20 * HZ)}, /* T11 15-20 seconds */ {(15 * HZ), (60 * HZ)}, /* T12 15-60 seconds */ {(5 * 60 * HZ), (15 * 60 * HZ)}, /* T13 5-15 minutes */ {(15 * HZ), (60 * HZ)}, /* T14 15-60 seconds */ {(5 * 60 * HZ), (15 * 60 * HZ)}, /* T15 5-15 minutes */ {(15 * HZ), (60 * HZ)}, /* T16 15-60 seconds */ {(5 * 60 * HZ), (15 * 60 * HZ)}, /* T17 5-15 minutes */ {(15 * HZ), (60 * HZ)}, /* T18 15-60 seconds */ {(5 * 60 * HZ), (15 * 60 * HZ)}, /* T19 5-15 minutes */ {(15 * HZ), (60 * HZ)}, /* T20 15-60 seconds */ {(5 * 60 * HZ), (15 * 60 * HZ)}, /* T21 5-15 minutes */ {(15 * HZ), (60 * HZ)}, /* T22 15-60 seconds */ {(5 * 60 * HZ), (15 * 60 * HZ)}, /* T23 5-15 minutes */ {(1 * HZ), (2 * HZ)}, /* T24 < 2 seconds */ {(1 * HZ), (10 * HZ)}, /* T25 1-10 seconds */ {(1 * 60 * HZ), (3 * 60 * HZ)}, /* T26 1-3 minutes */ {(4 * 60 * HZ), (4 * 60 * HZ)}, /* T27 4 minutes */ {(10 * HZ), (10 * HZ)}, /* T28 10 seconds */ {(300 * HZ / 1000), (600 * HZ / 1000)}, /* T29 300-600 milliseconds */ {(5 * HZ), (10 * HZ)}, /* T30 5-10 seconds */ {(6 * 60 * HZ), (7 * 60 * HZ)}, /* T31 > 6 minutes */ {(3 * HZ), (5 * HZ)}, /* T32 3-5 seconds */ {(12 * HZ), (15 * HZ)}, /* T33 12-15 seconds */ {(12 * HZ), (15 * HZ)}, /* T34 12-15 seconds */ {(15 * HZ), (20 * HZ)}, /* T35 15-20 seconds */ {(15 * HZ), (20 * HZ)}, /* T36 15-20 seconds */ {(2 * HZ), (4 * HZ)}, /* T37 2-4 seconds */ {(15 * HZ), (20 * HZ)} /* T38 15-20 seconds */};/* *INDENT-ON* */long test_start = 0;static int state;/* * Return the current time in milliseconds. */static longnow(void){ long ret; struct timeval now; if (gettimeofday(&now, NULL)) { int error = errno; lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "***************ERROR: couldn't get time!\n"); fprintf(stdout, " %s: %s\n", __FUNCTION__, strerror(error)); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); return (0); } if (!test_start) /* avoid blowing over precision */ test_start = now.tv_sec; ret = (now.tv_sec - test_start) * 1000L; ret += (now.tv_usec + 999L) / 1000L; return ret;}static longmilliseconds(char *t){ lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, " . . : . \n"); fprintf(stdout, " . . %6s . <%d>\n", t, state); fprintf(stdout, " . . : . \n"); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); return now();}static longmilliseconds_2nd(char *t){ lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, " . . : : . \n"); fprintf(stdout, " . . : %6s . <%d>\n", t, state); fprintf(stdout, " . . : : . \n"); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); return now();}/* * Check the current time against the beginning time provided as an argnument * and see if the time inverval falls between the low and high values for the * timer as specified by arguments. Return SUCCESS if the interval is within * the allowable range and FAILURE otherwise. */static intcheck_time(const char *t, long i, long lo, long hi){ float tol, dlo, dhi, itv; itv = i * timer_scale; dlo = lo; dhi = hi; tol = 100 * timer_scale; itv = itv / 1000; dlo = dlo / 1000; dhi = dhi / 1000; tol = tol / 1000; lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, " | |(%7.3g <= %7.3g <= %7.3g)| %s <%d>\n", dlo - tol, itv, dhi + tol, t, state); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); if (dlo - tol <= itv && itv <= dhi + tol) return SUCCESS; else return FAILURE;}static inttime_event(int event){ if (verbose > 1) { float t, m; struct timeval now; gettimeofday(&now, NULL); if (!test_start) test_start = now.tv_sec; t = (now.tv_sec - test_start); m = now.tv_usec; m = m / 1000000; t += m; lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, " | | %11.6g | <%d>\n", t, state); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } return (event);}static int timer_timeout = 0;static voidtimer_handler(int signum){ if (signum == SIGALRM) timer_timeout = 1; return;}static inttimer_sethandler(void){ sigset_t mask; struct sigaction act; act.sa_handler = timer_handler; act.sa_flags = SA_RESTART | SA_ONESHOT; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, NULL)) return FAILURE; sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_UNBLOCK, &mask, NULL); return SUCCESS;}/* * Start an interval timer as the overall test timer. */static intstart_tt(long duration){ struct itimerval setting = { {0, 0}, {duration / 1000, (duration % 1000) * 1000} }; if (timer_sethandler()) return FAILURE; if (setitimer(ITIMER_REAL, &setting, NULL)) return FAILURE; timer_timeout = 0; return SUCCESS;}static intstart_st(long duration){ long sdur = (duration + timer_scale - 1) / timer_scale; return start_tt(sdur);}static intstop_tt(void){ struct itimerval setting = { {0, 0}, {0, 0} }; sigset_t mask; struct sigaction act; if (setitimer(ITIMER_REAL, &setting, NULL)) return FAILURE; act.sa_handler = SIG_DFL; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, NULL)) return FAILURE; timer_timeout = 0; sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, NULL); return SUCCESS;}/* * ------------------------------------------------------------------------- * * Injected event encoding and display functions. * * ------------------------------------------------------------------------- */static intdo_signal(int fd, int action){ int result; struct strbuf ctrl_buf, data_buf, *ctrl = &ctrl_buf, *data = &data_buf; char cbuf[256], dbuf[256]; union T_primitives *p = (typeof(p)) cbuf; struct strioctl ic; ic.ic_cmd = 0; ic.ic_timout = 200; ic.ic_len = sizeof(cbuf); ic.ic_dp = cbuf; ctrl->maxlen = 0; ctrl->buf = cbuf; data->maxlen = 0; data->buf = dbuf; test_pflags = MSG_BAND; test_pband = 0; if (fd == top_fd) { switch (action) { case __TEST_PUSH: if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "--I_PUSH(timod)---->| | | [%d]\n", state); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } if (ioctl(top_fd, I_PUSH, "timod") < 0) { last_errno = errno; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "***************ERROR: ioctl I_PUSH failed\n"); fprintf(stdout, " : %s; %s\n", __FUNCTION__, strerror(last_errno)); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } return (FAILURE); } return (SUCCESS); case __TEST_POP: if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "--I_POP(timod)----->| | | [%d]\n", state); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } if (ioctl(top_fd, I_POP, NULL) < 0) { last_errno = errno; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "***************ERROR: ioctl I_POP failed\n"); fprintf(stdout, " : %s; %s\n", __FUNCTION__, strerror(last_errno)); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } return (FAILURE); } return (SUCCESS); case __TEST_O_NONBLOCK: { long flags; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "--fcntl(2)--------->| | O_NONBLOCK | [%d]\n", state); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } if ((flags = fcntl(top_fd, F_GETFL)) == -1) { last_errno = errno; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "***************ERROR: fcntl F_GETFL failed\n"); fprintf(stdout, " : %s; %s\n", __FUNCTION__, strerror(last_errno)); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } return (FAILURE); } if (fcntl(top_fd, F_SETFL, flags | O_NONBLOCK) == -1) { last_errno = errno; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "***************ERROR: fcntl F_SETFL failed\n"); fprintf(stdout, " : %s; %s\n", __FUNCTION__, strerror(last_errno)); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } return (FAILURE); } return (SUCCESS); } case __TEST_O_BLOCK: { long flags; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "--fcntl(2)--------->| | ~O_NONBLOCK | [%d]\n", state); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } if ((flags = fcntl(top_fd, F_GETFL)) == -1) { last_errno = errno; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "***************ERROR: fcntl F_GETFL failed\n"); fprintf(stdout, " : %s; %s\n", __FUNCTION__, strerror(last_errno)); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } return (FAILURE); } if (fcntl(top_fd, F_SETFL, flags & ~O_NONBLOCK) == -1) { last_errno = errno; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "***************ERROR: fcntl F_SETFL failed\n"); fprintf(stdout, " : %s; %s\n", __FUNCTION__, strerror(last_errno)); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } return (FAILURE); } return (SUCCESS); } case __TEST_WRITE: if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "--write(2)--------->| | | [%d]\n", state); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } data->len = sprintf(dbuf, "Write test data."); if (write(top_fd, dbuf, data->len) < 0) { last_errno = errno; if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "***************ERROR: write failed\n"); fprintf(stdout, " : %s; %s\n", __FUNCTION__, strerror(last_errno)); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); } return FAILURE; } return SUCCESS; case __TEST_WRITEV: { if (verbose) { lockf(fileno(stdout), F_LOCK, 0); fprintf(stdout, "--writev(2)-------->| | | [%d]\n", state); fflush(stdout); lockf(fileno(stdout), F_ULOCK, 0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -