PAPI  5.3.0.0
forkexec4.c
Go to the documentation of this file.
00001 /* 
00002 * File:    forkexec4.c
00003 * Author:  Philip Mucci
00004 *          mucci@cs.utk.edu
00005 * Mods:    <your name here>
00006 *          <your email address>
00007 */
00008 
00009 /* This file performs the following test:
00010 
00011                   PAPI_library_init()
00012        ** unlike forkexec2/forkexec3, no shutdown here **
00013                        fork()
00014                       /      \
00015                   parent    child
00016                   wait()   PAPI_library_init()
00017                execlp()
00018                PAPI_library_init()
00019 
00020  */
00021 
00022 #include "papi_test.h"
00023 #include <sys/wait.h>
00024 
00025 int
00026 main( int argc, char **argv )
00027 {
00028     int retval;
00029     int status;
00030 
00031     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00032 
00033     if ( ( argc > 1 ) && ( strcmp( argv[1], "xxx" ) == 0 ) ) {
00034         retval = PAPI_library_init( PAPI_VER_CURRENT );
00035         if ( retval != PAPI_VER_CURRENT )
00036             test_fail( __FILE__, __LINE__, "execed PAPI_library_init", retval );
00037     } else {
00038         retval = PAPI_library_init( PAPI_VER_CURRENT );
00039         if ( retval != PAPI_VER_CURRENT )
00040             test_fail( __FILE__, __LINE__, "main PAPI_library_init", retval );
00041 
00042         if ( fork(  ) == 0 ) {
00043             retval = PAPI_library_init( PAPI_VER_CURRENT );
00044             if ( retval != PAPI_VER_CURRENT )
00045                 test_fail( __FILE__, __LINE__, "forked PAPI_library_init",
00046                            retval );
00047 
00048             if ( execlp( argv[0], argv[0], "xxx", NULL ) == -1 )
00049                 test_fail( __FILE__, __LINE__, "execlp", PAPI_ESYS );
00050         } else {
00051             wait( &status );
00052             if ( WEXITSTATUS( status ) != 0 )
00053                 test_fail( __FILE__, __LINE__, "fork", WEXITSTATUS( status ) );
00054         }
00055     }
00056 
00057     test_pass( __FILE__, NULL, 0 );
00058     exit( 1 );
00059 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines