Bug 1825055 [wpt PR 39247] - Add support for allowing elements with display:contents...
[gecko.git] / nsprpub / pr / tests / join.c
blob24238e6e05ed76e5d52d57e9eb20cfb3990f2a0c
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 /***********************************************************************
7 **
8 ** Name: dbmalloc1.c
9 **
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 /***********************************************************************
23 ** Includes
24 ***********************************************************************/
25 /* Used to get the command line option */
26 #include "plgetopt.h"
27 #include "prttools.h"
29 #include "nspr.h"
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
35 /***********************************************************************
36 ** PRIVATE FUNCTION: Test_Result
37 ** DESCRIPTION: Used in conjunction with the regress tool, prints out the
38 ** status of the test case.
39 ** INPUTS: PASS/FAIL
40 ** OUTPUTS: None
41 ** RETURN: None
42 ** SIDE EFFECTS:
44 ** RESTRICTIONS:
45 ** None
46 ** MEMORY: NA
47 ** ALGORITHM: Determine what the status is and print accordingly.
49 ***********************************************************************/
52 static void Test_Result (int result)
54 if (result == PASS) {
55 printf ("PASS\n");
57 else {
58 printf ("FAIL\n");
60 exit (1);
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
67 completed.
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)
86 PRThread *low,*high;
88 /* create the low and high priority threads */
90 low = PR_CreateThread(PR_USER_THREAD,
91 lowPriority, 0,
92 PR_PRIORITY_LOW,
93 scope1,
94 PR_JOINABLE_THREAD,
95 0);
96 if (!low) {
97 if (debug_mode) {
98 printf("\tcannot create low priority thread\n");
100 else {
101 Test_Result(FAIL);
103 return;
106 high = PR_CreateThread(PR_USER_THREAD,
107 highPriority, 0,
108 PR_PRIORITY_HIGH,
109 scope2,
110 PR_JOINABLE_THREAD,
112 if (!high) {
113 if (debug_mode) {
114 printf("\tcannot create high priority thread\n");
116 else {
117 Test_Result(FAIL);
119 return;
122 /* Do the joining for both threads */
123 if (PR_JoinThread(low) == PR_FAILURE) {
124 if (debug_mode) {
125 printf("\tcannot join low priority thread\n");
127 else {
128 Test_Result (FAIL);
130 return;
131 } else {
132 if (debug_mode) {
133 printf("\tjoined low priority thread\n");
136 if (PR_JoinThread(high) == PR_FAILURE) {
137 if (debug_mode) {
138 printf("\tcannot join high priority thread\n");
140 else {
141 Test_Result(FAIL);
143 return;
144 } else {
145 if (debug_mode) {
146 printf("\tjoined high priority thread\n");
151 void joinWithUnjoinable(void)
153 PRThread *thread;
155 /* create the unjoinable thread */
157 thread = PR_CreateThread(PR_USER_THREAD,
158 unjoinable, 0,
159 PR_PRIORITY_NORMAL,
160 PR_GLOBAL_THREAD,
161 PR_UNJOINABLE_THREAD,
163 if (!thread) {
164 if (debug_mode) {
165 printf("\tcannot create unjoinable thread\n");
167 else {
168 Test_Result(FAIL);
170 return;
173 if (PR_JoinThread(thread) == PR_SUCCESS) {
174 if (debug_mode) {
175 printf("\tsuccessfully joined with unjoinable thread?!\n");
177 else {
178 Test_Result(FAIL);
180 return;
181 } else {
182 if (debug_mode) {
183 printf("\tcannot join with unjoinable thread, as expected\n");
185 if (PR_GetError() != PR_INVALID_ARGUMENT_ERROR) {
186 if (debug_mode) {
187 printf("\tWrong error code\n");
189 else {
190 Test_Result(FAIL);
192 return;
195 if (PR_Interrupt(thread) == PR_FAILURE) {
196 if (debug_mode) {
197 printf("\tcannot interrupt unjoinable thread\n");
199 else {
200 Test_Result(FAIL);
202 return;
203 } else {
204 if (debug_mode) {
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)
215 test.
216 Usage: test_name -d
219 PLOptStatus os;
220 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
221 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
223 if (PL_OPT_BAD == os) {
224 continue;
226 switch (opt->option)
228 case 'd': /* debug mode */
229 debug_mode = 1;
230 break;
231 default:
232 break;
235 PL_DestroyOptState(opt);
237 /* main test */
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();
249 printf("PASSED\n");
251 return 0;
257 int main(int argc, char **argv)
259 PRIntn rv;
261 PR_STDIO_INIT();
262 rv = PR_Initialize(RealMain, argc, argv, 0);
263 return rv;
264 } /* main */