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_globals.h"
36 int error; /* Return this error number on a call */
37 int print = 0, eventlog = 0, rxlog = 0;
38 struct clock computeTime, waitTime;
43 void Abort(char *msg, int a, int b, int c, int d, int e);
44 void Quit(char *msg, int a, int b, int c, int d, int e);
46 int FileRequest(struct rx_call *call);
47 int SimpleRequest(struct rx_call *call);
52 Quit("Interrupted",0,0,0,0,0);
56 quitSignal(int ignore)
58 static int quitCount = 0;
60 Quit("rx_ctest: second quit signal, aborting",0,0,0,0,0);
61 rx_debugFile = debugFile = fopen("rx_stest.db", "w");
63 rx_PrintStats(debugFile);
66 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
68 test_syscall(a3, a4, a5)
75 old = signal(SIGSYS, SIG_IGN);
77 syscall(31 /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3, a4, a5);
87 struct rx_service *service;
88 struct rx_securityClass *(secobjs[1]);
93 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
95 rxi_syscallp = test_syscall;
99 while (argc && **argv == '-') {
100 if (strcmp(*argv, "-verbose") == 0)
102 else if (strcmp(*argv, "-jumbo") == 0)
104 else if (strcmp(*argv, "-rxlog") == 0)
106 #if defined(RXDEBUG) && !defined(AFS_NT40_ENV)
107 else if (strcmp(*argv, "-trace") == 0)
108 strcpy(rxi_tracename, *(++argv)), argc--;
110 else if (strcmp(*argv, "-logstdout") == 0)
112 else if (strcmp(*argv, "-eventlog") == 0)
114 else if (strcmp(*argv, "-npb") == 0)
115 rx_nPackets = atoi(*++argv), argc--;
116 else if (!strcmp(*argv, "-nsf"))
117 rxi_nSendFrags = atoi(*++argv), argc--;
118 else if (!strcmp(*argv, "-nrf"))
119 rxi_nRecvFrags = atoi(*++argv), argc--;
120 else if (strcmp(*argv, "-twind") == 0)
121 rx_initSendWindow = atoi(*++argv), argc--;
122 else if (strcmp(*argv, "-rwind") == 0)
123 rx_initReceiveWindow = atoi(*++argv), argc--;
124 else if (strcmp(*argv, "-file") == 0)
125 rcvFile = *++argv, argc--;
126 else if (strcmp(*argv, "-drop") == 0) {
128 rx_intentionallyDroppedPacketsPer100 = atoi(*++argv), argc--;
130 fprintf(stderr, "ERROR: Compiled without RXDEBUG\n");
133 else if (strcmp(*argv, "-err") == 0)
134 error = atoi(*++argv), argc--;
135 else if (strcmp(*argv, "-compute") == 0) {
136 /* Simulated "compute" time for each call--to test acknowledgement protocol. This is simulated by doing an iomgr_select: imperfect, admittedly. */
137 computeTime.sec = atoi(*++argv), argc--;
138 computeTime.usec = atoi(*++argv), argc--;
139 } else if (strcmp(*argv, "-wait") == 0) {
140 /* Wait time between calls--to test lastack code */
141 waitTime.sec = atoi(*++argv), argc--;
142 waitTime.usec = atoi(*++argv), argc--;
143 } else if (strcmp(*argv, "-fd") == 0) {
144 /* Open at least this many fd's. */
145 setFD = atoi(*++argv), argc--;
152 if (err || argc != 0)
153 Quit("usage: rx_stest [-silent] [-rxlog] [-eventlog]",0,0,0,0,0);
155 if (rxlog || eventlog) {
159 debugFile = fopen("rx_stest.db", "w");
160 if (debugFile == NULL)
161 Quit("Couldn't open rx_stest.db",0,0,0,0,0);
163 rx_debugFile = debugFile;
165 rxevent_debugFile = debugFile;
168 signal(SIGINT, intSignal); /* Changed to SIGQUIT since dbx is broken right now */
170 signal(SIGQUIT, quitSignal);
177 rx_EnableHotThread();
183 rx_SetUdpBufSize(256 * 1024);
185 if (rx_Init(htons(2500)) != 0) {
186 printf("RX initialization failed, exiting.\n");
190 printf("rx_socket=%d\n", rx_socket);
193 secobjs[0] = rxnull_NewServerSecurityObject();
194 service = rx_NewService( /*port */ 0, /*service */ 3, "test", secobjs, /*nsec */
195 1, /*Execute request */
196 rcvFile ? FileRequest : SimpleRequest);
198 Abort("rx_NewService returned 0!\n",0,0,0,0,0);
200 rx_SetMinProcs(service, 2);
201 rx_SetMaxProcs(service, 100);
202 rx_SetCheckReach(service, 1);
204 printf("Using %d packet buffers\n", rx_nPackets);
208 static char buf[2000000];
210 int SimpleRequest(struct rx_call *call)
213 int nbytes = sizeof(buf);
214 while ((n = rx_Read(call, buf, nbytes)) > 0)
216 printf("stest: Received %d bytes\n", n);
217 if (!rx_Error(call)) {
218 /* Fake compute time (use select to lock out everything) */
222 if (!clock_IsZero(&computeTime)) {
224 Sleep(computeTime.sec * 1000 + 100 * computeTime.usec);
226 t.tv_sec = computeTime.sec;
227 t.tv_usec = computeTime.usec;
228 #ifdef AFS_PTHREAD_ENV
229 if (select(0, 0, 0, 0, &t) != 0)
230 Quit("Select didn't return 0",0,0,0,0,0);
232 IOMGR_Sleep(t.tv_sec);
236 /* Then wait time (use iomgr_select to allow rx to run) */
237 if (!clock_IsZero(&waitTime)) {
239 Sleep(waitTime.sec * 1000 + 100 * waitTime.usec);
241 t.tv_sec = waitTime.sec;
242 t.tv_usec = waitTime.usec;
243 #ifdef AFS_PTHREAD_ENV
244 select(0, 0, 0, 0, &t);
246 IOMGR_Sleep(t.tv_sec);
250 rx_Write(call, "So long, and thanks for all the fish!\n",
251 strlen("So long, and thanks for all the fish!\n"));
254 rx_PrintPeerStats(debugFile, rx_PeerOf(call->conn));
255 rx_PrintPeerStats(stdout, rx_PeerOf(call->conn));
260 FileRequest(struct rx_call *call)
264 int nbytes, blockSize;
267 #include <sys/statfs.h>
268 struct statfs tstatfs;
270 /* Open the file ahead of time: the client timing the operation doesn't have to include the open time */
271 fd = open(rcvFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
281 fstatfs(fd, &tstatfs);
282 blockSize = tstatfs.f_bsize;
284 blockSize = status.st_blksize;
286 #endif /* AFS_NT40_ENV */
287 buffer = (char *)malloc(blockSize);
289 rx_SetLocalStatus(call, 79); /* Emulation of file server's old "RCallBackReceivedStore" */
291 while (nbytes = rx_Read(call, buffer, blockSize)) {
292 if (write(fd, buffer, nbytes) != nbytes) {
294 Abort("Write Failed.\n",0,0,0,0,0);
298 rx_Write(call, "So long, and thanks for all the fish!\n",
299 strlen("So long, and thanks for all the fish!\n"));
300 printf("Received file %s\n", rcvFile);
303 rx_PrintPeerStats(debugFile, rx_PeerOf(call->conn));
304 rx_PrintPeerStats(stdout, rx_PeerOf(call->conn));
309 Abort(char *msg, int a, int b, int c, int d, int e)
311 printf((char *)msg, a, b, c, d, e);
314 rx_PrintStats(debugFile);
321 Quit(char *msg, int a, int b, int c, int d, int e)
323 printf((char *)msg, a, b, c, d, e);
326 rx_PrintStats(debugFile);
329 rx_PrintStats(stdout);
336 * Open file descriptors until file descriptor n or higher is returned.
338 #include <sys/stat.h>
347 for (i = 0; i < n; i++) {
348 if (fstat(i, &sbuf) == 0)
350 if ((fd = open("/dev/null", 0, 0)) < 0) {