PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
inherit.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <unistd.h>
3 #if defined(_AIX) || defined (__FreeBSD__) || defined (__APPLE__)
4 #include <sys/wait.h> /* ARGH! */
5 #else
6 #include <wait.h>
7 #endif
8 #include "papi_test.h"
9 
10 int
11 main( int argc, char **argv )
12 {
14  long long int values[] = {0,0};
15  PAPI_option_t opt;
16 
17  tests_quiet( argc, argv );
18 
19  if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
20  test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval );
21 
22  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
23  test_fail_exit( __FILE__, __LINE__, "PAPI_create_eventset", retval );
24 
25  if ( ( retval = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK )
26  test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
27 
28  memset( &opt, 0x0, sizeof ( PAPI_option_t ) );
31  if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) {
32  if ( retval == PAPI_ECMP) {
33  test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval );
34  } else {
35  test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval );
36  }
37  }
38 
39  if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK )
40  test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval );
41 
42  if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
43  test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
44 
45  retval = PAPI_query_event( PAPI_FP_INS );
46  if ( retval == PAPI_ENOEVNT ) {
47  test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval);
48  values[1] = NUM_FLOPS; /* fake a return value to pass the test */
49  } else if ( retval != PAPI_OK )
50  test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval );
51  else if ( ( retval = PAPI_add_event( EventSet, PAPI_FP_INS ) ) != PAPI_OK )
52  test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
53 
54  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
55  test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );
56 
57  pid = fork( );
58  if ( pid == 0 ) {
60  exit( 0 );
61  }
62  if ( waitpid( pid, &status, 0 ) == -1 ) {
63  perror( "waitpid()" );
64  exit( 1 );
65  }
66 
67  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
68  test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );
69 
70  if (!TESTS_QUIET) {
71  printf( "Test case inherit: parent starts, child works, parent stops.\n" );
72  printf( "------------------------------------------------------------\n" );
73 
74  printf( "Test run : \t1\n" );
75  printf( "PAPI_FP_INS : \t%lld\n", values[1] );
76  printf( "PAPI_TOT_CYC: \t%lld\n", values[0] );
77  printf( "------------------------------------------------------------\n" );
78 
79  printf( "Verification:\n" );
80  printf( "Row 1 at least %d\n", NUM_FLOPS );
81  printf( "Row 2 greater than row 1\n");
82  }
83 
84  if ( values[1] < NUM_FLOPS) {
85  test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 );
86  }
87 
88  if ( values[0] < values[1]) {
89  test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC < PAPI_FP_INS", 1 );
90  }
91 
92  test_pass( __FILE__, NULL, 0 );
93  exit( 1 );
94 }
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define NUM_FLOPS
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
#define PAPI_NULL
Definition: fpapi.h:13
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_ENOEVNT
Definition: fpapi.h:112
return PAPI_OK
Definition: linux-nvml.c:458
PAPI_inherit_option_t inherit
Definition: papi.h:847
tests_quiet(argc, argv)
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3360
int int argc
Definition: iozone.c:1609
#define PAPI_INHERIT
Definition: papi.h:456
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:495
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
#define PAPI_TOT_CYC
Definition: fpapi.h:194
static int pid
#define PAPI_ECMP
Definition: fpapi.h:109
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_INHERIT_ALL
Definition: papi.h:423
#define PAPI_FP_INS
Definition: fpapi.h:187
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1460
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:695
int EventSet
long long status
Definition: iozone.c:1335
int PAPI_start(int EventSet)
Definition: papi.c:2019
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
int main(int argc, char **argv)
List all appio events codes and names.
void exit()