Bug 1845715 - Check for failure when getting RegExp match result template r=iain
[gecko.git] / nsprpub / pr / tests / joinuk.c
blob418c5e0e91fff93ab4ce1c45e21413bbf98573e1
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: joinuk.c
9 **
10 ** Description: Join kernel - user
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 ** 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 ***********************************************************************/
24 /***********************************************************************
25 ** Includes
26 ***********************************************************************/
27 /* Used to get the command line option */
28 #include "plgetopt.h"
30 #include "nspr.h"
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
36 PRIntn failed_already=0;
37 PRIntn debug_mode;
39 Program to test joining of threads. Two threads are created. One
40 to be waited upon until it has started. The other to join after it has
41 completed.
45 static void lowPriority(void *arg)
49 static void highPriority(void *arg)
53 void runTest(PRThreadScope scope1, PRThreadScope scope2)
55 PRThread *low,*high;
57 /* create the low and high priority threads */
59 low = PR_CreateThread(PR_USER_THREAD,
60 lowPriority, 0,
61 PR_PRIORITY_LOW,
62 scope1,
63 PR_JOINABLE_THREAD,
64 0);
65 if (!low) {
66 if (debug_mode) {
67 printf("\tcannot create low priority thread\n");
69 else {
70 failed_already=1;
72 return;
75 high = PR_CreateThread(PR_USER_THREAD,
76 highPriority, 0,
77 PR_PRIORITY_HIGH,
78 scope2,
79 PR_JOINABLE_THREAD,
80 0);
81 if (!high) {
82 if (debug_mode) {
83 printf("\tcannot create high priority thread\n");
85 else {
86 failed_already=1;
88 return;
91 /* Do the joining for both threads */
92 if (PR_JoinThread(low) == PR_FAILURE) {
93 if (debug_mode) {
94 printf("\tcannot join low priority thread\n");
96 else {
97 failed_already=1;
99 return;
100 } else {
101 if (debug_mode) {
102 printf("\tjoined low priority thread\n");
105 if (PR_JoinThread(high) == PR_FAILURE) {
106 if (debug_mode) {
107 printf("\tcannot join high priority thread\n");
109 else {
110 failed_already=1;
112 return;
113 } else {
114 if (debug_mode) {
115 printf("\tjoined high priority thread\n");
120 static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
122 /* The command line argument: -d is used to determine if the test is being run
123 in debug mode. The regress tool requires only one line output:PASS or FAIL.
124 All of the printfs associated with this test has been handled with a if (debug_mode)
125 test.
126 Usage: test_name -d
129 PLOptStatus os;
130 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
131 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
133 if (PL_OPT_BAD == os) {
134 continue;
136 switch (opt->option)
138 case 'd': /* debug mode */
139 debug_mode = 1;
140 break;
141 default:
142 break;
145 PL_DestroyOptState(opt);
147 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
148 PR_STDIO_INIT();
150 /* main test */
152 if (debug_mode) {
153 printf("User-Kernel test\n");
155 runTest(PR_LOCAL_THREAD, PR_GLOBAL_THREAD);
158 if(failed_already)
160 printf("FAIL\n");
161 return 1;
162 } else
164 printf("PASS\n");
165 return 0;
170 int main(int argc, char **argv)
172 PRIntn rv;
174 PR_STDIO_INIT();
175 rv = PR_Initialize(RealMain, argc, argv, 0);
176 return rv;
177 } /* main */