⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-xnet.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** @(#) test-xnet.c,v openss7-0_9_2_E(0.9.2.12) 2007/03/15 10:15:15 ----------------------------------------------------------------------------- Copyright (c) 2001-2007  OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@openss7.org> All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------------------- 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 successor regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee.  See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2007/03/15 10:15:15 by brian ----------------------------------------------------------------------------- test-xnet.c,v Revision 0.9.2.12  2007/03/15 10:15:15  brian - test case reporting and release date Revision 0.9.2.11  2007/03/12 02:23:34  brian - updating tests Revision 0.9.2.10  2006/10/31 21:04:56  brian - changes for 32-bit compatibility and remove HZ dependency Revision 0.9.2.9  2006/07/08 07:25:46  brian - removed trigraphs Revision 0.9.2.8  2006/03/03 12:06:14  brian - 32/64-bit compatibility Revision 0.9.2.7  2005/12/28 09:58:34  brian - remove warnings on FC4 compile Revision 0.9.2.6  2005/05/14 08:31:40  brian - copyright header correction *****************************************************************************/#ident "@(#) test-xnet.c,v openss7-0_9_2_E(0.9.2.12) 2007/03/15 10:15:15"static char const ident[] = "test-xnet.c,v openss7-0_9_2_E(0.9.2.12) 2007/03/15 10:15:15";/* *  This is a ferry-clip XTI/TLI conformance test program for testing the *  OpenSS7 XTI/TLI Library. * *  GENERAL OPERATION: * *  The test program opens STREAMS pipe and pushes the "timod" module onto one *  side of the pipe. * *  The test program exchanges TPI primitives with one side of the open pipe *  and performs XTI/TLI Library Calls on a file descriptor at the other end *  of the pipe.  The side with the XTI/TLI Library represents the XTI user; *  the other side, the test harness, as shown below: * *                               USER SPACE *                              TEST PROGRAM *   ___________________________________  _________________________________ *  |                                   |            \   /  |               *  |                                   |             \ /   |               *  |                                   |              |    |               *  |                                   |              |    |               *  |             XTI/TLI               |              |    |               *  |             Library               |              |    |               *  |                                   |              |    |               *  |                                   |              |    |               *  |                                   |              |    |               *  |___________________________________|              |    |               *               \   /  |                              |    |               *                \ /   |                              |    |               *                 |   / \                             |    |               *     ____________|__/___\__________                  |    |               *    |                              |                 |    |               *    |                              |                 |    |               *    |            TIMOD             |                 |    |               *    |                              |                 |    |               *    |        STREAMS MODULE        |                 |    |               *    |                              |                 |    |               *    |                              |                 |    |               *    |______________________________|                 |    |               *               \   /  |                              |    |               *                \ /   |                              |    |               *                 |    |                              |    |               *                 |   / \                             |    |               *     ____________|__/___\____________________________|____|_____________  *    |                                                                   | *    |                                                                   | *    |                               PIPE                                | *    |                                                                   | *    |___________________________________________________________________| * * *  This test arrangement results in a a ferry-clip around the XTI/TLI Library *  and TIMOD module, where TPI primitives are injected and removed beneath *  the module as well XTI/TLI Library calls peformed 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 <sys/types.h>#include <stropts.h>#include <stdlib.h>#ifdef HAVE_INTTYPES_H# include <inttypes.h>#else# ifdef HAVE_STDINT_H#  include <stdint.h># endif#endif#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>#include <time.h>#ifdef HAVE_SYS_WAIT_H# include <sys/wait.h>#endif#ifdef _GNU_SOURCE#include <getopt.h>#endif#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#define NEED_T_USCALAR_T#include <xti.h>#include <tihdr.h>#include <timod.h>#include <xti_inet.h>/* *  ------------------------------------------------------------------------- * *  Configuration * *  ------------------------------------------------------------------------- */static const char *lpkgname = "OpenSS7 XTI/TLI Library";/* static const char *spkgname = "XNET"; */static const char *lstdname = "XNS 5.2";static const char *sstdname = "XNS";static const char *shortname = "XNET";#ifdef LFSstatic char devname[256] = "/dev/streams/clone/echo";#elsestatic char devname[256] = "/dev/echo";#endifstatic int repeat_verbose = 0;static int repeat_on_success = 0;static int repeat_on_failure = 0;static int exit_on_failure = 0;static int verbose = 1;static int show_msg = 0;static int show_acks = 0;static int show_timeout = 0;static int show_data = 1;static int last_prim = 0;static int last_event = 0;static int last_errno = 0;static int last_retval = 0;static int last_t_errno = 0;static int last_tevent = 0;static int last_qlen = 2;static int last_sequence = 1;static int last_servtype = T_COTS_ORD;static int last_provflag = T_SENDZERO | T_ORDRELDATA | T_XPG4_1;static int last_tstate = TS_UNBND;struct T_info_ack last_info = { 0, };static int last_prio = 0;static int MORE_flag = 0;static int DATA_flag = T_ODF_EX | T_ODF_MORE;int test_fd[3] = { 0, 0, 0 };#define BUFSIZE 5*4096#define FFLUSH(stream)#define SHORT_WAIT	  20	// 100 // 10#define NORMAL_WAIT	 100	// 500 // 100#define LONG_WAIT	 500	// 5000 // 500#define LONGER_WAIT	1000	// 10000 // 5000#define LONGEST_WAIT	5000	// 20000 // 10000#define TEST_DURATION	20000#define INFINITE_WAIT	-1static ulong test_duration = TEST_DURATION;	/* wait on other side */char cbuf[BUFSIZE];char dbuf[BUFSIZE];struct strbuf ctrl = { BUFSIZE, -1, cbuf };struct strbuf data = { BUFSIZE, -1, dbuf };static int test_sndflags = 0;		/* T_MORE | T_EXPEDITED | T_PUSH */static int test_rcvflags = 0;		/* T_MORE | T_EXPEDITED */static int test_pflags = MSG_BAND;	/* MSG_BAND | MSG_HIPRI */static int test_pband = 0;static int test_gflags = 0;		/* MSG_BAND | MSG_HIPRI */static int test_gband = 0;static int test_bufsize = 256;static int test_tidu = 256;static int test_mgmtflags = T_NEGOTIATE;static struct sockaddr_in *test_addr = NULL;static socklen_t test_alen = sizeof(*test_addr);static const char *test_data = NULL;static int test_resfd = -1;static int test_timout = 200;static void *test_opts = NULL;static int test_olen = 0;static int test_prio = 1;struct strfdinsert fdi = {	{BUFSIZE, 0, cbuf},	{BUFSIZE, 0, dbuf},	0,	0,	0};int flags = 0;int dummy = 0;struct timeval when;char test_opt[256], test_udata[256], test_locadd[256], test_remadd[256];struct t_unitdata test_sndudata = {	{256, 256, test_remadd},	{256, 256, test_opt},	{256, 256, test_udata}};struct t_unitdata test_rcvudata = {	{256, 0, test_remadd},	{256, 0, test_opt},	{256, 0, test_udata}};struct t_uderr test_uderr = {	{256, 0, test_remadd},	{256, 0, test_opt},	0};/* listen call used in t_listen */struct t_call test_liscall = {	{256, 0, test_remadd},	{256, 0, test_opt},	{256, 0, test_udata},	1};/* accepted call used in t_accept */struct t_call test_acccall = {	{256, 256, test_locadd},	{256, 256, test_opt},	{256, 256, test_udata},	1};/* send to call used in t_connect */struct t_call test_sndcall = {	{256, 256, test_remadd},	{256, 256, test_opt},	{256, 256, test_udata},	0};/* receive call used in t_connect an t_rcvconnect */struct t_call test_rcvcall = {	{256, 0, test_remadd},	{256, 0, test_opt},	{256, 0, test_udata},	0};struct t_call test_discall = {	{256, 256, test_locadd},	{256, 256, test_opt},	{256, 256, test_udata},	1};struct t_optmgmt test_req = {	{256, 256, test_opt},	T_NEGOTIATE};struct t_optmgmt test_ret = {	{256, 0, test_opt},	0};struct t_discon test_rcvdis = {	{256, 0, test_udata},	0};struct t_discon test_snddis = {	{256, 256, test_udata},	0, 1};struct t_bind test_bindreq = {	{256, 256, test_locadd},	2};struct t_bind test_bindret = {	{256, 0, test_locadd},	2};struct t_bind test_addrloc = {	{256, 0, test_locadd},	0};struct t_bind test_addrrem = {	{256, 0, test_remadd},	0};struct t_info test_info;struct iovec test_iov[4] = {	[0] = {test_udata, 64},	[1] = {test_udata + 64, 64},	[2] = {test_udata + 64 + 64, 64},	[3] = {test_udata + 64 + 64 + 64, 64},};struct t_iovec test_t_iov[4] = {	[0] = {test_udata, 64},	[1] = {test_udata + 64, 64},	[2] = {test_udata + 64 + 64, 64},	[3] = {test_udata + 64 + 64 + 64, 64},};unsigned int test_iovcount = 4;/* *  ------------------------------------------------------------------------- * *  Events and Actions * *  ------------------------------------------------------------------------- */enum {	__EVENT_EOF = -7, __EVENT_NO_MSG = -6, __EVENT_TIMEOUT = -5, __EVENT_UNKNOWN = -4,	__RESULT_DECODE_ERROR = -3, __RESULT_SCRIPT_ERROR = -2,	__RESULT_INCONCLUSIVE = -1, __RESULT_SUCCESS = 0, __RESULT_FAILURE = 1,	__RESULT_NOTAPPL = 3, __RESULT_SKIPPED = 77,};/* *  ------------------------------------------------------------------------- */int show = 1;enum {	__TEST_CONN_REQ = 100, __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_DATACK_REQ, __TEST_DATACK_IND, __TEST_RESET_REQ,	__TEST_RESET_IND, __TEST_RESET_RES, __TEST_RESET_CON,	__TEST_PRIM_TOO_SHORT, __TEST_PRIM_WAY_TOO_SHORT,	__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,	__TEST_TI_SETMYNAME_DATA, __TEST_TI_SETPEERNAME_DATA,	__TEST_TI_SETMYNAME_DISC, __TEST_TI_SETPEERNAME_DISC,	__TEST_TI_SETMYNAME_DISC_DATA, __TEST_TI_SETPEERNAME_DISC_DATA,	__TEST_O_NONBLOCK, __TEST_O_BLOCK,	__TEST_T_ACCEPT, __TEST_T_BIND, __TEST_T_CLOSE, __TEST_T_CONNECT,	__TEST_T_GETINFO, __TEST_T_GETPROTADDR, __TEST_T_GETSTATE,	__TEST_T_LISTEN, __TEST_T_LOOK, __TEST_T_OPTMGMT, __TEST_T_RCV,	__TEST_T_RCVCONNECT, __TEST_T_RCVDIS, __TEST_T_RCVREL,	__TEST_T_RCVRELDATA, __TEST_T_RCVUDATA, __TEST_T_RCVUDERR,	__TEST_T_RCVV, __TEST_T_RCVVUDATA, __TEST_T_SND, __TEST_T_SNDDIS,	__TEST_T_SNDREL, __TEST_T_SNDRELDATA, __TEST_T_SNDUDATA,	__TEST_T_SNDV, __TEST_T_SNDVUDATA, __TEST_T_SYNC, __TEST_T_UNBIND,};/* *  ------------------------------------------------------------------------- * *  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};long test_start = 0;static int state = 0;static const char *failure_string = NULL;#define __stringify_1(x) #x#define __stringify(x) __stringify_1(x)#define FAILURE_STRING(string) "[" __stringify(__LINE__) "] " string#if 1#undef lockf#define lockf(x,y,z) 0#endif#if 0/* *  Return the current time in milliseconds. */static longnow(void){	long ret;	struct timeval now;	if (gettimeofday(&now, NULL)) {		last_errno = errno;		dummy = lockf(fileno(stdout), F_LOCK, 0);		fprintf(stdout, "***************ERROR! couldn't get time!            !  !                    \n");		fprintf(stdout, "%20s! %-54s\n", __FUNCTION__, strerror(last_errno));		fflush(stdout);		dummy = 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){	if (verbose > 0) {		dummy = lockf(fileno(stdout), F_LOCK, 0);		fprintf(stdout, "                    .               :               .  .                    \n");		fprintf(stdout, "                    .             %6s            .  .                    <%d>\n", t, state);		fprintf(stdout, "                    .               :               .  .                    \n");		fflush(stdout);		dummy = lockf(fileno(stdout), F_ULOCK, 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -