PAPI 7.1.0.0
Loading...
Searching...
No Matches
forkexec.c
Go to the documentation of this file.
1/*
2* File: forkexec.c
3* Author: Philip Mucci
4* mucci@cs.utk.edu
5* Mods: <your name here>
6* <your email address>
7*/
8
9/* This file performs the following test:
10
11 PAPI_library_init();
12 PAPI_shutdown()
13 fork()
14 / \
15 parent child
16 wait() 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
31int
32main( int argc, char **argv )
33{
34 int retval;
35 int quiet;
36 int status;
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("Test fork/exec/PAPI_init\n");
50 /* Init PAPI */
52 if ( retval != PAPI_VER_CURRENT ) {
53 test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval );
54 }
55 /* Then shut down ? */
57
58 if ( fork( ) == 0 ) {
59 /* In child, exec ourself with "xxx" command line */
60 if ( execlp( argv[0], argv[0], "xxx", NULL ) == -1 ) {
61 test_fail( __FILE__, __LINE__, "execlp", PAPI_ESYS );
62 }
63 } else {
64 /* In parent, wait for child to finish */
65 wait( &status );
66 if ( WEXITSTATUS( status ) != 0 ) {
67 test_fail( __FILE__, __LINE__, "fork", WEXITSTATUS( status ) );
68 }
69 }
70 }
71
72 test_pass( __FILE__ );
73
74 return 0;
75
76}
initialize the PAPI library.
Finish using PAPI and free all related resources.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ESYS
Definition: f90papi.h:136
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
int retval
Definition: zero_fork.c:53