PAPI 7.1.0.0
Loading...
Searching...
No Matches
derived.c
Go to the documentation of this file.
1/* This file performs the following test: start, stop with a derived event */
2
3#include <stdio.h>
4#include <stdlib.h>
5
6#include "papi.h"
7#include "papi_test.h"
8
9#include "do_loops.h"
10
11#define EVENTSLEN 2
12
13unsigned int PAPI_events[EVENTSLEN] = { 0, 0 };
14static const int PAPI_events_len = 1;
15
16int
17main( int argc, char **argv )
18{
19 int retval, tmp;
20 int EventSet = PAPI_NULL;
21 int i;
23 long long values;
24 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_2MAX_STR_LEN];
25 int quiet=0;
26
27 /* Set TESTS_QUIET variable */
28 quiet=tests_quiet( argc, argv );
29
31 if ( retval != PAPI_VER_CURRENT ) {
32 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
33 }
34
35 if (!quiet) {
36 printf( "Test case %s: start, stop with a derived counter.\n",
37 __FILE__ );
38 printf( "------------------------------------------------\n" );
39 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
40 printf( "Default domain is: %d (%s)\n", tmp,
42 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
43 printf( "Default granularity is: %d (%s)\n\n", tmp,
45 }
46
48 do {
49 if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
50 if ( info.count > 1 ) {
51 PAPI_events[0] = ( unsigned int ) info.event_code;
52 break;
53 }
54 }
55 } while ( PAPI_enum_event( &i, 0 ) == PAPI_OK );
56
57 if ( PAPI_events[0] == 0 ) {
58 test_skip(__FILE__, __LINE__, "No events found", 0);
59 }
60
62 if ( retval != PAPI_OK ) {
63 test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval );
64 }
65
66 for ( i = 0; i < PAPI_events_len; i++ ) {
68 if ( !quiet ) {
69 printf( "Adding %s\n", event_name );
70 }
72 if ( retval != PAPI_OK ) {
73 test_fail(__FILE__, __LINE__, "PAPI_add_event", retval );
74 }
75 }
76
78 if ( retval != PAPI_OK ) {
79 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
80 }
81
82 if (!quiet) printf( "Running do_stuff().\n" );
83
84 do_stuff( );
85
87 if ( retval != PAPI_OK ) {
88 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
89 }
90
91 if (!quiet) {
92
93 sprintf( add_event_str, "%-12s : \t", event_name );
94 printf( TAB1, add_event_str, values );
95 printf( "------------------------------------------------\n" );
96 }
97
99 if ( retval != PAPI_OK ) {
100 test_fail(__FILE__,__LINE__, "PAPI_cleanup_eventset", retval );
101 }
102
104 if ( retval != PAPI_OK ) {
105 test_fail(__FILE__,__LINE__, "PAPI_cleanup_eventset", retval );
106 }
107
108 if (!quiet) printf( "Verification: Does it produce a non-zero value?\n" );
109
110 if ( values != 0 ) {
111 if (!quiet) {
112 printf( "Yes: " );
113 printf( LLDFMT, values );
114 printf( "\n" );
115 }
116 }
117 else {
118 test_fail(__FILE__,__LINE__, "Validation", 1 );
119 }
120
121 test_pass(__FILE__);
122
123 return 0;
124}
double tmp
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.
Convert a numeric hardware event code to a name.
Get the event's name and description info.
Get PAPI library or event set options.
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
static const int PAPI_events_len
Definition: derived.c:14
unsigned int PAPI_events[EVENTSLEN]
Definition: derived.c:13
#define EVENTSLEN
Definition: derived.c:11
void do_stuff(void)
Definition: do_loops.c:256
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DEFGRN
Definition: f90papi.h:26
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_2MAX_STR_LEN
Definition: f90papi.h:180
#define PAPI_DEFDOM
Definition: f90papi.h:188
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
#define PAPI_PRESET_MASK
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
#define LLDFMT
Definition: papi_test.h:104
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define TAB1
Definition: papi_test.h:98
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
unsigned int count
Definition: papi.h:981
unsigned int event_code
Definition: papi.h:958
int retval
Definition: zero_fork.c:53