VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/exit.c@ 22683

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

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 4.2 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#include "prio.h"
39#include "prprf.h"
40#include "prinit.h"
41#include "prthread.h"
42#include "prproces.h"
43#include "prinrval.h"
44
45#include "plgetopt.h"
46
47#include <stdlib.h>
48
49static PRInt32 dally = 0;
50static PRFileDesc *err = NULL;
51static PRBool verbose = PR_FALSE, force = PR_FALSE;
52
53static void Help(void)
54{
55 PR_fprintf(err, "Usage: [-t s] [-h]\n");
56 PR_fprintf(err, "\t-d Verbose output (default: FALSE)\n");
57 PR_fprintf(err, "\t-x Forced termination (default: FALSE)\n");
58 PR_fprintf(err, "\t-t Time for thread to block (default: 10 seconds)\n");
59 PR_fprintf(err, "\t-h This message and nothing else\n");
60} /* Help */
61
62static void Dull(void *arg)
63{
64 PR_Sleep(PR_SecondsToInterval(dally));
65 if (verbose && force)
66 PR_fprintf(err, "If you see this, the test failed\n");
67} /* Dull */
68
69static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
70{
71 PLOptStatus os;
72 PLOptState *opt = PL_CreateOptState(argc, argv, "ht:dx");
73
74 err = PR_GetSpecialFD(PR_StandardError);
75
76 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
77 {
78 if (PL_OPT_BAD == os) continue;
79 switch (opt->option)
80 {
81 case 'd': /* verbosity */
82 verbose = PR_TRUE;
83 break;
84 case 'x': /* force exit */
85 force = PR_TRUE;
86 break;
87 case 't': /* seconds to dally in child */
88 dally = atoi(opt->value);
89 break;
90 case 'h': /* user wants some guidance */
91 default:
92 Help(); /* so give him an earful */
93 return 2; /* but not a lot else */
94 }
95 }
96 PL_DestroyOptState(opt);
97
98 if (0 == dally) dally = 10;
99
100 /*
101 * Create LOCAL and GLOBAL threads
102 */
103 (void)PR_CreateThread(
104 PR_USER_THREAD, Dull, NULL, PR_PRIORITY_NORMAL,
105 PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
106
107 (void)PR_CreateThread(
108 PR_USER_THREAD, Dull, NULL, PR_PRIORITY_NORMAL,
109 PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
110
111 if (verbose)
112 PR_fprintf(
113 err, "Main is exiting now. Program should exit %s.\n",
114 (force) ? "immediately" : "after child dally time");
115
116 if (force)
117 {
118 PR_ProcessExit(0);
119 if (verbose)
120 {
121 PR_fprintf(err, "You should not have gotten here.\n");
122 return 1;
123 }
124 }
125 return 0;
126
127}
128
129
130PRIntn main(PRIntn argc, char *argv[])
131{
132 PRIntn rv;
133
134 PR_STDIO_INIT();
135 rv = PR_Initialize(RealMain, argc, argv, 0);
136 return rv;
137} /* main */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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