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