added two tests for fork(). Both fail on waitpid().

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18525 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-08-17 15:20:47 +00:00
parent e18b600868
commit 278510fe87
8 changed files with 544 additions and 0 deletions

View File

@ -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 ;

View File

@ -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 <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>
#include <signal.h>
/********************************************************************************************/
/****************************** 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;
}

View File

@ -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 <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>
/********************************************************************************************/
/****************************** 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;
}

View File

@ -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 ;

View File

@ -0,0 +1,93 @@
<assertions>
<assertion id="1" tag="ref:XSH6TC2:12992:12992">
fork() creates a new process.
</assertion>
<assertion id="2" tag="ref:XSH6TC2:12992:12993">
The new process is a copy of the original process
-- unless specified otherwise below.
</assertion>
<assertion id="3" tag="ref:XSH6TC2:12994:12995">
The new process' ID does not match any existing
process or group ID.
</assertion>
<assertion id="4" tag="ref:XSH6TC2:12996:12997">
The parent process ID (ppid) of the child process
is the process ID (pid) of the parent process
(caller of fork()).
</assertion>
<assertion id="5" tag="ref:XSH6TC2:12998:13000">
The opened file descriptors are copied to the child process
and refer to the same object.
</assertion>
<assertion id="6" tag="ref:XSH6TC2:13001:13003">
The opened directory streams are copied to the child process.
Positioning information may be shared between both processes.
</assertion>
<assertion id="7" tag="ref:XSH6TC2:13004:13004 pt:XSI">
The child process gets a copy of the parent message catalog descriptor.
</assertion>
<assertion id="8" tag="ref:XSH6TC2:13005:13005">
tms_utime, tms_stime, tms_cutime, and tms_cstime values
are set to 0 in the child process.
</assertion>
<assertion id="9" tag="ref:XSH6TC2:13006:13007">
The time left until an alarm clock signal is reset to zero,
and the alarm, if any, is canceled.
</assertion>
<assertion id="10" tag="ref:XSH6TC2:13008:13008 pt:XSI">
semadj values are cleared.
</assertion>
<assertion id="11" tag="ref:XSH6TC2:13009:13009">
The file locks are not inherited by the child process.
</assertion>
<assertion id="12" tag="ref:XSH6TC2:13010:13010">
The child process is created with no pending signals.
</assertion>
<assertion id="13" tag="ref:XSH6TC2:13011:13011 pt:XSI">
Interval timers are reset in the child process.
</assertion>
<assertion id="14" tag="ref:XSH6TC2:13012:13012 pt:SEM">
The opened semaphores are inherited in the child process.
</assertion>
<assertion id="15" tag="ref:XSH6TC2:13013:13014 pt:ML">
The child process does not inherit memory locks set by
the parent process with mlock or mlockall.
</assertion>
<assertion id="16" tag="ref:XSH6TC2:13015:13021 pt:MF|SHM">
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.
</assertion>
<assertion id="17" tag="ref:XSH6TC2:13022:13024 pt:PS">
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.
</assertion>
<assertion id="18" tag="ref:XSH6TC2:13025:13025 pt:TMR">
The per-process timers are not inherited.
</assertion>
<assertion id="19" tag="ref:XSH6TC2:13026:13028 pt:MSG">
The opened message queue descriptors are copied to the child
process and refer to the same object.
</assertion>
<assertion id="20" tag="ref:XSH6TC2:13029:13030 pt:AIO">
Asynchronous IO operations are not inherited by the child.
</assertion>
<assertion id="21" tag="ref:XSH6TC2:13031:13036 pt:THR">
The new process has only one thread.
</assertion>
<assertion id="22" tag="ref:XSH6TC2:13052:13053 pt:CPT_TCT">
The CPU-time clocks of the new process/ new process' thread
are initialized to 0.
</assertion>
<assertion id="23" tag="ref:XSH6TC2:13060:13062">
fork() returns 0 to the child and the child PID to the parent process when
succesful.
</assertion>
<assertion id="24" tag="ref:XSH6TC2:13063:13069">
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.
</assertion>
</assertions>

View File

@ -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

View File

@ -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 <time.h>
#include <sys/types.h>
/* 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

View File

@ -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 <string.h> /* 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