PAPI 7.1.0.0
Loading...
Searching...
No Matches
failed_events.c
Go to the documentation of this file.
1/*
2 * File: failed_events.c
3 * Author: Vince Weaver <vincent.weaver@maine.edu>
4 */
5
6/* This test tries adding events that don't exist */
7/* We've had issues where the name resolution code might do weird */
8/* things when passed invalid event names */
9
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "papi.h"
16#include "papi_test.h"
17
18
19#define LARGE_NAME_SIZE 4096
20
22
23int
24main( int argc, char **argv )
25{
26
27 int i, k, err_count = 0;
28 int retval;
29 PAPI_event_info_t info, info1;
30 const PAPI_component_info_t* cmpinfo;
31 int numcmp, cid;
32 int quiet;
33
34 int EventSet = PAPI_NULL;
35
36 /* Set quiet variable */
37 quiet=tests_quiet( argc, argv );
38
39 /* Init PAPI library */
41 if ( retval != PAPI_VER_CURRENT ) {
42 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
43 }
44
45 if (!quiet) {
46 printf("Test adding invalid events.\n");
47 }
48
49 /* Create an eventset */
51 if ( retval != PAPI_OK ) {
52 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
53 }
54
55
56 /* Simple Event */
57 if (!quiet) {
58 printf("+ Simple invalid event\t");
59 }
60
61 retval=PAPI_add_named_event(EventSet,"INVALID_EVENT");
62 if (retval==PAPI_OK) {
63 if (!quiet) {
64 printf("Unexpectedly opened!\n");
65 err_count++;
66 }
67 }
68 else {
69 if (!quiet) printf("OK\n");
70 }
71
72 /* Extra Colons */
73 if (!quiet) {
74 printf("+ Extra colons\t");
75 }
76
77 retval=PAPI_add_named_event(EventSet,"INV::::AL:ID:::_E=3V::E=NT");
78 if (retval==PAPI_OK) {
79 if (!quiet) {
80 printf("Unexpectedly opened!\n");
81 err_count++;
82 }
83 }
84 else {
85 if (!quiet) printf("OK\n");
86 }
87
88
89 /* Large Invalid Event */
90 if (!quiet) {
91 printf("+ Large invalid event\t");
92 }
93
94 memset(large_name,'A',LARGE_NAME_SIZE);
96
98 if (retval==PAPI_OK) {
99 if (!quiet) {
100 printf("Unexpectedly opened!\n");
101 err_count++;
102 }
103 }
104 else {
105 if (!quiet) printf("OK\n");
106 }
107
108 /* Large Unterminated Invalid Event */
109 if (!quiet) {
110 printf("+ Large unterminated invalid event\t");
111 }
112
113 memset(large_name,'A',LARGE_NAME_SIZE);
114
116 if (retval==PAPI_OK) {
117 if (!quiet) {
118 printf("Unexpectedly opened!\n");
119 err_count++;
120 }
121 }
122 else {
123 if (!quiet) printf("OK\n");
124 }
125
126
127 /* Randomly modifying valid events */
128 if (!quiet) {
129 printf("+ Randomly modifying valid events\t");
130 }
131
132 numcmp = PAPI_num_components( );
133
134 /* Loop through all components */
135 for( cid = 0; cid < numcmp; cid++ ) {
136
137
138 cmpinfo = PAPI_get_component_info( cid );
139 if (cmpinfo == NULL) {
140 test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 );
141 }
142
143 /* Include disabled components */
144 if (cmpinfo->disabled) {
145 // continue;
146 }
147
148
149 /* For platform independence, always ASK FOR the first event */
150 /* Don't just assume it'll be the first numeric value */
151 i = 0 | PAPI_NATIVE_MASK;
153
154 do {
155 retval = PAPI_get_event_info( i, &info );
156
157 k = i;
159 do {
160 retval = PAPI_get_event_info( k, &info1 );
161
162
163
164 /* Skip perf_raw event as it is hard to error out */
165 if (strstr(info1.symbol,"perf_raw")) {
166 break;
167 }
168
169// printf("%s\n",info1.symbol);
170
171 if (strlen(info1.symbol)>5) {
172 info1.symbol[strlen(info1.symbol)-4]^=0xa5;
173
175 if (retval==PAPI_OK) {
176 if (!quiet) {
177 printf("Unexpectedly opened %s!\n",
178 info1.symbol);
179 err_count++;
180 }
181 }
182 }
183 } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK );
184 } else {
185 /* Event didn't have any umasks */
186
187 // PROBLEM: info1 is NOT initialized by anyone!
188 // Original code referenced info1, changed to info. [Tony C. 11-27-19]
189// printf("%s\n",info.symbol);
190 if (strlen(info.symbol)>5) {
191 info.symbol[strlen(info.symbol)-4]^=0xa5;
192
194 if (retval==PAPI_OK) {
195 if (!quiet) {
196 printf("Unexpectedly opened %s!\n",
197 info.symbol);
198 err_count++;
199 }
200 }
201 }
202 }
203
204 } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK );
205
206 }
207
208
209
210 if ( err_count ) {
211 if (!quiet) {
212 printf( "%d Invalid events added.\n", err_count );
213 }
214 test_fail( __FILE__, __LINE__, "Invalid events added", 1 );
215 }
216
217 test_pass( __FILE__ );
218
219 return 0;
220}
int i
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
Enumerate PAPI preset or native events for a given component.
get information about a specific software component
Get the event's name and description info.
initialize the PAPI library.
Get the number of components available on the system.
char large_name[LARGE_NAME_SIZE]
Definition: failed_events.c:21
#define LARGE_NAME_SIZE
Definition: failed_events.c:19
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_NTV_ENUM_UMASKS
Definition: f90papi.h:66
static int EventSet
Definition: init_fini.c:8
#define PAPI_NATIVE_MASK
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
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
int retval
Definition: zero_fork.c:53