|
PAPI
5.3.0.0
|
00001 /****************************/ 00002 /* THIS IS OPEN SOURCE CODE */ 00003 /****************************/ 00004 00015 #include <stdio.h> 00016 #include <stdlib.h> 00017 #include "papi_test.h" 00018 00019 #define PINGADDR "127.0.0.1" 00020 00021 int main (int argc, char **argv) 00022 { 00023 int retval,cid,numcmp; 00024 int EventSet = PAPI_NULL; 00025 long long value; 00026 int code; 00027 char event_name[PAPI_MAX_STR_LEN]; 00028 int total_events=0; 00029 int r; 00030 const PAPI_component_info_t *cmpinfo = NULL; 00031 00032 /* Set TESTS_QUIET variable */ 00033 tests_quiet( argc, argv ); 00034 00035 /* PAPI Initialization */ 00036 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00037 if ( retval != PAPI_VER_CURRENT ) { 00038 test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); 00039 } 00040 00041 if (!TESTS_QUIET) { 00042 printf("Trying all net events\n"); 00043 } 00044 00045 numcmp = PAPI_num_components(); 00046 00047 for(cid=0; cid<numcmp; cid++) { 00048 00049 if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { 00050 test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1); 00051 } 00052 00053 if (!TESTS_QUIET) { 00054 printf("Component %d - %d events - %s\n", cid, 00055 cmpinfo->num_native_events, cmpinfo->name); 00056 } 00057 00058 if ( strstr(cmpinfo->name, "infiniband") == NULL) { 00059 continue; 00060 } 00061 00062 code = PAPI_NATIVE_MASK; 00063 00064 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); 00065 while ( r == PAPI_OK ) { 00066 00067 retval = PAPI_event_code_to_name( code, event_name ); 00068 if ( retval != PAPI_OK ) { 00069 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00070 } 00071 00072 if (!TESTS_QUIET) { 00073 printf("%#x %-24s = ", code, event_name); 00074 } 00075 00076 EventSet = PAPI_NULL; 00077 00078 retval = PAPI_create_eventset( &EventSet ); 00079 if (retval != PAPI_OK) { 00080 test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); 00081 } 00082 00083 retval = PAPI_add_event( EventSet, code ); 00084 if (retval != PAPI_OK) { 00085 test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval); 00086 } 00087 00088 retval = PAPI_start( EventSet ); 00089 if (retval != PAPI_OK) { 00090 test_fail(__FILE__, __LINE__, "PAPI_start()", retval); 00091 } 00092 00093 if (strcmp(event_name, "_recv") == 0) { 00094 /* XXX figure out a general method to generate some traffic 00095 * for infiniband 00096 * the operation should take more than one second in order 00097 * to guarantee that the network counters are updated */ 00098 retval = system("ping -c 4 " PINGADDR " > /dev/null"); 00099 if (retval < 0) { 00100 test_fail(__FILE__, __LINE__, "Unable to start ping", retval); 00101 } 00102 } 00103 00104 retval = PAPI_stop( EventSet, &value ); 00105 if (retval != PAPI_OK) { 00106 test_fail(__FILE__, __LINE__, "PAPI_stop()", retval); 00107 } 00108 00109 if (!TESTS_QUIET) printf("%lld\n", value); 00110 00111 retval = PAPI_cleanup_eventset( EventSet ); 00112 if (retval != PAPI_OK) { 00113 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval); 00114 } 00115 00116 retval = PAPI_destroy_eventset( &EventSet ); 00117 if (retval != PAPI_OK) { 00118 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval); 00119 } 00120 00121 total_events++; 00122 00123 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); 00124 } 00125 00126 } 00127 00128 if (total_events==0) { 00129 test_skip(__FILE__,__LINE__,"No net events found", 0); 00130 } 00131 00132 test_pass( __FILE__, NULL, 0 ); 00133 00134 return 0; 00135 } 00136 00137 // vim:set ai ts=4 sw=4 sts=4 et: