|
PAPI
5.0.1.0
|
00001 #include <stdio.h> 00002 #include <unistd.h> 00003 #if defined(_AIX) || defined (__FreeBSD__) || defined (__APPLE__) 00004 #include <sys/wait.h> /* ARGH! */ 00005 #else 00006 #include <wait.h> 00007 #endif 00008 #include "papi_test.h" 00009 00010 int 00011 main( int argc, char **argv ) 00012 { 00013 int retval, pid, status, EventSet = PAPI_NULL; 00014 long long int values[] = {0,0}; 00015 PAPI_option_t opt; 00016 00017 tests_quiet( argc, argv ); 00018 00019 if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) 00020 test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval ); 00021 00022 if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) 00023 test_fail_exit( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00024 00025 if ( ( retval = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK ) 00026 test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); 00027 00028 memset( &opt, 0x0, sizeof ( PAPI_option_t ) ); 00029 opt.inherit.inherit = PAPI_INHERIT_ALL; 00030 opt.inherit.eventset = EventSet; 00031 if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) { 00032 if ( retval == PAPI_ECMP) { 00033 test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval ); 00034 } else { 00035 test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval ); 00036 } 00037 } 00038 00039 if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK ) 00040 test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval ); 00041 00042 if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK ) 00043 test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); 00044 00045 retval = PAPI_query_event( PAPI_FP_INS ); 00046 if ( retval == PAPI_ENOEVNT ) { 00047 test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval); 00048 values[1] = NUM_FLOPS; /* fake a return value to pass the test */ 00049 } else if ( retval != PAPI_OK ) 00050 test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval ); 00051 else if ( ( retval = PAPI_add_event( EventSet, PAPI_FP_INS ) ) != PAPI_OK ) 00052 test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); 00053 00054 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) 00055 test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); 00056 00057 pid = fork( ); 00058 if ( pid == 0 ) { 00059 do_flops( NUM_FLOPS ); 00060 exit( 0 ); 00061 } 00062 if ( waitpid( pid, &status, 0 ) == -1 ) { 00063 perror( "waitpid()" ); 00064 exit( 1 ); 00065 } 00066 00067 if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) 00068 test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); 00069 00070 if (!TESTS_QUIET) { 00071 printf( "Test case inherit: parent starts, child works, parent stops.\n" ); 00072 printf( "------------------------------------------------------------\n" ); 00073 00074 printf( "Test run : \t1\n" ); 00075 printf( "PAPI_FP_INS : \t%lld\n", values[1] ); 00076 printf( "PAPI_TOT_CYC: \t%lld\n", values[0] ); 00077 printf( "------------------------------------------------------------\n" ); 00078 00079 printf( "Verification:\n" ); 00080 printf( "Row 1 at least %d\n", NUM_FLOPS ); 00081 printf( "Row 2 greater than row 1\n"); 00082 } 00083 00084 if ( values[1] < NUM_FLOPS) { 00085 test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 ); 00086 } 00087 00088 if ( values[0] < values[1]) { 00089 test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC < PAPI_FP_INS", 1 ); 00090 } 00091 00092 test_pass( __FILE__, NULL, 0 ); 00093 exit( 1 ); 00094 }