Back to index

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