1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/lazyinit.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 +** File: lazyinit.c 1.11 +** Description: Testing lazy initialization 1.12 +** 1.13 +** Since you only get to initialize once, you have to rerun the test 1.14 +** for each test case. The test cases are numbered. If you want to 1.15 +** add more tests, take the next number and add it to the switch 1.16 +** statement. 1.17 +** 1.18 +** This test is problematic on systems that don't support the notion 1.19 +** of console output. The workarounds to emulate that feature include 1.20 +** initializations themselves, which defeats the purpose here. 1.21 +*/ 1.22 + 1.23 +#include "prcvar.h" 1.24 +#include "prenv.h" 1.25 +#include "prinit.h" 1.26 +#include "prinrval.h" 1.27 +#include "prio.h" 1.28 +#include "prlock.h" 1.29 +#include "prlog.h" 1.30 +#include "prthread.h" 1.31 +#include "prtypes.h" 1.32 + 1.33 +#include <stdio.h> 1.34 +#include <stdlib.h> 1.35 + 1.36 +static void PR_CALLBACK lazyEntry(void *arg) 1.37 +{ 1.38 + PR_ASSERT(NULL == arg); 1.39 +} /* lazyEntry */ 1.40 + 1.41 + 1.42 +int main(int argc, char **argv) 1.43 +{ 1.44 + PRUintn pdkey; 1.45 + PRStatus status; 1.46 + char *path = NULL; 1.47 + PRDir *dir = NULL; 1.48 + PRLock *ml = NULL; 1.49 + PRCondVar *cv = NULL; 1.50 + PRThread *thread = NULL; 1.51 + PRIntervalTime interval = 0; 1.52 + PRFileDesc *file, *udp, *tcp, *pair[2]; 1.53 + PRIntn test; 1.54 + 1.55 + if ( argc < 2) 1.56 + { 1.57 + test = 0; 1.58 + } 1.59 + else 1.60 + test = atoi(argv[1]); 1.61 + 1.62 + switch (test) 1.63 + { 1.64 + case 0: ml = PR_NewLock(); 1.65 + break; 1.66 + 1.67 + case 1: interval = PR_SecondsToInterval(1); 1.68 + break; 1.69 + 1.70 + case 2: thread = PR_CreateThread( 1.71 + PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL, 1.72 + PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); 1.73 + break; 1.74 + 1.75 + case 3: file = PR_Open("/usr/tmp/", PR_RDONLY, 0); 1.76 + break; 1.77 + 1.78 + case 4: udp = PR_NewUDPSocket(); 1.79 + break; 1.80 + 1.81 + case 5: tcp = PR_NewTCPSocket(); 1.82 + break; 1.83 + 1.84 + case 6: dir = PR_OpenDir("/usr/tmp/"); 1.85 + break; 1.86 + 1.87 + case 7: (void)PR_NewThreadPrivateIndex(&pdkey, NULL); 1.88 + break; 1.89 + 1.90 + case 8: path = PR_GetEnv("PATH"); 1.91 + break; 1.92 + 1.93 + case 9: status = PR_NewTCPSocketPair(pair); 1.94 + break; 1.95 + 1.96 + case 10: PR_SetConcurrency(2); 1.97 + break; 1.98 + 1.99 + default: 1.100 + printf( 1.101 + "lazyinit: unrecognized command line argument: %s\n", 1.102 + argv[1] ); 1.103 + printf( "FAIL\n" ); 1.104 + exit( 1 ); 1.105 + break; 1.106 + } /* switch() */ 1.107 + return 0; 1.108 +} /* Lazy */ 1.109 + 1.110 +/* lazyinit.c */