|
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/. */ |
|
5 |
|
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. |
|
14 ** |
|
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. |
|
18 */ |
|
19 |
|
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" |
|
29 |
|
30 #include <stdio.h> |
|
31 #include <stdlib.h> |
|
32 |
|
33 static void PR_CALLBACK lazyEntry(void *arg) |
|
34 { |
|
35 PR_ASSERT(NULL == arg); |
|
36 } /* lazyEntry */ |
|
37 |
|
38 |
|
39 int main(int argc, char **argv) |
|
40 { |
|
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; |
|
51 |
|
52 if ( argc < 2) |
|
53 { |
|
54 test = 0; |
|
55 } |
|
56 else |
|
57 test = atoi(argv[1]); |
|
58 |
|
59 switch (test) |
|
60 { |
|
61 case 0: ml = PR_NewLock(); |
|
62 break; |
|
63 |
|
64 case 1: interval = PR_SecondsToInterval(1); |
|
65 break; |
|
66 |
|
67 case 2: thread = PR_CreateThread( |
|
68 PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL, |
|
69 PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); |
|
70 break; |
|
71 |
|
72 case 3: file = PR_Open("/usr/tmp/", PR_RDONLY, 0); |
|
73 break; |
|
74 |
|
75 case 4: udp = PR_NewUDPSocket(); |
|
76 break; |
|
77 |
|
78 case 5: tcp = PR_NewTCPSocket(); |
|
79 break; |
|
80 |
|
81 case 6: dir = PR_OpenDir("/usr/tmp/"); |
|
82 break; |
|
83 |
|
84 case 7: (void)PR_NewThreadPrivateIndex(&pdkey, NULL); |
|
85 break; |
|
86 |
|
87 case 8: path = PR_GetEnv("PATH"); |
|
88 break; |
|
89 |
|
90 case 9: status = PR_NewTCPSocketPair(pair); |
|
91 break; |
|
92 |
|
93 case 10: PR_SetConcurrency(2); |
|
94 break; |
|
95 |
|
96 default: |
|
97 printf( |
|
98 "lazyinit: unrecognized command line argument: %s\n", |
|
99 argv[1] ); |
|
100 printf( "FAIL\n" ); |
|
101 exit( 1 ); |
|
102 break; |
|
103 } /* switch() */ |
|
104 return 0; |
|
105 } /* Lazy */ |
|
106 |
|
107 /* lazyinit.c */ |