PAPI  5.7.0.0
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 <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 #include "papi.h"
22 #include "papi_test.h"
23 
24 int
25 main( int argc, char **argv )
26 {
27  int EventSet = PAPI_NULL;
28  int retval;
29  long long g1[2];
30  int eventcode = PAPI_TOT_INS;
31  PAPI_event_info_t info, info1, info2;
32  int quiet;
33 
34  /* Set TESTS_QUIET variable */
35  quiet=tests_quiet( argc, argv );
36 
37 
39  if (retval != PAPI_VER_CURRENT ) {
40  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
41  }
42 
43  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) {
44  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
45  }
46 
47  if ( ( retval = PAPI_query_event( eventcode ) ) != PAPI_OK ) {
48  if (!quiet) printf("Trouble checking event\n");
49  test_skip( __FILE__, __LINE__, "PAPI_query_event(PAPI_TOT_INS)",
50  retval );
51  }
52 
53  if ( ( retval = PAPI_add_event( EventSet, eventcode ) ) != PAPI_OK )
54  test_fail( __FILE__, __LINE__, "PAPI_add_event(PAPI_TOT_INS)", retval );
55 
56  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
57  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
58 
59  if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
60  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
61 
62  /* Case 0, no info, should fail */
63  eventcode = 0;
64 /*
65  if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) == PAPI_OK)
66  test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
67 */
68  if (!quiet) {
69  printf("This test expects a 'PAPI Error' to be returned from this PAPI call.\n");
70  }
71  if ( ( retval = PAPI_get_event_info( eventcode, &info ) ) == PAPI_OK )
72  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
73 
74  /* Case 1, fill in name field. */
75  eventcode = PAPI_TOT_INS;
76 /*
77  if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) != PAPI_OK)
78  test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
79 */
80  if ( ( retval = PAPI_get_event_info( eventcode, &info1 ) ) != PAPI_OK )
81  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
82 
83  if ( strcmp( info1.symbol, "PAPI_TOT_INS" ) != 0 )
84  test_fail( __FILE__, __LINE__,
85  "PAPI_get_event_info symbol value is bogus", retval );
86  if ( strlen( info1.long_descr ) == 0 )
87  test_fail( __FILE__, __LINE__,
88  "PAPI_get_event_info long_descr value is bogus", retval );
89 
90  eventcode = 0;
91 
92  /* Case 2, fill in code field. */
93 /*
94  if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) != PAPI_OK)
95  test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
96 */
97  if ( ( retval = PAPI_event_name_to_code( info1.symbol, ( int * ) &eventcode ) ) != PAPI_OK ) {
98  test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
99  }
100 
101  if ( eventcode != PAPI_TOT_INS )
102  test_fail( __FILE__, __LINE__,
103  "PAPI_event_name_to_code code value is bogus", retval );
104 
105  if ( ( retval = PAPI_get_event_info( eventcode, &info2 ) ) != PAPI_OK )
106  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
107 
108  if ( strcmp( info2.symbol, "PAPI_TOT_INS" ) != 0 )
109  test_fail( __FILE__, __LINE__,
110  "PAPI_get_event_info symbol value is bogus", retval );
111  if ( strlen( info2.long_descr ) == 0 )
112  test_fail( __FILE__, __LINE__,
113  "PAPI_get_event_info long_descr value is bogus", retval );
114 
115  test_pass( __FILE__ );
116 
117  return 0;
118 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:970
int EventSet
int PAPI_event_name_to_code(const char *in, int *out)
Definition: papi.c:1004
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_library_init(int version)
Definition: papi.c:500
#define PAPI_TOT_INS
Definition: fpapi.h:186
int quiet
Definition: rapl_overflow.c:18
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:967
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_query_event(int EventCode)
Definition: papi.c:684
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int main(int argc, char **argv)
Definition: describe.c:25
int PAPI_start(int EventSet)
Definition: papi.c:2096