2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Server test program */
12 #include <afsconfig.h>
13 #include <afs/param.h>
16 #include <sys/types.h>
24 #include <netinet/in.h>
33 #include <rx/rx_clock.h>
35 #include <rx/rx_globals.h>
36 #include <rx/rx_null.h>
38 int error; /* Return this error number on a call */
39 int print = 0, eventlog = 0, rxlog = 0;
40 struct clock computeTime, waitTime;
45 void Abort(char *msg, ...);
48 int FileRequest(struct rx_call *call);
49 int SimpleRequest(struct rx_call *call);
58 quitSignal(int ignore)
60 static int quitCount = 0;
62 Quit("rx_ctest: second quit signal, aborting");
63 rx_debugFile = debugFile = fopen("rx_stest.db", "w");
65 rx_PrintStats(debugFile);
68 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
70 test_syscall(a3, a4, a5)
77 old = signal(SIGSYS, SIG_IGN);
79 syscall(31 /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3, a4, a5);
89 struct rx_service *service;
90 struct rx_securityClass *(secobjs[1]);
95 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
97 rxi_syscallp = test_syscall;
101 while (argc && **argv == '-') {
102 if (strcmp(*argv, "-verbose") == 0)
104 else if (strcmp(*argv, "-jumbo") == 0)
106 else if (strcmp(*argv, "-rxlog") == 0)
108 #if defined(RXDEBUG) && !defined(AFS_NT40_ENV)
109 else if (strcmp(*argv, "-trace") == 0)
110 strcpy(rxi_tracename, *(++argv)), argc--;
112 else if (strcmp(*argv, "-logstdout") == 0)
114 else if (strcmp(*argv, "-eventlog") == 0)
116 else if (strcmp(*argv, "-npb") == 0)
117 rx_nPackets = atoi(*++argv), argc--;
118 else if (!strcmp(*argv, "-nsf"))
119 rxi_nSendFrags = atoi(*++argv), argc--;
120 else if (!strcmp(*argv, "-nrf"))
121 rxi_nRecvFrags = atoi(*++argv), argc--;
122 else if (strcmp(*argv, "-twind") == 0)
123 rx_initSendWindow = atoi(*++argv), argc--;
124 else if (strcmp(*argv, "-rwind") == 0)
125 rx_initReceiveWindow = atoi(*++argv), argc--;
126 else if (strcmp(*argv, "-file") == 0)
127 rcvFile = *++argv, argc--;
128 else if (strcmp(*argv, "-drop") == 0) {
130 rx_intentionallyDroppedPacketsPer100 = atoi(*++argv), argc--;
132 fprintf(stderr, "ERROR: Compiled without RXDEBUG\n");
135 else if (strcmp(*argv, "-err") == 0)
136 error = atoi(*++argv), argc--;
137 else if (strcmp(*argv, "-compute") == 0) {
138 /* Simulated "compute" time for each call--to test acknowledgement protocol. This is simulated by doing an iomgr_select: imperfect, admittedly. */
139 computeTime.sec = atoi(*++argv), argc--;
140 computeTime.usec = atoi(*++argv), argc--;
141 } else if (strcmp(*argv, "-wait") == 0) {
142 /* Wait time between calls--to test lastack code */
143 waitTime.sec = atoi(*++argv), argc--;
144 waitTime.usec = atoi(*++argv), argc--;
145 } else if (strcmp(*argv, "-fd") == 0) {
146 /* Open at least this many fd's. */
147 setFD = atoi(*++argv), argc--;
154 if (err || argc != 0)
155 Quit("usage: rx_stest [-silent] [-rxlog] [-eventlog]");
157 if (rxlog || eventlog) {
161 debugFile = fopen("rx_stest.db", "w");
162 if (debugFile == NULL)
163 Quit("Couldn't open rx_stest.db");
165 rx_debugFile = debugFile;
167 rxevent_debugFile = debugFile;
170 signal(SIGINT, intSignal); /* Changed to SIGQUIT since dbx is broken right now */
172 signal(SIGQUIT, quitSignal);
179 rx_EnableHotThread();
185 rx_SetUdpBufSize(256 * 1024);
187 if (rx_Init(htons(2500)) != 0) {
188 printf("RX initialization failed, exiting.\n");
192 printf("rx_socket=%d\n", rx_socket);
195 secobjs[0] = rxnull_NewServerSecurityObject();
196 service = rx_NewService( /*port */ 0, /*service */ 3, "test", secobjs, /*nsec */
197 1, /*Execute request */
198 rcvFile ? FileRequest : SimpleRequest);
200 Abort("rx_NewService returned 0!\n");
202 rx_SetMinProcs(service, 2);
203 rx_SetMaxProcs(service, 100);
204 rx_SetCheckReach(service, 1);
206 printf("Using %d packet buffers\n", rx_nPackets);
210 static char buf[2000000];
212 int SimpleRequest(struct rx_call *call)
215 int nbytes = sizeof(buf);
216 while ((n = rx_Read(call, buf, nbytes)) > 0)
218 printf("stest: Received %d bytes\n", n);
219 if (!rx_Error(call)) {
220 /* Fake compute time (use select to lock out everything) */
224 if (!clock_IsZero(&computeTime)) {
226 Sleep(computeTime.sec * 1000 + 100 * computeTime.usec);
228 t.tv_sec = computeTime.sec;
229 t.tv_usec = computeTime.usec;
230 #ifdef AFS_PTHREAD_ENV
231 if (select(0, 0, 0, 0, &t) != 0)
232 Quit("Select didn't return 0");
234 IOMGR_Sleep(t.tv_sec);
238 /* Then wait time (use iomgr_select to allow rx to run) */
239 if (!clock_IsZero(&waitTime)) {
241 Sleep(waitTime.sec * 1000 + 100 * waitTime.usec);
243 t.tv_sec = waitTime.sec;
244 t.tv_usec = waitTime.usec;
245 #ifdef AFS_PTHREAD_ENV
246 select(0, 0, 0, 0, &t);
248 IOMGR_Sleep(t.tv_sec);
252 rx_Write(call, "So long, and thanks for all the fish!\n",
253 strlen("So long, and thanks for all the fish!\n"));
256 rx_PrintPeerStats(debugFile, rx_PeerOf(call->conn));
257 rx_PrintPeerStats(stdout, rx_PeerOf(call->conn));
262 FileRequest(struct rx_call *call)
266 int nbytes, blockSize;
269 #include <sys/statfs.h>
270 struct statfs tstatfs;
272 /* Open the file ahead of time: the client timing the operation doesn't have to include the open time */
273 fd = open(rcvFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
283 fstatfs(fd, &tstatfs);
284 blockSize = tstatfs.f_bsize;
286 blockSize = status.st_blksize;
288 #endif /* AFS_NT40_ENV */
289 buffer = (char *)malloc(blockSize);
291 rx_SetLocalStatus(call, 79); /* Emulation of file server's old "RCallBackReceivedStore" */
293 while (nbytes = rx_Read(call, buffer, blockSize)) {
294 if (write(fd, buffer, nbytes) != nbytes) {
296 Abort("Write Failed.\n");
300 rx_Write(call, "So long, and thanks for all the fish!\n",
301 strlen("So long, and thanks for all the fish!\n"));
302 printf("Received file %s\n", rcvFile);
305 rx_PrintPeerStats(debugFile, rx_PeerOf(call->conn));
306 rx_PrintPeerStats(stdout, rx_PeerOf(call->conn));
311 Abort(char *msg, ...)
316 printf((char *)msg, args);
321 rx_PrintStats(debugFile);
333 rx_PrintStats(debugFile);
336 rx_PrintStats(stdout);
343 * Open file descriptors until file descriptor n or higher is returned.
345 #include <sys/stat.h>
354 for (i = 0; i < n; i++) {
355 if (fstat(i, &sbuf) == 0)
357 if ((fd = open("/dev/null", 0, 0)) < 0) {