PAPI  5.3.2.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  char event_name[BUFSIZ];
17 
18  tests_quiet( argc, argv );
19 
20  if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
21  test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval );
22 
23  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
24  test_fail_exit( __FILE__, __LINE__, "PAPI_create_eventset", retval );
25 
26  if ( ( retval = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK )
27  test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
28 
29  memset( &opt, 0x0, sizeof ( PAPI_option_t ) );
32  if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) {
33  if ( retval == PAPI_ECMP) {
34  test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval );
35  } else {
36  test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval );
37  }
38  }
39 
40  if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK )
41  test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval );
42 
43  if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
44  test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
45 
46  strcpy(event_name,"PAPI_FP_INS");
47  retval = PAPI_add_named_event( EventSet, event_name );
48  if (retval == PAPI_ENOEVNT) {
49  strcpy(event_name,"PAPI_TOT_INS");
50  retval = PAPI_add_named_event( EventSet, event_name );
51  }
52 
53  if ( retval != PAPI_OK ) {
54  test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
55  }
56 
57  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
58  test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );
59 
60  pid = fork( );
61  if ( pid == 0 ) {
63  exit( 0 );
64  }
65  if ( waitpid( pid, &status, 0 ) == -1 ) {
66  perror( "waitpid()" );
67  exit( 1 );
68  }
69 
70  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
71  test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );
72 
73  if (!TESTS_QUIET) {
74  printf( "Test case inherit: parent starts, child works, parent stops.\n" );
75  printf( "------------------------------------------------------------\n" );
76 
77  printf( "Test run : \t1\n" );
78  printf( "%s : \t%lld\n", event_name, values[1] );
79  printf( "PAPI_TOT_CYC: \t%lld\n", values[0] );
80  printf( "------------------------------------------------------------\n" );
81 
82  printf( "Verification:\n" );
83  printf( "Row 1 at least %d\n", NUM_FLOPS );
84  printf( "Row 2 greater than row 1\n");
85  }
86 
87  if ( values[1] < 100 ) {
88  test_fail( __FILE__, __LINE__, event_name, 1 );
89  }
90 
91  if ( (!strcmp(event_name,"PAPI_FP_INS")) && (values[1] < NUM_FLOPS)) {
92  test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 );
93  }
94 
95  test_pass( __FILE__, NULL, 0 );
96  exit( 1 );
97 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define NUM_FLOPS
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1816
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:3371
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
#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
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1467
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
strcpy(filename, default_filename)
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:696
int EventSet
long long status
Definition: iozone.c:1335
int PAPI_start(int EventSet)
Definition: papi.c:2026
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()