Back to index

lightning-sunbird  0.9+nobinonly
joinuk.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: joinuk.c
00041 **
00042 ** Description: Join kernel - user
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 PRIntn failed_already=0;
00073 PRIntn debug_mode;
00074 /*
00075        Program to test joining of threads.  Two threads are created.  One
00076        to be waited upon until it has started.  The other to join after it has
00077        completed.
00078 */
00079 
00080 
00081 static void lowPriority(void *arg)
00082 {
00083 }
00084 
00085 static void highPriority(void *arg)
00086 {
00087 }
00088 
00089 void runTest(PRThreadScope scope1, PRThreadScope scope2)
00090 {
00091        PRThread *low,*high;
00092 
00093        /* create the low and high priority threads */
00094        
00095        low = PR_CreateThread(PR_USER_THREAD,
00096                                   lowPriority, 0, 
00097                                   PR_PRIORITY_LOW,
00098                                   scope1,
00099                               PR_JOINABLE_THREAD,
00100                                   0);
00101        if (!low) {
00102               if (debug_mode) printf("\tcannot create low priority thread\n");
00103               else failed_already=1;
00104               return;
00105        }
00106 
00107        high = PR_CreateThread(PR_USER_THREAD,
00108                                   highPriority, 0, 
00109                                   PR_PRIORITY_HIGH,
00110                                   scope2,
00111                               PR_JOINABLE_THREAD,
00112                                   0);
00113        if (!high) {
00114               if (debug_mode) printf("\tcannot create high priority thread\n");
00115               else failed_already=1;
00116               return;
00117        }
00118 
00119        /* Do the joining for both threads */
00120        if (PR_JoinThread(low) == PR_FAILURE) {
00121               if (debug_mode) printf("\tcannot join low priority thread\n");
00122               else failed_already=1;
00123               return;
00124        } else {
00125        if (debug_mode) printf("\tjoined low priority thread\n");
00126     }
00127        if (PR_JoinThread(high) == PR_FAILURE) {
00128               if (debug_mode) printf("\tcannot join high priority thread\n");
00129               else failed_already=1;
00130               return;
00131        } else {
00132        if (debug_mode) printf("\tjoined high priority thread\n");
00133     }
00134 }
00135 
00136 static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
00137 {
00138        /* The command line argument: -d is used to determine if the test is being run
00139        in debug mode. The regress tool requires only one line output:PASS or FAIL.
00140        All of the printfs associated with this test has been handled with a if (debug_mode)
00141        test.
00142        Usage: test_name -d
00143        */
00144        
00145        PLOptStatus os;
00146        PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
00147        while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
00148     {
00149               if (PL_OPT_BAD == os) continue;
00150         switch (opt->option)
00151         {
00152         case 'd':  /* debug mode */
00153                      debug_mode = 1;
00154             break;
00155          default:
00156             break;
00157         }
00158     }
00159        PL_DestroyOptState(opt);
00160 
00161     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
00162     PR_STDIO_INIT();
00163 
00164 #ifdef XP_MAC
00165        SetupMacPrintfLog("joinuk.log");
00166 #endif
00167 
00168        
00169        
00170  /* main test */
00171 
00172     if (debug_mode) printf("User-Kernel test\n");
00173     runTest(PR_LOCAL_THREAD, PR_GLOBAL_THREAD);
00174 
00175 
00176        if(failed_already)   
00177        {
00178         printf("FAIL\n");
00179               return 1;
00180     } else 
00181     {
00182         printf("PASS\n");
00183               return 0;
00184     }
00185 }
00186 
00187 
00188 PRIntn main(PRIntn argc, char **argv)
00189 {
00190     PRIntn rv;
00191     
00192     PR_STDIO_INIT();
00193     rv = PR_Initialize(RealMain, argc, argv, 0);
00194     return rv;
00195 }  /* main */