nsprpub/pr/tests/joinuk.c

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /***********************************************************************
michael@0 7 **
michael@0 8 ** Name: joinuk.c
michael@0 9 **
michael@0 10 ** Description: Join kernel - user
michael@0 11 **
michael@0 12 ** Modification History:
michael@0 13 **
michael@0 14 ** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
michael@0 15 ** AGarcia- Converted the test to accomodate the debug_mode flag.
michael@0 16 ** The debug mode will print all of the printfs associated with this test.
michael@0 17 ** The regress mode will be the default mode. Since the regress tool limits
michael@0 18 ** the output to a one line status:PASS or FAIL,all of the printf statements
michael@0 19 ** have been handled with an if (debug_mode) statement.
michael@0 20 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
michael@0 21 ** recognize the return code from tha main program.
michael@0 22 ***********************************************************************/
michael@0 23
michael@0 24 /***********************************************************************
michael@0 25 ** Includes
michael@0 26 ***********************************************************************/
michael@0 27 /* Used to get the command line option */
michael@0 28 #include "plgetopt.h"
michael@0 29
michael@0 30 #include "nspr.h"
michael@0 31
michael@0 32 #include <stdio.h>
michael@0 33 #include <stdlib.h>
michael@0 34 #include <string.h>
michael@0 35
michael@0 36 PRIntn failed_already=0;
michael@0 37 PRIntn debug_mode;
michael@0 38 /*
michael@0 39 Program to test joining of threads. Two threads are created. One
michael@0 40 to be waited upon until it has started. The other to join after it has
michael@0 41 completed.
michael@0 42 */
michael@0 43
michael@0 44
michael@0 45 static void lowPriority(void *arg)
michael@0 46 {
michael@0 47 }
michael@0 48
michael@0 49 static void highPriority(void *arg)
michael@0 50 {
michael@0 51 }
michael@0 52
michael@0 53 void runTest(PRThreadScope scope1, PRThreadScope scope2)
michael@0 54 {
michael@0 55 PRThread *low,*high;
michael@0 56
michael@0 57 /* create the low and high priority threads */
michael@0 58
michael@0 59 low = PR_CreateThread(PR_USER_THREAD,
michael@0 60 lowPriority, 0,
michael@0 61 PR_PRIORITY_LOW,
michael@0 62 scope1,
michael@0 63 PR_JOINABLE_THREAD,
michael@0 64 0);
michael@0 65 if (!low) {
michael@0 66 if (debug_mode) printf("\tcannot create low priority thread\n");
michael@0 67 else failed_already=1;
michael@0 68 return;
michael@0 69 }
michael@0 70
michael@0 71 high = PR_CreateThread(PR_USER_THREAD,
michael@0 72 highPriority, 0,
michael@0 73 PR_PRIORITY_HIGH,
michael@0 74 scope2,
michael@0 75 PR_JOINABLE_THREAD,
michael@0 76 0);
michael@0 77 if (!high) {
michael@0 78 if (debug_mode) printf("\tcannot create high priority thread\n");
michael@0 79 else failed_already=1;
michael@0 80 return;
michael@0 81 }
michael@0 82
michael@0 83 /* Do the joining for both threads */
michael@0 84 if (PR_JoinThread(low) == PR_FAILURE) {
michael@0 85 if (debug_mode) printf("\tcannot join low priority thread\n");
michael@0 86 else failed_already=1;
michael@0 87 return;
michael@0 88 } else {
michael@0 89 if (debug_mode) printf("\tjoined low priority thread\n");
michael@0 90 }
michael@0 91 if (PR_JoinThread(high) == PR_FAILURE) {
michael@0 92 if (debug_mode) printf("\tcannot join high priority thread\n");
michael@0 93 else failed_already=1;
michael@0 94 return;
michael@0 95 } else {
michael@0 96 if (debug_mode) printf("\tjoined high priority thread\n");
michael@0 97 }
michael@0 98 }
michael@0 99
michael@0 100 static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
michael@0 101 {
michael@0 102 /* The command line argument: -d is used to determine if the test is being run
michael@0 103 in debug mode. The regress tool requires only one line output:PASS or FAIL.
michael@0 104 All of the printfs associated with this test has been handled with a if (debug_mode)
michael@0 105 test.
michael@0 106 Usage: test_name -d
michael@0 107 */
michael@0 108
michael@0 109 PLOptStatus os;
michael@0 110 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
michael@0 111 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
michael@0 112 {
michael@0 113 if (PL_OPT_BAD == os) continue;
michael@0 114 switch (opt->option)
michael@0 115 {
michael@0 116 case 'd': /* debug mode */
michael@0 117 debug_mode = 1;
michael@0 118 break;
michael@0 119 default:
michael@0 120 break;
michael@0 121 }
michael@0 122 }
michael@0 123 PL_DestroyOptState(opt);
michael@0 124
michael@0 125 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
michael@0 126 PR_STDIO_INIT();
michael@0 127
michael@0 128 /* main test */
michael@0 129
michael@0 130 if (debug_mode) printf("User-Kernel test\n");
michael@0 131 runTest(PR_LOCAL_THREAD, PR_GLOBAL_THREAD);
michael@0 132
michael@0 133
michael@0 134 if(failed_already)
michael@0 135 {
michael@0 136 printf("FAIL\n");
michael@0 137 return 1;
michael@0 138 } else
michael@0 139 {
michael@0 140 printf("PASS\n");
michael@0 141 return 0;
michael@0 142 }
michael@0 143 }
michael@0 144
michael@0 145
michael@0 146 int main(int argc, char **argv)
michael@0 147 {
michael@0 148 PRIntn rv;
michael@0 149
michael@0 150 PR_STDIO_INIT();
michael@0 151 rv = PR_Initialize(RealMain, argc, argv, 0);
michael@0 152 return rv;
michael@0 153 } /* main */

mercurial