PAPI  5.7.0.0
destroy.c
Go to the documentation of this file.
1 /* destroy.c */
2 
3 /* Test that PAPI_destroy_eventset() doesn't leak file descriptors */
4 
5 /* Run create/add/start/stop/remove/destroy in a large loop */
6 /* and make sure PAPI handles it OK */
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 #include "papi.h"
12 #include "papi_test.h"
13 
14 #include "testcode.h"
15 
16 #define NUM_EVENTS 1
17 #define NUM_LOOPS 16384
18 
19 int main( int argc, char **argv ) {
20 
21  int retval, i;
22  int EventSet1 = PAPI_NULL;
23  long long values[NUM_EVENTS];
24  int quiet=0;
25 
26  /* Set TESTS_QUIET variable */
27  quiet=tests_quiet( argc, argv );
28 
29  /* Init the PAPI library */
31  if ( retval != PAPI_VER_CURRENT ) {
32  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
33  }
34 
35  if (!quiet) {
36  printf("Testing to make sure we can destroy eventsets\n");
37  }
38 
39  for(i=0;i<NUM_LOOPS;i++) {
40 
41  /* Initialize the EventSet */
43  if (retval!=PAPI_OK) {
44  test_fail( __FILE__, __LINE__,
45  "PAPI_create_eventset", retval );
46  }
47 
48  /* Add PAPI_TOT_CYC */
49  retval=PAPI_add_named_event(EventSet1,"PAPI_TOT_CYC");
50  if (retval!=PAPI_OK) {
51  if (!quiet) {
52  printf("Trouble adding PAPI_TOT_CYC: %s\n",
54  }
55  test_fail( __FILE__, __LINE__,
56  "adding PAPI_TOT_CYC", retval );
57  }
58 
59  /* Start PAPI */
61  if ( retval != PAPI_OK ) {
62  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
63  }
64 
65  /* Stop PAPI */
67  if ( retval != PAPI_OK ) {
68  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
69  }
70 
71  /* Shutdown the EventSet */
72  retval = PAPI_remove_named_event( EventSet1, "PAPI_TOT_CYC" );
73  if (retval!=PAPI_OK) {
74  test_fail( __FILE__, __LINE__,
75  "PAPI_remove_named_event", retval );
76  }
77 
79  if (retval!=PAPI_OK) {
80  test_fail( __FILE__, __LINE__,
81  "PAPI_destroy_eventset", retval );
82  }
83 
84  }
85 
86  test_pass( __FILE__ );
87 
88  return 0;
89 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define NUM_EVENTS
Definition: destroy.c:16
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
#define NUM_LOOPS
Definition: destroy.c:17
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
char * PAPI_strerror(int errorCode)
Definition: papi.c:4603
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 PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_remove_named_event(int EventSet, const char *EventName)
Definition: papi.c:1961
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int main(int argc, char **argv)
Definition: destroy.c:19
int EventSet1
Definition: zero_fork.c:47
int i
Definition: fileop.c:140