michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** File: lazyinit.c michael@0: ** Description: Testing lazy initialization michael@0: ** michael@0: ** Since you only get to initialize once, you have to rerun the test michael@0: ** for each test case. The test cases are numbered. If you want to michael@0: ** add more tests, take the next number and add it to the switch michael@0: ** statement. michael@0: ** michael@0: ** This test is problematic on systems that don't support the notion michael@0: ** of console output. The workarounds to emulate that feature include michael@0: ** initializations themselves, which defeats the purpose here. michael@0: */ michael@0: michael@0: #include "prcvar.h" michael@0: #include "prenv.h" michael@0: #include "prinit.h" michael@0: #include "prinrval.h" michael@0: #include "prio.h" michael@0: #include "prlock.h" michael@0: #include "prlog.h" michael@0: #include "prthread.h" michael@0: #include "prtypes.h" michael@0: michael@0: #include michael@0: #include michael@0: michael@0: static void PR_CALLBACK lazyEntry(void *arg) michael@0: { michael@0: PR_ASSERT(NULL == arg); michael@0: } /* lazyEntry */ michael@0: michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRUintn pdkey; michael@0: PRStatus status; michael@0: char *path = NULL; michael@0: PRDir *dir = NULL; michael@0: PRLock *ml = NULL; michael@0: PRCondVar *cv = NULL; michael@0: PRThread *thread = NULL; michael@0: PRIntervalTime interval = 0; michael@0: PRFileDesc *file, *udp, *tcp, *pair[2]; michael@0: PRIntn test; michael@0: michael@0: if ( argc < 2) michael@0: { michael@0: test = 0; michael@0: } michael@0: else michael@0: test = atoi(argv[1]); michael@0: michael@0: switch (test) michael@0: { michael@0: case 0: ml = PR_NewLock(); michael@0: break; michael@0: michael@0: case 1: interval = PR_SecondsToInterval(1); michael@0: break; michael@0: michael@0: case 2: thread = PR_CreateThread( michael@0: PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL, michael@0: PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); michael@0: break; michael@0: michael@0: case 3: file = PR_Open("/usr/tmp/", PR_RDONLY, 0); michael@0: break; michael@0: michael@0: case 4: udp = PR_NewUDPSocket(); michael@0: break; michael@0: michael@0: case 5: tcp = PR_NewTCPSocket(); michael@0: break; michael@0: michael@0: case 6: dir = PR_OpenDir("/usr/tmp/"); michael@0: break; michael@0: michael@0: case 7: (void)PR_NewThreadPrivateIndex(&pdkey, NULL); michael@0: break; michael@0: michael@0: case 8: path = PR_GetEnv("PATH"); michael@0: break; michael@0: michael@0: case 9: status = PR_NewTCPSocketPair(pair); michael@0: break; michael@0: michael@0: case 10: PR_SetConcurrency(2); michael@0: break; michael@0: michael@0: default: michael@0: printf( michael@0: "lazyinit: unrecognized command line argument: %s\n", michael@0: argv[1] ); michael@0: printf( "FAIL\n" ); michael@0: exit( 1 ); michael@0: break; michael@0: } /* switch() */ michael@0: return 0; michael@0: } /* Lazy */ michael@0: michael@0: /* lazyinit.c */