Backed out changeset e43e26b7f7b9 (bug 1857101) for causing bc failures on browser_tr...
[gecko.git] / nsprpub / pr / tests / lazyinit.c
blob2a910f2051cf25f242ff115b1409803f5e97c75d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 ** File: lazyinit.c
8 ** Description: Testing lazy initialization
9 **
10 ** Since you only get to initialize once, you have to rerun the test
11 ** for each test case. The test cases are numbered. If you want to
12 ** add more tests, take the next number and add it to the switch
13 ** statement.
15 ** This test is problematic on systems that don't support the notion
16 ** of console output. The workarounds to emulate that feature include
17 ** initializations themselves, which defeats the purpose here.
20 #include "prcvar.h"
21 #include "prenv.h"
22 #include "prinit.h"
23 #include "prinrval.h"
24 #include "prio.h"
25 #include "prlock.h"
26 #include "prlog.h"
27 #include "prthread.h"
28 #include "prtypes.h"
30 #include <stdio.h>
31 #include <stdlib.h>
33 static void PR_CALLBACK lazyEntry(void *arg)
35 PR_ASSERT(NULL == arg);
36 } /* lazyEntry */
39 int main(int argc, char **argv)
41 PRUintn pdkey;
42 PRStatus status;
43 char *path = NULL;
44 PRDir *dir = NULL;
45 PRLock *ml = NULL;
46 PRCondVar *cv = NULL;
47 PRThread *thread = NULL;
48 PRIntervalTime interval = 0;
49 PRFileDesc *file, *udp, *tcp, *pair[2];
50 PRIntn test;
52 if ( argc < 2)
54 test = 0;
56 else {
57 test = atoi(argv[1]);
60 switch (test)
62 case 0: ml = PR_NewLock();
63 break;
65 case 1: interval = PR_SecondsToInterval(1);
66 break;
68 case 2: thread = PR_CreateThread(
69 PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
70 PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
71 break;
73 case 3: file = PR_Open("./tmp-", PR_RDONLY, 0);
74 break;
76 case 4: udp = PR_NewUDPSocket();
77 break;
79 case 5: tcp = PR_NewTCPSocket();
80 break;
82 case 6: dir = PR_OpenDir("./tmp-");
83 break;
85 case 7: (void)PR_NewThreadPrivateIndex(&pdkey, NULL);
86 break;
88 case 8: path = PR_GetEnv("PATH");
89 break;
91 case 9: status = PR_NewTCPSocketPair(pair);
92 break;
94 case 10: PR_SetConcurrency(2);
95 break;
97 default:
98 printf(
99 "lazyinit: unrecognized command line argument: %s\n",
100 argv[1] );
101 printf( "FAIL\n" );
102 exit( 1 );
103 break;
104 } /* switch() */
105 return 0;
106 } /* Lazy */
108 /* lazyinit.c */