Back to index

lightning-sunbird  0.9+nobinonly
joinkk.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /***********************************************************************
00039 **
00040 ** Name: dbmalloc1.c
00041 **
00042 ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
00043 **
00044 ** Modification History:
00045 ** 
00046 ** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
00047 **                    AGarcia- Converted the test to accomodate the debug_mode flag.
00048 **              The debug mode will print all of the printfs associated with this test.
00049 **                    The regress mode will be the default mode. Since the regress tool limits
00050 **           the output to a one line status:PASS or FAIL,all of the printf statements
00051 **                    have been handled with an if (debug_mode) statement.
00052 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
00053 **                   recognize the return code from tha main program.
00054 ***********************************************************************/
00055 
00056 /***********************************************************************
00057 ** Includes
00058 ***********************************************************************/
00059 /* Used to get the command line option */
00060 #include "plgetopt.h"
00061 
00062 #include "nspr.h"
00063 
00064 #include <stdio.h>
00065 #include <stdlib.h>
00066 #include <string.h>
00067 
00068 #ifdef XP_MAC
00069 #include "prlog.h"
00070 #define printf PR_LogPrint
00071 #endif
00072 
00073 PRIntn failed_already=0;
00074 PRIntn debug_mode;
00075 /*
00076        Program to test joining of threads.  Two threads are created.  One
00077        to be waited upon until it has started.  The other to join after it has
00078        completed.
00079 */
00080 
00081 
00082 static void lowPriority(void *arg)
00083 {
00084 }
00085 
00086 static void highPriority(void *arg)
00087 {
00088 }
00089 
00090 void runTest(PRThreadScope scope1, PRThreadScope scope2)
00091 {
00092        PRThread *low,*high;
00093 
00094        /* create the low and high priority threads */
00095        
00096        low = PR_CreateThread(PR_USER_THREAD,
00097                                   lowPriority, 0, 
00098                                   PR_PRIORITY_LOW,
00099                                   scope1,
00100                               PR_JOINABLE_THREAD,
00101                                   0);
00102        if (!low) {
00103               if (debug_mode) printf("\tcannot create low priority thread\n");
00104               else failed_already=1;
00105               return;
00106        }
00107 
00108        high = PR_CreateThread(PR_USER_THREAD,
00109                                   highPriority, 0, 
00110                                   PR_PRIORITY_HIGH,
00111                                   scope2,
00112                               PR_JOINABLE_THREAD,
00113                                   0);
00114        if (!high) {
00115               if (debug_mode) printf("\tcannot create high priority thread\n");
00116               else failed_already=1;
00117               return;
00118        }
00119 
00120        /* Do the joining for both threads */
00121        if (PR_JoinThread(low) == PR_FAILURE) {
00122               if (debug_mode) printf("\tcannot join low priority thread\n");
00123               else  failed_already=1;
00124               return;
00125        } else {
00126        if (debug_mode) printf("\tjoined low priority thread\n");
00127     }
00128        if (PR_JoinThread(high) == PR_FAILURE) {
00129               if (debug_mode) printf("\tcannot join high priority thread\n");
00130               else failed_already=1;
00131               return;
00132        } else {
00133        if (debug_mode) printf("\tjoined high priority thread\n");
00134     }
00135 }
00136 
00137 static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
00138 {
00139        /* The command line argument: -d is used to determine if the test is being run
00140        in debug mode. The regress tool requires only one line output:PASS or FAIL.
00141        All of the printfs associated with this test has been handled with a if (debug_mode)
00142        test.
00143        Usage: test_name -d
00144        */
00145        
00146        PLOptStatus os;
00147        PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
00148        while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
00149     {
00150               if (PL_OPT_BAD == os) continue;
00151         switch (opt->option)
00152         {
00153         case 'd':  /* debug mode */
00154                      debug_mode = 1;
00155             break;
00156          default:
00157             break;
00158         }
00159     }
00160        PL_DestroyOptState(opt);
00161 
00162 #ifdef XP_MAC
00163        SetupMacPrintfLog("join.log");
00164 #endif
00165 
00166        
00167        
00168  /* main test */
00169 
00170     if (debug_mode) printf("Kernel-Kernel test\n");
00171     runTest(PR_GLOBAL_THREAD, PR_GLOBAL_THREAD);
00172 
00173        if(failed_already)   
00174        {
00175         printf("FAIL\n");
00176               return 1;
00177        }
00178        else
00179        {
00180         printf("PASS\n");
00181               return 0;
00182        }
00183 
00184 }
00185 
00186 PRIntn main(PRIntn argc, char **argv)
00187 {
00188     PRIntn rv;
00189     
00190     PR_STDIO_INIT();
00191     rv = PR_Initialize(RealMain, argc, argv, 0);
00192     return rv;
00193 }  /* main */