lazyinit.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. ** File: lazyinit.c
  7. ** Description: Testing lazy initialization
  8. **
  9. ** Since you only get to initialize once, you have to rerun the test
  10. ** for each test case. The test cases are numbered. If you want to
  11. ** add more tests, take the next number and add it to the switch
  12. ** statement.
  13. **
  14. ** This test is problematic on systems that don't support the notion
  15. ** of console output. The workarounds to emulate that feature include
  16. ** initializations themselves, which defeats the purpose here.
  17. */
  18. #include "prcvar.h"
  19. #include "prenv.h"
  20. #include "prinit.h"
  21. #include "prinrval.h"
  22. #include "prio.h"
  23. #include "prlock.h"
  24. #include "prlog.h"
  25. #include "prthread.h"
  26. #include "prtypes.h"
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. static void PR_CALLBACK lazyEntry(void *arg)
  30. {
  31. PR_ASSERT(NULL == arg);
  32. } /* lazyEntry */
  33. int main(int argc, char **argv)
  34. {
  35. PRUintn pdkey;
  36. PRStatus status;
  37. char *path = NULL;
  38. PRDir *dir = NULL;
  39. PRLock *ml = NULL;
  40. PRCondVar *cv = NULL;
  41. PRThread *thread = NULL;
  42. PRIntervalTime interval = 0;
  43. PRFileDesc *file, *udp, *tcp, *pair[2];
  44. PRIntn test;
  45. if ( argc < 2)
  46. {
  47. test = 0;
  48. }
  49. else {
  50. test = atoi(argv[1]);
  51. }
  52. switch (test)
  53. {
  54. case 0: ml = PR_NewLock();
  55. break;
  56. case 1: interval = PR_SecondsToInterval(1);
  57. break;
  58. case 2: thread = PR_CreateThread(
  59. PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
  60. PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
  61. break;
  62. case 3: file = PR_Open("./tmp-", PR_RDONLY, 0);
  63. break;
  64. case 4: udp = PR_NewUDPSocket();
  65. break;
  66. case 5: tcp = PR_NewTCPSocket();
  67. break;
  68. case 6: dir = PR_OpenDir("./tmp-");
  69. break;
  70. case 7: (void)PR_NewThreadPrivateIndex(&pdkey, NULL);
  71. break;
  72. case 8: path = PR_GetEnv("PATH");
  73. break;
  74. case 9: status = PR_NewTCPSocketPair(pair);
  75. break;
  76. case 10: PR_SetConcurrency(2);
  77. break;
  78. default:
  79. printf(
  80. "lazyinit: unrecognized command line argument: %s\n",
  81. argv[1] );
  82. printf( "FAIL\n" );
  83. exit( 1 );
  84. break;
  85. } /* switch() */
  86. return 0;
  87. } /* Lazy */
  88. /* lazyinit.c */