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/. */
6 /***********************************************************************
10 ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
12 ** Modification History:
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 ***********************************************************************/
22 /***********************************************************************
24 ***********************************************************************/
25 /* Used to get the command line option */
35 /***********************************************************************
36 ** PRIVATE FUNCTION: Test_Result
37 ** DESCRIPTION: Used in conjunction with the regress tool, prints out the
38 ** status of the test case.
47 ** ALGORITHM: Determine what the status is and print accordingly.
49 ***********************************************************************/
52 static void Test_Result (int result
)
65 Program to test joining of threads. Two threads are created. One
66 to be waited upon until it has started. The other to join after it has
71 static void PR_CALLBACK
lowPriority(void *arg
)
75 static void PR_CALLBACK
highPriority(void *arg
)
79 static void PR_CALLBACK
unjoinable(void *arg
)
81 PR_Sleep(PR_INTERVAL_NO_TIMEOUT
);
84 void runTest(PRThreadScope scope1
, PRThreadScope scope2
)
88 /* create the low and high priority threads */
90 low
= PR_CreateThread(PR_USER_THREAD
,
98 printf("\tcannot create low priority thread\n");
106 high
= PR_CreateThread(PR_USER_THREAD
,
114 printf("\tcannot create high priority thread\n");
122 /* Do the joining for both threads */
123 if (PR_JoinThread(low
) == PR_FAILURE
) {
125 printf("\tcannot join low priority thread\n");
133 printf("\tjoined low priority thread\n");
136 if (PR_JoinThread(high
) == PR_FAILURE
) {
138 printf("\tcannot join high priority thread\n");
146 printf("\tjoined high priority thread\n");
151 void joinWithUnjoinable(void)
155 /* create the unjoinable thread */
157 thread
= PR_CreateThread(PR_USER_THREAD
,
161 PR_UNJOINABLE_THREAD
,
165 printf("\tcannot create unjoinable thread\n");
173 if (PR_JoinThread(thread
) == PR_SUCCESS
) {
175 printf("\tsuccessfully joined with unjoinable thread?!\n");
183 printf("\tcannot join with unjoinable thread, as expected\n");
185 if (PR_GetError() != PR_INVALID_ARGUMENT_ERROR
) {
187 printf("\tWrong error code\n");
195 if (PR_Interrupt(thread
) == PR_FAILURE
) {
197 printf("\tcannot interrupt unjoinable thread\n");
205 printf("\tinterrupted unjoinable thread\n");
210 static PRIntn PR_CALLBACK
RealMain(int argc
, char **argv
)
212 /* The command line argument: -d is used to determine if the test is being run
213 in debug mode. The regress tool requires only one line output:PASS or FAIL.
214 All of the printfs associated with this test has been handled with a if (debug_mode)
220 PLOptState
*opt
= PL_CreateOptState(argc
, argv
, "d:");
221 while (PL_OPT_EOL
!= (os
= PL_GetNextOpt(opt
)))
223 if (PL_OPT_BAD
== os
) {
228 case 'd': /* debug mode */
235 PL_DestroyOptState(opt
);
238 printf("User-User test\n");
239 runTest(PR_LOCAL_THREAD
, PR_LOCAL_THREAD
);
240 printf("User-Kernel test\n");
241 runTest(PR_LOCAL_THREAD
, PR_GLOBAL_THREAD
);
242 printf("Kernel-User test\n");
243 runTest(PR_GLOBAL_THREAD
, PR_LOCAL_THREAD
);
244 printf("Kernel-Kernel test\n");
245 runTest(PR_GLOBAL_THREAD
, PR_GLOBAL_THREAD
);
246 printf("Join with unjoinable thread\n");
247 joinWithUnjoinable();
257 int main(int argc
, char **argv
)
262 rv
= PR_Initialize(RealMain
, argc
, argv
, 0);