📄 test-tirdwr.c
字号:
/***************************************************************************** @(#) test-tirdwr.c,v strxnet-0_9_2-4(0.9) 2004/04/03 22:37:08 ----------------------------------------------------------------------------- Copyright (c) 2001-2004 OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@openss7.org> All Rights Reserved. Unauthorized distribution or duplication is prohibited. This software and related documentation is protected by copyright and distributed under licenses restricting its use, copying, distribution and decompilation. No part of this software or related documentation may be reproduced in any form by any means without the prior written authorization of the copyright holder, and licensors, if any. The recipient of this document, by its retention and use, warrants that the recipient will protect this information and keep it confidential, and will not disclose the information contained in this document without the written permission of its owner. The author reserves the right to revise this software and documentation for any reason, including but not limited to, conformity with standards promulgated by various agencies, utilization of advances in the state of the technical arts, or the reflection of changes in the design of any techniques, or procedures embodied, described, or referred to herein. The author is under no obligation to provide any feature listed herein. As an exception to the above, this software may be distributed under the GNU General Public License (GPL) Version 2 or later, so long as the software is distributed with, and only used for the testing of, OpenSS7 modules, drivers, and libraries. ----------------------------------------------------------------------------- U.S. GOVERNMENT RESTRICTED RIGHTS. If you are licensing this Software on behalf of the U.S. Government ("Government"), the following provisions apply to you. If the Software is supplied by the Department of Defense ("DoD"), it is classified as "Commercial Computer Software" under paragraph 252.227-7014 of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any successor regulations) and the Government is acquiring only the license rights granted herein (the license rights customarily provided to non-Government users). If the Software is supplied to any unit or agency of the Government other than DoD, it is classified as "Restricted Computer Software" and the Government's rights in the Software are defined in paragraph 52.227-19 of the Federal Acquisition Regulations ("FAR") (or any success regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Last Modified 2004/04/03 22:37:08 by <bidulock@openss7.org> *****************************************************************************/#ident "@(#) test-tirdwr.c,v strxnet-0_9_2-4(0.9) 2004/04/03 22:37:08"static char const ident[] = "test-tirdwr.c,v strxnet-0_9_2-4(0.9) 2004/04/03 22:37:08";/* * These is a ferry-clip TIRDWR conformance test program for testing the * OpenSS7 tirdwr STREAMS module. * * GENERAL OPERATION: * * The test program opens STREAMS pipe and pushes the "tirdwr" module onto one * side of the pipe. * * The test program exchanges TPI primitives with one side of the open pipe * and exchagnes TPI primitives and executes TIRDWR ioctls on the other side * of the pipe. The side of the pipe with the "tirdwr" STREAMS module pushed * represents the XTI library user of the TIRDWR module. The other side of * the pipe is the test harness, as shown below: * * USER SPACE * TEST PROGRAM * _________________________________________________________________________ * \ / | \ / | * \ / | \ / | * | / \ | | * ____________|__/___\__________ | | * | | | | * | | | | * | TIRDWR | | | * | | | | * | STREAMS MODULE | | | * | | | | * | | | | * |______________________________| | | * \ / | | | * \ / | | | * | | | | * | / \ | | * ____________|__/___\____________________________|____|_____________ * | | * | | * | PIPE | * | | * |___________________________________________________________________| * * * This test arrangement results in a a ferry-clip around the TIRDWR module, * where TPI primitives are injected and removed beneath the module as well * as both TPI primitives and ioctls being performed above the module. * * To preserve the environment and ensure that the tests are repeatable in * any order, the entire test harness (pipe) is assembled and disassembled * for each test. A test preamble is used to place the module in the correct * state for a test case to begin and then a postable is used to ensure that * the module can be removed correctly. */#include <stropts.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/poll.h>#include <stdio.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <signal.h>#include <sys/uio.h>#ifdef _GNU_SOURCE#include <getopt.h>#endif#define NEED_T_USCALAR_T#include <sys/types.h>#include <xti.h>#include <tihdr.h>#include <timod.h>#include <xti_inet.h>/* * ------------------------------------------------------------------------- * * Configuration * * ------------------------------------------------------------------------- */static int verbose = 1;static int show_msg = 0;static int show_acks = 0;static int show_timeout = 0;static int last_event = 0;static int last_errno = 0;static int top_fd = 0;static int bot_fd = 0;#define BUFSIZE 4096/* * ------------------------------------------------------------------------- * * Events and Actions * * ------------------------------------------------------------------------- */enum { NO_MSG = -6, TIMEOUT = -5, UNKNOWN = -4, DECODEERROR = -3, SCRIPTERROR = -2, INCONCLUSIVE = -1, SUCCESS = 0, FAILURE = 1,};enum { __TEST_CONN_REQ = 2, __TEST_CONN_RES, __TEST_DISCON_REQ, __TEST_DATA_REQ, __TEST_EXDATA_REQ, __TEST_INFO_REQ, __TEST_BIND_REQ, __TEST_UNBIND_REQ, __TEST_UNITDATA_REQ, __TEST_OPTMGMT_REQ, __TEST_ORDREL_REQ, __TEST_OPTDATA_REQ, __TEST_ADDR_REQ, __TEST_CAPABILITY_REQ, __TEST_CONN_IND, __TEST_CONN_CON, __TEST_DISCON_IND, __TEST_DATA_IND, __TEST_EXDATA_IND, __TEST_INFO_ACK, __TEST_BIND_ACK, __TEST_ERROR_ACK, __TEST_OK_ACK, __TEST_UNITDATA_IND, __TEST_UDERROR_IND, __TEST_OPTMGMT_ACK, __TEST_ORDREL_IND, __TEST_NRM_OPTDATA_IND, __TEST_EXP_OPTDATA_IND, __TEST_ADDR_ACK, __TEST_CAPABILITY_ACK, __TEST_WRITE, __TEST_WRITEV, __TEST_PUTMSG_DATA, __TEST_PUTPMSG_DATA, __TEST_PUSH, __TEST_POP, __TEST_READ, __TEST_READV, __TEST_GETMSG, __TEST_GETPMSG, __TEST_DATA, __TEST_O_TI_GETINFO, __TEST_O_TI_OPTMGMT, __TEST_O_TI_BIND, __TEST_O_TI_UNBIND, __TEST__O_TI_GETINFO, __TEST__O_TI_OPTMGMT, __TEST__O_TI_BIND, __TEST__O_TI_UNBIND, __TEST__O_TI_GETMYNAME, __TEST__O_TI_GETPEERNAME, __TEST__O_TI_XTI_HELLO, __TEST__O_TI_XTI_GET_STATE, __TEST__O_TI_XTI_CLEAR_EVENT, __TEST__O_TI_XTI_MODE, __TEST__O_TI_TLI_MODE, __TEST_TI_GETINFO, __TEST_TI_OPTMGMT, __TEST_TI_BIND, __TEST_TI_UNBIND, __TEST_TI_GETMYNAME, __TEST_TI_GETPEERNAME, __TEST_TI_SETMYNAME, __TEST_TI_SETPEERNAME, __TEST_TI_SYNC, __TEST_TI_GETADDRS, __TEST_TI_CAPABILITY,};/* * ------------------------------------------------------------------------- * * Timer Functions * * ------------------------------------------------------------------------- *//* * Timer values for tests: each timer has a low range (minus error margin) * and a high range (plus error margin). */static long timer_scale = 1;#define TEST_TIMEOUT 5000typedef struct timer_range { long lo; long hi;} timer_range_t;enum { t1 = 0, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, tmax};#undef HZ#define HZ 1000/* *INDENT-OFF* */static timer_range_t timer[tmax] = { {(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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -