diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile index 4759581ef7..7327666c73 100644 --- a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces difftime ; +SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces fork ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces kill ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_create ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_delete ; diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/3-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/3-1.c new file mode 100644 index 0000000000..4925da43f5 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/3-1.c @@ -0,0 +1,135 @@ +/* + * 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 new process' ID does not match any existing process or group ID. + + * The steps are: + * -> create a child; then terminate this child. + * -> check that no other process or group has the same ID. + + * The test fails if another object shares the same ID. + + */ + + + /* 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; + + /* Initialize output */ + output_init(); + + /* Create the child */ + child = fork(); + if (child == (pid_t) -1) { UNRESOLVED(errno, "Failed to fork"); } + + /* child */ + if (child == (pid_t) 0) + { + /* The child stops immediatly */ + 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)) + { + UNRESOLVED(status, "Child exited abnormally"); + } + + ret = kill(child, 0); + if ((ret == 0) || (errno != ESRCH)) + { + output("Kill returned %d (%d: %s)\n", ret, errno, strerror(errno)); + FAILED("Another process with the same PID as the child exists"); + } + + ret = kill((pid_t) (0 - (int)child), 0); + if ((ret == 0) || (errno != ESRCH)) + { + output("Kill returned %d (%d: %s)\n", ret, errno, strerror(errno)); + FAILED("A process group with the same PID as the child exists"); + } + + + /* Test passed */ + #if VERBOSE > 0 + output("Test passed\n"); + #endif + + PASSED; +} + + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/4-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/4-1.c new file mode 100644 index 0000000000..e5b5e50b1f --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/4-1.c @@ -0,0 +1,127 @@ +/* + * 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 parent process ID of the child is the process ID of the parent (caller of fork()) + + * The steps are: + * -> create a child + * -> check its parent process ID is the PID of its parent. + + * The test fails if the IDs differ. + + */ + + + /* 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 status; + pid_t child, ctl; + + /* Initialize output */ + output_init(); + + /* Get parent process ID */ + ctl = getpid(); + + /* Create the child */ + child = fork(); + if (child == (pid_t) -1) { UNRESOLVED(errno, "Failed to fork"); } + + /* child */ + if (child == (pid_t) 0) + { + /* Check the parent process ID */ + if (ctl != getppid()) + { + FAILED("The parent process ID is not the PID of the parent"); + } + + /* 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)) + { + UNRESOLVED(status, "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/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/Jamfile new file mode 100644 index 0000000000..937232d05a --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/Jamfile @@ -0,0 +1,6 @@ +SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces fork ; + +SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ; + +SimpleTest fork_3-1 : 3-1.c ; +SimpleTest fork_4-1 : 4-1.c ; diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/assertions.xml b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/assertions.xml new file mode 100644 index 0000000000..34fba955c6 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/assertions.xml @@ -0,0 +1,93 @@ + + + fork() creates a new process. + + + The new process is a copy of the original process + -- unless specified otherwise below. + + + The new process' ID does not match any existing + process or group ID. + + + The parent process ID (ppid) of the child process + is the process ID (pid) of the parent process + (caller of fork()). + + + The opened file descriptors are copied to the child process + and refer to the same object. + + + The opened directory streams are copied to the child process. + Positioning information may be shared between both processes. + + + The child process gets a copy of the parent message catalog descriptor. + + + tms_utime, tms_stime, tms_cutime, and tms_cstime values + are set to 0 in the child process. + + + The time left until an alarm clock signal is reset to zero, + and the alarm, if any, is canceled. + + + semadj values are cleared. + + + The file locks are not inherited by the child process. + + + The child process is created with no pending signals. + + + Interval timers are reset in the child process. + + + The opened semaphores are inherited in the child process. + + + The child process does not inherit memory locks set by + the parent process with mlock or mlockall. + + + Memory mappings created in the parent are retained in the + child process. If the mapping is MAP_PRIVATE, any modification + done after the fork() is visible only to the process doing the + modification. + + + For the SCHED_RR and SCHED_FIFO scheduling policies, the child + process inherits the policy and priority settings of the parent + process during the fork() execution. + + + The per-process timers are not inherited. + + + The opened message queue descriptors are copied to the child + process and refer to the same object. + + + Asynchronous IO operations are not inherited by the child. + + + The new process has only one thread. + + + The CPU-time clocks of the new process/ new process' thread + are initialized to 0. + + + fork() returns 0 to the child and the child PID to the parent process when + succesful. + + + fork() returns -1, errno is set to EAGAIN, and no child process + is created if the system lacks a resource to create the new process + or CHILD_MAX process are already running. + + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/messcat_src.txt b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/messcat_src.txt new file mode 100644 index 0000000000..e0067d9cc5 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/messcat_src.txt @@ -0,0 +1,26 @@ +$ 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 file is part of the 7-1.c test case for the fork() routine. + +$set 1 Message set for OPTS fork test case, English language +1 This is the first message +2 And this is the second + +$set 2 Message set for OPTS fork test case, French language +1 Voici le premier message +2 Et voilĂ  le second + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/testfrmw.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/testfrmw.c new file mode 100644 index 0000000000..38adaa8d90 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/testfrmw.c @@ -0,0 +1,71 @@ +/* + * 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 file is a wrapper to use the tests from the NPTL Test & Trace Project + * with either the Linux Test Project or the Open POSIX Test Suite. + + * The following function are defined: + * void output_init() + * void output_fini() + * void output(char * string, ...) + * + * The are used to output informative text (as a printf). + */ + +#include +#include + +/* We use a mutex to avoid conflicts in traces */ +static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; + +/*****************************************************************************************/ +/******************************* stdout module *****************************************/ +/*****************************************************************************************/ +/* The following functions will output to stdout */ +#if (1) +void output_init() +{ + /* do nothing */ + return; +} +void output( char * string, ... ) +{ + va_list ap; + char *ts="[??:??:??]"; + struct tm * now; + time_t nw; + + pthread_mutex_lock(&m_trace); + nw = time(NULL); + now = localtime(&nw); + if (now == NULL) + printf(ts); + else + printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); + va_start( ap, string); + vprintf(string, ap); + va_end(ap); + pthread_mutex_unlock(&m_trace); +} +void output_fini() +{ + /*do nothing */ + return; +} +#endif + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/testfrmw.h b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/testfrmw.h new file mode 100644 index 0000000000..239b7a5df4 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/fork/testfrmw.h @@ -0,0 +1,85 @@ +/* + * 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 file is a wrapper to use the tests from the NPTL Test & Trace Project + * with either the Linux Test Project or the Open POSIX Test Suite. + + * The following macros are defined here: + * 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 without calling one of those macros. + * + * + */ + +#include "posixtest.h" +#include /* for the strerror() routine */ + + +#ifdef __GNUC__ /* We are using GCC */ + + #define UNRESOLVED(x, s) \ + { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ + output_fini(); \ + exit(PTS_UNRESOLVED); } + + #define FAILED(s) \ + { output("Test %s FAILED: %s\n", __FILE__, s); \ + output_fini(); \ + exit(PTS_FAIL); } + + #define PASSED \ + output_fini(); \ + exit(PTS_PASS); + + #define UNTESTED(s) \ +{ output("File %s cannot test: %s\n", __FILE__, s); \ + output_fini(); \ + exit(PTS_UNTESTED); \ +} + +#else /* not using GCC */ + + #define UNRESOLVED(x, s) \ + { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ + output_fini(); \ + exit(PTS_UNRESOLVED); } + + #define FAILED(s) \ + { output("Test FAILED: %s\n", s); \ + output_fini(); \ + exit(PTS_FAIL); } + + #define PASSED \ + output_fini(); \ + exit(PTS_PASS); + + #define UNTESTED(s) \ +{ output("Unable to test: %s\n", s); \ + output_fini(); \ + exit(PTS_UNTESTED); \ +} + +#endif +