michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /*********************************************************************** michael@0: ** michael@0: ** Name: dbmalloc1.c michael@0: ** michael@0: ** Description: Join tests user - user michael@0: ** michael@0: ** Modification History: michael@0: ** michael@0: ** 19-May-97 AGarcia - separate the four join tests into different unit test modules. michael@0: ** AGarcia- Converted the test to accomodate the debug_mode flag. michael@0: ** The debug mode will print all of the printfs associated with this test. michael@0: ** The regress mode will be the default mode. Since the regress tool limits michael@0: ** the output to a one line status:PASS or FAIL,all of the printf statements michael@0: ** have been handled with an if (debug_mode) statement. michael@0: ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to michael@0: ** recognize the return code from tha main program. michael@0: ***********************************************************************/ michael@0: michael@0: /*********************************************************************** michael@0: ** Includes michael@0: ***********************************************************************/ michael@0: /* Used to get the command line option */ michael@0: #include "plgetopt.h" michael@0: michael@0: #include "nspr.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: PRIntn failed_already=0; michael@0: PRIntn debug_mode; michael@0: michael@0: michael@0: /* michael@0: Program to test joining of threads. Two threads are created. One michael@0: to be waited upon until it has started. The other to join after it has michael@0: completed. michael@0: */ michael@0: michael@0: michael@0: static void lowPriority(void *arg) michael@0: { michael@0: } michael@0: michael@0: static void highPriority(void *arg) michael@0: { michael@0: } michael@0: michael@0: void runTest(PRThreadScope scope1, PRThreadScope scope2) michael@0: { michael@0: PRThread *low,*high; michael@0: michael@0: /* create the low and high priority threads */ michael@0: michael@0: low = PR_CreateThread(PR_USER_THREAD, michael@0: lowPriority, 0, michael@0: PR_PRIORITY_LOW, michael@0: scope1, michael@0: PR_JOINABLE_THREAD, michael@0: 0); michael@0: if (!low) { michael@0: if (debug_mode) printf("\tcannot create low priority thread\n"); michael@0: else failed_already=1; michael@0: return; michael@0: } michael@0: michael@0: high = PR_CreateThread(PR_USER_THREAD, michael@0: highPriority, 0, michael@0: PR_PRIORITY_HIGH, michael@0: scope2, michael@0: PR_JOINABLE_THREAD, michael@0: 0); michael@0: if (!high) { michael@0: if (debug_mode) printf("\tcannot create high priority thread\n"); michael@0: else failed_already=1; michael@0: return; michael@0: } michael@0: michael@0: /* Do the joining for both threads */ michael@0: if (PR_JoinThread(low) == PR_FAILURE) { michael@0: if (debug_mode) printf("\tcannot join low priority thread\n"); michael@0: else failed_already=1; michael@0: return; michael@0: } else { michael@0: if (debug_mode) printf("\tjoined low priority thread\n"); michael@0: } michael@0: if (PR_JoinThread(high) == PR_FAILURE) { michael@0: if (debug_mode) printf("\tcannot join high priority thread\n"); michael@0: else failed_already=1; michael@0: return; michael@0: } else { michael@0: if (debug_mode) printf("\tjoined high priority thread\n"); michael@0: } michael@0: } michael@0: michael@0: static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv ) michael@0: { michael@0: /* The command line argument: -d is used to determine if the test is being run michael@0: in debug mode. The regress tool requires only one line output:PASS or FAIL. michael@0: All of the printfs associated with this test has been handled with a if (debug_mode) michael@0: test. michael@0: Usage: test_name -d michael@0: */ michael@0: michael@0: PLOptStatus os; michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "d:"); michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) michael@0: { michael@0: if (PL_OPT_BAD == os) continue; michael@0: switch (opt->option) michael@0: { michael@0: case 'd': /* debug mode */ michael@0: debug_mode = 1; michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: michael@0: PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); michael@0: PR_STDIO_INIT(); michael@0: michael@0: /* main test */ michael@0: if (debug_mode) printf("User-User test\n"); michael@0: runTest(PR_LOCAL_THREAD, PR_LOCAL_THREAD); michael@0: michael@0: if(failed_already) michael@0: { michael@0: printf("FAIL\n"); michael@0: return 1; michael@0: } else michael@0: { michael@0: printf("PASS\n"); michael@0: return 0; michael@0: } michael@0: michael@0: michael@0: } michael@0: michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRIntn rv; michael@0: michael@0: PR_STDIO_INIT(); michael@0: rv = PR_Initialize(RealMain, argc, argv, 0); michael@0: return rv; michael@0: } /* main */