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 #ifdef HAVE_SYS_FILE_H
21 #include <rx/rx_clock.h>
23 #include <rx/rx_globals.h>
24 #include <rx/rx_null.h>
26 int error
; /* Return this error number on a call */
27 int print
= 0, eventlog
= 0, rxlog
= 0;
28 struct clock computeTime
, waitTime
;
33 void Abort(char *msg
, ...);
36 int FileRequest(struct rx_call
*call
);
37 int SimpleRequest(struct rx_call
*call
);
46 quitSignal(int ignore
)
48 static int quitCount
= 0;
50 Quit("rx_ctest: second quit signal, aborting");
51 rx_debugFile
= debugFile
= fopen("rx_stest.db", "w");
53 rx_PrintStats(debugFile
);
56 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
58 test_syscall(a3
, a4
, a5
)
65 old
= signal(SIGSYS
, SIG_IGN
);
67 syscall(31 /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3
, a4
, a5
);
77 struct rx_service
*service
;
78 struct rx_securityClass
*(secobjs
[1]);
83 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
85 rxi_syscallp
= test_syscall
;
89 while (argc
&& **argv
== '-') {
90 if (strcmp(*argv
, "-verbose") == 0)
92 else if (strcmp(*argv
, "-jumbo") == 0)
94 else if (strcmp(*argv
, "-rxlog") == 0)
96 #if defined(RXDEBUG) && !defined(AFS_NT40_ENV)
97 else if (strcmp(*argv
, "-trace") == 0)
98 strcpy(rxi_tracename
, *(++argv
)), argc
--;
100 else if (strcmp(*argv
, "-logstdout") == 0)
102 else if (strcmp(*argv
, "-eventlog") == 0)
104 else if (strcmp(*argv
, "-npb") == 0)
105 rx_nPackets
= atoi(*++argv
), argc
--;
106 else if (!strcmp(*argv
, "-nsf"))
107 rxi_nSendFrags
= atoi(*++argv
), argc
--;
108 else if (!strcmp(*argv
, "-nrf"))
109 rxi_nRecvFrags
= atoi(*++argv
), argc
--;
110 else if (strcmp(*argv
, "-twind") == 0)
111 rx_initSendWindow
= atoi(*++argv
), argc
--;
112 else if (strcmp(*argv
, "-rwind") == 0)
113 rx_initReceiveWindow
= atoi(*++argv
), argc
--;
114 else if (strcmp(*argv
, "-file") == 0)
115 rcvFile
= *++argv
, argc
--;
116 else if (strcmp(*argv
, "-drop") == 0) {
118 rx_intentionallyDroppedPacketsPer100
= atoi(*++argv
), argc
--;
120 fprintf(stderr
, "ERROR: Compiled without RXDEBUG\n");
123 else if (strcmp(*argv
, "-err") == 0)
124 error
= atoi(*++argv
), argc
--;
125 else if (strcmp(*argv
, "-compute") == 0) {
126 /* Simulated "compute" time for each call--to test acknowledgement protocol. This is simulated by doing an iomgr_select: imperfect, admittedly. */
127 computeTime
.sec
= atoi(*++argv
), argc
--;
128 computeTime
.usec
= atoi(*++argv
), argc
--;
129 } else if (strcmp(*argv
, "-wait") == 0) {
130 /* Wait time between calls--to test lastack code */
131 waitTime
.sec
= atoi(*++argv
), argc
--;
132 waitTime
.usec
= atoi(*++argv
), argc
--;
133 } else if (strcmp(*argv
, "-fd") == 0) {
134 /* Open at least this many fd's. */
135 setFD
= atoi(*++argv
), argc
--;
142 if (err
|| argc
!= 0)
143 Quit("usage: rx_stest [-silent] [-rxlog] [-eventlog]");
145 if (rxlog
|| eventlog
) {
149 debugFile
= fopen("rx_stest.db", "w");
150 if (debugFile
== NULL
)
151 Quit("Couldn't open rx_stest.db");
153 rx_debugFile
= debugFile
;
155 rxevent_debugFile
= debugFile
;
158 signal(SIGINT
, intSignal
); /* Changed to SIGQUIT since dbx is broken right now */
160 signal(SIGQUIT
, quitSignal
);
167 rx_EnableHotThread();
173 rx_SetUdpBufSize(256 * 1024);
175 if (rx_Init(htons(2500)) != 0) {
176 printf("RX initialization failed, exiting.\n");
180 printf("rx_socket=%d\n", rx_socket
);
183 secobjs
[0] = rxnull_NewServerSecurityObject();
184 service
= rx_NewService( /*port */ 0, /*service */ 3, "test", secobjs
, /*nsec */
185 1, /*Execute request */
186 rcvFile
? FileRequest
: SimpleRequest
);
188 Abort("rx_NewService returned 0!\n");
190 rx_SetMinProcs(service
, 2);
191 rx_SetMaxProcs(service
, 100);
192 rx_SetCheckReach(service
, 1);
194 printf("Using %d packet buffers\n", rx_nPackets
);
198 static char buf
[2000000];
200 int SimpleRequest(struct rx_call
*call
)
203 int nbytes
= sizeof(buf
);
204 while ((n
= rx_Read(call
, buf
, nbytes
)) > 0)
206 printf("stest: Received %d bytes\n", n
);
207 if (!rx_Error(call
)) {
208 /* Fake compute time (use select to lock out everything) */
212 if (!clock_IsZero(&computeTime
)) {
214 Sleep(computeTime
.sec
* 1000 + 100 * computeTime
.usec
);
216 t
.tv_sec
= computeTime
.sec
;
217 t
.tv_usec
= computeTime
.usec
;
218 #ifdef AFS_PTHREAD_ENV
219 if (select(0, 0, 0, 0, &t
) != 0)
220 Quit("Select didn't return 0");
222 IOMGR_Sleep(t
.tv_sec
);
226 /* Then wait time (use iomgr_select to allow rx to run) */
227 if (!clock_IsZero(&waitTime
)) {
229 Sleep(waitTime
.sec
* 1000 + 100 * waitTime
.usec
);
231 t
.tv_sec
= waitTime
.sec
;
232 t
.tv_usec
= waitTime
.usec
;
233 #ifdef AFS_PTHREAD_ENV
234 select(0, 0, 0, 0, &t
);
236 IOMGR_Sleep(t
.tv_sec
);
240 rx_Write(call
, "So long, and thanks for all the fish!\n",
241 strlen("So long, and thanks for all the fish!\n"));
244 rx_PrintPeerStats(debugFile
, rx_PeerOf(rx_ConnectionOf(call
)));
245 rx_PrintPeerStats(stdout
, rx_PeerOf(rx_ConnectionOf(call
)));
250 FileRequest(struct rx_call
*call
)
254 int nbytes
, blockSize
;
257 #include <sys/statfs.h>
258 struct statfs tstatfs
;
260 /* Open the file ahead of time: the client timing the operation doesn't have to include the open time */
261 fd
= open(rcvFile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0666);
271 fstatfs(fd
, &tstatfs
);
272 blockSize
= tstatfs
.f_bsize
;
274 blockSize
= status
.st_blksize
;
276 #endif /* AFS_NT40_ENV */
277 buffer
= malloc(blockSize
);
279 rx_SetLocalStatus(call
, 79); /* Emulation of file server's old "RCallBackReceivedStore" */
281 while (nbytes
= rx_Read(call
, buffer
, blockSize
)) {
282 if (write(fd
, buffer
, nbytes
) != nbytes
) {
284 Abort("Write Failed.\n");
288 rx_Write(call
, "So long, and thanks for all the fish!\n",
289 strlen("So long, and thanks for all the fish!\n"));
290 printf("Received file %s\n", rcvFile
);
293 rx_PrintPeerStats(debugFile
, rx_PeerOf(rx_ConnectionOf(call
)));
294 rx_PrintPeerStats(stdout
, rx_PeerOf(rx_ConnectionOf(call
)));
299 Abort(char *msg
, ...)
304 printf((char *)msg
, args
);
309 rx_PrintStats(debugFile
);
321 rx_PrintStats(debugFile
);
324 rx_PrintStats(stdout
);
331 * Open file descriptors until file descriptor n or higher is returned.
341 for (i
= 0; i
< n
; i
++) {
342 if (fstat(i
, &sbuf
) == 0)
344 if ((fd
= open("/dev/null", 0, 0)) < 0) {