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