|
PAPI
5.0.1.0
|
00001 /* 00002 * File: timer_overflow.c 00003 * Author: Kevin London 00004 * london@cs.utk.edu 00005 * Mods: <your name here> 00006 * <your email address> 00007 */ 00008 00009 /* This file looks for possible timer overflows. */ 00010 00011 #include "papi_test.h" 00012 00013 #define TIMER_THRESHOLD 100 00014 extern int TESTS_QUIET; 00015 00016 int 00017 main( int argc, char **argv ) 00018 { 00019 int sleep_time = TIMER_THRESHOLD; 00020 int retval, i; 00021 long long timer; 00022 00023 if ( argc > 1 ) { 00024 if ( !strcmp( argv[1], "TESTS_QUIET" ) ) 00025 tests_quiet( argc, argv ); 00026 else { 00027 sleep_time = atoi( argv[1] ); 00028 if ( sleep_time <= 0 ) 00029 sleep_time = TIMER_THRESHOLD; 00030 } 00031 } 00032 00033 if ( TESTS_QUIET ) { 00034 /* Skip the test in TESTS_QUIET so that the main script doesn't 00035 * run this as it takes a long time to check for overflow 00036 */ 00037 printf( "%-40s SKIPPED\nLine # %d\n", __FILE__, __LINE__ ); 00038 printf( "timer_overflow takes a long time to run, run separately.\n" ); 00039 exit( 0 ); 00040 } 00041 00042 printf( "This test will take about: %f minutes.\n", 00043 ( float ) ( 20 * ( sleep_time / 60.0 ) ) ); 00044 if ( ( retval = 00045 PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) 00046 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00047 00048 timer = PAPI_get_real_usec( ); 00049 for ( i = 0; i <= 20; i++ ) { 00050 if ( timer < 0 ) 00051 break; 00052 sleep( ( unsigned int ) sleep_time ); 00053 timer = PAPI_get_real_usec( ); 00054 } 00055 if ( timer < 0 ) 00056 test_fail( __FILE__, __LINE__, "PAPI_get_real_usec: overflow", 1 ); 00057 else 00058 test_pass( __FILE__, NULL, 0 ); 00059 exit( 1 ); 00060 }