PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
forkexec2.c File Reference
Include dependency graph for forkexec2.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file forkexec2.c.

34 {
35  int retval;
36  int status;
37  int quiet;
38 
39  /* Set TESTS_QUIET variable */
40  quiet = tests_quiet( argc, argv );
41 
42  if ( ( argc > 1 ) && ( strcmp( argv[1], "xxx" ) == 0 ) ) {
43  /* In child */
45  if ( retval != PAPI_VER_CURRENT ) {
46  test_fail( __FILE__, __LINE__, "execed PAPI_library_init", retval );
47  }
48  return 0;
49  } else {
50  if (!quiet) printf("Testing fork/PAPI_init/PAPI_shudtdown/exec/PAPI_init\n");
51 
52  /* Init PAPI */
54  if ( retval != PAPI_VER_CURRENT ) {
55  test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval );
56  }
57  PAPI_shutdown( );
58 
59  if ( fork( ) == 0 ) {
60  /* Init PAPI in child before exec */
62  if ( retval != PAPI_VER_CURRENT ) {
63  test_fail( __FILE__, __LINE__, "forked PAPI_library_init",
64  retval );
65  }
66 
67  PAPI_shutdown( );
68 
69  if ( execlp( argv[0], argv[0], "xxx", NULL ) == -1 ) {
70  test_fail( __FILE__, __LINE__, "execlp", PAPI_ESYS );
71  }
72  } else {
73  /* In parent, wait for child to finish */
74  wait( &status );
75  if ( WEXITSTATUS( status ) != 0 ) {
76  test_fail( __FILE__, __LINE__, "fork", WEXITSTATUS( status ) );
77  }
78  }
79  }
80 
81  test_pass( __FILE__ );
82 
83  return 0;
84 
85 }
void test_pass(const char *filename)
Definition: test_utils.c:432
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
void PAPI_shutdown(void)
Definition: papi.c:4461
int quiet
Definition: rapl_overflow.c:18
int wait()
#define PAPI_ESYS
Definition: papi.h:255
printf("\tTry: -i 0 -i 1 \n\n")
long long status
Definition: iozone.c:1335
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
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225

Here is the call graph for this function: