1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/joinkk.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/*********************************************************************** 1.10 +** 1.11 +** Name: dbmalloc1.c 1.12 +** 1.13 +** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions. 1.14 +** 1.15 +** Modification History: 1.16 +** 1.17 +** 19-May-97 AGarcia - separate the four join tests into different unit test modules. 1.18 +** AGarcia- Converted the test to accomodate the debug_mode flag. 1.19 +** The debug mode will print all of the printfs associated with this test. 1.20 +** The regress mode will be the default mode. Since the regress tool limits 1.21 +** the output to a one line status:PASS or FAIL,all of the printf statements 1.22 +** have been handled with an if (debug_mode) statement. 1.23 +** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to 1.24 +** recognize the return code from tha main program. 1.25 +***********************************************************************/ 1.26 + 1.27 +/*********************************************************************** 1.28 +** Includes 1.29 +***********************************************************************/ 1.30 +/* Used to get the command line option */ 1.31 +#include "plgetopt.h" 1.32 + 1.33 +#include "nspr.h" 1.34 + 1.35 +#include <stdio.h> 1.36 +#include <stdlib.h> 1.37 +#include <string.h> 1.38 + 1.39 +PRIntn failed_already=0; 1.40 +PRIntn debug_mode; 1.41 +/* 1.42 + Program to test joining of threads. Two threads are created. One 1.43 + to be waited upon until it has started. The other to join after it has 1.44 + completed. 1.45 +*/ 1.46 + 1.47 + 1.48 +static void lowPriority(void *arg) 1.49 +{ 1.50 +} 1.51 + 1.52 +static void highPriority(void *arg) 1.53 +{ 1.54 +} 1.55 + 1.56 +void runTest(PRThreadScope scope1, PRThreadScope scope2) 1.57 +{ 1.58 + PRThread *low,*high; 1.59 + 1.60 + /* create the low and high priority threads */ 1.61 + 1.62 + low = PR_CreateThread(PR_USER_THREAD, 1.63 + lowPriority, 0, 1.64 + PR_PRIORITY_LOW, 1.65 + scope1, 1.66 + PR_JOINABLE_THREAD, 1.67 + 0); 1.68 + if (!low) { 1.69 + if (debug_mode) printf("\tcannot create low priority thread\n"); 1.70 + else failed_already=1; 1.71 + return; 1.72 + } 1.73 + 1.74 + high = PR_CreateThread(PR_USER_THREAD, 1.75 + highPriority, 0, 1.76 + PR_PRIORITY_HIGH, 1.77 + scope2, 1.78 + PR_JOINABLE_THREAD, 1.79 + 0); 1.80 + if (!high) { 1.81 + if (debug_mode) printf("\tcannot create high priority thread\n"); 1.82 + else failed_already=1; 1.83 + return; 1.84 + } 1.85 + 1.86 + /* Do the joining for both threads */ 1.87 + if (PR_JoinThread(low) == PR_FAILURE) { 1.88 + if (debug_mode) printf("\tcannot join low priority thread\n"); 1.89 + else failed_already=1; 1.90 + return; 1.91 + } else { 1.92 + if (debug_mode) printf("\tjoined low priority thread\n"); 1.93 + } 1.94 + if (PR_JoinThread(high) == PR_FAILURE) { 1.95 + if (debug_mode) printf("\tcannot join high priority thread\n"); 1.96 + else failed_already=1; 1.97 + return; 1.98 + } else { 1.99 + if (debug_mode) printf("\tjoined high priority thread\n"); 1.100 + } 1.101 +} 1.102 + 1.103 +static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv ) 1.104 +{ 1.105 + /* The command line argument: -d is used to determine if the test is being run 1.106 + in debug mode. The regress tool requires only one line output:PASS or FAIL. 1.107 + All of the printfs associated with this test has been handled with a if (debug_mode) 1.108 + test. 1.109 + Usage: test_name -d 1.110 + */ 1.111 + 1.112 + PLOptStatus os; 1.113 + PLOptState *opt = PL_CreateOptState(argc, argv, "d:"); 1.114 + while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) 1.115 + { 1.116 + if (PL_OPT_BAD == os) continue; 1.117 + switch (opt->option) 1.118 + { 1.119 + case 'd': /* debug mode */ 1.120 + debug_mode = 1; 1.121 + break; 1.122 + default: 1.123 + break; 1.124 + } 1.125 + } 1.126 + PL_DestroyOptState(opt); 1.127 + 1.128 + /* main test */ 1.129 + 1.130 + if (debug_mode) printf("Kernel-Kernel test\n"); 1.131 + runTest(PR_GLOBAL_THREAD, PR_GLOBAL_THREAD); 1.132 + 1.133 + if(failed_already) 1.134 + { 1.135 + printf("FAIL\n"); 1.136 + return 1; 1.137 + } 1.138 + else 1.139 + { 1.140 + printf("PASS\n"); 1.141 + return 0; 1.142 + } 1.143 + 1.144 +} 1.145 + 1.146 +int main(int argc, char **argv) 1.147 +{ 1.148 + PRIntn rv; 1.149 + 1.150 + PR_STDIO_INIT(); 1.151 + rv = PR_Initialize(RealMain, argc, argv, 0); 1.152 + return rv; 1.153 +} /* main */