PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
9static void
10test_continue( const char *call, int retval )
11{
12 if (!TESTS_QUIET) {
13 printf( "Expected error in %s: %s\n", call,
15 }
16}
17
18int
19main( 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
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
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
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
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
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 );
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 */
141 if (!quiet) printf( "Looking for highest definable native event: %#x...\n", code );
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}
Enumerate PAPI preset or native events.
Convert a numeric hardware event code to a name.
get information about a specific software component
initialize the PAPI library.
Returns a string describing the PAPI error code.
static void test_continue(const char *call, int retval)
Definition: code2name.c:10
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_EBUG
Definition: f90papi.h:176
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ENOCMP
Definition: f90papi.h:79
#define PAPI_FP_OPS
Definition: f90papi.h:319
#define PAPI_ECMP
Definition: f90papi.h:214
static struct temp_event * last
int TESTS_QUIET
Definition: test_utils.c:18
#define PAPI_NATIVE_AND_MASK
#define PAPI_PRESET_MASK
#define PAPI_PRESET_AND_MASK
#define PAPI_NATIVE_MASK
#define PAPI_MAX_PRESET_EVENTS
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
int
Definition: sde_internal.h:89
int retval
Definition: zero_fork.c:53