|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* File: forkexec2.c
|
|
Packit |
577717 |
* Author: Philip Mucci
|
|
Packit |
577717 |
* mucci@cs.utk.edu
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* This file performs the following test:
|
|
Packit |
577717 |
|
|
Packit |
577717 |
PAPI_library_init()
|
|
Packit |
577717 |
PAPI_shutdown()
|
|
Packit |
577717 |
fork()
|
|
Packit |
577717 |
/ \
|
|
Packit |
577717 |
parent child
|
|
Packit |
577717 |
wait() PAPI_library_init()
|
|
Packit |
577717 |
PAPI_shutdown()
|
|
Packit |
577717 |
execlp()
|
|
Packit |
577717 |
PAPI_library_init()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include <string.h>
|
|
Packit |
577717 |
#include <unistd.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <sys/wait.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
#include "papi_test.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
main( int argc, char **argv )
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
int status;
|
|
Packit |
577717 |
int quiet;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Set TESTS_QUIET variable */
|
|
Packit |
577717 |
quiet = tests_quiet( argc, argv );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( ( argc > 1 ) && ( strcmp( argv[1], "xxx" ) == 0 ) ) {
|
|
Packit |
577717 |
/* In child */
|
|
Packit |
577717 |
retval = PAPI_library_init( PAPI_VER_CURRENT );
|
|
Packit |
577717 |
if ( retval != PAPI_VER_CURRENT ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "execed PAPI_library_init", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
if (!quiet) printf("Testing fork/PAPI_init/PAPI_shudtdown/exec/PAPI_init\n");
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Init PAPI */
|
|
Packit |
577717 |
retval = PAPI_library_init( PAPI_VER_CURRENT );
|
|
Packit |
577717 |
if ( retval != PAPI_VER_CURRENT ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
PAPI_shutdown( );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( fork( ) == 0 ) {
|
|
Packit |
577717 |
/* Init PAPI in child before exec */
|
|
Packit |
577717 |
retval = PAPI_library_init( PAPI_VER_CURRENT );
|
|
Packit |
577717 |
if ( retval != PAPI_VER_CURRENT ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "forked PAPI_library_init",
|
|
Packit |
577717 |
retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
PAPI_shutdown( );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( execlp( argv[0], argv[0], "xxx", NULL ) == -1 ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "execlp", PAPI_ESYS );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
} else {
|
|
Packit |
577717 |
/* In parent, wait for child to finish */
|
|
Packit |
577717 |
wait( &status );
|
|
Packit |
577717 |
if ( WEXITSTATUS( status ) != 0 ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "fork", WEXITSTATUS( status ) );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
test_pass( __FILE__ );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
}
|