PAPI 7.1.0.0
Loading...
Searching...
No Matches
io_basic.c
Go to the documentation of this file.
1/****************************/
2/* THIS IS OPEN SOURCE CODE */
3/****************************/
4
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include "papi.h"
26#include "papi_test.h"
27
28#define NUM_EVENTS 3
29
30int main (int argc, char **argv)
31{
32
33 int retval,i;
34 int EventSet = PAPI_NULL;
35 long long values[NUM_EVENTS];
36 const PAPI_component_info_t *cmpinfo = NULL;
37 int numcmp,cid,example_cid=-1;
38 int code,maximum_code=0;
41 int quiet=0;
42
43 /* Set TESTS_QUIET variable */
44 quiet=tests_quiet( argc, argv );
45
46 /* PAPI Initialization */
48 if ( retval != PAPI_VER_CURRENT ) {
49 test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
50 }
51
52 if (!quiet) {
53 printf( "Testing I/O component with PAPI %d.%d.%d\n",
57 }
58
59 /* Find our component */
60
61 numcmp = PAPI_num_components();
62 for( cid=0; cid<numcmp; cid++) {
63 if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
64 test_fail(__FILE__, __LINE__,
65 "PAPI_get_component_info failed\n", 0);
66 }
67 if (!quiet) {
68 printf("\tComponent %d - %d events - %s\n", cid,
69 cmpinfo->num_native_events,
70 cmpinfo->name);
71 }
72 if (strstr(cmpinfo->name,"io")) {
73 /* FOUND! */
74 example_cid=cid;
75 }
76 }
77
78
79 if (example_cid<0) {
80 test_skip(__FILE__, __LINE__,
81 "Example component not found\n", 0);
82 }
83
84 if (!quiet) {
85 printf("\nFound io Component at id %d\n",example_cid);
86 printf("\nListing all events in this component:\n");
87 }
88
89 /**************************************************/
90 /* Listing all available events in this component */
91 /* Along with descriptions */
92 /**************************************************/
93 code = PAPI_NATIVE_MASK;
94
95 retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, example_cid );
96
97 while ( retval == PAPI_OK ) {
99 printf("Error translating %#x\n",code);
100 test_fail( __FILE__, __LINE__,
101 "PAPI_event_code_to_name", retval );
102 }
103
104 if (PAPI_get_event_info( code, &event_info)!=PAPI_OK) {
105 printf("Error getting info for event %#x\n",code);
106 test_fail( __FILE__, __LINE__,
107 "PAPI_get_event_info()", retval );
108 }
109
110 if (!quiet) {
111 printf("\tEvent %#x: %s -- %s\n",
112 code,event_name,event_info.long_descr);
113 }
114
115 maximum_code=code;
116
117 retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, example_cid );
118
119 }
120 if (!quiet) printf("\n");
121
122 /**********************************/
123 /* Try accessing an invalid event */
124 /**********************************/
125
126 retval=PAPI_event_code_to_name( maximum_code+10, event_name );
127 if (retval!=PAPI_ENOEVNT) {
128 test_fail( __FILE__, __LINE__,
129 "Failed to return PAPI_ENOEVNT on invalid event", retval );
130 }
131
132 /***********************************/
133 /* Test the rchar event */
134 /***********************************/
135
137 if ( retval != PAPI_OK ) {
138 test_fail( __FILE__, __LINE__,
139 "PAPI_create_eventset() failed\n", retval );
140 }
141
142 retval = PAPI_event_name_to_code("io:::rchar", &code);
143 if ( retval != PAPI_OK ) {
144 test_fail( __FILE__, __LINE__,
145 "io:::rchar not found\n",retval );
146 }
147
149 if ( retval != PAPI_OK ) {
150 test_fail( __FILE__, __LINE__,
151 "PAPI_add_events failed\n", retval );
152 }
153
155 if ( retval != PAPI_OK ) {
156 test_fail( __FILE__, __LINE__,
157 "PAPI_start failed\n",retval );
158 }
159
161 if ( retval != PAPI_OK ) {
162 test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
163 }
164
165 if (!quiet) printf("Testing io:::rchar: %lld\n",values[0]);
166
167 if (values[0]==0) {
168 test_fail( __FILE__, __LINE__, "Result should be != 0!\n", 0);
169 }
170
172 if (retval != PAPI_OK) {
173 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
174 }
175
177 if (retval != PAPI_OK) {
178 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
179 }
180
182
183
184 /***********************************/
185 /* Test the wchar event */
186 /***********************************/
187
189 if ( retval != PAPI_OK ) {
190 test_fail( __FILE__, __LINE__,
191 "PAPI_create_eventset() failed\n", retval );
192 }
193
194 retval = PAPI_event_name_to_code("io:::wchar", &code);
195 if ( retval != PAPI_OK ) {
196 test_fail( __FILE__, __LINE__,
197 "io:::wchar not found\n",retval );
198 }
199
201 if ( retval != PAPI_OK ) {
202 test_fail( __FILE__, __LINE__,
203 "PAPI_add_events failed\n", retval );
204 }
205
207 if ( retval != PAPI_OK ) {
208 test_fail( __FILE__, __LINE__,
209 "PAPI_start failed\n",retval );
210 }
211
213 if ( retval != PAPI_OK ) {
214 test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
215 }
216
217 if (!quiet) printf("Testing io:::wchar: %lld\n",values[0]);
218
219 if (values[0]==0) {
220 test_fail( __FILE__, __LINE__, "Result should be != 0!\n", 0);
221 }
222
223
224 /***********************************/
225 /* Test multiple reads */
226 /***********************************/
227
229 if ( retval != PAPI_OK ) {
230 test_fail( __FILE__, __LINE__,
231 "PAPI_start failed\n",retval );
232 }
233
234 for(i=0;i<10;i++) {
235
237 if ( retval != PAPI_OK ) {
238 test_fail( __FILE__, __LINE__, "PAPI_read failed\n", retval);
239 }
240 if (!quiet) printf("%lld ",values[0]);
241 }
242
244 if ( retval != PAPI_OK ) {
245 test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
246 }
247 if (!quiet) printf("%lld\n",values[0]);
248
249 // if (values[0]!=i) {
250 // test_fail( __FILE__, __LINE__, "Result wrong!\n", 0);
251 //}
252
253 /***********************************/
254 /* Test PAPI_reset() */
255 /***********************************/
256
258 if ( retval != PAPI_OK ) {
259 test_fail( __FILE__, __LINE__,
260 "PAPI_reset() failed\n",retval );
261 }
262
264 if ( retval != PAPI_OK ) {
265 test_fail( __FILE__, __LINE__,
266 "PAPI_start failed\n",retval );
267 }
268
270 if ( retval != PAPI_OK ) {
271 test_fail( __FILE__, __LINE__,
272 "PAPI_reset() failed\n",retval );
273 }
274
276 if ( retval != PAPI_OK ) {
277 test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
278 }
279
280
281 if (!quiet) printf("Testing after PAPI_reset(): %lld\n",
282 values[0]);
283
284 if (values[0]==0) {
285 test_fail( __FILE__, __LINE__, "Result zero!\n", 0);
286 }
287
289 if (retval != PAPI_OK) {
290 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
291 }
292
294 if (retval != PAPI_OK) {
295 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
296 }
297
299
300
301 /***********************************/
302 /* Test multiple events */
303 /***********************************/
304
305 if (!quiet) printf("Testing Multiple Events: ");
306
308 if ( retval != PAPI_OK ) {
309 test_fail( __FILE__, __LINE__,
310 "PAPI_create_eventset() failed\n", retval );
311 }
312
313 retval = PAPI_event_name_to_code("io:::rchar", &code);
314 if ( retval != PAPI_OK ) {
315 test_fail( __FILE__, __LINE__,
316 "io:::rchar not found\n",retval );
317 }
318
320 if ( retval != PAPI_OK ) {
321 test_fail( __FILE__, __LINE__,
322 "PAPI_add_events failed\n", retval );
323 }
324
325 retval = PAPI_event_name_to_code("io:::wchar", &code);
326 if ( retval != PAPI_OK ) {
327 test_fail( __FILE__, __LINE__,
328 "io:::wchar not found\n",retval );
329 }
330
332 if ( retval != PAPI_OK ) {
333 test_fail( __FILE__, __LINE__,
334 "PAPI_add_events failed\n", retval );
335 }
336
337 retval = PAPI_event_name_to_code("io:::read_bytes", &code);
338 if ( retval != PAPI_OK ) {
339 test_fail( __FILE__, __LINE__,
340 "io:::read_bytes not found\n",retval );
341 }
342
344 if ( retval != PAPI_OK ) {
345 test_fail( __FILE__, __LINE__,
346 "PAPI_add_events failed\n", retval );
347 }
348
349
351 if ( retval != PAPI_OK ) {
352 test_fail( __FILE__, __LINE__,
353 "PAPI_start failed\n",retval );
354 }
355
357 if ( retval != PAPI_OK ) {
358 test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
359 }
360
361 if (!quiet) {
362 for(i=0;i<3;i++) {
363 printf("%lld ",values[i]);
364 }
365 printf("\n");
366 }
367
368 if (values[0]==0) {
369 test_fail( __FILE__, __LINE__, "Result should be != 0!\n", 0);
370 }
371
373 if (retval != PAPI_OK) {
374 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
375 }
376
378 if (retval != PAPI_OK) {
379 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
380 }
381
383
384 /***********************************/
385 /* Test writing to an event */
386 /***********************************/
387
388 if (!quiet) printf("Testing Write\n");
389
391 if ( retval != PAPI_OK ) {
392 test_fail( __FILE__, __LINE__,
393 "PAPI_create_eventset() failed\n", retval );
394 }
395
396 retval = PAPI_event_name_to_code("io:::rchar", &code);
397 if ( retval != PAPI_OK ) {
398 test_fail( __FILE__, __LINE__,
399 "io:::rchar not found\n",retval );
400 }
401
403 if ( retval != PAPI_OK ) {
404 test_fail( __FILE__, __LINE__,
405 "PAPI_add_events failed\n", retval );
406 }
407
408 retval = PAPI_event_name_to_code("io:::read_bytes", &code);
409 if ( retval != PAPI_OK ) {
410 test_fail( __FILE__, __LINE__,
411 "io:::read_bytes not found\n",retval );
412 }
413
415 if ( retval != PAPI_OK ) {
416 test_fail( __FILE__, __LINE__,
417 "PAPI_add_events failed\n", retval );
418 }
419
420 retval = PAPI_event_name_to_code("io:::wchar", &code);
421 if ( retval != PAPI_OK ) {
422 test_fail( __FILE__, __LINE__,
423 "io:::wchar not found\n",retval );
424 }
425
427 if ( retval != PAPI_OK ) {
428 test_fail( __FILE__, __LINE__,
429 "PAPI_add_events failed\n", retval );
430 }
431
432
434 if ( retval != PAPI_OK ) {
435 test_fail( __FILE__, __LINE__,
436 "PAPI_start failed\n",retval );
437 }
438
440 if ( retval != PAPI_OK ) {
441 test_fail( __FILE__, __LINE__,
442 "PAPI_read failed\n",retval );
443 }
444
445 if (!quiet) {
446 printf("Before values: ");
447 for(i=0;i<3;i++) {
448 printf("%lld ",values[i]);
449 }
450 printf("\n");
451 }
452
453 values[0]=100;
454 values[1]=200;
455 values[2]=300;
456
458 if ( retval != PAPI_OK ) {
459 test_fail( __FILE__, __LINE__,
460 "PAPI_write failed\n",retval );
461 }
462
464 if ( retval != PAPI_OK ) {
465 test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
466 }
467
468 if (!quiet) {
469 printf("After values: ");
470 for(i=0;i<3;i++) {
471 printf("%lld ",values[i]);
472 }
473 printf("\n");
474 }
475
476
477 if (values[0]==0) {
478 test_fail( __FILE__, __LINE__, "Result should be != 0!\n", 0);
479 }
480
482 if (retval != PAPI_OK) {
483 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
484 }
485
487 if (retval != PAPI_OK) {
488 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
489 }
490
492
493
494 /************/
495 /* All Done */
496 /************/
497
498 if (!quiet) printf("\n");
499
500 test_pass( __FILE__ );
501
502 return 0;
503}
504
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
Convert a name to a numeric hardware event code.
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.
Read hardware counters from an event set.
Reset the hardware event counts in an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Write counter values into counters.
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_VERSION
Definition: f90papi.h:193
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
#define NUM_EVENTS
Definition: io_basic.c:28
static struct counter_info * event_info
#define PAPI_NATIVE_MASK
Return codes and api definitions.
#define PAPI_VERSION_REVISION(x)
Definition: papi.h:221
#define PAPI_VERSION_MAJOR(x)
Definition: papi.h:219
#define PAPI_VERSION_MINOR(x)
Definition: papi.h:220
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
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
int retval
Definition: zero_fork.c:53