PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
api.c
Go to the documentation of this file.
1 /*
2  * File: api.c
3  * CVS: $Id$
4  * Author: Brian Sheely
5  * bsheely@eecs.utk.edu
6  *
7  * Description: This test is designed to provide unit testing and complete
8  * coverage for all functions which comprise the "Low Level API"
9  * and the "High Level API" as defined in papi.h.
10  */
11 
12 #include "papi.h"
13 #include "papi_test.h"
14 
15 int
16 main( int argc, char **argv )
17 {
18  const int NUM_COUNTERS = 1;
19  int Events[] = { PAPI_TOT_INS };
20  long long values[NUM_COUNTERS];
21  float rtime, ptime, ipc, mflips, mflops;
22  long long ins, flpins, flpops;
23  int retval;
24 
25  tests_quiet( argc, argv );
26 
28  if ( retval != PAPI_VER_CURRENT )
29  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
30 
31 
32  /****** High Level API ******/
33 
34  if ( !TESTS_QUIET )
35  printf( "Testing PAPI_num_components... " );
36 
37  /* get the number of components available on the system */
38  retval = PAPI_num_components( );
39  if ( !TESTS_QUIET ) printf( "%d\n", retval );
40 
41  if ( retval == 0) {
42  if ( !TESTS_QUIET ) printf( "No components found, skipping high level tests\n");
43  }
44 
45  else {
46 
47  if ( !TESTS_QUIET ) printf( "Testing PAPI_num_counters... " );
48 
49  /* get the number of hardware counters available on the system */
50  retval = PAPI_num_counters( );
51  if ( retval != PAPI_get_cmp_opt( PAPI_MAX_HWCTRS, NULL, 0 ) )
52  test_fail_exit( __FILE__, __LINE__, "PAPI_num_counters", retval );
53  else if ( !TESTS_QUIET ) printf( "%d\n", retval );
54 
55 
56  if ( !TESTS_QUIET ) printf( "Testing PAPI_start_counters... " );
57  retval = PAPI_start_counters( NULL, NUM_COUNTERS ); // pass invalid 1st argument
58  if ( retval != PAPI_EINVAL )
59  test_fail_exit( __FILE__, __LINE__, "PAPI_start_counters", retval );
60  retval = PAPI_start_counters( Events, 0 ); // pass invalid 2nd argument
61  if ( retval != PAPI_EINVAL )
62  test_fail_exit( __FILE__, __LINE__, "PAPI_start_counters", retval );
63  retval = PAPI_start_counters( Events, NUM_COUNTERS ); // start counting hardware events
64  if ( retval != PAPI_OK )
65  test_fail_exit( __FILE__, __LINE__, "PAPI_start_counters", retval );
66  else if ( !TESTS_QUIET )
67  printf( "started PAPI_TOT_INS\n" );
68 
69 
70  if ( !TESTS_QUIET )
71  printf( "Testing PAPI_stop_counters... " );
72  retval = PAPI_stop_counters( NULL, NUM_COUNTERS ); // pass invalid 1st argument
73  if ( retval != PAPI_EINVAL )
74  test_fail_exit( __FILE__, __LINE__, "PAPI_stop_counters", retval );
75  retval = PAPI_stop_counters( values, 0 ); // pass invalid 2nd argument
76  if ( retval != PAPI_EINVAL )
77  test_fail_exit( __FILE__, __LINE__, "PAPI_stop_counters", retval );
78  retval = PAPI_stop_counters( values, NUM_COUNTERS ); // stop counters and return current counts
79  if ( retval != PAPI_OK )
80  test_fail_exit( __FILE__, __LINE__, "PAPI_stop_counters", retval );
81  else if ( !TESTS_QUIET )
82  printf( "stopped counting PAPI_TOT_INS\n" );
83  //NOTE: There are currently no checks on whether or not counter values are correct
84 
85 
86  retval = PAPI_start_counters( Events, NUM_COUNTERS ); // start counting hardware events again
87  if ( retval != PAPI_OK )
88  test_fail_exit( __FILE__, __LINE__, "PAPI_start_counters", retval );
89 
90 
91  if ( !TESTS_QUIET )
92  printf( "Testing PAPI_read_counters... " );
93  retval = PAPI_read_counters( NULL, NUM_COUNTERS ); // pass invalid 1st argument
94  if ( retval != PAPI_EINVAL )
95  test_fail_exit( __FILE__, __LINE__, "PAPI_read_counters", retval );
96  retval = PAPI_read_counters( values, 0 ); // pass invalid 2nd argument
97  if ( retval != PAPI_EINVAL )
98  test_fail_exit( __FILE__, __LINE__, "PAPI_read_counters", retval );
99  retval = PAPI_read_counters( values, NUM_COUNTERS ); // copy current counts to array and reset counters
100  if ( retval != PAPI_OK )
101  test_fail_exit( __FILE__, __LINE__, "PAPI_read_counters", retval );
102  else if ( !TESTS_QUIET )
103  printf( "read PAPI_TOT_INS counts and reset counter\n" );
104  //NOTE: There are currently no checks on whether or not counter values are correct
105 
106 
107  if ( !TESTS_QUIET )
108  printf( "Testing PAPI_accum_counters... " );
109  retval = PAPI_accum_counters( NULL, NUM_COUNTERS ); // pass invalid 1st argument
110  if ( retval != PAPI_EINVAL )
111  test_fail_exit( __FILE__, __LINE__, "PAPI_accum_counters", retval );
112  retval = PAPI_accum_counters( values, 0 ); // pass invalid 2nd argument
113  if ( retval != PAPI_EINVAL )
114  test_fail_exit( __FILE__, __LINE__, "PAPI_accum_counters", retval );
115  retval = PAPI_accum_counters( values, NUM_COUNTERS ); // add current counts to array and reset counters
116  if ( retval != PAPI_OK )
117  test_fail_exit( __FILE__, __LINE__, "PAPI_accum_counters", retval );
118  else if ( !TESTS_QUIET )
119  printf( "added PAPI_TOT_INS counts and reset counter\n" );
120  //NOTE: There are currently no checks on whether or not counter values are correct
121 
122 
123  retval = PAPI_stop_counters( values, NUM_COUNTERS ); // stop counting hardware events
124  if ( retval != PAPI_OK )
125  test_fail_exit( __FILE__, __LINE__, "PAPI_stop_counters", retval );
126 
127 
128  if ( !TESTS_QUIET )
129  printf( "Testing PAPI_ipc... " );
130  retval = PAPI_ipc( NULL, &ptime, &ins, &ipc ); // pass invalid 1st argument
131  if ( retval != PAPI_EINVAL )
132  test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
133  retval = PAPI_ipc( &rtime, NULL, &ins, &ipc ); // pass invalid 2nd argument
134  if ( retval != PAPI_EINVAL )
135  test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
136  retval = PAPI_ipc( &rtime, &ptime, NULL, &ipc ); // pass invalid 3rd argument
137  if ( retval != PAPI_EINVAL )
138  test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
139  retval = PAPI_ipc( &rtime, &ptime, &ins, NULL ); // pass invalid 4th argument
140  if ( retval != PAPI_EINVAL )
141  test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
142  retval = PAPI_ipc( &rtime, &ptime, &ins, &ipc ); // get instructions per cycle, real and processor time
143  if ( retval != PAPI_OK )
144  test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
145  else if ( !TESTS_QUIET )
146  printf( "got instructions per cycle, real and processor time\n" );
147  //NOTE: There are currently no checks on whether or not returned values are correct
148 
149 
150  //NOTE: PAPI_flips and PAPI_flops fail if any other low-level calls have been made!
151  PAPI_shutdown( );
153  if ( retval != PAPI_VER_CURRENT )
154  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
155 
156 
157  if ( !TESTS_QUIET )
158  printf( "Testing PAPI_flips... " );
159  retval = PAPI_flips( NULL, &ptime, &flpins, &mflips ); // pass invalid 1st argument
160  if ( retval != PAPI_EINVAL )
161  test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
162  retval = PAPI_flips( &rtime, NULL, &flpins, &mflips ); // pass invalid 2nd argument
163  if ( retval != PAPI_EINVAL )
164  test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
165  retval = PAPI_flips( &rtime, &ptime, NULL, &mflips ); // pass invalid 3rd argument
166  if ( retval != PAPI_EINVAL )
167  test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
168  retval = PAPI_flips( &rtime, &ptime, &flpins, NULL ); // pass invalid 4th argument
169  if ( retval != PAPI_EINVAL )
170  test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
171  retval = PAPI_flips( &rtime, &ptime, &flpins, &mflips ); // get Mflips/s, real and processor time
172  if ( retval == PAPI_ENOEVNT )
173  test_warn( __FILE__, __LINE__, "PAPI_flips", retval);
174  else if ( retval != PAPI_OK )
175  test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
176  else if ( !TESTS_QUIET )
177  printf( "got Mflips/s, real and processor time\n" );
178  //NOTE: There are currently no checks on whether or not returned values are correct
179 
180 
181  PAPI_shutdown( );
183  if ( retval != PAPI_VER_CURRENT )
184  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
185 
186 
187  if ( !TESTS_QUIET )
188  printf( "Testing PAPI_flops... " );
189  retval = PAPI_flops( NULL, &ptime, &flpops, &mflops ); // pass invalid 1st argument
190  if ( retval != PAPI_EINVAL )
191  test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval );
192  retval = PAPI_flops( &rtime, NULL, &flpops, &mflops ); // pass invalid 2nd argument
193  if ( retval != PAPI_EINVAL )
194  test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval );
195  retval = PAPI_flops( &rtime, &ptime, NULL, &mflops ); // pass invalid 3rd argument
196  if ( retval != PAPI_EINVAL )
197  test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval );
198  retval = PAPI_flops( &rtime, &ptime, &flpops, NULL ); // pass invalid 4th argument
199  if ( retval != PAPI_EINVAL )
200  test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval );
201  retval = PAPI_flops( &rtime, &ptime, &flpops, &mflops ); // get Mflops/s, real and processor time
202  if ( retval == PAPI_ENOEVNT )
203  test_warn( __FILE__, __LINE__, "PAPI_flops", retval);
204  else if ( retval != PAPI_OK ) {
205  test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval ); }
206  else if ( !TESTS_QUIET ) {
207  printf( "got Mflops/s, real and processor time\n" ); }
208  //NOTE: There are currently no checks on whether or not returned values are correct
209  }
210 
211  /***************************/
212  /****** Low Level API ******/
213  /***************************/
214 /*
215  int PAPI_accum(int EventSet, long long * values); // accumulate and reset hardware events from an event set
216  int PAPI_add_event(int EventSet, int Event); // add single PAPI preset or native hardware event to an event set
217  int PAPI_add_events(int EventSet, int *Events, int number); // add array of PAPI preset or native hardware events to an event set
218  int PAPI_assign_eventset_component(int EventSet, int cidx); // assign a component index to an existing but empty eventset
219  int PAPI_attach(int EventSet, unsigned long tid); // attach specified event set to a specific process or thread id
220  int PAPI_cleanup_eventset(int EventSet); // remove all PAPI events from an event set
221  int PAPI_create_eventset(int *EventSet); // create a new empty PAPI event set
222  int PAPI_detach(int EventSet); // detach specified event set from a previously specified process or thread id
223  int PAPI_destroy_eventset(int *EventSet); // deallocates memory associated with an empty PAPI event set
224  int PAPI_enum_event(int *EventCode, int modifier); // return the event code for the next available preset or natvie event
225  int PAPI_event_code_to_name(int EventCode, char *out); // translate an integer PAPI event code into an ASCII PAPI preset or native name
226  int PAPI_event_name_to_code(char *in, int *out); // translate an ASCII PAPI preset or native name into an integer PAPI event code
227  int PAPI_get_dmem_info(PAPI_dmem_info_t *dest); // get dynamic memory usage information
228  int PAPI_get_event_info(int EventCode, PAPI_event_info_t * info); // get the name and descriptions for a given preset or native event code
229  const PAPI_exe_info_t *PAPI_get_executable_info(void); // get the executable's address space information
230  const PAPI_hw_info_t *PAPI_get_hardware_info(void); // get information about the system hardware
231  const PAPI_component_info_t *PAPI_get_component_info(int cidx); // get information about the component features
232  int PAPI_get_multiplex(int EventSet); // get the multiplexing status of specified event set
233  int PAPI_get_opt(int option, PAPI_option_t * ptr); // query the option settings of the PAPI library or a specific event set
234  int PAPI_get_cmp_opt(int option, PAPI_option_t * ptr,int cidx); // query the component specific option settings of a specific event set
235  long long PAPI_get_real_cyc(void); // return the total number of cycles since some arbitrary starting point
236  long long PAPI_get_real_nsec(void); // return the total number of nanoseconds since some arbitrary starting point
237  long long PAPI_get_real_usec(void); // return the total number of microseconds since some arbitrary starting point
238  const PAPI_shlib_info_t *PAPI_get_shared_lib_info(void); // get information about the shared libraries used by the process
239  int PAPI_get_thr_specific(int tag, void **ptr); // return a pointer to a thread specific stored data structure
240  int PAPI_get_overflow_event_index(int Eventset, long long overflow_vector, int *array, int *number); // # decomposes an overflow_vector into an event index array
241  long long PAPI_get_virt_cyc(void); // return the process cycles since some arbitrary starting point
242  long long PAPI_get_virt_nsec(void); // return the process nanoseconds since some arbitrary starting point
243  long long PAPI_get_virt_usec(void); // return the process microseconds since some arbitrary starting point
244  int PAPI_is_initialized(void); // return the initialized state of the PAPI library
245  int PAPI_library_init(int version); // initialize the PAPI library
246  int PAPI_list_events(int EventSet, int *Events, int *number); // list the events that are members of an event set
247  int PAPI_list_threads(unsigned long *tids, int *number); // list the thread ids currently known to PAPI
248  int PAPI_lock(int); // lock one of two PAPI internal user mutex variables
249  int PAPI_multiplex_init(void); // initialize multiplex support in the PAPI library
250  int PAPI_num_hwctrs(void); // return the number of hardware counters for the cpu
251  int PAPI_num_cmp_hwctrs(int cidx); // return the number of hardware counters for a specified component
252  int PAPI_num_hwctrs(void); // for backward compatibility
253  int PAPI_num_events(int EventSet); // return the number of events in an event set
254  int PAPI_overflow(int EventSet, int EventCode, int threshold,
255  int flags, PAPI_overflow_handler_t handler); // set up an event set to begin registering overflows
256  int PAPI_perror( char *msg); // convert PAPI error codes to strings
257  int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset,
258  unsigned scale, int EventSet, int EventCode,
259  int threshold, int flags); // generate PC histogram data where hardware counter overflow occurs
260  int PAPI_query_event(int EventCode); // query if a PAPI event exists
261  int PAPI_read(int EventSet, long long * values); // read hardware events from an event set with no reset
262  int PAPI_read_ts(int EventSet, long long * values, long long *cyc);
263  int PAPI_register_thread(void); // inform PAPI of the existence of a new thread
264  int PAPI_remove_event(int EventSet, int EventCode); // remove a hardware event from a PAPI event set
265  int PAPI_remove_events(int EventSet, int *Events, int number); // remove an array of hardware events from a PAPI event set
266  int PAPI_reset(int EventSet); // reset the hardware event counts in an event set
267  int PAPI_set_debug(int level); // set the current debug level for PAPI
268  int PAPI_set_cmp_domain(int domain, int cidx); // set the component specific default execution domain for new event sets
269  int PAPI_set_domain(int domain); // set the default execution domain for new event sets
270  int PAPI_set_cmp_granularity(int granularity, int cidx); // set the component specific default granularity for new event sets
271  int PAPI_set_granularity(int granularity); //set the default granularity for new event sets
272  int PAPI_set_multiplex(int EventSet); // convert a standard event set to a multiplexed event set
273  int PAPI_set_opt(int option, PAPI_option_t * ptr); // change the option settings of the PAPI library or a specific event set
274  int PAPI_set_thr_specific(int tag, void *ptr); // save a pointer as a thread specific stored data structure
275  void PAPI_shutdown(void); // finish using PAPI and free all related resources
276  int PAPI_sprofil(PAPI_sprofil_t * prof, int profcnt, int EventSet, int EventCode, int threshold, int flags); // generate hardware counter profiles from multiple code regions
277  int PAPI_start(int EventSet); // start counting hardware events in an event set
278  int PAPI_state(int EventSet, int *status); // return the counting state of an event set
279  int PAPI_stop(int EventSet, long long * values); // stop counting hardware events in an event set and return current events
280  char *PAPI_strerror(int); // return a pointer to the error message corresponding to a specified error code
281  unsigned long PAPI_thread_id(void); // get the thread identifier of the current thread
282  int PAPI_thread_init(unsigned long (*id_fn) (void)); // initialize thread support in the PAPI library
283  int PAPI_unlock(int); // unlock one of two PAPI internal user mutex variables
284  int PAPI_unregister_thread(void); // inform PAPI that a previously registered thread is disappearing
285  int PAPI_write(int EventSet, long long * values); // write counter values into counters
286 */
287  test_pass( __FILE__, NULL, 0 );
288  exit( 1 );
289 }
#define PAPI_ENOEVNT
Definition: papi.h:258
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
int PAPI_ipc(float *rtime, float *ptime, long long *ins, float *ipc)
Definition: papi_hl.c:316
int PAPI_flops(float *rtime, float *ptime, long long *flpops, float *mflops)
Definition: papi_hl.c:259
int PAPI_accum_counters(long long *values, int array_len)
Definition: papi_hl.c:756
int PAPI_num_components(void)
Definition: papi.c:4326
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
return PAPI_EINVAL
Definition: linux-nvml.c:408
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
int PAPI_flips(float *rtime, float *ptime, long long *flpins, float *mflips)
Definition: papi_hl.c:204
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
void PAPI_shutdown(void)
Definition: papi.c:4400
int PAPI_get_cmp_opt(int option, PAPI_option_t *ptr, int cidx)
Definition: papi.c:4274
int PAPI_read_counters(long long *values, int array_len)
Definition: papi_hl.c:706
int PAPI_num_counters(void)
Definition: papi_hl.c:537
int PAPI_start_counters(int *events, int array_len)
Definition: papi_hl.c:593
#define PAPI_MAX_HWCTRS
Definition: papi.h:441
void test_fail_exit(char *file, int line, char *call, int retval)
Definition: test_utils.c:567
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
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()