nsprpub/pr/tests/joinkk.c

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

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: dbmalloc1.c
michael@0 9 **
michael@0 10 ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
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 /* main test */
michael@0 126
michael@0 127 if (debug_mode) printf("Kernel-Kernel test\n");
michael@0 128 runTest(PR_GLOBAL_THREAD, PR_GLOBAL_THREAD);
michael@0 129
michael@0 130 if(failed_already)
michael@0 131 {
michael@0 132 printf("FAIL\n");
michael@0 133 return 1;
michael@0 134 }
michael@0 135 else
michael@0 136 {
michael@0 137 printf("PASS\n");
michael@0 138 return 0;
michael@0 139 }
michael@0 140
michael@0 141 }
michael@0 142
michael@0 143 int main(int argc, char **argv)
michael@0 144 {
michael@0 145 PRIntn rv;
michael@0 146
michael@0 147 PR_STDIO_INIT();
michael@0 148 rv = PR_Initialize(RealMain, argc, argv, 0);
michael@0 149 return rv;
michael@0 150 } /* main */

mercurial