PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
forkexec3.c
Go to the documentation of this file.
1 /*
2 * File: forkexec3.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  PAPI_shutdown()
11  fork()
12  / \
13  parent child
14  wait() PAPI_library_init()
15  **unlike forkexec2, no shutdown here**
16  execlp()
17  PAPI_library_init()
18 
19  */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <sys/wait.h>
26 
27 #include "papi.h"
28 #include "papi_test.h"
29 
30 
31 int
32 main( int argc, char **argv )
33 {
34  int retval;
35  int status;
36  int quiet;
37 
38  /* Set TESTS_QUIET variable */
39  quiet = tests_quiet( argc, argv );
40 
41  if ( ( argc > 1 ) && ( strcmp( argv[1], "xxx" ) == 0 ) ) {
42  /* In child */
44  if ( retval != PAPI_VER_CURRENT ) {
45  test_fail( __FILE__, __LINE__, "execed PAPI_library_init", retval );
46  }
47  return 0;
48  } else {
49  if (!quiet) printf("Testing Init/Shutdown/fork/init/exec/init\n");
50  /* Init PAPI */
52  if ( retval != PAPI_VER_CURRENT )
53  test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval );
54 
55  PAPI_shutdown( );
56 
57  if ( fork( ) == 0 ) {
58  /* In child */
60  if ( retval != PAPI_VER_CURRENT ) {
61  test_fail( __FILE__, __LINE__, "forked PAPI_library_init",
62  retval );
63  }
64 
65  if ( execlp( argv[0], argv[0], "xxx", NULL ) == -1 ) {
66  test_fail( __FILE__, __LINE__, "execlp", PAPI_ESYS );
67  }
68  } else {
69  wait( &status );
70  if ( WEXITSTATUS( status ) != 0 ) {
71  test_fail( __FILE__, __LINE__, "fork", WEXITSTATUS( status ) );
72  }
73  }
74  }
75 
76  test_pass( __FILE__ );
77 
78  return 0;
79 
80 }
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
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
int main(int argc, char **argv)
List all appio events codes and names.