PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
timer_overflow.c
Go to the documentation of this file.
1 /*
2  * File: timer_overflow.c
3  * Author: Kevin London
4  * london@cs.utk.edu
5  * Mods: <your name here>
6  * <your email address>
7  */
8 
9 /* This file looks for possible timer overflows. */
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <string.h>
15 
16 #include "papi.h"
17 #include "papi_test.h"
18 
19 #define TIMER_THRESHOLD 100
20 
21 int
22 main( int argc, char **argv )
23 {
24  int sleep_time = TIMER_THRESHOLD;
25  int retval, i;
26  long long timer;
27 
28  if ( argc > 1 ) {
29  if ( !strcmp( argv[1], "TESTS_QUIET" ) )
30  tests_quiet( argc, argv );
31  else {
32  sleep_time = atoi( argv[1] );
33  if ( sleep_time <= 0 )
34  sleep_time = TIMER_THRESHOLD;
35  }
36  }
37 
38  if ( TESTS_QUIET ) {
39  /* Skip the test in TESTS_QUIET so that the main script doesn't
40  * run this as it takes a long time to check for overflow
41  */
42  printf( "%-40s SKIPPED\nLine # %d\n", __FILE__, __LINE__ );
43  printf( "timer_overflow takes a long time to run, run separately.\n" );
44  exit( 0 );
45  }
46 
47  printf( "This test will take about: %f minutes.\n",
48  ( float ) ( 20 * ( sleep_time / 60.0 ) ) );
49  if ( ( retval =
51  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
52 
53  timer = PAPI_get_real_usec( );
54  for ( i = 0; i <= 20; i++ ) {
55  if ( timer < 0 )
56  break;
57  sleep( ( unsigned int ) sleep_time );
58  timer = PAPI_get_real_usec( );
59  }
60  if ( timer < 0 )
61  test_fail( __FILE__, __LINE__, "PAPI_get_real_usec: overflow", 1 );
62  else
63  test_pass( __FILE__ );
64 
65  return 0;
66 }
#define TIMER_THRESHOLD
int atoi()
void test_pass(const char *filename)
Definition: test_utils.c:432
sleep(1)
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.
void exit()