|
PAPI
5.0.1.0
|
00001 /* This file performs the following test: event_code_to_name */ 00002 00003 #include "papi_test.h" 00004 00005 static void 00006 test_continue( char *call, int retval ) 00007 { 00008 printf( "Expected error in %s: %s\n", call, PAPI_strerror(retval) ); 00009 } 00010 00011 int 00012 main( int argc, char **argv ) 00013 { 00014 int retval; 00015 int code = PAPI_TOT_CYC, last; 00016 char event_name[PAPI_MAX_STR_LEN]; 00017 const PAPI_hw_info_t *hwinfo = NULL; 00018 const PAPI_component_info_t *cmp_info; 00019 00020 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00021 00022 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00023 if ( retval != PAPI_VER_CURRENT ) 00024 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00025 00026 retval = 00027 papi_print_header 00028 ( "Test case code2name.c: Check limits and indexing of event tables.\n", 00029 &hwinfo ); 00030 if ( retval != PAPI_OK ) 00031 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); 00032 00033 printf( "Looking for PAPI_TOT_CYC...\n" ); 00034 retval = PAPI_event_code_to_name( code, event_name ); 00035 if ( retval != PAPI_OK ) 00036 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00037 printf( "Found |%s|\n", event_name ); 00038 00039 code = PAPI_FP_OPS; 00040 printf( "Looking for highest defined preset event (PAPI_FP_OPS): 0x%x...\n", 00041 code ); 00042 retval = PAPI_event_code_to_name( code, event_name ); 00043 if ( retval != PAPI_OK ) 00044 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00045 printf( "Found |%s|\n", event_name ); 00046 00047 code = PAPI_PRESET_MASK | ( PAPI_MAX_PRESET_EVENTS - 1 ); 00048 printf( "Looking for highest allocated preset event: 0x%x...\n", code ); 00049 retval = PAPI_event_code_to_name( code, event_name ); 00050 if ( retval != PAPI_OK ) 00051 test_continue( "PAPI_event_code_to_name", retval ); 00052 else 00053 printf( "Found |%s|\n", event_name ); 00054 00055 code = PAPI_PRESET_MASK | ( int ) PAPI_NATIVE_AND_MASK; 00056 printf( "Looking for highest possible preset event: 0x%x...\n", code ); 00057 retval = PAPI_event_code_to_name( code, event_name ); 00058 if ( retval != PAPI_OK ) 00059 test_continue( "PAPI_event_code_to_name", retval ); 00060 else 00061 printf( "Found |%s|\n", event_name ); 00062 00063 /* Find the first defined native event */ 00064 /* For platform independence, always ASK FOR the first event */ 00065 /* Don't just assume it'll be the first numeric value */ 00066 code = PAPI_NATIVE_MASK; 00067 PAPI_enum_event( &code, PAPI_ENUM_FIRST ); 00068 00069 printf( "Looking for first native event: 0x%x...\n", code ); 00070 retval = PAPI_event_code_to_name( code, event_name ); 00071 if ( retval != PAPI_OK ) { 00072 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00073 } 00074 else { 00075 printf( "Found |%s|\n", event_name ); 00076 } 00077 00078 /* Find the last defined native event */ 00079 00080 /* FIXME: hardcoded cmp 0 */ 00081 cmp_info = PAPI_get_component_info( 0 ); 00082 if ( cmp_info == NULL ) { 00083 test_fail( __FILE__, __LINE__, 00084 "PAPI_get_component_info", PAPI_ECMP ); 00085 } 00086 00087 code = PAPI_NATIVE_MASK; 00088 PAPI_enum_event( &code, PAPI_ENUM_FIRST ); 00089 00090 while ( PAPI_enum_event( &code, PAPI_ENUM_EVENTS ) == PAPI_OK ) { 00091 last=code; 00092 } 00093 00094 code = last; 00095 printf( "Looking for last native event: 0x%x...\n", code ); 00096 retval = PAPI_event_code_to_name( code, event_name ); 00097 if ( retval != PAPI_OK ) { 00098 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00099 } 00100 else { 00101 printf( "Found |%s|\n", event_name ); 00102 } 00103 00104 /* Highly doubtful we have this many natives */ 00105 /* Turn on all bits *except* PRESET bit and COMPONENT bits */ 00106 code = PAPI_PRESET_AND_MASK; 00107 printf( "Looking for highest definable native event: 0x%x...\n", code ); 00108 retval = PAPI_event_code_to_name( code, event_name ); 00109 if ( retval != PAPI_OK ) 00110 test_continue( "PAPI_event_code_to_name", retval ); 00111 else 00112 printf( "Found |%s|\n", event_name ); 00113 if ( ( retval == PAPI_ENOCMP) || ( retval == PAPI_ENOEVNT ) || ( retval == PAPI_OK ) ) 00114 test_pass( __FILE__, 0, 0 ); 00115 00116 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", PAPI_EBUG ); 00117 00118 exit( 1 ); 00119 }