Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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: Join tests user - user
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 ***********************************************************************/
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;
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 */
47 static void lowPriority(void *arg)
48 {
49 }
51 static void highPriority(void *arg)
52 {
53 }
55 void runTest(PRThreadScope scope1, PRThreadScope scope2)
56 {
57 PRThread *low,*high;
59 /* create the low and high priority threads */
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 }
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 }
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 }
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 */
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);
127 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
128 PR_STDIO_INIT();
130 /* main test */
131 if (debug_mode) printf("User-User test\n");
132 runTest(PR_LOCAL_THREAD, PR_LOCAL_THREAD);
134 if(failed_already)
135 {
136 printf("FAIL\n");
137 return 1;
138 } else
139 {
140 printf("PASS\n");
141 return 0;
142 }
145 }
148 int main(int argc, char **argv)
149 {
150 PRIntn rv;
152 PR_STDIO_INIT();
153 rv = PR_Initialize(RealMain, argc, argv, 0);
154 return rv;
155 } /* main */