diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/12-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/12-1.c new file mode 100644 index 0000000000..3d69095921 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/12-1.c @@ -0,0 +1,287 @@ +/* +* Copyright (c) 2004, Bull S.A.. All rights reserved. +* Created by: Sebastien Decugis + +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write the Free Software Foundation, Inc., 59 +* Temple Place - Suite 330, Boston MA 02111-1307, USA. + + +* This sample test aims to check the following assertion: +* +* The child process is created with no pending signal + +* The steps are: +* -> block SIGUSR1 and SIGUSR2 +* -> send those signals and wait they are pending +* -> fork +* -> check the signals are blocked but not pending in the new process. + +* The test fails if the signals are pending or if +* they are not blocked (this counters assertion 2). + +*/ + + +/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ +#define _POSIX_C_SOURCE 200112L + +/********************************************************************************************/ +/****************************** standard includes *****************************************/ +/********************************************************************************************/ +#include + #include + #include + #include + #include + #include + +#include + #include + +#include + +/********************************************************************************************/ +/****************************** Test framework *****************************************/ +/********************************************************************************************/ +#include "testfrmw.h" + #include "testfrmw.c" +/* This header is responsible for defining the following macros: + * UNRESOLVED(ret, descr); + * where descr is a description of the error and ret is an int (error code for example) + * FAILED(descr); + * where descr is a short text saying why the test has failed. + * PASSED(); + * No parameter. + * + * Both three macros shall terminate the calling process. + * The testcase shall not terminate in any other maneer. + * + * The other file defines the functions + * void output_init() + * void output(char * string, ...) + * + * Those may be used to output information. + */ + +/********************************************************************************************/ +/********************************** Configuration ******************************************/ +/********************************************************************************************/ +#ifndef VERBOSE +#define VERBOSE 1 +#endif + +/********************************************************************************************/ +/*********************************** Test case *****************************************/ +/********************************************************************************************/ + +/* The main test function. */ +int main( int argc, char * argv[] ) +{ + int ret, status; + pid_t child, ctl; + + sigset_t mask, pending; + + /* Initialize output */ + output_init(); + + /* block SIGUSR1 and SIGUSR2 */ + ret = sigemptyset( &mask ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "Failed to initialize signal set" ); + } + + ret = sigaddset( &mask, SIGUSR1 ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "Failed to add SIGUSR1 to signal set" ); + } + + ret = sigaddset( &mask, SIGUSR2 ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "Failed to add SIGUSR2 to signal set" ); + } + + ret = sigprocmask( SIG_BLOCK, &mask, NULL ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "Sigprocmask failed" ); + } + + /* Make the signals pending */ + ret = kill( getpid(), SIGUSR1 ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "failed to kill with SIGUSR1" ); + } + + ret = kill( getpid(), SIGUSR2 ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "failed to kill with SIGUSR2" ); + } + + do + { + ret = sigpending( &pending ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "failed to examine pending signal set" ); + } + + ret = sigismember( &pending, SIGUSR1 ); + + if ( ret < 0 ) + { + UNRESOLVED( errno, "Unable to check signal USR1 presence" ); + } + + if ( ret == 1 ) + { + ret = sigismember( &pending, SIGUSR2 ); + + if ( ret < 0 ) + { + UNRESOLVED( errno, "Unable to check signal USR2 presence" ); + } + } + } + while ( ret != 1 ); + +#if VERBOSE > 0 + + output( "SIGUSR1 and SIGUSR2 are pending, we can fork\n" ); + +#endif + + /* Create the child */ + child = fork(); + + if ( child == ( pid_t ) - 1 ) + { + UNRESOLVED( errno, "Failed to fork" ); + } + + /* child */ + if ( child == ( pid_t ) 0 ) + { + /* Examine the current blocked signal set. USR1 & USR2 shall be present */ + ret = sigprocmask( 0, NULL, &mask ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "Sigprocmask failed in child" ); + } + + ret = sigismember( &mask, SIGUSR1 ); + + if ( ret < 0 ) + { + UNRESOLVED( errno, "Unable to check signal USR1 presence" ); + } + + if ( ret == 0 ) + { + FAILED( "The new process does not mask SIGUSR1 as its parent" ); + } + + ret = sigismember( &mask, SIGUSR2 ); + + if ( ret < 0 ) + { + UNRESOLVED( errno, "Unable to check signal USR2 presence" ); + } + + if ( ret == 0 ) + { + FAILED( "The new process does not mask SIGUSR2 as its parent" ); + } + +#if VERBOSE > 0 + output( "SIGUSR1 and SIGUSR2 are blocked in child\n" ); + +#endif + + /* Examine pending signals */ + ret = sigpending( &pending ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "failed to examine pending signal set in child" ); + } + + ret = sigismember( &pending, SIGUSR1 ); + + if ( ret < 0 ) + { + UNRESOLVED( errno, "Unable to check signal USR1 presence" ); + } + + if ( ret != 0 ) + { + FAILED( "The new process was created with SIGUSR1 pending" ); + } + + ret = sigismember( &pending, SIGUSR2 ); + + if ( ret < 0 ) + { + UNRESOLVED( errno, "Unable to check signal USR2 presence" ); + } + + if ( ret != 0 ) + { + FAILED( "The new process was created with SIGUSR2 pending" ); + } + +#if VERBOSE > 0 + output( "SIGUSR1 and SIGUSR2 are not pending in child\n" ); + +#endif + + /* We're done */ + exit( PTS_PASS ); + } + + /* Parent joins the child */ + ctl = waitpid( child, &status, 0 ); + + if ( ctl != child ) + { + UNRESOLVED( errno, "Waitpid returned the wrong PID" ); + } + + if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) + { + FAILED( "Child exited abnormally" ); + } + + /* Test passed */ +#if VERBOSE > 0 + + output( "Test passed\n" ); + +#endif + + PASSED; +} + + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/6-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/6-1.c new file mode 100644 index 0000000000..84a2484095 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/6-1.c @@ -0,0 +1,199 @@ +/* +* Copyright (c) 2004, Bull S.A.. All rights reserved. +* Created by: Sebastien Decugis + +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write the Free Software Foundation, Inc., 59 +* Temple Place - Suite 330, Boston MA 02111-1307, USA. + + +* This sample test aims to check the following assertion: +* +* The opened directory streams are copied to the child process. +* Positionning information may be shared between both processes. + +* The steps are: +* -> Open the current directory, +* -> Count the directory entries, then rewind. +* -> create a child +* -> The child counts the directory entries. + +* The test fails if the directory is read in the parent and not in the child. + +*/ + + +/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ +#define _POSIX_C_SOURCE 200112L + +/********************************************************************************************/ +/****************************** standard includes *****************************************/ +/********************************************************************************************/ +#include + #include + #include + #include + #include + #include + +#include + #include + +#include + +/********************************************************************************************/ +/****************************** Test framework *****************************************/ +/********************************************************************************************/ +#include "testfrmw.h" + #include "testfrmw.c" +/* This header is responsible for defining the following macros: + * UNRESOLVED(ret, descr); + * where descr is a description of the error and ret is an int (error code for example) + * FAILED(descr); + * where descr is a short text saying why the test has failed. + * PASSED(); + * No parameter. + * + * Both three macros shall terminate the calling process. + * The testcase shall not terminate in any other maneer. + * + * The other file defines the functions + * void output_init() + * void output(char * string, ...) + * + * Those may be used to output information. + */ + +/********************************************************************************************/ +/********************************** Configuration ******************************************/ +/********************************************************************************************/ +#ifndef VERBOSE +#define VERBOSE 1 +#endif + +/********************************************************************************************/ +/*********************************** Test case *****************************************/ +/********************************************************************************************/ + +int count( DIR * thedir ) +{ + int counter = 0; + + struct dirent *dp; + + rewinddir( thedir ); + + /* Count the directory entries */ + + do + { + dp = readdir( thedir ); + + if ( dp != NULL ) + counter++; + } + while ( dp != NULL ); + + return counter; +} + +/* The main test function. */ +int main( int argc, char * argv[] ) +{ + int ret, status; + pid_t child, ctl; + + int counted; + + /* the '.' directory pointers */ + DIR *dotdir; + + /* Initialize output */ + output_init(); + + /* Open the directory */ + dotdir = opendir( "." ); + + if ( dotdir == NULL ) + { + UNRESOLVED( errno, "opendir failed" ); + } + + /* Count entries */ + counted = count( dotdir ); + +#if VERBOSE > 0 + + output( "Found %d entries in current dir\n", counted ); + +#endif + + /* Create the child */ + child = fork(); + + if ( child == ( pid_t ) - 1 ) + { + UNRESOLVED( errno, "Failed to fork" ); + } + + /* child */ + if ( child == ( pid_t ) 0 ) + { + /* Count in child process */ + counted = count( dotdir ); + +#if VERBOSE > 0 + + output( "Found %d entries in current dir from child\n", counted ); +#endif + + ret = closedir( dotdir ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "Failed to close dir in child" ); + } + + /* We're done */ + exit( PTS_PASS ); + } + + /* Parent joins the child */ + ctl = waitpid( child, &status, 0 ); + + if ( ctl != child ) + { + UNRESOLVED( errno, "Waitpid returned the wrong PID" ); + } + + if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) + { + FAILED( "Child exited abnormally -- dir stream not copied?" ); + } + + /* close the directory stream */ + ret = closedir( dotdir ); + + if ( ret != 0 ) + { + UNRESOLVED( errno, "Failed to closedir in parent" ); + } + + /* Test passed */ +#if VERBOSE > 0 + output( "Test passed\n" ); + +#endif + + PASSED; +} + + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/8-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/8-1.c new file mode 100644 index 0000000000..c8821b8213 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/8-1.c @@ -0,0 +1,236 @@ +/* +* Copyright (c) 2004, Bull S.A.. All rights reserved. +* Created by: Sebastien Decugis + +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write the Free Software Foundation, Inc., 59 +* Temple Place - Suite 330, Boston MA 02111-1307, USA. + + +* This sample test aims to check the following assertion: +* +* tms_{,c}{u,s}time values are set to 0 in the child process. + + +* The steps are: +* -> Work for 1 second and save the tms information +* -> fork +* -> Check that the child has tms values less than the saved tms. +* -> join the child process +* -> check tms_c{u,s}time are not 0 anymore. + +* The test fails if one of the described checking fails. + +*/ + + +/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ +#define _POSIX_C_SOURCE 200112L + +/********************************************************************************************/ +/****************************** standard includes *****************************************/ +/********************************************************************************************/ +#include + #include + #include + #include + #include + #include + +#include + #include + +#include + +/********************************************************************************************/ +/****************************** Test framework *****************************************/ +/********************************************************************************************/ +#include "testfrmw.h" + #include "testfrmw.c" +/* This header is responsible for defining the following macros: + * UNRESOLVED(ret, descr); + * where descr is a description of the error and ret is an int (error code for example) + * FAILED(descr); + * where descr is a short text saying why the test has failed. + * PASSED(); + * No parameter. + * + * Both three macros shall terminate the calling process. + * The testcase shall not terminate in any other maneer. + * + * The other file defines the functions + * void output_init() + * void output(char * string, ...) + * + * Those may be used to output information. + */ + +/********************************************************************************************/ +/********************************** Configuration ******************************************/ +/********************************************************************************************/ +#ifndef VERBOSE +#define VERBOSE 1 +#endif + +/********************************************************************************************/ +/*********************************** Test case *****************************************/ +/********************************************************************************************/ + +/* The main test function. */ +int main( int argc, char * argv[] ) +{ + int status; + pid_t child, ctl; + + clock_t st_time, cur_time; + + struct tms ini_tms, parent_tms, child_tms; + + /* Initialize output */ + output_init(); + + /* Initialize first times */ + st_time = times( &ini_tms ); + + if ( st_time == ( clock_t ) - 1 ) + { + UNRESOLVED( errno, "times failed" ); + } + + if ( ( ini_tms.tms_cutime != 0 ) || ( ini_tms.tms_cstime != 0 ) ) + { + FAILED( "The process is created with non-zero tms_cutime or tms_cstime" ); + } + +#if VERBOSE > 1 + output( "Starting loop...\n" ); + +#endif + + /* Busy loop for some times */ + do + { + cur_time = times( &parent_tms ); + + if ( cur_time == ( clock_t ) - 1 ) + { + UNRESOLVED( errno, "times failed" ); + } + } + while ( ( cur_time - st_time ) < sysconf( _SC_CLK_TCK ) ); + +#if VERBOSE > 1 + + output( "Busy loop terminated\n" ); + + output( " Real time: %ld, User Time %ld, System Time %ld, Ticks per sec %ld\n", + ( long ) ( cur_time - st_time ), + ( long ) ( parent_tms.tms_utime - ini_tms.tms_utime ), + ( long ) ( parent_tms.tms_stime - ini_tms.tms_stime ), + sysconf( _SC_CLK_TCK ) ); + +#endif + + /* Create the child */ + child = fork(); + + if ( child == ( pid_t ) - 1 ) + { + UNRESOLVED( errno, "Failed to fork" ); + } + + /* child */ + if ( child == ( pid_t ) 0 ) + { + + cur_time = times( &child_tms ); + + if ( cur_time == ( clock_t ) - 1 ) + { + UNRESOLVED( errno, "times failed" ); + } + + if ( child_tms.tms_utime + child_tms.tms_stime >= sysconf( _SC_CLK_TCK ) ) + { + FAILED( "The tms struct was not reset during fork() operation" ); + } + + do + { + cur_time = times( &child_tms ); + + if ( cur_time == ( clock_t ) - 1 ) + { + UNRESOLVED( errno, "times failed" ); + } + } + while ( ( child_tms.tms_utime + child_tms.tms_stime ) <= 0 ); + + /* We're done */ + exit( PTS_PASS ); + } + + /* Parent joins the child */ + ctl = waitpid( child, &status, 0 ); + + if ( ctl != child ) + { + UNRESOLVED( errno, "Waitpid returned the wrong PID" ) + ; + } + + if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) + { + FAILED( "Child exited abnormally" ) + ; + } + + /* Check the children times were reported as expected */ + cur_time = times( &parent_tms ); + +#if VERBOSE > 1 + + output( "Child joined\n" ); + + output( " Real time: %ld,\n" + " User Time %ld, System Time %ld,\n" + " Child User Time %ld, Child System Time %ld\n", + ( long ) ( cur_time - st_time ), + ( long ) ( parent_tms.tms_utime - ini_tms.tms_utime ), + ( long ) ( parent_tms.tms_stime - ini_tms.tms_stime ), + ( long ) ( parent_tms.tms_cutime - ini_tms.tms_cutime ), + ( long ) ( parent_tms.tms_cstime - ini_tms.tms_cstime ) + ); + +#endif + + if ( cur_time == ( clock_t ) - 1 ) + { + UNRESOLVED( errno, "times failed" ); + } + + if ( ( parent_tms.tms_cutime == 0 ) && ( parent_tms.tms_cstime == 0 ) ) + { + FAILED( "The process is created with non-zero tms_cutime or tms_cstime" ); + } + + + /* Test passed */ +#if VERBOSE > 0 + + output( "Test passed\n" ); + +#endif + + PASSED; +} + + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/9-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/9-1.c new file mode 100644 index 0000000000..477708bef2 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/9-1.c @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2004, Bull S.A.. All rights reserved. +* Created by: Sebastien Decugis + +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write the Free Software Foundation, Inc., 59 +* Temple Place - Suite 330, Boston MA 02111-1307, USA. + + +* This sample test aims to check the following assertion: +* +* The time left until an alarm clock is triggered is reset to zero, +* and the alarm, if any, is canceled + +* The steps are: +* -> Trig an alarm +* -> fork +* -> Check the alarm is not running in the child process. +* -> join the child + +* The test fails if the child has a pending alarm. + +*/ + + +/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ +#define _POSIX_C_SOURCE 200112L + +/********************************************************************************************/ +/****************************** standard includes *****************************************/ +/********************************************************************************************/ +#include + #include + #include + #include + #include + #include + +#include + #include + + +/********************************************************************************************/ +/****************************** Test framework *****************************************/ +/********************************************************************************************/ +#include "testfrmw.h" + #include "testfrmw.c" +/* This header is responsible for defining the following macros: + * UNRESOLVED(ret, descr); + * where descr is a description of the error and ret is an int (error code for example) + * FAILED(descr); + * where descr is a short text saying why the test has failed. + * PASSED(); + * No parameter. + * + * Both three macros shall terminate the calling process. + * The testcase shall not terminate in any other maneer. + * + * The other file defines the functions + * void output_init() + * void output(char * string, ...) + * + * Those may be used to output information. + */ + +/********************************************************************************************/ +/********************************** Configuration ******************************************/ +/********************************************************************************************/ +#ifndef VERBOSE +#define VERBOSE 1 +#endif + +/********************************************************************************************/ +/*********************************** Test case *****************************************/ +/********************************************************************************************/ + +/* The main test function. */ +int main( int argc, char * argv[] ) +{ + int ret, status; + pid_t child, ctl; + + /* Initialize output */ + output_init(); + + /* Set the alarm pending */ + alarm( 10 ); + + /* Check the alarm() behavior */ + ret = alarm( 10 ); + + if ( ret == 0 ) + { + FAILED( "the alarm() routine does not behave as expected" ); + } + + /* Create the child */ + child = fork(); + + if ( child == ( pid_t ) - 1 ) + { + UNRESOLVED( errno, "Failed to fork" ); + } + + /* child */ + if ( child == ( pid_t ) 0 ) + { + + ret = alarm( 10 ); + + if ( ret != 0 ) + { + FAILED( "The child alarm pending was not reset." ); + } + + /* We're done */ + exit( PTS_PASS ); + } + + /* Parent joins the child */ + ctl = waitpid( child, &status, 0 ); + + if ( ctl != child ) + { + UNRESOLVED( errno, "Waitpid returned the wrong PID" ); + } + + if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) + { + FAILED( "Child exited abnormally" ); + } + + alarm( 0 ); + + /* Test passed */ +#if VERBOSE > 0 + + output( "Test passed\n" ); + +#endif + + PASSED; +} + + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/Jamfile index 937232d05a..6d37c77984 100644 --- a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/Jamfile +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/Jamfile @@ -4,3 +4,7 @@ SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ; SimpleTest fork_3-1 : 3-1.c ; SimpleTest fork_4-1 : 4-1.c ; +SimpleTest fork_6-1 : 6-1.c ; +SimpleTest fork_8-1 : 8-1.c ; +SimpleTest fork_9-1 : 9-1.c ; +SimpleTest fork_12-1 : 12-1.c ;