lazyinit.c (2516B)
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 PR_ASSERT(NULL == arg); 35 } /* lazyEntry */ 36 37 int main(int argc, char** argv) { 38 PRUintn pdkey; 39 PRStatus status; 40 char* path = NULL; 41 PRDir* dir = NULL; 42 PRLock* ml = NULL; 43 PRCondVar* cv = NULL; 44 PRThread* thread = NULL; 45 PRIntervalTime interval = 0; 46 PRFileDesc *file, *udp, *tcp, *pair[2]; 47 PRIntn test; 48 49 if (argc < 2) { 50 test = 0; 51 } else { 52 test = atoi(argv[1]); 53 } 54 55 switch (test) { 56 case 0: 57 ml = PR_NewLock(); 58 break; 59 60 case 1: 61 interval = PR_SecondsToInterval(1); 62 break; 63 64 case 2: 65 thread = 66 PR_CreateThread(PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL, 67 PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); 68 break; 69 70 case 3: 71 file = PR_Open("./tmp-", PR_RDONLY, 0); 72 break; 73 74 case 4: 75 udp = PR_NewUDPSocket(); 76 break; 77 78 case 5: 79 tcp = PR_NewTCPSocket(); 80 break; 81 82 case 6: 83 dir = PR_OpenDir("./tmp-"); 84 break; 85 86 case 7: 87 (void)PR_NewThreadPrivateIndex(&pdkey, NULL); 88 break; 89 90 case 8: 91 path = PR_GetEnv("PATH"); 92 break; 93 94 case 9: 95 status = PR_NewTCPSocketPair(pair); 96 break; 97 98 case 10: 99 PR_SetConcurrency(2); 100 break; 101 102 default: 103 printf("lazyinit: unrecognized command line argument: %s\n", argv[1]); 104 printf("FAIL\n"); 105 exit(1); 106 break; 107 } /* switch() */ 108 return 0; 109 } /* Lazy */ 110 111 /* lazyinit.c */