Wed, 31 Dec 2014 06:55:46 +0100
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: Join tests user - 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 | |
michael@0 | 40 | /* |
michael@0 | 41 | Program to test joining of threads. Two threads are created. One |
michael@0 | 42 | to be waited upon until it has started. The other to join after it has |
michael@0 | 43 | completed. |
michael@0 | 44 | */ |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | static void lowPriority(void *arg) |
michael@0 | 48 | { |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | static void highPriority(void *arg) |
michael@0 | 52 | { |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void runTest(PRThreadScope scope1, PRThreadScope scope2) |
michael@0 | 56 | { |
michael@0 | 57 | PRThread *low,*high; |
michael@0 | 58 | |
michael@0 | 59 | /* create the low and high priority threads */ |
michael@0 | 60 | |
michael@0 | 61 | low = PR_CreateThread(PR_USER_THREAD, |
michael@0 | 62 | lowPriority, 0, |
michael@0 | 63 | PR_PRIORITY_LOW, |
michael@0 | 64 | scope1, |
michael@0 | 65 | PR_JOINABLE_THREAD, |
michael@0 | 66 | 0); |
michael@0 | 67 | if (!low) { |
michael@0 | 68 | if (debug_mode) printf("\tcannot create low priority thread\n"); |
michael@0 | 69 | else failed_already=1; |
michael@0 | 70 | return; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | high = PR_CreateThread(PR_USER_THREAD, |
michael@0 | 74 | highPriority, 0, |
michael@0 | 75 | PR_PRIORITY_HIGH, |
michael@0 | 76 | scope2, |
michael@0 | 77 | PR_JOINABLE_THREAD, |
michael@0 | 78 | 0); |
michael@0 | 79 | if (!high) { |
michael@0 | 80 | if (debug_mode) printf("\tcannot create high priority thread\n"); |
michael@0 | 81 | else failed_already=1; |
michael@0 | 82 | return; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | /* Do the joining for both threads */ |
michael@0 | 86 | if (PR_JoinThread(low) == PR_FAILURE) { |
michael@0 | 87 | if (debug_mode) printf("\tcannot join low priority thread\n"); |
michael@0 | 88 | else failed_already=1; |
michael@0 | 89 | return; |
michael@0 | 90 | } else { |
michael@0 | 91 | if (debug_mode) printf("\tjoined low priority thread\n"); |
michael@0 | 92 | } |
michael@0 | 93 | if (PR_JoinThread(high) == PR_FAILURE) { |
michael@0 | 94 | if (debug_mode) printf("\tcannot join high priority thread\n"); |
michael@0 | 95 | else failed_already=1; |
michael@0 | 96 | return; |
michael@0 | 97 | } else { |
michael@0 | 98 | if (debug_mode) printf("\tjoined high priority thread\n"); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv ) |
michael@0 | 103 | { |
michael@0 | 104 | /* The command line argument: -d is used to determine if the test is being run |
michael@0 | 105 | in debug mode. The regress tool requires only one line output:PASS or FAIL. |
michael@0 | 106 | All of the printfs associated with this test has been handled with a if (debug_mode) |
michael@0 | 107 | test. |
michael@0 | 108 | Usage: test_name -d |
michael@0 | 109 | */ |
michael@0 | 110 | |
michael@0 | 111 | PLOptStatus os; |
michael@0 | 112 | PLOptState *opt = PL_CreateOptState(argc, argv, "d:"); |
michael@0 | 113 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
michael@0 | 114 | { |
michael@0 | 115 | if (PL_OPT_BAD == os) continue; |
michael@0 | 116 | switch (opt->option) |
michael@0 | 117 | { |
michael@0 | 118 | case 'd': /* debug mode */ |
michael@0 | 119 | debug_mode = 1; |
michael@0 | 120 | break; |
michael@0 | 121 | default: |
michael@0 | 122 | break; |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | PL_DestroyOptState(opt); |
michael@0 | 126 | |
michael@0 | 127 | PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); |
michael@0 | 128 | PR_STDIO_INIT(); |
michael@0 | 129 | |
michael@0 | 130 | /* main test */ |
michael@0 | 131 | if (debug_mode) printf("User-User test\n"); |
michael@0 | 132 | runTest(PR_LOCAL_THREAD, PR_LOCAL_THREAD); |
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 | |
michael@0 | 147 | |
michael@0 | 148 | int main(int argc, char **argv) |
michael@0 | 149 | { |
michael@0 | 150 | PRIntn rv; |
michael@0 | 151 | |
michael@0 | 152 | PR_STDIO_INIT(); |
michael@0 | 153 | rv = PR_Initialize(RealMain, argc, argv, 0); |
michael@0 | 154 | return rv; |
michael@0 | 155 | } /* main */ |