PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
code2name.c
Go to the documentation of this file.
1 /* This file performs the following test: event_code_to_name */
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 
6 #include "papi.h"
7 #include "papi_test.h"
8 
9 static void
10 test_continue( const char *call, int retval )
11 {
12  if (!TESTS_QUIET) {
13  printf( "Expected error in %s: %s\n", call,
14  PAPI_strerror(retval) );
15  }
16 }
17 
18 int
19 main( int argc, char **argv )
20 {
21  int retval;
22  int code = PAPI_TOT_CYC, last;
24  const PAPI_component_info_t *cmp_info;
25  int quiet;
26 
27  /* Set TESTS_QUIET variable */
28  quiet=tests_quiet( argc, argv );
29 
30 
32  if ( retval != PAPI_VER_CURRENT )
33  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
34 
35  if (!quiet) {
36  printf( "Test case code2name.c: "
37  "Check limits and indexing of event tables.\n");
38  printf( "Looking for PAPI_TOT_CYC...\n" );
39  }
40 
41  retval = PAPI_event_code_to_name( code, event_name );
42  if ( retval != PAPI_OK ) {
43  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
44  }
45 
46  if (!quiet) printf( "Found |%s|\n", event_name );
47 
48  code = PAPI_FP_OPS;
49 
50  if (!quiet) {
51  printf( "Looking for highest defined preset event "
52  "(PAPI_FP_OPS): %#x...\n",code );
53  }
54 
55  retval = PAPI_event_code_to_name( code, event_name );
56  if ( retval != PAPI_OK )
57  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
58 
59  if (!quiet) printf( "Found |%s|\n", event_name );
60 
62 
63  if (!quiet) {
64  printf( "Looking for highest allocated preset event:"
65  " %#x...\n", code );
66  }
67 
68  retval = PAPI_event_code_to_name( code, event_name );
69  if ( retval != PAPI_OK ) {
70  test_continue( "PAPI_event_code_to_name", retval );
71  }
72  else {
73  if (!quiet) printf( "Found |%s|\n", event_name );
74  }
75 
76  code = PAPI_PRESET_MASK | ( unsigned int ) PAPI_NATIVE_AND_MASK;
77 
78  if (!quiet) {
79  printf( "Looking for highest possible preset event:"
80  " %#x...\n", code );
81  }
82 
83  retval = PAPI_event_code_to_name( code, event_name );
84 
85  if ( retval != PAPI_OK ) {
86  test_continue( "PAPI_event_code_to_name", retval );
87  }
88  else {
89  if (!quiet) printf( "Found |%s|\n", event_name );
90  }
91 
92  /* Find the first defined native event in component 0 */
93  /* For platform independence, always ASK FOR the first event */
94  /* Don't just assume it'll be the first numeric value */
95  code = PAPI_NATIVE_MASK;
97 
98  if (!quiet) {
99  printf( "Looking for first native event: %#x...\n", code );
100  }
101 
102  retval = PAPI_event_code_to_name( code, event_name );
103  if ( retval != PAPI_OK ) {
104  if (!quiet) printf("Could not find first native event\n");
105  test_skip( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
106  }
107  else {
108  if (!quiet) printf( "Found |%s|\n", event_name );
109  }
110 
111  /* Find the last defined native event */
112 
113  /* FIXME: hardcoded cmp 0 */
114  cmp_info = PAPI_get_component_info( 0 );
115  if ( cmp_info == NULL ) {
116  test_fail( __FILE__, __LINE__,
117  "PAPI_get_component_info", PAPI_ECMP );
118  }
119 
120  code = PAPI_NATIVE_MASK;
121  last = code;
123 
124  while ( PAPI_enum_event( &code, PAPI_ENUM_EVENTS ) == PAPI_OK ) {
125  last=code;
126  }
127 
128  code = last;
129  if (!quiet) printf( "Looking for last native event: %#x...\n", code );
130  retval = PAPI_event_code_to_name( code, event_name );
131  if ( retval != PAPI_OK ) {
132  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
133  }
134  else {
135  if (!quiet) printf( "Found |%s|\n", event_name );
136  }
137 
138  /* Highly doubtful we have this many natives */
139  /* Turn on all bits *except* PRESET bit and COMPONENT bits */
140  code = PAPI_PRESET_AND_MASK;
141  if (!quiet) printf( "Looking for highest definable native event: %#x...\n", code );
142  retval = PAPI_event_code_to_name( code, event_name );
143  if ( retval != PAPI_OK ) {
144  test_continue( "PAPI_event_code_to_name", retval );
145  }
146  else {
147  if (!quiet) printf( "Found |%s|\n", event_name );
148  }
149 
150  if ( ( retval == PAPI_ENOCMP) || ( retval == PAPI_ENOEVNT ) || ( retval == PAPI_OK ) ) {
151  test_pass( __FILE__ );
152  }
153 
154  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", PAPI_EBUG );
155 
156  return 1;
157 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_ENOEVNT
Definition: papi.h:260
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_FP_OPS
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1152
#define PAPI_MAX_PRESET_EVENTS
#define PAPI_EBUG
Definition: papi.h:259
return PAPI_OK
Definition: linux-nvml.c:497
#define PAPI_PRESET_MASK
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
static void test_continue(const char *call, int retval)
Definition: code2name.c:10
#define PAPI_ECMP
Definition: papi.h:256
static struct temp_event * last
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
#define PAPI_ENOCMP
Definition: papi.h:270
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
char * PAPI_strerror(int errorCode)
Definition: papi.c:4603
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
int
Definition: iozone.c:18528
#define PAPI_NATIVE_AND_MASK
#define PAPI_PRESET_AND_MASK
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
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.