summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/tests/select2.c
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
commitf7d30133221896638f7bf4f66c504255c4b14f48 (patch)
tree5f3e07a049f388a3a309a615b8884318f6668a98 /nsprpub/pr/tests/select2.c
parent26b297510a11758727438df4669357a2a2bc42ce (diff)
downloadUXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.gz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.lz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.xz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.zip
Issue #1338 - Part 1: Update NSPR to 4.24
Diffstat (limited to 'nsprpub/pr/tests/select2.c')
-rw-r--r--nsprpub/pr/tests/select2.c219
1 files changed, 141 insertions, 78 deletions
diff --git a/nsprpub/pr/tests/select2.c b/nsprpub/pr/tests/select2.c
index d82bb1ef9..da7360b02 100644
--- a/nsprpub/pr/tests/select2.c
+++ b/nsprpub/pr/tests/select2.c
@@ -11,10 +11,10 @@
**
** Modification History:
** 20-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
-** The debug mode will print all of the printfs associated with this test.
-** The regress mode will be the default mode. Since the regress tool limits
+** The debug mode will print all of the printfs associated with this test.
+** The regress mode will be the default mode. Since the regress tool limits
** the output to a one line status:PASS or FAIL,all of the printf statements
-** have been handled with an if (debug_mode) statement.
+** have been handled with an if (debug_mode) statement.
***********************************************************************/
/***********************************************************************
@@ -40,34 +40,34 @@ PRInt32 count;
/***********************************************************************
** PRIVATE FUNCTION: Test_Result
** DESCRIPTION: Used in conjunction with the regress tool, prints out the
-** status of the test case.
+** status of the test case.
** INPUTS: PASS/FAIL
** OUTPUTS: None
** RETURN: None
** SIDE EFFECTS:
-**
+**
** RESTRICTIONS:
** None
** MEMORY: NA
** ALGORITHM: Determine what the status is and print accordingly.
-**
+**
***********************************************************************/
static void Test_Result (int result)
{
- switch (result)
- {
- case PASS:
- printf ("PASS\n");
- break;
- case FAIL:
- printf ("FAIL\n");
- break;
- default:
- printf ("NOSTATUS\n");
- break;
- }
+ switch (result)
+ {
+ case PASS:
+ printf ("PASS\n");
+ break;
+ case FAIL:
+ printf ("FAIL\n");
+ break;
+ default:
+ printf ("NOSTATUS\n");
+ break;
+ }
}
static void EmptyPRSelect(void)
@@ -75,8 +75,9 @@ static void EmptyPRSelect(void)
PRInt32 index = count;
PRInt32 rv;
- for (; index--;)
+ for (; index--;) {
rv = PR_Select(0, NULL, NULL, NULL, PR_INTERVAL_NO_WAIT);
+ }
}
static void EmptyNativeSelect(void)
@@ -86,8 +87,9 @@ static void EmptyNativeSelect(void)
struct timeval timeout;
timeout.tv_sec = timeout.tv_usec = 0;
- for (; index--;)
+ for (; index--;) {
rv = select(0, NULL, NULL, NULL, &timeout);
+ }
}
static void PRSelectTest(void)
@@ -96,7 +98,9 @@ static void PRSelectTest(void)
PRNetAddr serverAddr;
if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
return;
}
@@ -106,17 +110,23 @@ static void PRSelectTest(void)
serverAddr.inet.ip = PR_htonl(INADDR_ANY);
if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error binding to server address\n");
+ if (debug_mode) {
+ printf("\tServer error binding to server address\n");
+ }
PR_Close(listenSocket);
return;
}
if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
PR_Close(listenSocket);
return;
}
- if (debug_mode) printf("Listening on port %d\n", PORT);
+ if (debug_mode) {
+ printf("Listening on port %d\n", PORT);
+ }
{
PRFileDesc *newSock;
@@ -129,40 +139,60 @@ static void PRSelectTest(void)
loops++;
- if (debug_mode) printf("Going into accept\n");
+ if (debug_mode) {
+ printf("Going into accept\n");
+ }
- newSock = PR_Accept(listenSocket,
- &rAddr,
- PR_INTERVAL_NO_TIMEOUT);
+ newSock = PR_Accept(listenSocket,
+ &rAddr,
+ PR_INTERVAL_NO_TIMEOUT);
- if (newSock) {
- if (debug_mode) printf("Got connection!\n");
+ if (newSock) {
+ if (debug_mode) {
+ printf("Got connection!\n");
+ }
} else {
- if (debug_mode) printf("PR_Accept failed: error code %d\n", PR_GetError());
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("PR_Accept failed: error code %d\n", PR_GetError());
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
PR_FD_ZERO(&rdset);
PR_FD_SET(newSock, &rdset);
- if (debug_mode) printf("Going into select \n");
+ if (debug_mode) {
+ printf("Going into select \n");
+ }
rv = PR_Select(0, &rdset, 0, 0, PR_INTERVAL_NO_TIMEOUT);
- if (debug_mode) printf("return from select is %d\n", rv);
+ if (debug_mode) {
+ printf("return from select is %d\n", rv);
+ }
if (PR_FD_ISSET(newSock, &rdset)) {
- if (debug_mode) printf("I can't believe it- the socket is ready okay!\n");
+ if (debug_mode) {
+ printf("I can't believe it- the socket is ready okay!\n");
+ }
} else {
- if (debug_mode) printf("Damn; the select test failed...\n");
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("Damn; the select test failed...\n");
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
strcpy(buf, "XXXXXXXXXX");
bytesRead = PR_Recv(newSock, buf, 10, 0, PR_INTERVAL_NO_TIMEOUT);
- buf[10] = '\0';
+ buf[10] = '\0';
- if (debug_mode) printf("Recv completed with %d bytes, %s\n", bytesRead, buf);
+ if (debug_mode) {
+ printf("Recv completed with %d bytes, %s\n", bytesRead, buf);
+ }
PR_Close(newSock);
}
@@ -177,7 +207,9 @@ static void NativeSelectTest(void)
PRNetAddr serverAddr;
if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
return;
}
@@ -187,17 +219,23 @@ static void NativeSelectTest(void)
serverAddr.inet.ip = PR_htonl(INADDR_ANY);
if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error binding to server address\n");
+ if (debug_mode) {
+ printf("\tServer error binding to server address\n");
+ }
PR_Close(listenSocket);
return;
}
if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
PR_Close(listenSocket);
return;
}
- if (debug_mode) printf("Listening on port %d\n", PORT);
+ if (debug_mode) {
+ printf("Listening on port %d\n", PORT);
+ }
{
PRIntn osfd;
@@ -210,42 +248,61 @@ static void NativeSelectTest(void)
loops++;
- if (debug_mode) printf("Going into accept\n");
+ if (debug_mode) {
+ printf("Going into accept\n");
+ }
newSock = PR_Accept(listenSocket, &rAddr, PR_INTERVAL_NO_TIMEOUT);
- if (newSock) {
- if (debug_mode) printf("Got connection!\n");
+ if (newSock) {
+ if (debug_mode) {
+ printf("Got connection!\n");
+ }
} else {
- if (debug_mode) printf("PR_Accept failed: error code %d\n", PR_GetError());
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("PR_Accept failed: error code %d\n", PR_GetError());
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
osfd = PR_FileDesc2NativeHandle(newSock);
FD_ZERO(&rdset);
FD_SET(osfd, &rdset);
- if (debug_mode) printf("Going into select \n");
+ if (debug_mode) {
+ printf("Going into select \n");
+ }
timeout.tv_sec = 2; timeout.tv_usec = 0;
rv = select(osfd + 1, &rdset, NULL, NULL, &timeout);
- if (debug_mode) printf("return from select is %d\n", rv);
+ if (debug_mode) {
+ printf("return from select is %d\n", rv);
+ }
if (FD_ISSET(osfd, &rdset)) {
- if (debug_mode)
+ if (debug_mode) {
printf("I can't believe it- the socket is ready okay!\n");
+ }
} else {
- if (debug_mode) printf("Damn; the select test failed...\n");
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("Damn; the select test failed...\n");
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
strcpy(buf, "XXXXXXXXXX");
bytesRead = PR_Recv(newSock, buf, 10, 0, PR_INTERVAL_NO_TIMEOUT);
- buf[10] = '\0';
+ buf[10] = '\0';
- if (debug_mode) printf("Recv completed with %d bytes, %s\n", bytesRead, buf);
+ if (debug_mode) {
+ printf("Recv completed with %d bytes, %s\n", bytesRead, buf);
+ }
PR_Close(newSock);
}
@@ -269,43 +326,47 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
tot = PR_IntervalToMilliseconds(stop-start);
- if (debug_mode) printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
+ if (debug_mode) {
+ printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
+ }
}
int main(int argc, char **argv)
{
-
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'd': /* debug mode */
- debug_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
+
+ /* main test */
- /* main test */
-
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (argc > 2) {
- count = atoi(argv[2]);
+ count = atoi(argv[2]);
} else {
- count = DEFAULT_COUNT;
+ count = DEFAULT_COUNT;
}
#if defined(XP_UNIX)
@@ -315,7 +376,9 @@ int main(int argc, char **argv)
Measure(EmptyNativeSelect, "time to call Empty select()");
Measure(PRSelectTest, "time to call 1 element PR_select()");
- if (!debug_mode) Test_Result (NOSTATUS);
+ if (!debug_mode) {
+ Test_Result (NOSTATUS);
+ }
PR_Cleanup();