VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/joinuk.c@ 55761

最後變更 在這個檔案從55761是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.6 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/***********************************************************************
39**
40** Name: joinuk.c
41**
42** Description: Join kernel - user
43**
44** Modification History:
45**
46** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
47** AGarcia- Converted the test to accomodate the debug_mode flag.
48** The debug mode will print all of the printfs associated with this test.
49** The regress mode will be the default mode. Since the regress tool limits
50** the output to a one line status:PASS or FAIL,all of the printf statements
51** have been handled with an if (debug_mode) statement.
52** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
53** recognize the return code from tha main program.
54***********************************************************************/
55
56/***********************************************************************
57** Includes
58***********************************************************************/
59/* Used to get the command line option */
60#include "plgetopt.h"
61
62#include "nspr.h"
63
64#include <stdio.h>
65#include <stdlib.h>
66#include <string.h>
67
68#ifdef XP_MAC
69#include "prlog.h"
70#define printf PR_LogPrint
71#endif
72PRIntn failed_already=0;
73PRIntn debug_mode;
74/*
75 Program to test joining of threads. Two threads are created. One
76 to be waited upon until it has started. The other to join after it has
77 completed.
78*/
79
80
81static void lowPriority(void *arg)
82{
83}
84
85static void highPriority(void *arg)
86{
87}
88
89void runTest(PRThreadScope scope1, PRThreadScope scope2)
90{
91 PRThread *low,*high;
92
93 /* create the low and high priority threads */
94
95 low = PR_CreateThread(PR_USER_THREAD,
96 lowPriority, 0,
97 PR_PRIORITY_LOW,
98 scope1,
99 PR_JOINABLE_THREAD,
100 0);
101 if (!low) {
102 if (debug_mode) printf("\tcannot create low priority thread\n");
103 else failed_already=1;
104 return;
105 }
106
107 high = PR_CreateThread(PR_USER_THREAD,
108 highPriority, 0,
109 PR_PRIORITY_HIGH,
110 scope2,
111 PR_JOINABLE_THREAD,
112 0);
113 if (!high) {
114 if (debug_mode) printf("\tcannot create high priority thread\n");
115 else failed_already=1;
116 return;
117 }
118
119 /* Do the joining for both threads */
120 if (PR_JoinThread(low) == PR_FAILURE) {
121 if (debug_mode) printf("\tcannot join low priority thread\n");
122 else failed_already=1;
123 return;
124 } else {
125 if (debug_mode) printf("\tjoined low priority thread\n");
126 }
127 if (PR_JoinThread(high) == PR_FAILURE) {
128 if (debug_mode) printf("\tcannot join high priority thread\n");
129 else failed_already=1;
130 return;
131 } else {
132 if (debug_mode) printf("\tjoined high priority thread\n");
133 }
134}
135
136static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
137{
138 /* The command line argument: -d is used to determine if the test is being run
139 in debug mode. The regress tool requires only one line output:PASS or FAIL.
140 All of the printfs associated with this test has been handled with a if (debug_mode)
141 test.
142 Usage: test_name -d
143 */
144
145 PLOptStatus os;
146 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
147 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
148 {
149 if (PL_OPT_BAD == os) continue;
150 switch (opt->option)
151 {
152 case 'd': /* debug mode */
153 debug_mode = 1;
154 break;
155 default:
156 break;
157 }
158 }
159 PL_DestroyOptState(opt);
160
161 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
162 PR_STDIO_INIT();
163
164#ifdef XP_MAC
165 SetupMacPrintfLog("joinuk.log");
166#endif
167
168
169
170 /* main test */
171
172 if (debug_mode) printf("User-Kernel test\n");
173 runTest(PR_LOCAL_THREAD, PR_GLOBAL_THREAD);
174
175
176 if(failed_already)
177 {
178 printf("FAIL\n");
179 return 1;
180 } else
181 {
182 printf("PASS\n");
183 return 0;
184 }
185}
186
187
188PRIntn main(PRIntn argc, char **argv)
189{
190 PRIntn rv;
191
192 PR_STDIO_INIT();
193 rv = PR_Initialize(RealMain, argc, argv, 0);
194 return rv;
195} /* main */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette