|
PAPI
5.0.1.0
|
00001 #include "papi_test.h" 00002 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00003 00004 int 00005 main( int argc, char **argv ) 00006 { 00007 int FPEventSet = PAPI_NULL; 00008 long long values; 00009 int PAPI_event, retval; 00010 char event_name[PAPI_MAX_STR_LEN]; 00011 00012 /* Set TESTS_QUIET variable */ 00013 tests_quiet( argc, argv ); 00014 00015 /* init PAPI */ 00016 if ( ( retval = 00017 PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) 00018 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00019 00020 /* Use PAPI_FP_INS if available, otherwise use PAPI_TOT_INS */ 00021 if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) 00022 PAPI_event = PAPI_FP_INS; 00023 else 00024 PAPI_event = PAPI_TOT_INS; 00025 00026 if ( ( retval = PAPI_query_event( PAPI_event ) ) != PAPI_OK ) 00027 test_fail( __FILE__, __LINE__, "PAPI_query_event", retval ); 00028 00029 /* Create the eventset */ 00030 if ( ( retval = PAPI_create_eventset( &FPEventSet ) ) != PAPI_OK ) 00031 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00032 00033 /* Add event to the eventset */ 00034 if ( ( retval = PAPI_add_event( FPEventSet, PAPI_event ) ) != PAPI_OK ) 00035 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00036 00037 /* Start counting */ 00038 if ( ( retval = PAPI_start( FPEventSet ) ) != PAPI_OK ) 00039 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00040 00041 /* Try to cleanup while running */ 00042 /* Fail test if this isn't refused */ 00043 if ( ( retval = PAPI_cleanup_eventset( FPEventSet ) ) != PAPI_EISRUN ) 00044 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); 00045 00046 /* Try to destroy eventset while running */ 00047 /* Fail test if this isn't refused */ 00048 if ( ( retval = PAPI_destroy_eventset( &FPEventSet ) ) != PAPI_EISRUN ) 00049 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); 00050 00051 /* do some work */ 00052 do_flops( 1000000 ); 00053 00054 /* stop counting */ 00055 if ( ( retval = PAPI_stop( FPEventSet, &values ) ) != PAPI_OK ) 00056 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00057 00058 /* Try to destroy eventset without cleaning first */ 00059 /* Fail test if this isn't refused */ 00060 if ( ( retval = PAPI_destroy_eventset( &FPEventSet ) ) != PAPI_EINVAL ) 00061 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); 00062 00063 /* Try to cleanup eventset. */ 00064 /* This should pass. */ 00065 if ( ( retval = PAPI_cleanup_eventset( FPEventSet ) ) != PAPI_OK ) 00066 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); 00067 00068 /* Try to destroy eventset. */ 00069 /* This should pass. */ 00070 if ( ( retval = PAPI_destroy_eventset( &FPEventSet ) ) != PAPI_OK ) 00071 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); 00072 00073 /* Make sure eventset was set to PAPI_NULL */ 00074 if ( FPEventSet != PAPI_NULL ) 00075 test_fail( __FILE__, __LINE__, "FPEventSet != PAPI_NULL", retval ); 00076 00077 if ( !TESTS_QUIET ) { 00078 if ( ( retval = 00079 PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) 00080 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00081 00082 printf( "Test case John May 2: cleanup / destroy eventset.\n" ); 00083 printf( "-------------------------------------------------\n" ); 00084 printf( "Test run : \t1\n" ); 00085 printf( "%s : \t", event_name ); 00086 printf( LLDFMT, values ); 00087 printf( "\n" ); 00088 printf( "-------------------------------------------------\n" ); 00089 printf( "The following messages will appear if PAPI is compiled with debug enabled:\n" ); 00090 printf 00091 ( "\tPAPI Error Code -10: PAPI_EISRUN: EventSet is currently counting\n" ); 00092 printf 00093 ( "\tPAPI Error Code -10: PAPI_EISRUN: EventSet is currently counting\n" ); 00094 printf( "\tPAPI Error Code -1: PAPI_EINVAL: Invalid argument\n" ); 00095 } 00096 test_pass( __FILE__, NULL, 0 ); 00097 exit( 1 ); 00098 }