PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
describe.c
Go to the documentation of this file.
1 /* From Paul Drongowski at HP. Thanks. */
2 
3 /* I have not been able to call PAPI_describe_event without
4  incurring a segv, including the sample code on the man page.
5  I noticed that PAPI_describe_event is not exercised by the
6  PAPI test programs, so I haven't been able to check the
7  function call using known good code. (Or steal your code
8  for that matter. :-)
9 */
10 
11 /* PAPI_describe_event has been deprecated in PAPI 3, since
12  its functionality exists in other API calls. Below shows
13  several ways that this call was used, with replacement
14  code compatible with PAPI 3.
15 */
16 
17 #include "papi_test.h"
18 
19 extern int TESTS_QUIET; /* Declared in test_utils.c */
20 
21 int
22 main( int argc, char **argv )
23 {
24  int EventSet = PAPI_NULL;
25  int retval;
26  long long g1[2];
27  int eventcode = PAPI_TOT_INS;
28  PAPI_event_info_t info, info1, info2;
29 
30  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
31 
32  if ( ( retval =
34  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
35 
36 
37  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
38  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
39 
40  if ( ( retval = PAPI_query_event( eventcode ) ) != PAPI_OK )
41  test_fail( __FILE__, __LINE__, "PAPI_query_event(PAPI_TOT_INS)",
42  retval );
43 
44  if ( ( retval = PAPI_add_event( EventSet, eventcode ) ) != PAPI_OK )
45  test_fail( __FILE__, __LINE__, "PAPI_add_event(PAPI_TOT_INS)", retval );
46 
47  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
48  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
49 
50  if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
51  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
52 
53  /* Case 0, no info, should fail */
54  eventcode = 0;
55 /*
56  if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) == PAPI_OK)
57  test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
58 */
59  if (!TESTS_QUIET) {
60  printf("This test expects a 'PAPI Error' to be returned from this PAPI call.\n");
61  }
62  if ( ( retval = PAPI_get_event_info( eventcode, &info ) ) == PAPI_OK )
63  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
64 
65  /* Case 1, fill in name field. */
66  eventcode = PAPI_TOT_INS;
67 /*
68  if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) != PAPI_OK)
69  test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
70 */
71  if ( ( retval = PAPI_get_event_info( eventcode, &info1 ) ) != PAPI_OK )
72  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
73 
74  if ( strcmp( info1.symbol, "PAPI_TOT_INS" ) != 0 )
75  test_fail( __FILE__, __LINE__,
76  "PAPI_get_event_info symbol value is bogus", retval );
77  if ( strlen( info1.long_descr ) == 0 )
78  test_fail( __FILE__, __LINE__,
79  "PAPI_get_event_info long_descr value is bogus", retval );
80 
81  eventcode = 0;
82 
83  /* Case 2, fill in code field. */
84 /*
85  if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) != PAPI_OK)
86  test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
87 */
88  if ( ( retval = PAPI_event_name_to_code( info1.symbol, ( int * ) &eventcode ) ) != PAPI_OK ) {
89  test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
90  }
91 
92  if ( eventcode != PAPI_TOT_INS )
93  test_fail( __FILE__, __LINE__,
94  "PAPI_event_name_to_code code value is bogus", retval );
95 
96  if ( ( retval = PAPI_get_event_info( eventcode, &info2 ) ) != PAPI_OK )
97  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
98 
99  if ( strcmp( info2.symbol, "PAPI_TOT_INS" ) != 0 )
100  test_fail( __FILE__, __LINE__,
101  "PAPI_get_event_info symbol value is bogus", retval );
102  if ( strlen( info2.long_descr ) == 0 )
103  test_fail( __FILE__, __LINE__,
104  "PAPI_get_event_info long_descr value is bogus", retval );
105 
106  test_pass( __FILE__, NULL, 0 );
107  exit( 1 );
108 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
#define PAPI_NULL
Definition: papi.h:290
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:966
int EventSet
Definition: data_range.c:25
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:846
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1010
int PAPI_query_event(int EventCode)
Definition: papi.c:698
int PAPI_start(int EventSet)
Definition: papi.c:2053
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
void exit()