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