joinkk.c (4136B)
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 ** 8 ** Name: dbmalloc1.c 9 ** 10 ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions. 11 ** 12 ** Modification History: 13 ** 14 ** 19-May-97 AGarcia - separate the four join tests into different unit test 15 *modules. 16 ** AGarcia- Converted the test to accomodate the debug_mode flag. 17 ** The debug mode will print all of the printfs associated with this 18 *test. 19 ** The regress mode will be the default mode. Since the regress tool 20 *limits 21 ** the output to a one line status:PASS or FAIL,all of the printf 22 *statements 23 ** have been handled with an if (debug_mode) statement. 24 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been 25 *updated to 26 ** recognize the return code from tha main program. 27 ***********************************************************************/ 28 29 /*********************************************************************** 30 ** Includes 31 ***********************************************************************/ 32 /* Used to get the command line option */ 33 #include "plgetopt.h" 34 35 #include "nspr.h" 36 37 #include <stdio.h> 38 #include <stdlib.h> 39 #include <string.h> 40 41 PRIntn failed_already = 0; 42 PRIntn debug_mode; 43 /* 44 Program to test joining of threads. Two threads are created. One 45 to be waited upon until it has started. The other to join after it has 46 completed. 47 */ 48 49 static void lowPriority(void* arg) {} 50 51 static void highPriority(void* arg) {} 52 53 void runTest(PRThreadScope scope1, PRThreadScope scope2) { 54 PRThread *low, *high; 55 56 /* create the low and high priority threads */ 57 58 low = PR_CreateThread(PR_USER_THREAD, lowPriority, 0, PR_PRIORITY_LOW, scope1, 59 PR_JOINABLE_THREAD, 0); 60 if (!low) { 61 if (debug_mode) { 62 printf("\tcannot create low priority thread\n"); 63 } else { 64 failed_already = 1; 65 } 66 return; 67 } 68 69 high = PR_CreateThread(PR_USER_THREAD, highPriority, 0, PR_PRIORITY_HIGH, 70 scope2, PR_JOINABLE_THREAD, 0); 71 if (!high) { 72 if (debug_mode) { 73 printf("\tcannot create high priority thread\n"); 74 } else { 75 failed_already = 1; 76 } 77 return; 78 } 79 80 /* Do the joining for both threads */ 81 if (PR_JoinThread(low) == PR_FAILURE) { 82 if (debug_mode) { 83 printf("\tcannot join low priority thread\n"); 84 } else { 85 failed_already = 1; 86 } 87 return; 88 } else { 89 if (debug_mode) { 90 printf("\tjoined low priority thread\n"); 91 } 92 } 93 if (PR_JoinThread(high) == PR_FAILURE) { 94 if (debug_mode) { 95 printf("\tcannot join high priority thread\n"); 96 } else { 97 failed_already = 1; 98 } 99 return; 100 } else { 101 if (debug_mode) { 102 printf("\tjoined high priority thread\n"); 103 } 104 } 105 } 106 107 static PRIntn PR_CALLBACK RealMain(PRIntn argc, char** argv) { 108 /* The command line argument: -d is used to determine if the test is being run 109 in debug mode. The regress tool requires only one line output:PASS or FAIL. 110 All of the printfs associated with this test has been handled with a if 111 (debug_mode) test. Usage: test_name -d 112 */ 113 114 PLOptStatus os; 115 PLOptState* opt = PL_CreateOptState(argc, argv, "d:"); 116 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { 117 if (PL_OPT_BAD == os) { 118 continue; 119 } 120 switch (opt->option) { 121 case 'd': /* debug mode */ 122 debug_mode = 1; 123 break; 124 default: 125 break; 126 } 127 } 128 PL_DestroyOptState(opt); 129 130 /* main test */ 131 132 if (debug_mode) { 133 printf("Kernel-Kernel test\n"); 134 } 135 runTest(PR_GLOBAL_THREAD, PR_GLOBAL_THREAD); 136 137 if (failed_already) { 138 printf("FAIL\n"); 139 return 1; 140 } else { 141 printf("PASS\n"); 142 return 0; 143 } 144 } 145 146 int main(int argc, char** argv) { 147 PRIntn rv; 148 149 rv = PR_Initialize(RealMain, argc, argv, 0); 150 return rv; 151 } /* main */