home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / joinkk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.7 KB  |  175 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /***********************************************************************
  20. **
  21. ** Name: dbmalloc1.c
  22. **
  23. ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
  24. **
  25. ** Modification History:
  26. ** 
  27. ** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
  28. **             AGarcia- Converted the test to accomodate the debug_mode flag.
  29. **             The debug mode will print all of the printfs associated with this test.
  30. **             The regress mode will be the default mode. Since the regress tool limits
  31. **           the output to a one line status:PASS or FAIL,all of the printf statements
  32. **             have been handled with an if (debug_mode) statement.
  33. ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
  34. **            recognize the return code from tha main program.
  35. ***********************************************************************/
  36.  
  37. /***********************************************************************
  38. ** Includes
  39. ***********************************************************************/
  40. /* Used to get the command line option */
  41. #include "plgetopt.h"
  42.  
  43. #include "nspr.h"
  44.  
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49. #ifdef XP_MAC
  50. #include "prlog.h"
  51. #define printf PR_LogPrint
  52. #endif
  53.  
  54. PRIntn failed_already=0;
  55. PRIntn debug_mode;
  56. /*
  57.     Program to test joining of threads.  Two threads are created.  One
  58.     to be waited upon until it has started.  The other to join after it has
  59.     completed.
  60. */
  61.  
  62.  
  63. static void lowPriority(void *arg)
  64. {
  65. }
  66.  
  67. static void highPriority(void *arg)
  68. {
  69. }
  70.  
  71. void runTest(PRThreadScope scope1, PRThreadScope scope2)
  72. {
  73.     PRThread *low,*high;
  74.  
  75.     /* create the low and high priority threads */
  76.     
  77.     low = PR_CreateThread(PR_USER_THREAD,
  78.                       lowPriority, 0, 
  79.                       PR_PRIORITY_LOW,
  80.                       scope1,
  81.                       PR_JOINABLE_THREAD,
  82.                       0);
  83.     if (!low) {
  84.         if (debug_mode) printf("\tcannot create low priority thread\n");
  85.         else failed_already=1;
  86.         return;
  87.     }
  88.  
  89.     high = PR_CreateThread(PR_USER_THREAD,
  90.                       highPriority, 0, 
  91.                       PR_PRIORITY_HIGH,
  92.                       scope2,
  93.                       PR_JOINABLE_THREAD,
  94.                       0);
  95.     if (!high) {
  96.         if (debug_mode) printf("\tcannot create high priority thread\n");
  97.         else failed_already=1;
  98.         return;
  99.     }
  100.  
  101.     /* Do the joining for both threads */
  102.     if (PR_JoinThread(low) == PR_FAILURE) {
  103.         if (debug_mode) printf("\tcannot join low priority thread\n");
  104.         else  failed_already=1;
  105.         return;
  106.     } else {
  107.         if (debug_mode) printf("\tjoined low priority thread\n");
  108.     }
  109.     if (PR_JoinThread(high) == PR_FAILURE) {
  110.         if (debug_mode) printf("\tcannot join high priority thread\n");
  111.         else failed_already=1;
  112.         return;
  113.     } else {
  114.         if (debug_mode) printf("\tjoined high priority thread\n");
  115.     }
  116. }
  117.  
  118. static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
  119. {
  120.     /* The command line argument: -d is used to determine if the test is being run
  121.     in debug mode. The regress tool requires only one line output:PASS or FAIL.
  122.     All of the printfs associated with this test has been handled with a if (debug_mode)
  123.     test.
  124.     Usage: test_name -d
  125.     */
  126.     
  127.     PLOptStatus os;
  128.     PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
  129.     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  130.     {
  131.         if (PL_OPT_BAD == os) continue;
  132.         switch (opt->option)
  133.         {
  134.         case 'd':  /* debug mode */
  135.             debug_mode = 1;
  136.             break;
  137.          default:
  138.             break;
  139.         }
  140.     }
  141.     PL_DestroyOptState(opt);
  142.  
  143. #ifdef XP_MAC
  144.     SetupMacPrintfLog("join.log");
  145. #endif
  146.  
  147.     
  148.     
  149.  /* main test */
  150.  
  151.     if (debug_mode) printf("Kernel-Kernel test\n");
  152.     runTest(PR_GLOBAL_THREAD, PR_GLOBAL_THREAD);
  153.  
  154.     if(failed_already)    
  155.     {
  156.         printf("FAIL\n");
  157.         return 0;
  158.     }
  159.     else
  160.     {
  161.         printf("PASS\n");
  162.         return 1;
  163.     }
  164.  
  165. }
  166.  
  167. PRIntn main(PRIntn argc, char **argv)
  168. {
  169.     PRIntn rv;
  170.     
  171.     PR_STDIO_INIT();
  172.     rv = PR_Initialize(RealMain, argc, argv, 0);
  173.     return rv;
  174. }  /* main */
  175.