PAPI  5.7.0.0
inherit.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 
6 #if defined(_AIX) || defined (__FreeBSD__) || defined (__APPLE__)
7 #include <sys/wait.h> /* ARGH! */
8 #else
9 #include <wait.h>
10 #endif
11 
12 #include "papi.h"
13 #include "papi_test.h"
14 
15 #include "do_loops.h"
16 
17 int
18 main( int argc, char **argv )
19 {
21  long long int values[] = {0,0};
22  PAPI_option_t opt;
23  char event_name[BUFSIZ];
24  int quiet;
25 
26  quiet=tests_quiet( argc, argv );
27 
29  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
30 
31  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
32  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
33 
35  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
36 
37  memset( &opt, 0x0, sizeof ( PAPI_option_t ) );
40  if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) {
41  if ( retval == PAPI_ECMP) {
42  test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval );
43  } else if (retval == PAPI_EPERM) {
44  test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval );
45  } else {
46  test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval );
47  }
48  }
49 
50  if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK ) {
51  if (!quiet) printf("Trouble finding PAPI_TOT_CYC\n");
52  test_skip( __FILE__, __LINE__, "PAPI_query_event", retval );
53  }
54 
56  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
57 
58  strcpy(event_name,"PAPI_FP_INS");
60  if (retval == PAPI_ENOEVNT) {
61  strcpy(event_name,"PAPI_TOT_INS");
63  }
64 
65  if ( retval != PAPI_OK ) {
66  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
67  }
68 
69  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
70  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
71 
72  pid = fork( );
73  if ( pid == 0 ) {
75  exit( 0 );
76  }
77  if ( waitpid( pid, &status, 0 ) == -1 ) {
78  perror( "waitpid()" );
79  exit( 1 );
80  }
81 
82  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
83  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
84 
85  if (!quiet) {
86  printf( "Test case inherit: parent starts, child works, parent stops.\n" );
87  printf( "------------------------------------------------------------\n" );
88 
89  printf( "Test run : \t1\n" );
90  printf( "%s : \t%lld\n", event_name, values[1] );
91  printf( "PAPI_TOT_CYC: \t%lld\n", values[0] );
92  printf( "------------------------------------------------------------\n" );
93 
94  printf( "Verification:\n" );
95  printf( "Row 1 at least %d\n", NUM_FLOPS );
96  printf( "Row 2 greater than row 1\n");
97  }
98 
99  if ( values[1] < 100 ) {
100  test_fail( __FILE__, __LINE__, event_name, 1 );
101  }
102 
103  if ( (!strcmp(event_name,"PAPI_FP_INS")) && (values[1] < NUM_FLOPS)) {
104  test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 );
105  }
106 
107  test_pass( __FILE__ );
108 
109  return 0;
110 
111 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#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
int EventSet
PAPI_inherit_option_t inherit
Definition: papi.h:853
#define PAPI_EPERM
Definition: fpapi.h:120
int retval
Definition: zero_fork.c:53
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:849
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3465
#define PAPI_INHERIT
Definition: papi.h:459
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
#define PAPI_ECMP
Definition: fpapi.h:109
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
static int pid
#define PAPI_NULL
Definition: fpapi.h:13
int main(int argc, char **argv)
Definition: inherit.c:18
#define PAPI_INHERIT_ALL
Definition: papi.h:426
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
void do_flops(int n)
Definition: multiplex.c:23
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
long long status
Definition: iozone.c:1335
#define PAPI_ENOEVNT
Definition: fpapi.h:112
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define PAPI_TOT_CYC
Definition: fpapi.h:195
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void exit()