home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / joinuu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.7 KB  |  179 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: Join tests user - user
  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. PRIntn failed_already=0;
  54. PRIntn debug_mode;
  55.  
  56.  
  57. /*
  58.     Program to test joining of threads.  Two threads are created.  One
  59.     to be waited upon until it has started.  The other to join after it has
  60.     completed.
  61. */
  62.  
  63.  
  64. static void lowPriority(void *arg)
  65. {
  66. }
  67.  
  68. static void highPriority(void *arg)
  69. {
  70. }
  71.  
  72. void runTest(PRThreadScope scope1, PRThreadScope scope2)
  73. {
  74.     PRThread *low,*high;
  75.  
  76.     /* create the low and high priority threads */
  77.     
  78.     low = PR_CreateThread(PR_USER_THREAD,
  79.                       lowPriority, 0, 
  80.                       PR_PRIORITY_LOW,
  81.                       scope1,
  82.                       PR_JOINABLE_THREAD,
  83.                       0);
  84.     if (!low) {
  85.         if (debug_mode) printf("\tcannot create low priority thread\n");
  86.         else failed_already=1;
  87.         return;
  88.     }
  89.  
  90.     high = PR_CreateThread(PR_USER_THREAD,
  91.                       highPriority, 0, 
  92.                       PR_PRIORITY_HIGH,
  93.                       scope2,
  94.                       PR_JOINABLE_THREAD,
  95.                       0);
  96.     if (!high) {
  97.         if (debug_mode) printf("\tcannot create high priority thread\n");
  98.         else failed_already=1;
  99.         return;
  100.     }
  101.  
  102.     /* Do the joining for both threads */
  103.     if (PR_JoinThread(low) == PR_FAILURE) {
  104.         if (debug_mode) printf("\tcannot join low priority thread\n");
  105.         else failed_already=1;
  106.         return;
  107.     } else {
  108.         if (debug_mode) printf("\tjoined low priority thread\n");
  109.     }
  110.     if (PR_JoinThread(high) == PR_FAILURE) {
  111.         if (debug_mode) printf("\tcannot join high priority thread\n");
  112.         else failed_already=1;
  113.         return;
  114.     } else {
  115.         if (debug_mode) printf("\tjoined high priority thread\n");
  116.     }
  117. }
  118.  
  119. static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
  120. {
  121.     /* The command line argument: -d is used to determine if the test is being run
  122.     in debug mode. The regress tool requires only one line output:PASS or FAIL.
  123.     All of the printfs associated with this test has been handled with a if (debug_mode)
  124.     test.
  125.     Usage: test_name -d
  126.     */
  127.     
  128.     PLOptStatus os;
  129.     PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
  130.     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  131.     {
  132.         if (PL_OPT_BAD == os) continue;
  133.         switch (opt->option)
  134.         {
  135.         case 'd':  /* debug mode */
  136.             debug_mode = 1;
  137.             break;
  138.          default:
  139.             break;
  140.         }
  141.     }
  142.     PL_DestroyOptState(opt);
  143.  
  144.     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  145.     PR_STDIO_INIT();
  146.  
  147. #ifdef XP_MAC
  148.     SetupMacPrintfLog("joinuu.log");
  149. #endif
  150.  
  151.     
  152.     
  153.  /* main test */
  154.     if (debug_mode) printf("User-User test\n");
  155.     runTest(PR_LOCAL_THREAD, PR_LOCAL_THREAD);
  156.  
  157.     if(failed_already)    
  158.     {
  159.         printf("FAIL\n");
  160.         return 1;
  161.     } else 
  162.     {
  163.         printf("PASS\n");
  164.         return 0;
  165.     }
  166.  
  167.  
  168. }
  169.  
  170.  
  171. PRIntn main(PRIntn argc, char **argv)
  172. {
  173.     PRIntn rv;
  174.     
  175.     PR_STDIO_INIT();
  176.     rv = PR_Initialize(RealMain, argc, argv, 0);
  177.     return rv;
  178. }  /* main */
  179.