PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
forkexec4.c
Go to the documentation of this file.
1 /*
2 * File: forkexec4.c
3 * Author: Philip Mucci
4 * mucci@cs.utk.edu
5 */
6 
7 /* This file performs the following test:
8 
9  PAPI_library_init()
10  ** unlike forkexec2/forkexec3, no shutdown here **
11  fork()
12  / \
13  parent child
14  wait() PAPI_library_init()
15  execlp()
16  PAPI_library_init()
17 
18  */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <string.h>
24 #include <sys/wait.h>
25 
26 #include "papi.h"
27 #include "papi_test.h"
28 
29 
30 int
31 main( int argc, char **argv )
32 {
33  int retval;
34  int status;
35  int quiet;
36 
37  /* Set TESTS_QUIET variable */
38  quiet = tests_quiet( argc, argv );
39 
40  if ( ( argc > 1 ) && ( strcmp( argv[1], "xxx" ) == 0 ) ) {
41  /* In child */
43  if ( retval != PAPI_VER_CURRENT ) {
44  test_fail( __FILE__, __LINE__, "execed PAPI_library_init", retval );
45  }
46  return 0;
47  } else {
48  if (!quiet) printf("Testing Init/fork/exec/Init\n");
49 
50  /* Init PAPI */
52  if ( retval != PAPI_VER_CURRENT ) {
53  test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval );
54  }
55 
56  if ( fork( ) == 0 ) {
57  /* In Child */
59  if ( retval != PAPI_VER_CURRENT ) {
60  test_fail( __FILE__, __LINE__, "forked PAPI_library_init",
61  retval );
62  }
63 
64  if ( execlp( argv[0], argv[0], "xxx", NULL ) == -1 ) {
65  test_fail( __FILE__, __LINE__, "execlp", PAPI_ESYS );
66  }
67  } else {
68  /* Waiting in parent */
69  wait( &status );
70  if ( WEXITSTATUS( status ) != 0 ) {
71  test_fail( __FILE__, __LINE__, "fork", WEXITSTATUS( status ) );
72  } }
73  }
74 
75  test_pass( __FILE__ );
76 
77  return 0;
78 }
void test_pass(const char *filename)
Definition: test_utils.c:432
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
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
int main(int argc, char **argv)
List all appio events codes and names.