예제 #1
0
int main(int argc, char **argv) {
  int rv;

  debug_mode = 1;
  
  PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  PR_SetThreadGCAble();

#ifdef XP_MAC
  SetupMacPrintfLog("thrashgc.log");
  debug_mode = 1;
#endif

  PR_InitGC(0, 0, 0, PR_GLOBAL_THREAD);
  PR_STDIO_INIT();
  stderrLock = PR_NewLock();
  tix1 = PR_RegisterType(&type1);
  tix2 = PR_RegisterType(&type2);
  tix3 = PR_RegisterType(&type3);
  gcInfo = PR_GetGCInfo();
  rv = padMain(argc, argv);
  printf("PASS\n");
  PR_Cleanup();
  return rv;
}
예제 #2
0
int main(int argc, char **argv)
{


#ifdef XP_MAC
	SetupMacPrintfLog("pr_open_re.log");
#endif
	

	
    PR_STDIO_INIT();
	t1 = PR_Open("/usr/tmp/err02.tmp",  PR_RDWR, 0666);
	if (t1 == NULL) 
		if (PR_GetError() == PR_FILE_NOT_FOUND_ERROR) {

				printf ("error code is %d \n", PR_GetError());
				printf ("PASS\n");
				return 0;
		}
		else {
					printf ("error code is %d \n", PR_GetError());
					printf ("FAIL\n");
					return 1;
		}
}			
예제 #3
0
static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
{
	/* The command line argument: -d is used to determine if the test is being run
	in debug mode. The regress tool requires only one line output:PASS or FAIL.
	All of the printfs associated with this test has been handled with a if (debug_mode)
	test.
	Usage: test_name -d
	*/
	
	PLOptStatus os;
	PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
		if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
			debug_mode = 1;
            break;
         default:
            break;
        }
    }
	PL_DestroyOptState(opt);

    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    PR_STDIO_INIT();

#ifdef XP_MAC
	SetupMacPrintfLog("joinuk.log");
#endif

	
	
 /* main test */

    if (debug_mode) printf("User-Kernel test\n");
    runTest(PR_LOCAL_THREAD, PR_GLOBAL_THREAD);


	if(failed_already)	
	{
        printf("FAIL\n");
		return 1;
    } else 
    {
        printf("PASS\n");
		return 0;
    }
}
예제 #4
0
static PRIntn PR_CALLBACK RealMain(int argc, char **argv)
{
    /* The command line argument: -d is used to determine if the test is being run
    in debug mode. The regress tool requires only one line output:PASS or FAIL.
    All of the printfs associated with this test has been handled with a if (debug_mode)
    test.
    Usage: test_name [-d] [-c n]
    */
    PLOptStatus os;
    PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
        if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
            debug_mode = 1;
            break;
        case 'c':  /* loop count */
            count = atoi(opt->value);
            break;
        default:
            break;
        }
    }
    PL_DestroyOptState(opt);

    if (0 == count) count = DEFAULT_COUNT;

#ifdef XP_MAC
    SetupMacPrintfLog("cvar.log");
    debug_mode = 1;
#endif

    mon = PR_NewMonitor();

    Measure(CondWaitContextSwitchUU, "cond var wait context switch- user/user");
    Measure(CondWaitContextSwitchUK, "cond var wait context switch- user/kernel");
    Measure(CondWaitContextSwitchKK, "cond var wait context switch- kernel/kernel");

    PR_DestroyMonitor(mon);

    if (debug_mode) printf("%s\n", (failed) ? "FAILED" : "PASSED");

    if(failed)
        return 1;
    else
        return 0;
}
예제 #5
0
int main(PRIntn argc, const char **argv)
{
    PRThread *thread;

    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    PR_STDIO_INIT();

#ifndef XP_MAC
    if (argc > 1)
    {
        if (!PR_SetLogFile(argv[1]))
        {
            Error("Access: Cannot create log file");
            goto exit;
        }
    }
#else
	SetupMacPrintfLog("logger.log");
#endif

    /* Start logging something here */
    PR_LogPrint("%s logging into %s\n", argv[0], argv[1]);

    PR_LogPrint("%s creating new thread\n", argv[0]);

    /*
    ** Now change buffering.
    */
    PR_SetLogBuffering( 65500 );    
	thread = PR_CreateThread(
	    PR_USER_THREAD, forked, (void*)argv[0], PR_PRIORITY_NORMAL,
	    PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
    PR_LogPrint("%s joining thread\n", argv[0]);

    UserLogStuff();

    PR_JoinThread(thread);

    PR_LogFlush();
    return 0;

exit:
    return -1;
}
예제 #6
0
int main(int argc, char **argv)
{
	char nameTooLong[TOO_LONG];
	int i;

	/* Generate a really long pathname */
	for (i = 0; i < TOO_LONG - 1; i++) {
		if (i % 10 == 0) {
			nameTooLong[i] = '/';
		} else {
			nameTooLong[i] = 'a';
		}
	}
	nameTooLong[TOO_LONG - 1] = 0;

#ifdef XP_MAC
	SetupMacPrintfLog("pr_open_re.log");
#endif
	
    PR_STDIO_INIT();
	t1 = PR_Open(nameTooLong, PR_RDWR, 0666);
	if (t1 == NULL) {
		if (PR_GetError() == PR_NAME_TOO_LONG_ERROR) {
            PL_PrintError("error code is");
			printf ("PASS\n");
			return 0;
		}
		else {
            PL_PrintError("error code is");
			printf ("FAIL\n");
			return 1;
		}
	}
	
		else {
			printf ("Test passed\n");
			return 0;
		}
	


}			
예제 #7
0
int main(int argc, char **argv)
{


#ifdef XP_MAC
	SetupMacPrintfLog("pr_open_re.log");
#endif
	

	
    PR_STDIO_INIT();
	err01 = PR_Open("err01.tmp", PR_CREATE_FILE | PR_RDWR, 0);
	if (err01 == NULL) 
		if (PR_GetError() == PR_NO_ACCESS_RIGHTS_ERROR) {
				printf ("error code is %d\n",PR_GetError());
				printf ("PASS\n");
			return 0;
		}
		else {
			printf ("FAIL\n");
			return 1;
		}
}			
예제 #8
0
int main(int argc, char** argv)
{
	/* The command line argument: -d is used to determine if the test is being run
	in debug mode. The regress tool requires only one line output:PASS or FAIL.
	All of the printfs associated with this test has been handled with a if (debug_mode)
	test.
	Usage: test_name -d
	*/
	PLOptStatus os;
	PLOptState *opt;
    
    PR_STDIO_INIT();
	opt = PL_CreateOptState(argc, argv, "d");
	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
		if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
			debug_mode = PR_TRUE;
            break;
         default:
            break;
        }
    }
	PL_DestroyOptState(opt);

 /* main test */
	
    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);

#ifdef XP_MAC
	SetupMacPrintfLog("timetest.log");
	debug_mode = PR_TRUE;
#endif
    /* Testing zero PRTime (the epoch) */
    {
	PRTime t;
	PRExplodedTime et;

	LL_I2L(t, 0);
	if (debug_mode) printf("The NSPR epoch is:\n");
        PR_ExplodeTime(t, PR_LocalTimeParameters, &et);
	printExplodedTime(&et);
	if (debug_mode) printf("\n");
	PR_ExplodeTime(t, PR_GMTParameters, &et);
	printExplodedTime(&et);
	if (debug_mode) printf("\n\n");
	testParseTimeString(t);
    }

    /*
     *************************************************************
     **
     **  Testing PR_Now(), PR_ExplodeTime, and PR_ImplodeTime
     **  on the current time
     **
     *************************************************************
     */

    {
	PRTime t1, t2;
	PRExplodedTime et;

	if (debug_mode) {
	printf("*********************************************\n");
	printf("**                                         **\n");
    printf("** Testing PR_Now(), PR_ExplodeTime, and   **\n");
	printf("** PR_ImplodeTime on the current time      **\n");
	printf("**                                         **\n");
	printf("*********************************************\n\n");
	}
	t1 = PR_Now();

        /* First try converting to UTC */

        PR_ExplodeTime(t1, PR_GMTParameters, &et);
        if (et.tm_params.tp_gmt_offset || et.tm_params.tp_dst_offset) {
	    if (debug_mode) printf("ERROR: UTC has nonzero gmt or dst offset.\n");
		else failed_already=1;
	    return 1;
        }
        if (debug_mode) printf("Current UTC is ");
	printExplodedTime(&et);
	if (debug_mode) printf("\n");

        t2 = PR_ImplodeTime(&et);
        if (LL_NE(t1, t2)) {
	    if (debug_mode) printf("ERROR: Explode and implode are NOT inverse.\n");
		else printf("FAIL\n");
	    return 1;
        }

        /* Next, try converting to local (US Pacific) time */

        PR_ExplodeTime(t1, PR_LocalTimeParameters, &et);
        if (debug_mode) printf("Current local time is ");
	printExplodedTime(&et);
	if (debug_mode) printf("\n");
	if (debug_mode) printf("GMT offset is %ld, DST offset is %ld\n",
		et.tm_params.tp_gmt_offset, et.tm_params.tp_dst_offset);
        t2 = PR_ImplodeTime(&et);
        if (LL_NE(t1, t2)) {
	    if (debug_mode) printf("ERROR: Explode and implode are NOT inverse.\n");
	    return 1;
	}

	if (debug_mode) printf("Please examine the results\n");
	testParseTimeString(t1);
    }


    /*
     *******************************************
     **
     ** Testing PR_NormalizeTime()
     **
     *******************************************
     */

    /* July 4, 2001 is Wednesday */
    {
	PRExplodedTime et;

	if (debug_mode)  {
	printf("\n");
	printf("**********************************\n");
	printf("**                              **\n");
	printf("** Testing PR_NormalizeTime()   **\n");
	printf("**                              **\n");
	printf("**********************************\n\n");
	}
        et.tm_year    = 2001;
        et.tm_month   = 7 - 1;
        et.tm_mday    = 4;
        et.tm_hour    = 0;
        et.tm_min     = 0;
        et.tm_sec     = 0;
	et.tm_usec    = 0;
        et.tm_params  = PR_GMTParameters(&et);

	PR_NormalizeTime(&et, PR_GMTParameters);

	if (debug_mode) printf("July 4, 2001 is %s.\n", dayOfWeek[et.tm_wday]);
	if (et.tm_wday == 3) {
	    if (debug_mode) printf("PASS\n");
        } else {
            if (debug_mode) printf("ERROR: It should be Wednesday\n");
			else failed_already=1;
	    return 1;
	}
	testParseTimeString(PR_ImplodeTime(&et));

        /* June 12, 1997 23:00 PST == June 13, 1997 00:00 PDT */
        et.tm_year    = 1997;
        et.tm_month   = 6 - 1;
        et.tm_mday    = 12;
        et.tm_hour    = 23;
        et.tm_min     = 0;
        et.tm_sec     = 0;
	et.tm_usec    = 0;
        et.tm_params.tp_gmt_offset = -8 * 3600;
	et.tm_params.tp_dst_offset = 0;

	PR_NormalizeTime(&et, PR_USPacificTimeParameters);

	if (debug_mode) {
	    printf("Thu Jun 12, 1997 23:00:00 PST is ");
	}
	printExplodedTime(&et);
	if (debug_mode) printf(".\n");
	if (et.tm_wday == 5) {
	    if (debug_mode) printf("PASS\n");
        } else {
            if (debug_mode) printf("ERROR: It should be Friday\n");
			else failed_already=1;
	    return 1;
	}
	testParseTimeString(PR_ImplodeTime(&et));

        /* Feb 14, 1997 00:00:00 PDT == Feb 13, 1997 23:00:00 PST */
        et.tm_year    = 1997;
        et.tm_month   = 2 - 1;
        et.tm_mday    = 14;
        et.tm_hour    = 0;
        et.tm_min     = 0;
        et.tm_sec     = 0;
	et.tm_usec    = 0;
        et.tm_params.tp_gmt_offset = -8 * 3600;
	et.tm_params.tp_dst_offset = 3600;

	PR_NormalizeTime(&et, PR_USPacificTimeParameters);

	if (debug_mode) {
	    printf("Fri Feb 14, 1997 00:00:00 PDT is ");
	}
	printExplodedTime(&et);
	if (debug_mode) printf(".\n");
	if (et.tm_wday == 4) {
	    if (debug_mode) printf("PASS\n");
        } else {
            if (debug_mode) printf("ERROR: It should be Thursday\n");
			else failed_already=1;
	    return 1;
	}
	testParseTimeString(PR_ImplodeTime(&et));

        /* What time is Nov. 7, 1996, 18:29:23 PDT? */
        et.tm_year    = 1996;
        et.tm_month   = 11 - 1;
        et.tm_mday    = 7;
        et.tm_hour    = 18;
        et.tm_min     = 29;
        et.tm_sec     = 23;
	et.tm_usec    = 0;
        et.tm_params.tp_gmt_offset = -8 * 3600;  /* PDT */
	et.tm_params.tp_dst_offset = 3600; 

	PR_NormalizeTime(&et, PR_LocalTimeParameters);
        if (debug_mode) printf("Nov 7 18:29:23 PDT 1996 is ");
	printExplodedTime(&et);
	if (debug_mode) printf(".\n");
	testParseTimeString(PR_ImplodeTime(&et));

        /* What time is Oct. 7, 1995, 18:29:23 PST? */
        et.tm_year    = 1995;
        et.tm_month   = 10 - 1;
        et.tm_mday    = 7;
        et.tm_hour    = 18;
        et.tm_min     = 29;
        et.tm_sec     = 23;
        et.tm_params.tp_gmt_offset = -8 * 3600;  /* PST */
	et.tm_params.tp_dst_offset = 0;

	PR_NormalizeTime(&et, PR_LocalTimeParameters);
        if (debug_mode) printf("Oct 7 18:29:23 PST 1995 is ");
	printExplodedTime(&et);
	if (debug_mode) printf(".\n");
	testParseTimeString(PR_ImplodeTime(&et));

	if (debug_mode) printf("Please examine the results\n");
    }

    /*
     **************************************************************
     **
     ** Testing range of years
     **
     **************************************************************
     */

    {
	PRExplodedTime et1, et2;
    PRTime  ttt;
	PRTime secs;

	if (debug_mode) {
	printf("\n");
	printf("***************************************\n");
	printf("**                                   **\n");
	printf("**  Testing range of years           **\n");
	printf("**                                   **\n");
	printf("***************************************\n\n");
	}
	/* April 4, 1917 GMT */
	et1.tm_usec = 0;
	et1.tm_sec = 0;
	et1.tm_min = 0;
	et1.tm_hour = 0;
	et1.tm_mday = 4;
	et1.tm_month = 4 - 1;
	et1.tm_year = 1917;
	et1.tm_params = PR_GMTParameters(&et1);
	PR_NormalizeTime(&et1, PR_LocalTimeParameters);
	secs = PR_ImplodeTime(&et1);
	if (LL_GE_ZERO(secs)) {
	    if (debug_mode)
		printf("ERROR: April 4, 1917 GMT returns a nonnegative second count\n");
		failed_already = 1;
	    return 1;
        }
	PR_ExplodeTime(secs, PR_LocalTimeParameters, &et2);
	if (!explodedTimeIsEqual(&et1, &et2)) {
		if (debug_mode)
		printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for April 4, 1917 GMT\n");
		failed_already=1;
	    return 1;
        }
    ttt = PR_ImplodeTime(&et1);
	testParseTimeString( ttt );

	if (debug_mode) printf("Test passed for April 4, 1917\n");

	/* July 4, 2050 */
	et1.tm_usec = 0;
	et1.tm_sec = 0;
	et1.tm_min = 0;
	et1.tm_hour = 0;
	et1.tm_mday = 4;
	et1.tm_month = 7 - 1;
	et1.tm_year = 2050;
	et1.tm_params = PR_GMTParameters(&et1);
	PR_NormalizeTime(&et1, PR_LocalTimeParameters);
	secs = PR_ImplodeTime(&et1);
	if (!LL_GE_ZERO(secs)) {
	    if (debug_mode)
			printf("ERROR: July 4, 2050 GMT returns a negative second count\n");
		failed_already = 1;
	    return 1;
        }
	PR_ExplodeTime(secs, PR_LocalTimeParameters, &et2);
	if (!explodedTimeIsEqual(&et1, &et2)) {
	    if (debug_mode)
		printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for July 4, 2050 GMT\n");
		failed_already=1;
	    return 1;
        }
	testParseTimeString(PR_ImplodeTime(&et1));

	if (debug_mode) printf("Test passed for July 4, 2050\n");

    }

    /*
     **************************************************************
     **
     **  Stress test
     *
     **      Go through four years, starting from
     **      00:00:00 PST Jan. 1, 1993, incrementing
     **      every 10 minutes.
     **
     **************************************************************
     */

    {
	PRExplodedTime et, et1, et2;
	PRInt64 usecPer10Min;
	int day, hour, min;
	PRTime usecs;
	int dstInEffect = 0;

	if (debug_mode) {
	printf("\n");
	printf("*******************************************************\n");
	printf("**                                                   **\n");
	printf("**                 Stress test                       **\n");
	printf("**  Starting from midnight Jan. 1, 1993 PST,         **\n");
	printf("**  going through four years in 10-minute increment  **\n");
	printf("**                                                   **\n");
	printf("*******************************************************\n\n");
	}
	LL_I2L(usecPer10Min, 600000000L);

	/* 00:00:00 PST Jan. 1, 1993 */
	et.tm_usec = 0;
	et.tm_sec = 0;
	et.tm_min = 0;
	et.tm_hour = 0;
	et.tm_mday = 1;
	et.tm_month = 0;
	et.tm_year = 1993;
	et.tm_params.tp_gmt_offset = -8 * 3600;
	et.tm_params.tp_dst_offset = 0;
	usecs = PR_ImplodeTime(&et);

        for (day = 0; day < 4 * 365 + 1; day++) {
	    for (hour = 0; hour < 24; hour++) {
		for (min = 0; min < 60; min += 10) {
	            LL_ADD(usecs, usecs, usecPer10Min);
		    PR_ExplodeTime(usecs, PR_USPacificTimeParameters, &et1);

		    et2 = et;
		    et2.tm_usec += 600000000L;
		    PR_NormalizeTime(&et2, PR_USPacificTimeParameters);

		    if (!explodedTimeIsEqual(&et1, &et2)) {
		        if (debug_mode) printf("ERROR: componentwise comparison failed\n");
			printExplodedTime(&et1);
			if (debug_mode) printf("\n");
			printExplodedTime(&et2);
			if (debug_mode) printf("\n");
			failed_already=1;
		        return 1;
		    }

		    if (LL_NE(usecs, PR_ImplodeTime(&et1))) { 
                        if (debug_mode)
					printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
			printExplodedTime(&et1);
			if (debug_mode) printf("\n");
			failed_already=1;
		        return 1;
		    }
		    testParseTimeString(usecs);

		    if (!dstInEffect && et1.tm_params.tp_dst_offset) {
		        dstInEffect = 1;
		        if (debug_mode) printf("DST changeover from ");
			printExplodedTime(&et);
			if (debug_mode) printf(" to ");
			printExplodedTime(&et1);
			if (debug_mode) printf(".\n");
                    } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
		        dstInEffect = 0;
			if (debug_mode) printf("DST changeover from ");
			printExplodedTime(&et);
			if (debug_mode) printf(" to ");
			printExplodedTime(&et1);
			if (debug_mode) printf(".\n");
                    }

		    et = et1;
		}
	    }
        }
	if (debug_mode) printf("Test passed\n");
    }


    /* Same stress test, but with PR_LocalTimeParameters */

    {
	PRExplodedTime et, et1, et2;
	PRInt64 usecPer10Min;
	int day, hour, min;
	PRTime usecs;
	int dstInEffect = 0;

	if (debug_mode) {
	printf("\n");
	printf("*******************************************************\n");
	printf("**                                                   **\n");
	printf("**                 Stress test                       **\n");
	printf("**  Starting from midnight Jan. 1, 1993 PST,         **\n");
	printf("**  going through four years in 10-minute increment  **\n");
	printf("**                                                   **\n");
	printf("*******************************************************\n\n");
	}
	
	LL_I2L(usecPer10Min, 600000000L);

	/* 00:00:00 PST Jan. 1, 1993 */
	et.tm_usec = 0;
	et.tm_sec = 0;
	et.tm_min = 0;
	et.tm_hour = 0;
	et.tm_mday = 1;
	et.tm_month = 0;
	et.tm_year = 1993;
	et.tm_params.tp_gmt_offset = -8 * 3600;
	et.tm_params.tp_dst_offset = 0;
	usecs = PR_ImplodeTime(&et);

        for (day = 0; day < 4 * 365 + 1; day++) {
	    for (hour = 0; hour < 24; hour++) {
		for (min = 0; min < 60; min += 10) {
	            LL_ADD(usecs, usecs, usecPer10Min);
		    PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);

		    et2 = et;
		    et2.tm_usec += 600000000L;
		    PR_NormalizeTime(&et2, PR_LocalTimeParameters);

		    if (!explodedTimeIsEqual(&et1, &et2)) {
		        if (debug_mode) printf("ERROR: componentwise comparison failed\n");
			printExplodedTime(&et1);
			if (debug_mode) printf("\n");
			printExplodedTime(&et2);
			if (debug_mode) printf("\n");
		        return 1;
		    }

		    if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
                        printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
			printExplodedTime(&et1);
			if (debug_mode) printf("\n");
			failed_already=1;
		        return 1;
		    }
		    testParseTimeString(usecs);

		    if (!dstInEffect && et1.tm_params.tp_dst_offset) {
		        dstInEffect = 1;
		        if (debug_mode) printf("DST changeover from ");
			printExplodedTime(&et);
			if (debug_mode) printf(" to ");
			printExplodedTime(&et1);
			if (debug_mode) printf(".\n");
                    } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
		        dstInEffect = 0;
			if (debug_mode) printf("DST changeover from ");
			printExplodedTime(&et);
			if (debug_mode) printf(" to ");
			printExplodedTime(&et1);
			if (debug_mode) printf(".\n");
                    }

		    et = et1;
		}
	    }
        }
	if (debug_mode) printf("Test passed\n");
    }

    /* Same stress test, but with PR_LocalTimeParameters and going backward */

    {
	PRExplodedTime et, et1, et2;
	PRInt64 usecPer10Min;
	int day, hour, min;
	PRTime usecs;
	int dstInEffect = 0;

	if (debug_mode) {
	printf("\n");
	printf("*******************************************************\n");
	printf("**                                                   **\n");
	printf("**                 Stress test                       **\n");
	printf("**  Starting from midnight Jan. 1, 1997 PST,         **\n");
	printf("**  going back four years in 10-minute increment     **\n");
	printf("**                                                   **\n");
	printf("*******************************************************\n\n");
	}

	LL_I2L(usecPer10Min, 600000000L);

	/* 00:00:00 PST Jan. 1, 1997 */
	et.tm_usec = 0;
	et.tm_sec = 0;
	et.tm_min = 0;
	et.tm_hour = 0;
	et.tm_mday = 1;
	et.tm_month = 0;
	et.tm_year = 1997;
	et.tm_params.tp_gmt_offset = -8 * 3600;
	et.tm_params.tp_dst_offset = 0;
	usecs = PR_ImplodeTime(&et);

        for (day = 0; day < 4 * 365 + 1; day++) {
	    for (hour = 0; hour < 24; hour++) {
		for (min = 0; min < 60; min += 10) {
	            LL_SUB(usecs, usecs, usecPer10Min);
		    PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);

		    et2 = et;
		    et2.tm_usec -= 600000000L;
		    PR_NormalizeTime(&et2, PR_LocalTimeParameters);

		    if (!explodedTimeIsEqual(&et1, &et2)) {
		        if (debug_mode) printf("ERROR: componentwise comparison failed\n");
			printExplodedTime(&et1);
			if (debug_mode) printf("\n");
			printExplodedTime(&et2);
			if (debug_mode) printf("\n");
		        return 1;
		    }

		    if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
                   if (debug_mode)
					printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
			printExplodedTime(&et1);
			if (debug_mode) printf("\n");
			failed_already=1;
		        return 1;
		    }
		    testParseTimeString(usecs);

		    if (!dstInEffect && et1.tm_params.tp_dst_offset) {
		        dstInEffect = 1;
		        if (debug_mode) printf("DST changeover from ");
			printExplodedTime(&et);
			if (debug_mode) printf(" to ");
			printExplodedTime(&et1);
			if (debug_mode) printf(".\n");
                    } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
		        dstInEffect = 0;
			if (debug_mode) printf("DST changeover from ");
			printExplodedTime(&et);
			if (debug_mode) printf(" to ");
			printExplodedTime(&et1);
			if (debug_mode) printf(".\n");
                    }

		    et = et1;
		}
	    }
        }
    }

	if (failed_already) return 1;
	else return 0;

}
예제 #9
0
int main(int argc,  char **argv)
{
    PRBool rv = PR_TRUE;
    PRIntervalTime duration;
    PRUint32 cpu, cpus = 2, loops = 100;

	
    PR_STDIO_INIT();
    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    {
    	/* The command line argument: -d is used to determine if the test is being run
    	in debug mode. The regress tool requires only one line output:PASS or FAIL.
    	All of the printfs associated with this test has been handled with a if (debug_mode)
    	test.
        Command line argument -l <num> sets the number of loops.
        Command line argument -c <num> sets the number of cpus.
        Usage: lock [-d] [-l <num>] [-c <num>]
    	*/
    	PLOptStatus os;
    	PLOptState *opt = PL_CreateOptState(argc, argv, "dl:c:");
    	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
        {
    		if (PL_OPT_BAD == os) continue;
            switch (opt->option)
            {
            case 'd':  /* debug mode */
    			debug_mode = 1;
                break;
            case 'l':  /* number of loops */
                loops = atoi(opt->value);
                break;
            case 'c':  /* number of cpus */
                cpus = atoi(opt->value);
                break;
             default:
                break;
            }
        }
    	PL_DestroyOptState(opt);
    }

 /* main test */
    PR_SetConcurrency(8);

#ifdef XP_MAC
	SetupMacPrintfLog("lock.log");
	debug_mode = 1;
#endif

    if (loops == 0) loops = 100;
    if (debug_mode) printf("Lock: Using %d loops\n", loops);

    if (cpus == 0) cpus = 2;
    if (debug_mode) printf("Lock: Using %d cpu(s)\n", cpus);

    (void)Sleeper(10);  /* try filling in the caches */

    for (cpu = 1; cpu <= cpus; ++cpu)
    {
        if (debug_mode) printf("\nLock: Using %d CPU(s)\n", cpu);
        PR_SetConcurrency(cpu);

        duration = Test("Overhead of PR_Sleep", Sleeper, loops, 0);
        duration = 0;

        (void)Test("Lock creation/deletion", MakeLock, loops, 0);
        (void)Test("Lock non-contentious locking/unlocking", NonContentiousLock, loops, 0);
        (void)Test("Lock contentious locking/unlocking", ContentiousLock, loops, duration);
        (void)Test("Monitor creation/deletion", MakeMonitor, loops, 0);
        (void)Test("Monitor non-contentious locking/unlocking", NonContentiousMonitor, loops, 0);
        (void)Test("Monitor contentious locking/unlocking", ContentiousMonitor, loops, duration);

        (void)Test("Cached monitor non-contentious locking/unlocking", NonContentiousCMonitor, loops, 0);
        (void)Test("Cached monitor contentious locking/unlocking", ContentiousCMonitor, loops, duration);

        (void)ReentrantMonitor(loops);
    }

    if (debug_mode) printf("%s: test %s\n", "Lock(mutex) test", ((rv) ? "passed" : "failed"));
	else {
		 if (!rv)
			 failed_already=1;
	}

	if(failed_already)	
	{
	    printf("FAIL\n"); 
		return 1;
    } 
	else
    {
	    printf("PASS\n"); 
		return 0;
    }

}  /* main */
예제 #10
0
/***********************************************************************
** PRIVATE FUNCTION:    main
** DESCRIPTION:
**   Hammer on the file I/O system
** INPUTS:      The usual argc and argv
**              argv[0] - program name (not used)
**              argv[1] - the number of times to execute the major loop
**              argv[2] - the number of threads to toss into the batch
**              argv[3] - the clipping number applied to randoms
**              default values: loops = 2, threads = 10, limit = 57
** OUTPUTS:     None
** RETURN:      None
** SIDE EFFECTS:
**      Creates, accesses and deletes lots of files
** RESTRICTIONS:
**      (Currently) must have file create permission in "/usr/tmp".
** MEMORY:      NA
** ALGORITHM:
**      1) Fork a "Thread()"
**      2) Wait for 'interleave' seconds
**      3) For [0..'threads') repeat [1..2]
**      4) Mark all objects to stop
**      5) Collect the threads, accumulating the results
**      6) For [0..'loops') repeat [1..5]
**      7) Print accumulated results and exit
**
**      Characteristic output (from IRIX)
**          Random File: Using loops = 2, threads = 10, limit = 57
**          Random File: [min [avg] max] writes/sec average
***********************************************************************/
int main (int argc,      char   *argv[])
{
    PRLock *ml;
    PRUint32 id = 0;
    int active, poll;
    PRIntervalTime interleave;
    PRIntervalTime duration = 0;
    int limit = 0, loops = 0, threads = 0, times;
    PRUint32 writes, writesMin = 0x7fffffff, writesTot = 0, durationTot = 0, writesMax = 0;

    const char *where[] = {"okay", "open", "close", "delete", "write", "seek"};

	/* The command line argument: -d is used to determine if the test is being run
	in debug mode. The regress tool requires only one line output:PASS or FAIL.
	All of the printfs associated with this test has been handled with a if (debug_mode)
	test.
	Usage: test_name -d
	*/
	PLOptStatus os;
	PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:t:i:");
	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
		if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'G':  /* global threads */
			thread_scope = PR_GLOBAL_THREAD;
            break;
        case 'd':  /* debug mode */
			debug_mode = 1;
            break;
        case 'l':  /* limiting number */
			limit = atoi(opt->value);
            break;
        case 't':  /* number of threads */
			threads = atoi(opt->value);
            break;
        case 'i':  /* iteration counter */
			loops = atoi(opt->value);
            break;
         default:
            break;
        }
    }
	PL_DestroyOptState(opt);

 /* main test */
	
    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    PR_STDIO_INIT();

    interleave = PR_SecondsToInterval(10);

#ifdef XP_MAC
	SetupMacPrintfLog("ranfile.log");
	debug_mode = 1;
#endif

    ml = PR_NewLock();
    cv = PR_NewCondVar(ml);

    if (loops == 0) loops = DEFAULT_LOOPS;
    if (limit == 0) limit = DEFAULT_LIMIT;
    if (threads == 0) threads = DEFAULT_THREADS;

    if (debug_mode) printf(
        "%s: Using loops = %d, threads = %d, limit = %d and %s threads\n",
        programName, loops, threads, limit,
        (thread_scope == PR_LOCAL_THREAD) ? "LOCAL" : "GLOBAL");

    for (times = 0; times < loops; ++times)
    {
        if (debug_mode) printf("%s: Setting concurrency level to %d\n", programName, times + 1);
        PR_SetConcurrency(times + 1);
        for (active = 0; active < threads; active++)
        {
            hammer[active].ml = ml;
            hammer[active].cv = cv;
            hammer[active].id = id++;
            hammer[active].writes = 0;
            hammer[active].action = sg_go;
            hammer[active].problem = sg_okay;
            hammer[active].limit = (Random() % limit) + 1;
            hammer[active].timein = PR_IntervalNow();
            hammer[active].thread = PR_CreateThread(
                PR_USER_THREAD, Thread, &hammer[active],
                PR_GetThreadPriority(PR_GetCurrentThread()),
                thread_scope, PR_JOINABLE_THREAD, 0);

            PR_Lock(ml);
            PR_WaitCondVar(cv, interleave);  /* start new ones slowly */
            PR_Unlock(ml);
        }

        /*
         * The last thread started has had the opportunity to run for
         * 'interleave' seconds. Now gather them all back in.
         */
        PR_Lock(ml);
        for (poll = 0; poll < threads; poll++)
        {
            if (hammer[poll].action == sg_go)  /* don't overwrite done */
                hammer[poll].action = sg_stop;  /* ask him to stop */
        }
        PR_Unlock(ml);

        while (active > 0)
        {
            for (poll = 0; poll < threads; poll++)
            {
                PR_Lock(ml);
                while (hammer[poll].action < sg_done)
                    PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
                PR_Unlock(ml);

                active -= 1;  /* this is another one down */
                (void)PR_JoinThread(hammer[poll].thread);
                hammer[poll].thread = NULL;
                if (hammer[poll].problem == sg_okay)
                {
                    duration = PR_IntervalToMilliseconds(
                        PR_IntervalNow() - hammer[poll].timein);
                    writes = hammer[poll].writes * 1000 / duration;
                    if (writes < writesMin) 
                        writesMin = writes;
                    if (writes > writesMax) 
                        writesMax = writes;
                    writesTot += hammer[poll].writes;
                    durationTot += duration;
                }
                else
                    if (debug_mode) printf(
                        "%s: test failed %s after %ld seconds\n",
                        programName, where[hammer[poll].problem], duration);
					else failed_already=1;
            }
        }
    }
    if (debug_mode) printf(
        "%s: [%ld [%ld] %ld] writes/sec average\n",
        programName, writesMin, writesTot * 1000 / durationTot, writesMax);

    PR_DestroyCondVar(cv);
    PR_DestroyLock(ml);

	if (failed_already) 
	{
	    printf("FAIL\n");
		return 1;
	}
    else
    {
        printf("PASS\n");
		return 0;
    }
}  /* main */
예제 #11
0
static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
{
    PRFileDesc *listenSock, *sock;
    PRUint16 listenPort;
    PRNetAddr addr;
    char buf[CHUNK_SIZE];
    PRThread *clientThread;
    PRInt32 retVal;
    PRIntn optval = 1;
    PRIntn i;
    PRIntervalTime unitTime = PR_MillisecondsToInterval(UNIT_TIME);

#ifdef XP_MAC
	SetupMacPrintfLog("nonblock.log");
#endif

    /* Create a listening socket */
    if ((listenSock = PR_NewTCPSocket()) == NULL) {
	fprintf(stderr, "Can't create a new TCP socket\n");
	exit(1);
    }
    addr.inet.family = AF_INET;
    addr.inet.ip = PR_htonl(INADDR_ANY);
    addr.inet.port = PR_htons(0);
    if (PR_Bind(listenSock, &addr) == PR_FAILURE) {
	fprintf(stderr, "Can't bind socket\n");
	exit(1);
    }
    if (PR_GetSockName(listenSock, &addr) == PR_FAILURE) {
	fprintf(stderr, "PR_GetSockName failed\n");
	exit(1);
    }
    listenPort = PR_ntohs(addr.inet.port);
    if (PR_Listen(listenSock, 5) == PR_FAILURE) {
	fprintf(stderr, "Can't listen on a socket\n");
	exit(1);
    }

    PR_snprintf(buf, sizeof(buf),
	    "The server thread is listening on port %hu\n\n",
	    listenPort);
    printf("%s", buf);

    clientThread = PR_CreateThread(PR_USER_THREAD,
	    clientThreadFunc, (void *) listenPort,
	    PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
	    PR_UNJOINABLE_THREAD, 0);
    if (clientThread == NULL) {
	fprintf(stderr, "can't create thread\n");
	exit(1);
    }

    printf("client thread created.\n");

    PR_SetSockOpt(listenSock, PR_SockOpt_Nonblocking, &optval,
	sizeof(PRIntn));
    /* time 0 */
    sock = PR_Accept(listenSock, NULL, PR_INTERVAL_NO_TIMEOUT);
    if (sock != NULL || PR_GetError() != PR_WOULD_BLOCK_ERROR) {
        PL_PrintError("First Accept\n");
        fprintf(stderr, "First PR_Accept() xxx\n" );
		    exit(1);
    }
    printf("accept: EWOULDBLOCK, good\n");
    fflush(stdout);
    /* time 2 */
    PR_Sleep(2 * unitTime);
    sock = PR_Accept(listenSock, NULL, PR_INTERVAL_NO_TIMEOUT);
    if (sock == NULL) {
        PL_PrintError("Second Accept\n");
        fprintf(stderr, "Second PR_Accept() failed: (%d, %d)\n",
                PR_GetError(), PR_GetOSError());
		    exit(1);
    }
    printf("accept: succeeded, good\n");
    fflush(stdout);
    PR_Close(listenSock);

    PR_SetSockOpt(sock, PR_SockOpt_Nonblocking, &optval, sizeof(PRIntn));

    /* time 3, 5, 6, 8, etc. */
    for (i = 0; i < NUMBER_ROUNDS; i++) {
	PR_Sleep(unitTime);
	retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
	if (retVal != -1 || PR_GetError() != PR_WOULD_BLOCK_ERROR) {
        PL_PrintError("First Receive:\n");
	    fprintf(stderr, "First PR_Recv: retVal: %ld, Error: %ld\n",
            retVal, PR_GetError());
	    exit(1);
        }
	printf("read: EWOULDBLOCK, good\n");
	fflush(stdout);
	PR_Sleep(2 * unitTime);
	retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
	if (retVal != CHUNK_SIZE) {
        PL_PrintError("Second Receive:\n");
	    fprintf(stderr, "Second PR_Recv: retVal: %ld, Error: %ld\n", 
            retVal, PR_GetError());
	    exit(1);
        }
	printf("read: %d bytes, good\n", retVal);
	fflush(stdout);
    }
    PR_Close(sock);

    printf("All tests finished\n");
    printf("PASS\n");
    return 0;
}
예제 #12
0
int main(int argc, char **argv)
{
	PRThread *r;

    PR_STDIO_INIT();
    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);

    {
    	/* The command line argument: -d is used to determine if the test is being run
    	in debug mode. The regress tool requires only one line output:PASS or FAIL.
    	All of the printfs associated with this test has been handled with a if (debug_mode)
    	test.
    	Usage: test_name -d
    	*/
    	PLOptStatus os;
    	PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
    	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
        {
    		if (PL_OPT_BAD == os) continue;
            switch (opt->option)
            {
            case 'd':  /* debug mode */
    			debug_mode = 1;
                break;
             default:
                break;
            }
        }
    	PL_DestroyOptState(opt);
    }        

 /* main test */

#ifdef XP_MAC
	SetupMacPrintfLog("sem.log");
	debug_mode = 1;
#endif

    emptyBufs = PR_NewSem(2);	/* two empty buffers */

    fullBufs = PR_NewSem(0);	/* zero full buffers */

	/* create the reader thread */
	
	r = PR_CreateThread(PR_USER_THREAD,
				      reader, 0, 
				      PR_PRIORITY_NORMAL,
				      PR_LOCAL_THREAD,
    				  PR_UNJOINABLE_THREAD,
				      0);

	/* Do the writer operation in this thread */
	writer();

	PR_DestroySem(emptyBufs);
	PR_DestroySem(fullBufs);

	if (finalResult == PR_SUCCESS) {
		if (debug_mode) printf("sem Test Passed.\n");
	}
	else{
		if (debug_mode) printf("sem Test Failed.\n");
		failed_already=1;
	}
    PR_Cleanup();
	if(failed_already)	
		return 1;
	else
		return 0;
}
예제 #13
0
int
main(int argc, char **argv)
{
    /*
     * -d           debug mode
     */

    PLOptStatus os;
    PLOptState *opt = PL_CreateOptState(argc, argv, "d");
    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
        if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'd':  /* debug mode */
            _debug_on = 1;
            break;
        default:
            break;
        }
    }
    PL_DestroyOptState(opt);

    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    PR_STDIO_INIT();

#ifdef XP_MAC
    SetupMacPrintfLog("socket.log");
#endif
    PR_SetConcurrency(4);
    /*
     * run client-server test with TCP
     */
    if (TCP_Socket_Client_Server_Test() < 0) {
        printf("TCP_Socket_Client_Server_Test failed\n");
        goto done;
    } else
        printf("TCP_Socket_Client_Server_Test Passed\n");
    /*
     * run client-server test with UDP
     */
    if (UDP_Socket_Client_Server_Test() < 0) {
        printf("UDP_Socket_Client_Server_Test failed\n");
        goto done;
    } else
        printf("UDP_Socket_Client_Server_Test Passed\n");
    /*
     * Misc socket tests - including transmitfile, etc.
     */

#if !defined(WIN16)
    /*
** The 'transmit file' test does not run because
** transmit file is not implemented in NSPR yet.
**
*/
    if (Socket_Misc_Test() < 0) {
        printf("Socket_Misc_Test failed\n");
        failed_already=1;
        goto done;
    } else
        printf("Socket_Misc_Test passed\n");

    /*
     * run client-server test with TCP again to test
     * recycling used sockets from PR_TransmitFile().
     */
    if (TCP_Socket_Client_Server_Test() < 0) {
        printf("TCP_Socket_Client_Server_Test failed\n");
        goto done;
    } else
        printf("TCP_Socket_Client_Server_Test Passed\n");
#endif

done:
    PR_Cleanup();
    if (failed_already) return 1;
    else return 0;
}
예제 #14
0
int main(int argc, char **argv)
{
    PRHostEnt he;
    char buf[1024];
    PRNetAddr addr;
    PRFileDesc *sock;
    PRPollDesc pd;
    PRStatus rv;
    PRSocketOptionData optData;
    PRIntn n;

#ifdef XP_MAC
	int index;
	PRIntervalTime timeout;
	SetupMacPrintfLog("nbconn.log");
	for (index=0; index<4; index++) {
	argv[1] = hosts[index];
	timeout = PR_INTERVAL_NO_TIMEOUT;
	if (index == 3)
		timeout = PR_SecondsToInterval(10UL);
#endif

    PR_STDIO_INIT();
#ifndef XP_MAC
    if (argc != 2) {
        fprintf(stderr, "Usage: nbconn <hostname>\n");
        exit(1);
    }
#endif

    if (PR_GetHostByName(argv[1], buf, sizeof(buf), &he) == PR_FAILURE) {
        printf( "Unknown host: %s\n", buf);
        exit(1);
    } else {
        printf( "host: %s\n", buf);
    }
    PR_EnumerateHostEnt(0, &he, 80, &addr);

    sock = PR_NewTCPSocket();
    optData.option = PR_SockOpt_Nonblocking;
    optData.value.non_blocking = PR_TRUE;
    PR_SetSocketOption(sock, &optData);
    rv = PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
    if (rv == PR_FAILURE && PR_GetError() == PR_IN_PROGRESS_ERROR) {
        printf( "Connect in progress\n");
    }

    pd.fd = sock;
    pd.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT;
#ifndef XP_MAC
    n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
#else
    n = PR_Poll(&pd, 1, timeout);
#endif
    if (n == -1) {
        printf( "PR_Poll failed\n");
        exit(1);
    }
    printf( "PR_Poll returns %d\n", n);
    if (pd.out_flags & PR_POLL_READ) {
        printf( "PR_POLL_READ\n");
    }
    if (pd.out_flags & PR_POLL_WRITE) {
        printf( "PR_POLL_WRITE\n");
    }
    if (pd.out_flags & PR_POLL_EXCEPT) {
        printf( "PR_POLL_EXCEPT\n");
    }
    if (pd.out_flags & PR_POLL_ERR) {
        printf( "PR_POLL_ERR\n");
    }
    if (pd.out_flags & PR_POLL_NVAL) {
        printf( "PR_POLL_NVAL\n");
    }

    if (PR_GetConnectStatus(&pd) == PR_SUCCESS) {
        printf("PR_GetConnectStatus: connect succeeded\n");
        /* Mac and Win16 have trouble printing to the console. */
#if !defined(XP_MAC) && !defined(WIN16)
        PR_Write(sock, "GET /\r\n\r\n", 9);
        PR_Shutdown(sock, PR_SHUTDOWN_SEND);
        pd.in_flags = PR_POLL_READ;
        while (1) {
            n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
            printf( "poll returns %d\n", n);
            n = PR_Read(sock, buf, sizeof(buf));
            printf( "read returns %d\n", n);
            if (n <= 0) {
                break;
            }
            PR_Write(PR_STDOUT, buf, n);
        }
#endif
    } else {
        if (PR_GetError() == PR_IN_PROGRESS_ERROR) {
            printf( "PR_GetConnectStatus: connect still in progress\n");
            exit(1);
        }
        printf( "PR_GetConnectStatus: connect failed: (%ld, %ld)\n",
                PR_GetError(), PR_GetOSError());
    }
    PR_Close(sock);
#ifdef XP_MAC
	} /* end of for loop */
#endif

    printf( "PASS\n");
    return 0;
}
예제 #15
0
int main(int argc, char **argv)
{

    /* The command line argument: -d is used to determine if the test is being run
    in debug mode. The regress tool requires only one line output:PASS or FAIL.
    All of the printfs associated with this test has been handled with a if (debug_mode)
    test.
    Usage: test_name [-d] [-c n]
    */
    PLOptStatus os;
    PLOptState *opt = PL_CreateOptState(argc, argv, "Gdc:");
    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
        if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'G':  /* global threads */
            thread_scope = PR_GLOBAL_THREAD;
            break;
        case 'd':  /* debug mode */
            debug_mode = 1;
            break;
        case 'c':  /* loop counter */
            count = atoi(opt->value);
            break;
        default:
            break;
        }
    }
    PL_DestroyOptState(opt);


    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    PR_STDIO_INIT();

#ifdef XP_MAC
    SetupMacPrintfLog("accept.log");
    debug_mode = 1;
#endif

    timeoutTime = PR_SecondsToInterval(TIMEOUTSECS);
    if (debug_mode)
        printf("\nRun accept() sucessful connection tests\n");

    Measure(AcceptUpdatedTest, "PR_Accept()");
    Measure(AcceptReadTest, "PR_AcceptRead()");
#ifdef WINNT
    Measure(AcceptNotUpdatedTest, "PR_NTFast_Accept()");
    Measure(AcceptReadNotUpdatedTest, "PR_NTFast_AcceptRead()");
    Measure(AcceptReadCallbackTest, "PR_NTFast_AcceptRead_WithTimeoutCallback()");
#endif
    if (debug_mode)
        printf("\nRun accept() timeout in the accept tests\n");
#ifdef WINNT
    Measure(TimeoutReadReadCallbackTest, "PR_NTFast_AcceptRead_WithTimeoutCallback()");
#endif
    if (debug_mode)
        printf("\nRun accept() timeout in the read tests\n");
    Measure(TimeoutReadUpdatedTest, "PR_Accept()");
    Measure(TimeoutReadReadTest, "PR_AcceptRead()");
#ifdef WINNT
    Measure(TimeoutReadNotUpdatedTest, "PR_NTFast_Accept()");
    Measure(TimeoutReadReadNotUpdatedTest, "PR_NTFast_AcceptRead()");
    Measure(TimeoutReadReadCallbackTest, "PR_NTFast_AcceptRead_WithTimeoutCallback()");
#endif
    if(failed_already)
    {
        printf("FAIL\n");
        return 1;
    }
    else
    {
        printf("PASS\n");
        return 0;

    }
}
예제 #16
0
int main(int argc, char **argv)
{
	PRThread *r, *w;


	PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    PR_STDIO_INIT();

#ifdef XP_MAC
	SetupMacPrintfLog("fileio.log");
	debug_mode = 1;
#endif

    emptyBufs = PR_NewSem(2);	/* two empty buffers */

    fullBufs = PR_NewSem(0);	/* zero full buffers */

	/* Create initial temp file setup */
	InitialSetup();
	
	/* create the reader thread */
	
	r = PR_CreateThread(PR_USER_THREAD,
				      reader, t1, 
				      PR_PRIORITY_NORMAL,
				      PR_LOCAL_THREAD,
    				  PR_JOINABLE_THREAD,
				      0);

	w = PR_CreateThread(PR_USER_THREAD,
				      writer, t2, 
				      PR_PRIORITY_NORMAL,
                      PR_LOCAL_THREAD,
                      PR_JOINABLE_THREAD,
                      0);

    /* Do the joining for both threads */
    (void) PR_JoinThread(r);
    (void) PR_JoinThread(w);

    /* Do the verification and clean up */
    VerifyAndCleanup();

    PR_DestroySem(emptyBufs);
    PR_DestroySem(fullBufs);

    PR_Cleanup();

    if(failed_already)
    {
        printf("Fail\n");
        return 1;
    }
    else
    {
        printf("PASS\n");
        return 0;
    }


}
예제 #17
0
int prmain(int argc, char** argv)
{
    PRUint32 cpu, cpus = 0, loops = 0;

	/* The command line argument: -d is used to determine if the test is being run
	in debug mode. The regress tool requires only one line output:PASS or FAIL.
	All of the printfs associated with this test has been handled with a if (debug_mode)
	test.
	Usage: test_name [-d]
	*/
	PLOptStatus os;
	PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:c:");
	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    {
		if (PL_OPT_BAD == os) continue;
        switch (opt->option)
        {
        case 'G':  /* GLOBAL threads */
			thread_scope = PR_GLOBAL_THREAD;
            break;
        case 'd':  /* debug mode */
			debug_mode = 1;
            break;
        case 'l':  /* loop count */
			loops = atoi(opt->value);
            break;
        case 'c':  /* concurrency limit */
			cpus = atoi(opt->value);
            break;
         default:
            break;
        }
    }
	PL_DestroyOptState(opt);


    if (cpus == 0) cpus = 1;
    if (loops == 0) loops = 4;

	if (debug_mode)
		printf("Alarm: Using %d loops\n", loops);

	if (debug_mode)		
        printf("Alarm: Using %d cpu(s)\n", cpus);
#ifdef XP_MAC
	SetupMacPrintfLog("alarm.log");
	debug_mode = 1;
#endif

    for (cpu = 1; cpu <= cpus; ++cpu)
    {
    if (debug_mode)
        printf("\nAlarm: Using %d CPU(s)\n", cpu);

	PR_SetConcurrency(cpu);
        
        /* some basic time test */
        (void)TimeThis("ConditionNotify", ConditionNotify, loops);
        (void)TimeThis("ConditionTimeout", ConditionTimeout, loops);
        (void)TimeThis("Alarms1", Alarms1, loops);
        (void)TimeThis("Alarms2", Alarms2, loops);
        (void)TimeThis("Alarms3", Alarms3, loops);
    }
    return 0;
}