Removed partial (unknown version) Open POSIX Test Suite from the build.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36039 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -159,5 +159,4 @@ SEARCH on [ FGristFiles
|
||||
|
||||
SubInclude HAIKU_TOP src tests system libroot posix bonnie++-1.03d ;
|
||||
SubInclude HAIKU_TOP src tests system libroot posix math ;
|
||||
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite ;
|
||||
SubInclude HAIKU_TOP src tests system libroot posix string ;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite ;
|
||||
|
||||
MakeLocatePlatform run_posix_tests ;
|
||||
Shell run_posix_tests : run_posix_tests.sh ;
|
||||
|
||||
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance ;
|
||||
@@ -1,3 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance ;
|
||||
|
||||
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces ;
|
||||
@@ -1,19 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces ;
|
||||
|
||||
HaikuSubInclude difftime ;
|
||||
HaikuSubInclude fork ;
|
||||
HaikuSubInclude kill ;
|
||||
HaikuSubInclude pthread_attr_destroy ;
|
||||
HaikuSubInclude pthread_create ;
|
||||
HaikuSubInclude pthread_key_create ;
|
||||
HaikuSubInclude pthread_key_delete ;
|
||||
HaikuSubInclude pthread_getspecific ;
|
||||
HaikuSubInclude pthread_once ;
|
||||
HaikuSubInclude pthread_setspecific ;
|
||||
HaikuSubInclude sighold ;
|
||||
HaikuSubInclude sigignore ;
|
||||
HaikuSubInclude sigprocmask ;
|
||||
HaikuSubInclude sigrelse ;
|
||||
HaikuSubInclude signal ;
|
||||
HaikuSubInclude sigset ;
|
||||
HaikuSubInclude sigsuspend ;
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002-3, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Test that the difftime function shall return the difference between
|
||||
two calendar times.
|
||||
*/
|
||||
|
||||
#define WAIT_DURATION 1
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
time_t time1, time0;
|
||||
|
||||
double time_diff;
|
||||
time_diff = 0;
|
||||
time0 = time(NULL);
|
||||
sleep(WAIT_DURATION);
|
||||
time1 = time(NULL);
|
||||
time_diff = difftime(time1, time0);
|
||||
|
||||
if (time_diff != WAIT_DURATION) {
|
||||
printf("%sdifftime_1-1: Test FAILED: "
|
||||
"difftime did not return the correct value%s\n",
|
||||
red, normal);
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%sdifftime_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces difftime ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest difftime_1-1 : 1-1.c ;
|
||||
|
||||
@@ -1,301 +0,0 @@
|
||||
/*
|
||||
* 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 <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;
|
||||
|
||||
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 > 1
|
||||
|
||||
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 > 1
|
||||
output( "SIGUSR1 and SIGUSR2 are blocked in child\n" );
|
||||
|
||||
#endif
|
||||
|
||||
/* Examine pending signals */
|
||||
ret = sigpending( &pending );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
printf("%sfork_12-1:%s "
|
||||
"%sFAILED: failed to examine pending signal set in child: %s%s\n",
|
||||
boldOn, boldOff, red, strerror(errno), normal);
|
||||
}
|
||||
|
||||
ret = sigismember( &pending, SIGUSR1 );
|
||||
|
||||
if ( ret < 0 )
|
||||
{
|
||||
printf("%sfork_12-1:%s "
|
||||
"%sFAILED: Unable to check signal USR1 presence%s\n",
|
||||
boldOn, boldOff, red, normal);
|
||||
}
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
printf("%sfork_12-1:%s "
|
||||
"%sFAILED: The new process was created with SIGUSR1 pending%s\n",
|
||||
boldOn, boldOff, red, normal);
|
||||
}
|
||||
|
||||
ret = sigismember( &pending, SIGUSR2 );
|
||||
|
||||
if ( ret < 0 )
|
||||
{
|
||||
printf("%sfork_12-1:%s "
|
||||
"%sFAILED: Unable to check signal USR2 presence: %s%s\n",
|
||||
boldOn, boldOff, red, strerror(errno), normal);
|
||||
}
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
printf("%sfork_12-1:%s "
|
||||
"%sFAILED: The new process was created with SIGUSR2 pending%s\n",
|
||||
boldOn, boldOff, red, normal);
|
||||
}
|
||||
|
||||
#if VERBOSE > 1
|
||||
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 )
|
||||
{
|
||||
printf("%sfork_12-1:%s "
|
||||
"%sFAILED: Waitpid returned the wrong PID: %s%s\n",
|
||||
boldOn, boldOff, red, strerror(errno), normal);
|
||||
}
|
||||
|
||||
if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) )
|
||||
{
|
||||
printf("%sfork_12-1:%s %sFAILED: Child exited abnormally%s\n",
|
||||
boldOn, boldOff, red, normal);
|
||||
|
||||
}
|
||||
|
||||
/* Test passed */
|
||||
#if VERBOSE > 0
|
||||
|
||||
printf("%sfork_12-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* 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)) {
|
||||
printf("%sfork_3-1:%s "
|
||||
"%sFAILED: Another process with the same PID as the child exists: %s%s\n",
|
||||
boldOn, boldOff, red, strerror(errno), normal);
|
||||
printf("%sfork_3-1:%s %sFAILED: See bug #1639%s\n", boldOn, boldOff, red, normal);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = kill((pid_t) (0 - (int)child), 0);
|
||||
if ((ret == 0) || (errno != ESRCH)) {
|
||||
printf("%sfork_3-1:%s "
|
||||
"%sFAILED: A process group with the same PID as the child exists: %s%s\n",
|
||||
boldOn, boldOff, red, strerror(errno), normal);
|
||||
printf("%sfork_3-1:%s %sFAILED: See bug #1639%s\n", boldOn, boldOff, red, normal);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Test passed */
|
||||
#if VERBOSE > 0
|
||||
printf("%sfork_3-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* 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))
|
||||
{
|
||||
printf("%sfork_4-1:%s "
|
||||
"%sFAILED Child exited abnormally %s%s\n",
|
||||
boldOn, boldOff, red, strerror(status), normal);
|
||||
}
|
||||
|
||||
/* Test passed */
|
||||
#if VERBOSE > 0
|
||||
printf("%sfork_4-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* 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 <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 <dirent.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 *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
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 > 1
|
||||
|
||||
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 > 1
|
||||
|
||||
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
|
||||
printf("%sfork_6-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,234 +0,0 @@
|
||||
/*
|
||||
* 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 <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 <sys/times.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;
|
||||
|
||||
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
|
||||
printf("%sfork_8-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* 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 <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 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
|
||||
printf("%sfork_9-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
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 ;
|
||||
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 ;
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
<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>
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
$ 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
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,30 +0,0 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that if the signal is the null signal (0), no signal is sent.
|
||||
* 1) Call kill on the current process with the null signal.
|
||||
* 2) If process is still functional after kill() is called, consider
|
||||
* the test a pass (most likely no signal was sent).
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
if (kill(getpid(), 0) != 0) {
|
||||
printf("Could not call kill with sig = 0\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%skill_2-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces kill ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest kill_2-1 : 2-1.c ;
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_attr_destroy()
|
||||
* shall destory a thread attributes object. An implementation may cause
|
||||
* pthread_attr_destroy() to set 'attr' to an implementation-defined invalid
|
||||
* value.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Initialize a pthread_attr_t object using pthread_attr_init()
|
||||
* 2. Destroy that initialized attribute using pthread_attr_destroy()
|
||||
* 3. Using pthread_attr_create(), pass to it the destroyed attribute. It
|
||||
* should return the error EINVAL, the value specified by 'attr' is
|
||||
* is invalid.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
|
||||
void *a_thread_func()
|
||||
{
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
pthread_attr_t new_attr;
|
||||
int ret;
|
||||
|
||||
/* Initialize attribute */
|
||||
if(pthread_attr_init(&new_attr) != 0)
|
||||
{
|
||||
perror("Cannot initialize attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Destroy attribute */
|
||||
if(pthread_attr_destroy(&new_attr) != 0)
|
||||
{
|
||||
perror("Cannot destroy the attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Creating a thread, passing to it the destroyed attribute, should
|
||||
* result in an error value of EINVAL (invalid 'attr' value). */
|
||||
ret=pthread_create(&new_th, &new_attr, a_thread_func, NULL);
|
||||
|
||||
if(ret==EINVAL)
|
||||
{
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
else if((ret != 0) && ((ret == EPERM) || (ret == EAGAIN)))
|
||||
{
|
||||
perror("Error created a new thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
else if(ret==0)
|
||||
{
|
||||
printf("Test PASSED: NOTE*: Though returned 0 when creating a thread with a destroyed attribute, this behavior is compliant with garbage-in-garbage-out. \n");
|
||||
return PTS_PASS;
|
||||
} else
|
||||
{
|
||||
printf("Test FAILED: (1) Incorrect return code from pthread_create(); %d not EINVAL or (2) Error in pthread_create()'s behavior in returning error codes \n", ret);
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* A destroyed 'attr' attributes object can be reinitialized using
|
||||
* pthread_attr_init(); the results of otherwise referencing the object
|
||||
* after it has been destroyed are undefined.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Initialize a pthread_attr_t object using pthread_attr_init()
|
||||
* 2. Destroy that initialized attribute using pthread_attr_destroy()
|
||||
* 3. Initialize the pthread_attr_t object again. This should not result
|
||||
* in an error.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_attr_t new_attr;
|
||||
|
||||
/* Initialize attribute */
|
||||
if(pthread_attr_init(&new_attr) != 0)
|
||||
{
|
||||
perror("Cannot initialize attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Destroy attribute */
|
||||
if(pthread_attr_destroy(&new_attr) != 0)
|
||||
{
|
||||
perror("Cannot destroy the attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Initialize attribute. This shouldn't result in an error. */
|
||||
if(pthread_attr_init(&new_attr) != 0)
|
||||
{
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Upon successful completion, pthread_attr_destroy() shall return a value of 0.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Initialize a pthread_attr_t object using pthread_attr_init()
|
||||
* 2. Destroy that initialized attribute using pthread_attr_destroy().
|
||||
* This should return 0;
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_attr_t new_attr;
|
||||
|
||||
/* Initialize attribute */
|
||||
if(pthread_attr_init(&new_attr) != 0)
|
||||
{
|
||||
perror("Cannot initialize attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Destroy attribute */
|
||||
if(pthread_attr_destroy(&new_attr) != 0)
|
||||
{
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_attr_destroy ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest pthread_attr_destroy_1-1 : 1-1.c ;
|
||||
SimpleTest pthread_attr_destroy_2-1 : 2-1.c ;
|
||||
SimpleTest pthread_attr_destroy_3-1 : 3-1.c ;
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_create() creates a new thread with attributes specified
|
||||
* by 'attr', within a process.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a thread using pthread_create()
|
||||
* 2. Compare the thread ID of 'main' to the thread ID of the newly created
|
||||
* thread. They should be different.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void *a_thread_func()
|
||||
{
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t main_th, new_th;
|
||||
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Obtain the thread ID of this main function */
|
||||
main_th=pthread_self();
|
||||
|
||||
/* Compare the thread ID of the new thread to the main thread.
|
||||
* They should be different. If not, the test fails. */
|
||||
if(pthread_equal(new_th, main_th) != 0)
|
||||
{
|
||||
printf("Test FAILED: A new thread wasn't created\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_create() creates a new thread with attributes specified
|
||||
* by 'attr', within a process.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a thread using pthread_create()
|
||||
* 2. Cancel that thread with pthread_cancel()
|
||||
* 3. If that thread doesn't exist, then it pthread_cancel() will return
|
||||
* an error code. This would mean that pthread_create() did not create
|
||||
* a thread successfully.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void *a_thread_func()
|
||||
{
|
||||
sleep(10);
|
||||
|
||||
/* Shouldn't reach here. If we do, then the pthread_cancel()
|
||||
* function did not succeed. */
|
||||
perror("Could not send cancel request correctly\n");
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) < 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Try to cancel the newly created thread. If an error is returned,
|
||||
* then the thread wasn't created successfully. */
|
||||
if(pthread_cancel(new_th) != 0)
|
||||
{
|
||||
printf("Test FAILED: A new thread wasn't created\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-82
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_create() creates a new thread with attributes specified
|
||||
* by 'attr', within a process.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a new thread that will go into a never-ending while loop.
|
||||
* 2. If the thread is truly asynchronise, then the main function will
|
||||
* continue instead of waiting for the thread to return (which in never
|
||||
* does in this test case).
|
||||
* 3. An alarm is set to go off (i.e. send the SIGARLM signal) after 3
|
||||
* seconds. This is done for 'timeing-out' reasons, in case main DOES
|
||||
* wait for the thread to return. This would also mean that the test
|
||||
* failed.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void *a_thread_function();
|
||||
void alarm_handler();
|
||||
|
||||
pthread_t a;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
/* Set the action for SIGALRM to generate an error if it is
|
||||
* reached. This is because if SIGALRM was sent, then the
|
||||
* test timed out. */
|
||||
if (signal(SIGALRM, alarm_handler) == SIG_ERR)
|
||||
{
|
||||
printf("Error in signal()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* SIGALRM will be sent in 5 seconds. */
|
||||
alarm(5);
|
||||
|
||||
/* Create a new thread. */
|
||||
if(pthread_create(&a, NULL, a_thread_function, NULL) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
pthread_cancel(a);
|
||||
/* If 'main' has reached here, then the test passed because it means
|
||||
* that the thread is truly asynchronise, and main isn't waiting for
|
||||
* it to return in order to move on. */
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
/* A never-ending thread function */
|
||||
void *a_thread_function()
|
||||
{
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
|
||||
while(1)
|
||||
sleep(1);
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If this handler is called, that means that the test has failed. */
|
||||
void alarm_handler()
|
||||
{
|
||||
printf("Test FAILED\n");
|
||||
exit(PTS_FAIL);
|
||||
}
|
||||
|
||||
-234
@@ -1,234 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
*
|
||||
* pthread_create creates a new thread within the process
|
||||
|
||||
* The steps are:
|
||||
*
|
||||
* -> get the thread ID and the process ID of the main thread.
|
||||
* -> create a new thread, get the thread & process ID.
|
||||
* -> check that the thread IDs are different but process IDs are the same
|
||||
|
||||
* The test fails if the thread IDs are the same or the proces IDs are different.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
/* Some routines are part of the XSI Extensions */
|
||||
#ifndef WITHOUT_XOPEN
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
/********************************************************************************************/
|
||||
/****************************** standard includes *****************************************/
|
||||
/********************************************************************************************/
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.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 cases *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
#include "threads_scenarii.c"
|
||||
|
||||
/* This file will define the following objects:
|
||||
* scenarii: array of struct __scenario type.
|
||||
* NSCENAR : macro giving the total # of scenarii
|
||||
* scenar_init(): function to call before use the scenarii array.
|
||||
* scenar_fini(): function to call after end of use of the scenarii array.
|
||||
*/
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Real Test *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
struct testdata
|
||||
{
|
||||
pthread_t tid;
|
||||
pid_t pid;
|
||||
sem_t * sem;
|
||||
};
|
||||
|
||||
int global; /* This value is used to check both threads share the same process memory (and not a copy) */
|
||||
|
||||
void * threaded (void * arg)
|
||||
{
|
||||
struct testdata * td=(struct testdata *) arg;
|
||||
pthread_t mytid;
|
||||
pid_t mypid;
|
||||
int ret = 0;
|
||||
|
||||
/* Compare the process IDs */
|
||||
mypid=getpid();
|
||||
#if VERBOSE > 0
|
||||
output(" Main pid: %i thread pid: %i\n", td->pid, mypid);
|
||||
#endif
|
||||
|
||||
if (mypid != td->pid)
|
||||
{
|
||||
FAILED("New thread does not belong to the same process as its parent thread");
|
||||
}
|
||||
|
||||
/* Compare the threads IDs */
|
||||
mytid = pthread_self();
|
||||
#if VERBOSE > 0
|
||||
/* pthread_t is a pointer with Linux/nptl. This output can be erroneous for other arcs */
|
||||
output(" Main tid: %p thread tid: %p\n", td->tid, mytid);
|
||||
#endif
|
||||
|
||||
if (pthread_equal(mytid, td->tid) != 0)
|
||||
{
|
||||
FAILED("The created thread has the same thread ID as its parent");
|
||||
}
|
||||
|
||||
/* Change the global value */
|
||||
global++;
|
||||
|
||||
/* Post the semaphore to unlock the main thread in case of a detached thread */
|
||||
do { ret = sem_post(td->sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); }
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int ret=0;
|
||||
struct testdata td;
|
||||
void * rval;
|
||||
pthread_t child;
|
||||
int i;
|
||||
|
||||
output_init();
|
||||
|
||||
td.tid=pthread_self();
|
||||
td.pid=getpid();
|
||||
|
||||
scenar_init();
|
||||
|
||||
for (i=0; i < NSCENAR; i++)
|
||||
{
|
||||
#if VERBOSE > 0
|
||||
output("-----\n");
|
||||
output("Starting test with scenario (%i): %s\n", i, scenarii[i].descr);
|
||||
#endif
|
||||
|
||||
td.sem = &scenarii[i].sem;
|
||||
|
||||
global = 2*i;
|
||||
|
||||
ret = pthread_create(&child, &scenarii[i].ta, threaded, &td);
|
||||
switch (scenarii[i].result)
|
||||
{
|
||||
case 0: /* Operation was expected to succeed */
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); }
|
||||
break;
|
||||
|
||||
case 1: /* Operation was expected to fail */
|
||||
if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); }
|
||||
break;
|
||||
|
||||
case 2: /* We did not know the expected result */
|
||||
default:
|
||||
#if VERBOSE > 0
|
||||
if (ret == 0)
|
||||
{ output("Thread has been created successfully for this scenario\n"); }
|
||||
else
|
||||
{ output("Thread creation failed with the error: %s\n", strerror(ret)); }
|
||||
#endif
|
||||
}
|
||||
if (ret == 0) /* The new thread is running */
|
||||
{
|
||||
if (scenarii[i].detached == 0)
|
||||
{
|
||||
ret = pthread_join(child, &rval);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); }
|
||||
|
||||
if (rval != &td)
|
||||
{
|
||||
FAILED("Could not get the thread return value. Did it execute?");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Just wait for the thread terminate */
|
||||
do { ret = sem_wait(td.sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); }
|
||||
}
|
||||
|
||||
if (global != (2*i + 1))
|
||||
{
|
||||
/* Maybe a possible issue with CPU memory-caching here? */
|
||||
FAILED("The threads do not share the same process memory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scenar_fini();
|
||||
#if VERBOSE > 0
|
||||
output("-----\n");
|
||||
output("All test data destroyed\n");
|
||||
output("Test PASSED\n");
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
-263
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
*
|
||||
* pthread_create creates a thread with attributes as specified in the attr parameter.
|
||||
|
||||
* The steps are:
|
||||
*
|
||||
* -> Create a new thread with known parameters.
|
||||
* -> Check the thread behavior conforms to these parameters.
|
||||
* This checking consists in:
|
||||
* -> If an alternative stack has been specified, check that the new thread stack is within this specified area.
|
||||
* -> If stack size and guard size are known, check that accessing the guard size fails. (new process)
|
||||
* -> If we are able to run threads with high priority and known sched policy, check that a high priority thread executes before a low priority thread.
|
||||
(This will be done in another test has it fails with Linux kernel (2.6.8 at least)
|
||||
* -> The previous test could be extended to cross-process threads to check the scope attribute behavior (postponned for now).
|
||||
* (*) The detachstate attribute is not tested cause this would mean a speculative test. Moreover, it is already tested elsewhere.
|
||||
|
||||
* The test fails if one of those tests fails.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
/* Some routines are part of the XSI Extensions */
|
||||
#ifndef WITHOUT_XOPEN
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
/********************************************************************************************/
|
||||
/****************************** standard includes *****************************************/
|
||||
/********************************************************************************************/
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.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 cases *****************************************/
|
||||
/********************************************************************************************/
|
||||
#define STD_MAIN /* This allows main() to be defined in the included file */
|
||||
#include "threads_scenarii.c"
|
||||
|
||||
/* This file will define the following objects:
|
||||
* scenarii: array of struct __scenario type.
|
||||
* NSCENAR : macro giving the total # of scenarii
|
||||
* scenar_init(): function to call before use the scenarii array.
|
||||
* scenar_fini(): function to call after end of use of the scenarii array.
|
||||
*/
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Real Test *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
/* The overflow function is used to test the stack overflow */
|
||||
void * overflow(void * arg)
|
||||
{
|
||||
void * current;
|
||||
void * pad[50]; /* We want to consume the stack quickly */
|
||||
long stacksize = sysconf(_SC_THREAD_STACK_MIN); /* make sure we touch the current stack memory */
|
||||
int ret=0;
|
||||
|
||||
pad[1]=NULL; /* so compiler stops complaining about unused variables */
|
||||
|
||||
if (arg == NULL)
|
||||
{
|
||||
/* first call */
|
||||
current = overflow(¤t);
|
||||
|
||||
/* Terminate the overflow thread */
|
||||
/* Post the semaphore to unlock the main thread in case of a detached thread */
|
||||
do { ret = sem_post(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); }
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* we cast the pointers into long, which might be a problem on some architectures... */
|
||||
if ( ((long)arg) < ((long)¤t))
|
||||
{
|
||||
/* the stack is growing up */
|
||||
if ( ((long)¤t) - ((long)arg) >= stacksize)
|
||||
{
|
||||
output("Growing up stack started below %p and we are currently up to %p\n", arg, ¤t);
|
||||
return (void *)0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the stack is growing down */
|
||||
if ( ((long)arg) - ((long)¤t) >= stacksize)
|
||||
{
|
||||
output("Growing down stack started upon %p and we are currently down to %p\n", arg, ¤t);
|
||||
return (void *)0;
|
||||
}
|
||||
}
|
||||
|
||||
/* We are not yet overflowing, so we loop */
|
||||
{
|
||||
return overflow(arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void * threaded (void * arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
#if VERBOSE > 4
|
||||
output("Thread %i starting...\n", sc);
|
||||
#endif
|
||||
|
||||
/* Alternate stack test */
|
||||
if (scenarii[sc].bottom != NULL)
|
||||
{
|
||||
#ifdef WITHOUT_XOPEN
|
||||
output("Unable to test the alternate stack feature; need an integer pointer cast\n");
|
||||
#else
|
||||
intptr_t stack_start, stack_end, current_pos;
|
||||
|
||||
stack_start = (intptr_t) scenarii[sc].bottom;
|
||||
stack_end = stack_start + (intptr_t)sysconf(_SC_THREAD_STACK_MIN);
|
||||
current_pos = (intptr_t)&ret;
|
||||
|
||||
#if VERBOSE > 2
|
||||
output("Stack bottom: %p\n", scenarii[sc].bottom);
|
||||
output("Stack end : %p (stack is 0x%lx bytes)\n", (void *)stack_end, stack_end - stack_start);
|
||||
output("Current pos : %p\n", &ret);
|
||||
#endif
|
||||
if ((stack_start > current_pos) || (current_pos > stack_end))
|
||||
{ FAILED("The specified stack was not used.\n"); }
|
||||
|
||||
#endif // WITHOUT_XOPEN
|
||||
}
|
||||
|
||||
|
||||
/* Guard size test */
|
||||
if ((scenarii[sc].bottom == NULL) /* no alternative stack was specified */
|
||||
&& (scenarii[sc].guard == 2) /* guard area size is 1 memory page */
|
||||
&& (scenarii[sc].altsize == 1))/* We know the stack size */
|
||||
{
|
||||
pid_t child, ctrl;
|
||||
int status;
|
||||
|
||||
child=fork(); /* We'll test the feature in another process as this test may segfault */
|
||||
|
||||
if (child == -1) { UNRESOLVED(errno, "Failed to fork()"); }
|
||||
|
||||
if (child != 0) /* father */
|
||||
{
|
||||
/* Just wait for the child and check its return value */
|
||||
ctrl = waitpid(child, &status, 0);
|
||||
if (ctrl != child) { UNRESOLVED(errno, "Failed to wait for process termination"); }
|
||||
|
||||
if (WIFEXITED(status)) /* The process exited */
|
||||
{
|
||||
if (WEXITSTATUS(status) == 0)
|
||||
{ FAILED("Overflow into the guard area did not fail"); }
|
||||
if (WEXITSTATUS(status) == PTS_UNRESOLVED)
|
||||
{ UNRESOLVED(-1, "The child process returned unresolved status"); }
|
||||
#if VERBOSE > 4
|
||||
else
|
||||
{ output("The child process returned: %i\n", WEXITSTATUS(status)); }
|
||||
}
|
||||
else
|
||||
{
|
||||
output("The child process did not returned\n");
|
||||
if (WIFSIGNALED(status))
|
||||
output("It was killed with signal %i\n", WTERMSIG(status));
|
||||
else
|
||||
output("neither was it killed. (status = %i)\n", status);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (child == 0) /* this is the new process */
|
||||
{
|
||||
pthread_t th;
|
||||
|
||||
ret = pthread_create(&th, &scenarii[sc].ta, overflow, NULL); /* Create a new thread with the same attributes */
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to create another thread with the same attributes in the new process"); }
|
||||
|
||||
if (scenarii[sc].detached == 0)
|
||||
{
|
||||
ret = pthread_join(th, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); }
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Just wait for the thread to terminate */
|
||||
do { ret = sem_wait(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
}
|
||||
|
||||
/* Terminate the child process here */
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Post the semaphore to unlock the main thread in case of a detached thread */
|
||||
do { ret = sem_post(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); }
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
-282
@@ -1,282 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
*
|
||||
* pthread_create creates a thread with attributes as specified in the attr parameter.
|
||||
|
||||
* The steps are:
|
||||
*
|
||||
* -> See test 1-5.c for details
|
||||
* -> This one will test the scheduling behavior is correct.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
/* Some routines are part of the XSI Extensions */
|
||||
#ifndef WITHOUT_XOPEN
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
/********************************************************************************************/
|
||||
/****************************** standard includes *****************************************/
|
||||
/********************************************************************************************/
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.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
|
||||
|
||||
/* The value below shall be >= to the # of CPU on the test architecture */
|
||||
#define NCPU (4)
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Test cases *****************************************/
|
||||
/********************************************************************************************/
|
||||
#define STD_MAIN /* This allows main() to be defined in the included file */
|
||||
|
||||
#include "threads_scenarii.c"
|
||||
|
||||
/* This file will define the following objects:
|
||||
* scenarii: array of struct __scenario type.
|
||||
* NSCENAR : macro giving the total # of scenarii
|
||||
* scenar_init(): function to call before use the scenarii array.
|
||||
* scenar_fini(): function to call after end of use of the scenarii array.
|
||||
*/
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Real Test *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
|
||||
/* The 2 following functions are used for the scheduling tests */
|
||||
void * lp_func(void * arg)
|
||||
{
|
||||
int * ctrl = (int *) arg;
|
||||
*ctrl=2;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void * hp_func(void * arg)
|
||||
{
|
||||
int *ctrl = (int *) arg;
|
||||
int dummy=0, i;
|
||||
do
|
||||
{
|
||||
/* some dummy task */
|
||||
dummy += 3;
|
||||
dummy %= 17;
|
||||
dummy *= 47;
|
||||
for (i=0; i<1000000000; i++);
|
||||
#if VERBOSE > 6
|
||||
output("%p\n", pthread_self());
|
||||
#endif
|
||||
}
|
||||
while (*ctrl == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void * threaded (void * arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
#if VERBOSE > 4
|
||||
output("Thread %i starting...\n", sc);
|
||||
#endif
|
||||
|
||||
/* Scheduling (priority) tests */
|
||||
if ((sysconf(_SC_THREAD_PRIORITY_SCHEDULING) > 0)
|
||||
&& (scenarii[sc].explicitsched != 0)
|
||||
&& (scenarii[sc].schedpolicy != 0)
|
||||
&& (scenarii[sc].schedparam == 1))
|
||||
{
|
||||
/* We will create NCPU threads running with a high priority with the same sched policy policy
|
||||
and one with a low-priority.
|
||||
The low-priority thread should not run until the other threads stop running,
|
||||
unless the machine has more than NCPU processors... */
|
||||
|
||||
pthread_t hpth[NCPU]; /* High priority threads */
|
||||
pthread_t lpth; /* Low Priority thread */
|
||||
int ctrl; /* Check value */
|
||||
pthread_attr_t ta;
|
||||
struct sched_param sp;
|
||||
int policy;
|
||||
int i=0;
|
||||
struct timespec now, timeout;
|
||||
|
||||
/* Start with checking we are executing with the required parameters */
|
||||
ret = pthread_getschedparam(pthread_self(), &policy, &sp);
|
||||
if (ret != 0) { UNRESOLVED(ret , "Failed to get current thread policy"); }
|
||||
|
||||
if (((scenarii[sc].schedpolicy == 1) && (policy != SCHED_FIFO))
|
||||
|| ((scenarii[sc].schedpolicy == 2) && (policy != SCHED_RR)))
|
||||
{
|
||||
FAILED("The thread is not using the scheduling policy that was required");
|
||||
}
|
||||
if (((scenarii[sc].schedparam == 1) && (sp.sched_priority != sched_get_priority_max(policy)))
|
||||
|| ((scenarii[sc].schedparam ==-1) && (sp.sched_priority != sched_get_priority_min(policy))))
|
||||
{
|
||||
|
||||
FAILED("The thread is not using the scheduling parameter that was required");
|
||||
}
|
||||
|
||||
ctrl = 0; /* Initial state */
|
||||
|
||||
/* Get the policy information */
|
||||
ret = pthread_attr_getschedpolicy(&scenarii[sc].ta, &policy);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to read sched policy"); }
|
||||
|
||||
/* We put a timeout cause the test might lock the machine when it runs */
|
||||
alarm(60);
|
||||
|
||||
/* Create the high priority threads */
|
||||
ret = pthread_attr_init(&ta);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a thread attribute object"); }
|
||||
|
||||
ret = pthread_attr_setinheritsched(&ta, PTHREAD_EXPLICIT_SCHED);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to set inheritsched attribute"); }
|
||||
|
||||
ret = pthread_attr_setschedpolicy(&ta, policy);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to set the sched policy"); }
|
||||
|
||||
sp.sched_priority = sched_get_priority_max(policy) - 1;
|
||||
|
||||
ret = pthread_attr_setschedparam(&ta, &sp);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to set the sched param"); }
|
||||
|
||||
#if VERBOSE > 1
|
||||
output("Starting %i high- and 1 low-priority threads.\n", NCPU);
|
||||
#endif
|
||||
for (i=0; i<NCPU; i++)
|
||||
{
|
||||
ret = pthread_create(&hpth[i], &ta, hp_func, &ctrl);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to create enough threads"); }
|
||||
}
|
||||
#if VERBOSE > 5
|
||||
output("The %i high-priority threads are running\n", NCPU);
|
||||
#endif
|
||||
|
||||
/* Create the low-priority thread */
|
||||
sp.sched_priority = sched_get_priority_min(policy);
|
||||
|
||||
ret = pthread_attr_setschedparam(&ta, &sp);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to set the sched param"); }
|
||||
|
||||
ret = pthread_create(&lpth, &ta, lp_func, &ctrl);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to create enough threads"); }
|
||||
|
||||
/* Keep going */
|
||||
ret = clock_gettime(CLOCK_REALTIME, &now);
|
||||
if (ret != 0) { UNRESOLVED(errno, "Failed to read current time"); }
|
||||
|
||||
timeout.tv_sec = now.tv_sec;
|
||||
timeout.tv_nsec = now.tv_nsec + 500000000;
|
||||
while (timeout.tv_nsec >= 1000000000)
|
||||
{
|
||||
timeout.tv_sec++;
|
||||
timeout.tv_nsec -= 1000000000;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (ctrl != 0)
|
||||
{
|
||||
output("The low priority thread executed. This might be normal if you have more than %i CPU.\n", NCPU + 1);
|
||||
FAILED("Low priority thread executed -- the sched parameters are ignored?");
|
||||
}
|
||||
ret = clock_gettime(CLOCK_REALTIME, &now);
|
||||
if (ret != 0) { UNRESOLVED(errno, "Failed to read current time"); }
|
||||
#if VERBOSE > 5
|
||||
output("Time: %d.%09d (to: %d.%09d)\n", now.tv_sec, now.tv_nsec, timeout.tv_sec, timeout.tv_nsec);
|
||||
#endif
|
||||
}
|
||||
while ((now.tv_sec <= timeout.tv_sec) && (now.tv_nsec <= timeout.tv_nsec));
|
||||
|
||||
/* Ok the low priority thread did not execute :) */
|
||||
|
||||
/* tell the other high priority to terminate */
|
||||
ctrl = 1;
|
||||
|
||||
for (i=0; i<NCPU; i++)
|
||||
{
|
||||
ret = pthread_join(hpth[i], NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to join a thread"); }
|
||||
}
|
||||
|
||||
/* Ok so now the low priority should execute when we stop this one (or earlier). */
|
||||
ret = pthread_join(lpth, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to join the low priority thread"); }
|
||||
|
||||
/* We just check that it executed */
|
||||
if (ctrl != 2) { FAILED("Joined the low-priority thread but it did not execute."); }
|
||||
|
||||
#if VERBOSE > 1
|
||||
output("The scheduling parameter was set accordingly to the thread attribute.\n");
|
||||
#endif
|
||||
|
||||
/* We're done. */
|
||||
ret = pthread_attr_destroy(&ta);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to destroy a thread attribute object"); }
|
||||
}
|
||||
|
||||
/* Post the semaphore to unlock the main thread in case of a detached thread */
|
||||
do { ret = sem_post(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); }
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test pthread_create().
|
||||
*
|
||||
* If pthread_create() fails, no new thread is created and the contents of the
|
||||
* location referenced by 'thread' is undefined.
|
||||
*
|
||||
* EXPLANATION: 3 ways that pthread_create can fail is if (1) The system lacked memory
|
||||
* resources. (2) The caller did not have the appropriate permissions. (3) An invalid
|
||||
* attributes object was passed. Since the last situation is the easiest to implement, that
|
||||
* is the one I chose to use in order to make pthread_create fail.
|
||||
*
|
||||
* The problem with that is that accessing an uninitialized attributes object will cause a
|
||||
* segmentation fault (since it usually points to garbage). So the idea here is to catch
|
||||
* the SIGSEGV signal (segmentation faults), and to see if the thread was ever created, by
|
||||
* setting a flag in the thread's starting routine.
|
||||
*
|
||||
* I recognize that causing pthread_create() to fail gracefully is a very difficult task,
|
||||
* especially taking into consideration that a lot of it is implementation-specific. I did
|
||||
* try to manually set the members of a pthread_attr_t object to invalid values, but that didn't
|
||||
* seem to make pthread_create() fail at all, in any of the implementations I tested on. So for
|
||||
* now, this is what we have.
|
||||
*
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a thread using pthread_create() with an invalid attributes object (uninitialized).
|
||||
* 2. Catch the SIGSEGV (seg fault) signal. In the signal handler, check to make sure that
|
||||
* the start routine for the thread was never reached, meaning the thread was never created.
|
||||
* 3. If SIGSEGV was not caught in 10 seconds, the test times out and fails. If the signal
|
||||
* was caught, but the thread start routine was called at some point, the test also fails.
|
||||
*
|
||||
*
|
||||
* - [email protected]: 2004-04-30
|
||||
* This case will end with segmentation fault.
|
||||
* I happened to find on NPTL pthread_create() can fail is
|
||||
* pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_INHERIT), while
|
||||
* does not call pthread_attr_setschedparam() to set the prority. (since
|
||||
* by default the priority will be 0. But this is implementation specific.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int created_thread; /* Flag indicating that the thread start routine was reached, and
|
||||
therefore, the thread was created. */
|
||||
int segfault_flag; /* Flag indicating that a segmentation fault occured. */
|
||||
|
||||
/* Thread's start routine. */
|
||||
void *a_thread_func()
|
||||
{
|
||||
/* Indicate that the thread start routine was reached. If it was reached, the test
|
||||
* fails, as the thread should have not been created in the first place. */
|
||||
created_thread = 1;
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Signal handler for SIGSEGV (segmentation fault signal) */
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
/* If a segmentation fault occured when it was supposed to (i.e. when pthread_create()
|
||||
* was called with the invalid attributes object). */
|
||||
if(segfault_flag == 1)
|
||||
{
|
||||
/* check if the thread start routine was called. If yes, then the thread was
|
||||
* created, meaning the test fails. */
|
||||
if(created_thread == 1)
|
||||
{
|
||||
printf("Test FAILED: Created thread though an invalid attribute was passed to pthread_create().\n");
|
||||
pthread_exit((void*)PTS_FAIL);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
pthread_exit((void*)PTS_PASS);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Test FAILED: Did not receive segmentation fault signal, waited 10 seconds.\n");
|
||||
pthread_exit((void*)PTS_FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* MAIN */
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
pthread_attr_t inv_attr;
|
||||
struct sigaction act;
|
||||
|
||||
/* Inializing flags. */
|
||||
segfault_flag = 1;
|
||||
created_thread = 0;
|
||||
|
||||
/* Set signal handler for SIGSEGV (seg fault) */
|
||||
act.sa_handler = sig_handler;
|
||||
act.sa_flags = 0;
|
||||
sigaction(SIGSEGV, &act, NULL);
|
||||
|
||||
/* Create the thread with the invalid, uninitialized attributes object. */
|
||||
pthread_create(&new_th, &inv_attr, a_thread_func, NULL);
|
||||
|
||||
/* Should not reach here if process correctly seg-faulted. */
|
||||
segfault_flag = 0;
|
||||
|
||||
/* Timeout after 10 seconds if a segfault was not encountered. The test then fails. */
|
||||
sleep(10);
|
||||
|
||||
/* Manually send the SIGSEGV signal to the signal handler. If this point is reached,
|
||||
* the test fails. */
|
||||
if(raise(SIGSEGV) != 0)
|
||||
{
|
||||
perror("Error in raise()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("Test FAILED.\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2004, Intel Corporation. All rights reserved.
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
*
|
||||
* [email protected]
|
||||
*
|
||||
* if _POSIX_THREAD_CPUTIME is defined, the new thread shall have a CPU-time
|
||||
* clock accessible, and the initial value of this clock shall be set to 0.
|
||||
*/
|
||||
/* Create a new thread and get the time of the thread CUP-time clock
|
||||
* using clock_gettime().
|
||||
* Note, the tv_nsec cannot be exactly 0 at the time of calling
|
||||
* clock_gettime() since the thread has executed some time. */
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void *a_thread_func()
|
||||
{
|
||||
clockid_t cpuclock;
|
||||
struct timespec ts = {.tv_sec = 1, .tv_nsec = 1};
|
||||
pthread_getcpuclockid(pthread_self(), &cpuclock);
|
||||
clock_gettime(cpuclock, &ts);
|
||||
/* Just test the tv_sec field here. */
|
||||
if (ts.tv_sec != 0)
|
||||
{
|
||||
printf("ts.tv_sec: %ld, ts.tv_nsec: %ld\n",
|
||||
ts.tv_sec, ts.tv_nsec);
|
||||
exit(PTS_FAIL);
|
||||
}
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _POSIX_THREAD_CPUTIME == -1
|
||||
printf("_POSIX_THREAD_CPUTIME not supported\n");
|
||||
return PTS_UNSUPPORTED;
|
||||
#endif
|
||||
pthread_t new_th;
|
||||
|
||||
if (sysconf(_SC_THREAD_CPUTIME) == -1) {
|
||||
printf("_POSIX_THREAD_CPUTIME not supported\n");
|
||||
return PTS_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
pthread_join(new_th, NULL);
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test pthread_create()
|
||||
*
|
||||
* If success, pthread_create() returns zero.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a thread using pthread_create(), passing to it all valid values.
|
||||
* 2. If the return code was not EGAIN, EPERM or EINVAL, it should return 0.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
/* Thread starting routine that really does nothing. */
|
||||
void *a_thread_func()
|
||||
{
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
int ret;
|
||||
|
||||
/* Create new thread and check the return value. */
|
||||
ret = pthread_create(&new_th, NULL, a_thread_func, NULL);
|
||||
if(ret != 0)
|
||||
{
|
||||
if((ret != EINVAL) && (ret != EAGAIN) && (ret != EPERM))
|
||||
|
||||
printf("Test FAILED: Wrong return code: %d\n", ret);
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-333
@@ -1,333 +0,0 @@
|
||||
/*
|
||||
* 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 function does not return EINTR
|
||||
|
||||
* The steps are:
|
||||
* -> pthread_kill a thread which creates threads
|
||||
* -> check that EINTR is never returned
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
/* Some routines are part of the XSI Extensions */
|
||||
#ifndef WITHOUT_XOPEN
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
/********************************************************************************************/
|
||||
/****************************** standard includes *****************************************/
|
||||
/********************************************************************************************/
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.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
|
||||
|
||||
#define WITH_SYNCHRO
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Test cases *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
#include "threads_scenarii.c"
|
||||
|
||||
/* This file will define the following objects:
|
||||
* scenarii: array of struct __scenario type.
|
||||
* NSCENAR : macro giving the total # of scenarii
|
||||
* scenar_init(): function to call before use the scenarii array.
|
||||
* scenar_fini(): function to call after end of use of the scenarii array.
|
||||
*/
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Real Test *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
char do_it=1;
|
||||
char woken=0;
|
||||
unsigned long count_ope=0;
|
||||
#ifdef WITH_SYNCHRO
|
||||
sem_t semsig1;
|
||||
sem_t semsig2;
|
||||
unsigned long count_sig=0;
|
||||
#endif
|
||||
|
||||
sigset_t usersigs;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sig;
|
||||
#ifdef WITH_SYNCHRO
|
||||
sem_t *sem;
|
||||
#endif
|
||||
} thestruct;
|
||||
|
||||
/* the following function keeps on sending the signal to the process */
|
||||
void * sendsig (void * arg)
|
||||
{
|
||||
thestruct *thearg = (thestruct *) arg;
|
||||
int ret;
|
||||
pid_t process;
|
||||
|
||||
process=getpid();
|
||||
|
||||
/* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */
|
||||
ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread"); }
|
||||
|
||||
while (do_it)
|
||||
{
|
||||
#ifdef WITH_SYNCHRO
|
||||
if ((ret = sem_wait(thearg->sem)))
|
||||
{ UNRESOLVED(errno, "Sem_wait in sendsig"); }
|
||||
count_sig++;
|
||||
#endif
|
||||
|
||||
ret = kill(process, thearg->sig);
|
||||
if (ret != 0) { UNRESOLVED(errno, "Kill in sendsig"); }
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Next are the signal handlers. */
|
||||
/* This one is registered for signal SIGUSR1 */
|
||||
void sighdl1(int sig)
|
||||
{
|
||||
#ifdef WITH_SYNCHRO
|
||||
if (sem_post(&semsig1))
|
||||
{ UNRESOLVED(errno, "Sem_post in signal handler 1"); }
|
||||
#endif
|
||||
}
|
||||
/* This one is registered for signal SIGUSR2 */
|
||||
void sighdl2(int sig)
|
||||
{
|
||||
#ifdef WITH_SYNCHRO
|
||||
if (sem_post(&semsig2))
|
||||
{ UNRESOLVED(errno, "Sem_post in signal handler 2"); }
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Thread function -- almost does nothing */
|
||||
void * threaded(void * arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Signal we're done (especially in case of a detached thread) */
|
||||
do { ret = sem_post(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
|
||||
/* return */
|
||||
return arg;
|
||||
}
|
||||
|
||||
/* Test function -- creates the threads and check that EINTR is never returned. */
|
||||
void * test(void * arg)
|
||||
{
|
||||
int ret=0;
|
||||
pthread_t child;
|
||||
|
||||
/* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */
|
||||
ret = pthread_sigmask(SIG_UNBLOCK, &usersigs, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread"); }
|
||||
|
||||
sc = 0;
|
||||
|
||||
while (do_it)
|
||||
{
|
||||
#if VERBOSE > 5
|
||||
output("-----\n");
|
||||
output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr);
|
||||
#endif
|
||||
|
||||
count_ope++;
|
||||
|
||||
ret = pthread_create(&child, &scenarii[sc].ta, threaded, NULL);
|
||||
if (ret == EINTR) { FAILED("pthread_create returned EINTR"); }
|
||||
switch (scenarii[sc].result)
|
||||
{
|
||||
case 0: /* Operation was expected to succeed */
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); }
|
||||
break;
|
||||
|
||||
case 1: /* Operation was expected to fail */
|
||||
if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); }
|
||||
break;
|
||||
|
||||
case 2: /* We did not know the expected result */
|
||||
default:
|
||||
#if VERBOSE > 5
|
||||
if (ret == 0)
|
||||
{ output("Thread has been created successfully for this scenario\n"); }
|
||||
else
|
||||
{ output("Thread creation failed with the error: %s\n", strerror(ret)); }
|
||||
#endif
|
||||
;
|
||||
}
|
||||
if (ret == 0) /* The new thread is running */
|
||||
{
|
||||
if (scenarii[sc].detached == 0)
|
||||
{
|
||||
ret = pthread_join(child, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); }
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Just wait for the thread to terminate */
|
||||
do { ret = sem_wait(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
}
|
||||
}
|
||||
|
||||
/* Change thread attribute for the next loop */
|
||||
sc++;
|
||||
sc %= NSCENAR;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Main function */
|
||||
int main (int argc, char * argv[])
|
||||
{
|
||||
int ret;
|
||||
pthread_t th_work, th_sig1, th_sig2;
|
||||
thestruct arg1, arg2;
|
||||
struct sigaction sa;
|
||||
|
||||
/* Initialize output routine */
|
||||
output_init();
|
||||
|
||||
/* Initialize thread attribute objects */
|
||||
scenar_init();
|
||||
|
||||
/* We need to register the signal handlers for the PROCESS */
|
||||
sigemptyset (&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = sighdl1;
|
||||
if ((ret = sigaction (SIGUSR1, &sa, NULL)))
|
||||
{ UNRESOLVED(ret, "Unable to register signal handler1"); }
|
||||
sa.sa_handler = sighdl2;
|
||||
if ((ret = sigaction (SIGUSR2, &sa, NULL)))
|
||||
{ UNRESOLVED(ret, "Unable to register signal handler2"); }
|
||||
|
||||
/* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */
|
||||
sigemptyset(&usersigs);
|
||||
ret = sigaddset(&usersigs, SIGUSR1);
|
||||
ret |= sigaddset(&usersigs, SIGUSR2);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set"); }
|
||||
|
||||
/* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */
|
||||
ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread"); }
|
||||
|
||||
#ifdef WITH_SYNCHRO
|
||||
if (sem_init(&semsig1, 0, 1))
|
||||
{ UNRESOLVED(errno, "Semsig1 init"); }
|
||||
if (sem_init(&semsig2, 0, 1))
|
||||
{ UNRESOLVED(errno, "Semsig2 init"); }
|
||||
#endif
|
||||
|
||||
if ((ret = pthread_create(&th_work, NULL, test, NULL)))
|
||||
{ UNRESOLVED(ret, "Worker thread creation failed"); }
|
||||
|
||||
arg1.sig = SIGUSR1;
|
||||
arg2.sig = SIGUSR2;
|
||||
#ifdef WITH_SYNCHRO
|
||||
arg1.sem = &semsig1;
|
||||
arg2.sem = &semsig2;
|
||||
#endif
|
||||
|
||||
if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1)))
|
||||
{ UNRESOLVED(ret, "Signal 1 sender thread creation failed"); }
|
||||
if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2)))
|
||||
{ UNRESOLVED(ret, "Signal 2 sender thread creation failed"); }
|
||||
|
||||
/* Let's wait for a while now */
|
||||
sleep(1);
|
||||
|
||||
/* Now stop the threads and join them */
|
||||
do { do_it=0; }
|
||||
while (do_it);
|
||||
|
||||
if ((ret = pthread_join(th_sig1, NULL)))
|
||||
{ UNRESOLVED(ret, "Signal 1 sender thread join failed"); }
|
||||
if ((ret = pthread_join(th_sig2, NULL)))
|
||||
{ UNRESOLVED(ret, "Signal 2 sender thread join failed"); }
|
||||
|
||||
if ((ret = pthread_join(th_work, NULL)))
|
||||
{ UNRESOLVED(ret, "Worker thread join failed"); }
|
||||
|
||||
scenar_fini();
|
||||
|
||||
#if VERBOSE > 0
|
||||
output("Test executed successfully.\n");
|
||||
output(" %d thread creations.\n", count_ope);
|
||||
#ifdef WITH_SYNCHRO
|
||||
output(" %d signals were sent meanwhile.\n", count_sig);
|
||||
#endif
|
||||
#endif
|
||||
PASSED;
|
||||
}
|
||||
|
||||
-156
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
*
|
||||
* If the current thread has an alternate stack, the new thread does not inherit
|
||||
* this stack
|
||||
|
||||
* The steps are:
|
||||
* -> Create a thread with an alternate stack.
|
||||
* -> From this thread, create another thread.
|
||||
* -> Check that the new thread does not use the same stack.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
/* Some routines are part of the XSI Extensions */
|
||||
#ifndef WITHOUT_XOPEN
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
/********************************************************************************************/
|
||||
/****************************** standard includes *****************************************/
|
||||
/********************************************************************************************/
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.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 cases *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
#define STD_MAIN
|
||||
#include "threads_scenarii.c"
|
||||
|
||||
/* This file will define the following objects:
|
||||
* scenarii: array of struct __scenario type.
|
||||
* NSCENAR : macro giving the total # of scenarii
|
||||
* scenar_init(): function to call before use the scenarii array.
|
||||
* scenar_fini(): function to call after end of use of the scenarii array.
|
||||
*/
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Real Test *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
void * teststack(void * arg)
|
||||
{
|
||||
int ret=0;
|
||||
*(int **)arg = &ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Thread function */
|
||||
void * threaded(void * arg)
|
||||
{
|
||||
int ret;
|
||||
int * child_stack;
|
||||
pthread_t gchild;
|
||||
|
||||
int sz = sysconf(_SC_THREAD_STACK_MIN);
|
||||
|
||||
if (scenarii[sc].bottom != NULL)
|
||||
{
|
||||
#if VERBOSE > 1
|
||||
output("Processing test\n");
|
||||
#endif
|
||||
|
||||
/* Create a new thread and get a location inside its stack */
|
||||
ret = pthread_create(&gchild, NULL, teststack, &child_stack);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to create a thread with default attribute"); }
|
||||
|
||||
ret = pthread_join(gchild, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to join the test thread"); }
|
||||
|
||||
/* Check the new thread stack location was outside of the current thread location */
|
||||
/* We convert all the @ to longs */
|
||||
#if VERBOSE > 4
|
||||
output("Current stack : %p -> %p\n", scenarii[sc].bottom, sz + (long)scenarii[sc].bottom);
|
||||
output("Child location: %p\n", child_stack);
|
||||
#endif
|
||||
|
||||
if ( (((long)scenarii[sc].bottom) < ((long)child_stack))
|
||||
&& (((long)child_stack) < (((long)scenarii[sc].bottom) + sz)))
|
||||
{
|
||||
FAILED("The new thread inherited th alternate stack from its parent");
|
||||
}
|
||||
}
|
||||
|
||||
/* Signal we're done (especially in case of a detached thread) */
|
||||
do { ret = sem_post(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
|
||||
/* return */
|
||||
return arg;
|
||||
}
|
||||
|
||||
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test If 'attr' is NULL, the default attributes shall be used.
|
||||
* The attribute that will be tested is the detached state, because that is
|
||||
* the only state that has a default listed in the specification.
|
||||
*
|
||||
* default: PTHREAD_CREATE_JOINABLE
|
||||
* Other valid values: PTHREAD_CREATE_DETACHED
|
||||
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a thread using pthread_create() and passing 'NULL' for 'attr'.
|
||||
* 2. Check to see if the thread is joinable, since that is the default.
|
||||
* 3. We do this by calling pthread_join() and pthread_detach(). If
|
||||
* they fail, then the thread is not joinable, and the test fails.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void *a_thread_func()
|
||||
{
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
/* Create a new thread. The default attribute should be that
|
||||
* it is joinable. */
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* The new thread should be able to be joined. */
|
||||
if(pthread_join(new_th, NULL) == EINVAL)
|
||||
{
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
/* The new thread should be able to be detached. */
|
||||
if(pthread_detach(new_th) == EINVAL)
|
||||
{
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test if the attributes specified by 'attr' are modified later, the thread's
|
||||
* attributes shall not be affected.
|
||||
* The attribute that will be tested is the detached state.
|
||||
*
|
||||
*
|
||||
* Steps:
|
||||
* 1. Set a pthread_attr_t object to be PTHREAD_CREATE_JOINABLE.
|
||||
* 2. Create a new thread using pthread_create() and passing this attribute
|
||||
* object.
|
||||
* 3. Change the attribute object to be in a detached state rather than
|
||||
* joinable.
|
||||
* 4. Doing this should not effect the fact that the thread that was created
|
||||
* is joinable, and so calling the functions pthread_detach() should not fail.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
# define TIMEOUT 10 /* Timeout value of 10 seconds. */
|
||||
# define INTHREAD 0 /* Control going to or is already for Thread */
|
||||
# define INMAIN 1 /* Control going to or is already for Main */
|
||||
|
||||
int sem1; /* Manual semaphore */
|
||||
|
||||
void *a_thread_func()
|
||||
{
|
||||
/* Indicate to main() that the thread was created. */
|
||||
sem1=INTHREAD;
|
||||
|
||||
/* Wait for main to detach change the attribute object and try and detach this thread.
|
||||
* Wait for a timeout value of 10 seconds before timing out if the thread was not able
|
||||
* to be detached. */
|
||||
sleep(TIMEOUT);
|
||||
|
||||
printf("Test FAILED: Did not detach the thread, main still waiting for it to end execution.\n");
|
||||
pthread_exit((void*)PTS_FAIL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
pthread_attr_t new_attr;
|
||||
int ret;
|
||||
|
||||
/* Initializing */
|
||||
sem1 = INMAIN;
|
||||
if(pthread_attr_init(&new_attr) != 0)
|
||||
{
|
||||
perror("Error intializing attribute object\n");
|
||||
return PTS_UNRESOLVED;
|
||||
|
||||
}
|
||||
|
||||
/* Make the new attribute object joinable */
|
||||
if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_JOINABLE) != 0)
|
||||
{
|
||||
perror("Error setting the detached state of the attribute\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Create a new thread and pass it the attribute object that will
|
||||
* make it joinable. */
|
||||
if(pthread_create(&new_th, &new_attr, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
while(sem1==INMAIN)
|
||||
sleep(1);
|
||||
|
||||
/* Now change the attribute object to be in a detached state */
|
||||
if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_DETACHED) != 0)
|
||||
{
|
||||
perror("Error setting the detached state of the attribute\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* The new thread should still be able to be detached. */
|
||||
if((ret=pthread_detach(new_th)) == EINVAL)
|
||||
{
|
||||
printf("Test FAILED: pthread_detach failed on joinable thread. Return value is %d\n", ret);
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-649
@@ -1,649 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
*
|
||||
* Once the thread has been created, subsequent changes to the
|
||||
* thread attribute object don't affect the running thread.
|
||||
|
||||
* The steps are:
|
||||
* -> stack grow
|
||||
* -> create a thread with minimal stack size
|
||||
* -> change the stack size to a bigger value
|
||||
* -> check that the thread stack size did not change.
|
||||
* -> stack decrease
|
||||
* -> create a thread with a known stack size (> minimum)
|
||||
* -> change the stack size to the min value
|
||||
* -> check that the thread stack size did not change.
|
||||
* -> sched policy/param change
|
||||
* -> create a new thread with a known policy
|
||||
* -> change the policy in the thread attribute and check the thread policy did not change
|
||||
* -> change the schedparam in the thread attribute and check the thread priority did not change
|
||||
* -> change the policy in the running thread and check the thread attribute did not change.
|
||||
* -> change the priority in the running thread and check the thread attribute did not change.
|
||||
|
||||
* The test fails if one of the checking fails
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
/* Some routines are part of the XSI Extensions */
|
||||
#ifndef WITHOUT_XOPEN
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
/********************************************************************************************/
|
||||
/****************************** standard includes *****************************************/
|
||||
/********************************************************************************************/
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.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 cases *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
#include "threads_scenarii.c"
|
||||
|
||||
/* This file will define the following objects:
|
||||
* scenarii: array of struct __scenario type.
|
||||
* NSCENAR : macro giving the total # of scenarii
|
||||
* scenar_init(): function to call before use the scenarii array.
|
||||
* scenar_fini(): function to call after end of use of the scenarii array.
|
||||
*/
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Real Test *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
sem_t semsync[2]; /* These semaphores will only be used in child process! */
|
||||
|
||||
/* The overflow function is used to test the stack overflow */
|
||||
void * overflow(void * arg)
|
||||
{
|
||||
void * current;
|
||||
void * pad[50]; /* We want to consume the stack quickly */
|
||||
long stacksize = sysconf(_SC_THREAD_STACK_MIN); /* make sure we touch the current stack memory */
|
||||
|
||||
pad[1]=NULL; /* so compiler stops complaining about unused variables */
|
||||
int ret = 0;
|
||||
|
||||
if (arg == NULL)
|
||||
{
|
||||
/* first call */
|
||||
|
||||
/* Synchronize with the parent */
|
||||
do { ret = sem_wait(&semsync[0]); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
|
||||
|
||||
/* Go to recursion */
|
||||
current = overflow(¤t);
|
||||
|
||||
/* Terminated */
|
||||
do { ret = sem_post(&semsync[1]); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); }
|
||||
|
||||
/* Terminate the overflow thread */
|
||||
return current;
|
||||
}
|
||||
|
||||
/* we cast the pointers into long, which might be a problem on some architectures... */
|
||||
if ( ((long)arg) < ((long)¤t))
|
||||
{
|
||||
/* the stack is growing up */
|
||||
if ( ((long)¤t) - ((long)arg) >= stacksize)
|
||||
{
|
||||
output("Growing up stack started below %p and we are currently up to %p\n", arg, ¤t);
|
||||
return (void *)0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the stack is growing down */
|
||||
if ( ((long)arg) - ((long)¤t) >= stacksize)
|
||||
{
|
||||
output("Growing down stack started upon %p and we are currently down to %p\n", arg, ¤t);
|
||||
return (void *)0;
|
||||
}
|
||||
}
|
||||
|
||||
/* We are not yet overflowing, so we loop */
|
||||
return overflow(arg);
|
||||
}
|
||||
|
||||
/* The following function will return
|
||||
0 if a thread created with the attribute ta is able to fill the stack up to {minstacksize}.
|
||||
1 if the operation failed.
|
||||
2 if an error prevented the test to complete
|
||||
|
||||
If newsize is not 0, the stack size in ta will be set to this value once the thread is created.
|
||||
|
||||
*/
|
||||
int test_stack(pthread_attr_t * ta, size_t newsize)
|
||||
{
|
||||
pid_t child, ctrl;
|
||||
int status;
|
||||
int ret;
|
||||
|
||||
child=fork(); /* We'll test the feature in another process as this test may segfault */
|
||||
|
||||
if (child == -1)
|
||||
{
|
||||
output("Failed to fork (%s)\n", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (child != 0) /* father */
|
||||
{
|
||||
/* Just wait for the child and check its return value */
|
||||
ctrl = waitpid(child, &status, 0);
|
||||
if (ctrl != child)
|
||||
{
|
||||
output("Failed to wait for process termination (%s)\n", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (WIFEXITED(status)) /* The process exited */
|
||||
{
|
||||
if (WEXITSTATUS(status) == 0)
|
||||
{ return 0; } /* We were able to fill the stack */
|
||||
if (WEXITSTATUS(status) == PTS_UNRESOLVED)
|
||||
{
|
||||
output("The child process returned unresolved status\n");
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
output("The child process returned: %i\n", WEXITSTATUS(status));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if VERBOSE > 4
|
||||
output("The child process did not return\n");
|
||||
if (WIFSIGNALED(status))
|
||||
output("It was killed with signal %i\n", WTERMSIG(status));
|
||||
else
|
||||
output("neither was it killed. (status = %i)\n", status);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* else */
|
||||
/* this is the new process */
|
||||
{
|
||||
pthread_t th;
|
||||
void * rc;
|
||||
int detach;
|
||||
|
||||
/* Semaphore to force the child to wait */
|
||||
ret = sem_init(&semsync[0], 0,0);
|
||||
if (ret == -1) { UNRESOLVED(errno, "Unable to init a semaphore"); }
|
||||
/* Semaphore to detect thread ending */
|
||||
ret = sem_init(&semsync[1], 0,0);
|
||||
if (ret == -1) { UNRESOLVED(errno, "Unable to init a semaphore"); }
|
||||
|
||||
ret = pthread_create(&th, ta, overflow, NULL); /* Create a new thread with the same attributes */
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to create a thread in the new process"); }
|
||||
|
||||
/* If we were asked to perform a change on ta, do it now. */
|
||||
if (newsize)
|
||||
{
|
||||
ret = pthread_attr_setstacksize(ta, newsize);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to set the new stack size"); }
|
||||
}
|
||||
|
||||
/* Ok the child can run now */
|
||||
do { ret = sem_post(&semsync[0]); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); }
|
||||
|
||||
|
||||
/* Wait for its termination */
|
||||
do { ret = sem_wait(&semsync[1]); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
|
||||
if (ta != NULL)
|
||||
{
|
||||
ret = pthread_attr_getdetachstate(ta, &detach);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to get detach state from the thread attribute"); }
|
||||
}
|
||||
else
|
||||
{
|
||||
detach = PTHREAD_CREATE_JOINABLE; /* default */
|
||||
}
|
||||
|
||||
if (detach == PTHREAD_CREATE_JOINABLE)
|
||||
{
|
||||
ret = pthread_join(th, &rc);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); }
|
||||
if (rc != (void *)0)
|
||||
{ UNRESOLVED((int)(long)rc, "The overflow function returned an unexpected value"); }
|
||||
}
|
||||
|
||||
|
||||
/* Terminate the child process here */
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
pthread_barrier_t bar;
|
||||
int policy;
|
||||
struct sched_param param;
|
||||
} testdata_t;
|
||||
|
||||
void * schedtest(void * arg)
|
||||
{
|
||||
testdata_t * td = (testdata_t *)arg;
|
||||
int newpol, ret=0;
|
||||
struct sched_param newparam;
|
||||
|
||||
/* Read the current sched policy & param */
|
||||
ret = pthread_getschedparam(pthread_self(), &(td->policy), &(td->param));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to read current thread policy / param"); }
|
||||
|
||||
/* sync 1 */
|
||||
ret = pthread_barrier_wait(&(td->bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* sync 2 */
|
||||
ret = pthread_barrier_wait(&(td->bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* Read the current sched policy & param */
|
||||
ret = pthread_getschedparam(pthread_self(), &(td->policy), &(td->param));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to read current thread policy / param"); }
|
||||
|
||||
/* sync 3 */
|
||||
ret = pthread_barrier_wait(&(td->bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* sync 4 */
|
||||
ret = pthread_barrier_wait(&(td->bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* Change the current sched policy & param */
|
||||
if (td->policy == SCHED_RR)
|
||||
newpol = SCHED_FIFO;
|
||||
else
|
||||
newpol = SCHED_RR;
|
||||
|
||||
newparam.sched_priority = sched_get_priority_max(newpol);
|
||||
|
||||
if (newparam.sched_priority == td->param.sched_priority)
|
||||
newparam.sched_priority--;
|
||||
|
||||
ret = pthread_setschedparam(pthread_self(), newpol, &newparam);
|
||||
#if VERBOSE > 0
|
||||
if (ret != 0)
|
||||
output("Changing the current thread sched policy failed with error: %s\n", strerror(ret));
|
||||
#endif
|
||||
#if VERBOSE > 2
|
||||
else
|
||||
output("Executing thread scheduling policy changed\n");
|
||||
#endif
|
||||
|
||||
/* sync 5 */
|
||||
ret = pthread_barrier_wait(&(td->bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* Post the sem in case of a detached thread */
|
||||
do { ret = sem_post(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); }
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int ret=0;
|
||||
int do_stack_tests;
|
||||
int do_sched_tests;
|
||||
|
||||
/* Initialize output routine */
|
||||
output_init();
|
||||
|
||||
/* Test abilities */
|
||||
do_sched_tests = (sysconf(_SC_THREAD_PRIORITY_SCHEDULING)>0?1:0);
|
||||
do_stack_tests = (test_stack(NULL,0)==0?1:0);
|
||||
#if VERBOSE > 0
|
||||
output("Test starting\n Stack tests %s be executed.\n Sched tests %s be executed.\n",
|
||||
do_stack_tests?"will":"won't",
|
||||
do_sched_tests?"will":"won't");
|
||||
#endif
|
||||
|
||||
/* Initialize thread attribute objects */
|
||||
scenar_init();
|
||||
|
||||
for (sc=0; sc < NSCENAR; sc++)
|
||||
{
|
||||
#if VERBOSE > 0
|
||||
output("-----\n");
|
||||
output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr);
|
||||
#endif
|
||||
|
||||
if (do_stack_tests)
|
||||
{
|
||||
/* stack grow test */
|
||||
/* We need the thread attribute to specify a minimal stack */
|
||||
if ((scenarii[sc].altstack == 0) && (scenarii[sc].altsize == 1))
|
||||
{
|
||||
#if VERBOSE > 2
|
||||
output("Processing stack grow test\n");
|
||||
#endif
|
||||
|
||||
ret = test_stack(&scenarii[sc].ta, 2*sysconf(_SC_THREAD_STACK_MIN));
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
if (scenarii[sc].guard == 2)
|
||||
{
|
||||
FAILED("Changing the stacksize after the thread was created changed the running thread stack size");
|
||||
}
|
||||
#if VERBOSE > 2
|
||||
else
|
||||
output("We were able to overflow the stack, but the guard area is unknow or null\n");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
if ((ret != 2) && (scenarii[sc].result == 1))
|
||||
{
|
||||
UNRESOLVED(-1, "An error was expected but the thread creation succeeded");
|
||||
}
|
||||
|
||||
#if VERBOSE > 2
|
||||
if ((ret == 1))
|
||||
{
|
||||
output("Stack grow test passed\n");
|
||||
}
|
||||
|
||||
if ((ret == 2) && (scenarii[sc].result == 2))
|
||||
{
|
||||
output("Something went wrong -- we don't care in this case\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((ret == 2) && (scenarii[sc].result == 0))
|
||||
{
|
||||
UNRESOLVED(-1, "An unexpected error occured\n");
|
||||
}
|
||||
|
||||
/* Ok, set back the thread attribute object to a correct value */
|
||||
ret = pthread_attr_setstacksize(&scenarii[sc].ta, sysconf(_SC_THREAD_STACK_MIN));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to set stacksize back"); }
|
||||
}
|
||||
|
||||
|
||||
/* stack decrease test */
|
||||
if ((scenarii[sc].altstack == 0) && (scenarii[sc].altsize == 0))
|
||||
{
|
||||
#if VERBOSE > 2
|
||||
output("Processing stack decrease test\n");
|
||||
#endif
|
||||
|
||||
ret = test_stack(&scenarii[sc].ta, sysconf(_SC_THREAD_STACK_MIN));
|
||||
|
||||
if (ret == 1) { FAILED("Decreasing the stack size after thread is created had an influence on the thread"); }
|
||||
|
||||
if ((ret == 0) && (scenarii[sc].result == 1))
|
||||
{
|
||||
UNRESOLVED(-1, "An error was expected but the thread creation succeeded");
|
||||
}
|
||||
|
||||
if ((ret == 2) && (scenarii[sc].result == 0))
|
||||
{
|
||||
UNRESOLVED(-1, "An unexpected error occured\n");
|
||||
}
|
||||
|
||||
#if VERBOSE > 2
|
||||
if (ret == 0)
|
||||
output("Stack decrease test passed.\n");
|
||||
else
|
||||
output("Something failed but we don't care here.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} /* if do_stack_tests */
|
||||
|
||||
if (do_sched_tests)
|
||||
{
|
||||
/* Sched policy/param change test */
|
||||
if (scenarii[sc].explicitsched != 0) /* We need a specified policy */
|
||||
{
|
||||
pthread_t child;
|
||||
int policy_ori, newpol_max;
|
||||
struct sched_param param_ori, tmp;
|
||||
|
||||
testdata_t td;
|
||||
|
||||
#if VERBOSE > 2
|
||||
output("Processing sched policy/param change test\n");
|
||||
#endif
|
||||
|
||||
/* Backup the scenario object */
|
||||
ret = pthread_attr_getschedpolicy(&(scenarii[sc].ta), &policy_ori);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to read sched policy from thread attribute"); }
|
||||
ret = pthread_attr_getschedparam(&(scenarii[sc].ta), ¶m_ori);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to read sched param from thread attribute"); }
|
||||
|
||||
/* Initialize the barrier */
|
||||
ret = pthread_barrier_init(&(td.bar), NULL, 2);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the barrier"); }
|
||||
|
||||
/* Create a new thread with this scenario attribute */
|
||||
ret = pthread_create(&child, &(scenarii[sc].ta), schedtest, &td);
|
||||
if (ret != 0)
|
||||
{
|
||||
if (scenarii[sc].result == 0)
|
||||
{ UNRESOLVED(ret , "Failed to create a thread"); }
|
||||
|
||||
#if VERBOSE > 2
|
||||
if (scenarii[sc].result == 2)
|
||||
{
|
||||
output("The thread creation failed -- we don't care\n");
|
||||
}
|
||||
if (scenarii[sc].result == 1)
|
||||
{
|
||||
output("The thread creation failed as expected\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else /* Thread created */
|
||||
{
|
||||
if (scenarii[sc].result == 1)
|
||||
{ UNRESOLVED(-1, "The thread was created where an error was expected"); }
|
||||
|
||||
#if VERBOSE > 2
|
||||
if (scenarii[sc].result == 2)
|
||||
output("Thread is created\n");
|
||||
#endif
|
||||
|
||||
/* sync 1 */
|
||||
ret = pthread_barrier_wait(&(td.bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* Check the new thread reports the attributes */
|
||||
if (td.policy != policy_ori)
|
||||
{ FAILED("The new thread does not report the scheluling policy that was specified"); }
|
||||
|
||||
if (td.param.sched_priority != param_ori.sched_priority)
|
||||
{ FAILED("The new thread does not report the scheduling priority that was specified at creation"); }
|
||||
|
||||
/* Change the thread attribute object policy & param */
|
||||
if (policy_ori == SCHED_RR)
|
||||
{
|
||||
ret = pthread_attr_setschedpolicy(&(scenarii[sc].ta), SCHED_FIFO);
|
||||
newpol_max = sched_get_priority_max(SCHED_FIFO);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = pthread_attr_setschedpolicy(&(scenarii[sc].ta), SCHED_RR);
|
||||
newpol_max = sched_get_priority_max(SCHED_RR);
|
||||
}
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to change the attribute object"); }
|
||||
|
||||
if (newpol_max == param_ori.sched_priority)
|
||||
newpol_max--;
|
||||
|
||||
tmp.sched_priority = newpol_max;
|
||||
|
||||
ret = pthread_attr_setschedparam(&(scenarii[sc].ta), &tmp);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to set the attribute sched param"); }
|
||||
|
||||
/* sync 2 */
|
||||
ret = pthread_barrier_wait(&(td.bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* sync 3 */
|
||||
ret = pthread_barrier_wait(&(td.bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* Check if the thread saw the change (should not) */
|
||||
if (td.policy != policy_ori)
|
||||
{ FAILED("The new thread does not report the scheluling policy that was specified"); }
|
||||
|
||||
if (td.param.sched_priority != param_ori.sched_priority)
|
||||
{ FAILED("The new thread does not report the scheduling priority that was specified at creation"); }
|
||||
|
||||
/* Check what we can see for the child thread from here */
|
||||
ret = pthread_getschedparam(child, &(td.policy), &(td.param));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to read child thread policy / param"); }
|
||||
|
||||
if (td.policy != policy_ori)
|
||||
{ FAILED("The child thread does not report the scheduling policy that was specified at creation"); }
|
||||
|
||||
if (td.param.sched_priority != param_ori.sched_priority)
|
||||
{ FAILED("The child thread does not report the scheduling priority that was specified at creation"); }
|
||||
|
||||
/* Restore the thread attribute */
|
||||
ret = pthread_attr_setschedpolicy(&(scenarii[sc].ta), policy_ori);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to read sched policy from thread attribute"); }
|
||||
ret = pthread_attr_setschedparam(&(scenarii[sc].ta), ¶m_ori);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to read sched param from thread attribute"); }
|
||||
|
||||
/* sync 4*/
|
||||
ret = pthread_barrier_wait(&(td.bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* sync 5*/
|
||||
ret = pthread_barrier_wait(&(td.bar));
|
||||
if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); }
|
||||
|
||||
/* check if the thread attribute reports a change (should not) */
|
||||
ret = pthread_attr_getschedpolicy(&(scenarii[sc].ta), &(td.policy));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to read sched policy from thread attribute"); }
|
||||
ret = pthread_attr_getschedparam(&(scenarii[sc].ta), &(td.param));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to read sched param from thread attribute"); }
|
||||
|
||||
if (td.policy != policy_ori)
|
||||
{ FAILED("The child thread does not report the scheduling policy that was specified at creation"); }
|
||||
|
||||
if (td.param.sched_priority != param_ori.sched_priority)
|
||||
{ FAILED("The child thread does not report the scheduling priority that was specified at creation"); }
|
||||
|
||||
/* Wait for the sem and join eventually the thread */
|
||||
do { ret = sem_wait(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
|
||||
if (scenarii[sc].detached == 0)
|
||||
{
|
||||
ret = pthread_join(child, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); }
|
||||
}
|
||||
|
||||
#if VERBOSE > 2
|
||||
output("Sched policy/param change test passed\n");
|
||||
#endif
|
||||
} /* thread created */
|
||||
}
|
||||
|
||||
/* We could also test if the inheritsched does not influence the new thread */
|
||||
|
||||
} /* if do_sched_tests */
|
||||
}
|
||||
|
||||
scenar_fini();
|
||||
#if VERBOSE > 0
|
||||
output("-----\n");
|
||||
output("All test data destroyed\n");
|
||||
output("Test PASSED\n");
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
*
|
||||
* Test upon successful completion, pthread_create() shall store the ID of the
|
||||
* the created thread in the location referenced by 'thread'.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a thread using pthread_create()
|
||||
* 2. Save the thread ID resulting from pthread_create()
|
||||
* 3. Get the thread ID from the new thread by calling
|
||||
* pthread_self().
|
||||
* 4. These 2 values should be equal. (i.e. the one from pthread_create()
|
||||
* and the one from pthread_self()).
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void *a_thread_func();
|
||||
|
||||
pthread_t self_th; /* Save the value of the function call pthread_self()
|
||||
within the thread. Keeping it global so 'main' can
|
||||
see it too. */
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
/* Create a new thread */
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait for the thread function to return to make sure we got
|
||||
* the thread ID value from pthread_self(). */
|
||||
if(pthread_join(new_th, NULL) != 0)
|
||||
{
|
||||
perror("Error calling pthread_join()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* If the value of pthread_self() and the return value from
|
||||
* pthread_create() is equal, then the test passes. */
|
||||
if(pthread_equal(new_th, self_th) == 0)
|
||||
{
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
/* The thread function that calls pthread_self() to obtain its thread ID */
|
||||
void *a_thread_func()
|
||||
{
|
||||
self_th=pthread_self();
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test pthread_create()
|
||||
* The thread is created executing 'start_routine' with 'arg' as its only
|
||||
* argument.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create 5 separete threads using pthread_create() passing to it a single int 'arg'.
|
||||
* 2. Use that passed int argument in the thread function start routine and make sure no
|
||||
* errors occur.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUM_THREADS 5
|
||||
|
||||
/* The thread start routine. */
|
||||
void *a_thread_func(void* num)
|
||||
{
|
||||
intptr_t i = (intptr_t) num;
|
||||
printf("Passed argument for thread: %d\n", (int)i);
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
long i;
|
||||
|
||||
for(i=1;i<NUM_THREADS+1;i++)
|
||||
{
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, (void*)i) != 0)
|
||||
{
|
||||
printf("Error creating thread\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
/* Wait for thread to end execution */
|
||||
pthread_join(new_th, NULL);
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test pthread_create()
|
||||
* The thread is created executing 'start_routine' with 'arg' as its only
|
||||
* argument.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a thread using pthread_create() passing to it an array of 'int's as an argument.
|
||||
* 2. Use that passed int argument in the thread function start routine and make sure no
|
||||
* errors occur.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUM_THREADS 5
|
||||
|
||||
/* The thread start routine. */
|
||||
void *a_thread_func(void* num)
|
||||
{
|
||||
int *i, j;
|
||||
|
||||
i = (int *)num;
|
||||
|
||||
for(j=0;j<NUM_THREADS;j++)
|
||||
printf("Passed argument %d for thread\n", i[j]);
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
int i[NUM_THREADS], j;
|
||||
|
||||
for(j=0;j<NUM_THREADS;j++)
|
||||
i[j] = j+1;
|
||||
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, (void*)&i) != 0)
|
||||
{
|
||||
printf("Error creating thread\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
/* Wait for thread to end execution */
|
||||
pthread_join(new_th, NULL);
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-163
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test pthread_create()
|
||||
*
|
||||
* The signal state of the new thread will be initialized as so:
|
||||
*
|
||||
* - The signal mask shall be inherited from the created thread
|
||||
* - The set of signals pending for the new thread shall be empty.
|
||||
*
|
||||
* Steps:
|
||||
* 1. In main(), create a signal mask with a few signals in the set (SIGUSR1 and SIGUSR2).
|
||||
* 2. Raise those signals in main. These signals now should be pending.
|
||||
* 3. Create a thread using pthread_create().
|
||||
* 4. The thread should have the same signal mask, but no signals should be pending.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
sigset_t th_pendingset, th_sigmask;
|
||||
|
||||
void *a_thread_func()
|
||||
{
|
||||
/* Obtain the signal mask of this thread. */
|
||||
pthread_sigmask(SIG_SETMASK, NULL, &th_sigmask);
|
||||
|
||||
/* Obtain the pending signals of this thread. It should be empty. */
|
||||
if (sigpending(&th_pendingset) != 0) {
|
||||
printf("Error calling sigpending()\n");
|
||||
return (void *)PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
sigset_t main_sigmask, main_pendingset;
|
||||
int ret;
|
||||
|
||||
/* Empty set of signal mask and blocked signals */
|
||||
if ( (sigemptyset(&main_sigmask) != 0) ||
|
||||
(sigemptyset(&main_pendingset) != 0) )
|
||||
{
|
||||
perror("Error in sigemptyset()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Add SIGCONT, SIGUSR1 and SIGUSR2 to the set of blocked signals */
|
||||
if (sigaddset(&main_sigmask, SIGUSR1) != 0)
|
||||
{
|
||||
perror("Error in sigaddset()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (sigaddset(&main_sigmask, SIGUSR2) != 0)
|
||||
{
|
||||
perror("Error in sigaddset()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Block those signals. */
|
||||
if (pthread_sigmask(SIG_SETMASK, &main_sigmask, NULL) != 0)
|
||||
{
|
||||
printf("Error in pthread_sigmask()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Raise those signals so they are now pending. */
|
||||
if (raise(SIGUSR1) != 0) {
|
||||
printf("Could not raise SIGALRM\n");
|
||||
return -1;
|
||||
}
|
||||
if (raise(SIGUSR2) != 0) {
|
||||
printf("Could not raise SIGALRM\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Create a new thread. */
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait until the thread has finished execution. */
|
||||
if(pthread_join(new_th, NULL) != 0)
|
||||
{
|
||||
perror("Error in pthread_join()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Check to make sure that the sigmask of the thread is the same as the main thread */
|
||||
ret = sigismember(&th_sigmask, SIGUSR1);
|
||||
if(ret != 1)
|
||||
{
|
||||
if(ret == 0)
|
||||
{
|
||||
printf("Error: Thread did not inherit main()s signal mask. SIGUSR1 not a member of the signal set.\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
perror("Error is sigismember()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
ret = sigismember(&th_sigmask, SIGUSR2);
|
||||
if(ret != 1)
|
||||
{
|
||||
if(ret == 0)
|
||||
{
|
||||
printf("Test FAILED: Thread did not inherit main()s signal mask. SIGUSR2 not a member of the signal set.\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
perror("Error is sigismember()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Check to make sure that the pending set of the thread does not contain SIGUSR1 or
|
||||
* SIGUSR2. */
|
||||
|
||||
ret = sigismember(&th_pendingset, SIGUSR1);
|
||||
if(ret != 0)
|
||||
{
|
||||
if(ret == 1)
|
||||
{
|
||||
printf("Error: Thread did not inherit main()s signal mask. SIGUSR1 not a member of the signal set.\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
perror("Error is sigismember()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
ret = sigismember(&th_pendingset, SIGUSR2);
|
||||
if(ret != 0)
|
||||
{
|
||||
if(ret == 1)
|
||||
{
|
||||
printf("Test FAILED: Thread did not inherit main()s signal mask. SIGUSR2 not a member of the signal set.\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
perror("Error is sigismember()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-270
@@ -1,270 +0,0 @@
|
||||
/*
|
||||
* 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 thread inherits is signal mask from the calling thread,
|
||||
* and has no pending signal at creation time.
|
||||
|
||||
* The steps are:
|
||||
* 1. In main(), create a signal mask with a few signals in the set (SIGUSR1 and SIGUSR2).
|
||||
* 2. Raise those signals in main. These signals now should be pending.
|
||||
* 3. Create a thread using pthread_create().
|
||||
* 4. The thread should have the same signal mask, but no signals should be pending.
|
||||
|
||||
* Parts of this test are copied from 8-1.c (author: rolla.n.selbak REMOVE-THIS AT intel DOT com)
|
||||
*/
|
||||
|
||||
|
||||
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
/* Some routines are part of the XSI Extensions */
|
||||
#ifndef WITHOUT_XOPEN
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
/********************************************************************************************/
|
||||
/****************************** standard includes *****************************************/
|
||||
/********************************************************************************************/
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.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 cases *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
#include "threads_scenarii.c"
|
||||
|
||||
/* This file will define the following objects:
|
||||
* scenarii: array of struct __scenario type.
|
||||
* NSCENAR : macro giving the total # of scenarii
|
||||
* scenar_init(): function to call before use the scenarii array.
|
||||
* scenar_fini(): function to call after end of use of the scenarii array.
|
||||
*/
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Real Test *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
sigset_t mask;
|
||||
sigset_t pending;
|
||||
} testdata_t;
|
||||
|
||||
|
||||
/* Thread function; which will check the signal mask and pending signals */
|
||||
void * threaded(void * arg)
|
||||
{
|
||||
int ret;
|
||||
testdata_t * td=(testdata_t *)arg;
|
||||
|
||||
/* Obtain the signal mask of this thread. */
|
||||
ret = pthread_sigmask(SIG_SETMASK, NULL, &(td->mask));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to get the signal mask of the thread"); }
|
||||
|
||||
/* Obtain the pending signals of this thread. It should be empty. */
|
||||
ret = sigpending(&(td->pending));
|
||||
if (ret != 0) { UNRESOLVED(errno, "Failed to get pending signals from the thread"); }
|
||||
|
||||
/* Signal we're done (especially in case of a detached thread) */
|
||||
do { ret = sem_post(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
|
||||
/* return */
|
||||
return arg;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int ret=0;
|
||||
pthread_t child;
|
||||
|
||||
testdata_t td_parent, td_thread;
|
||||
|
||||
/* Initialize output routine */
|
||||
output_init();
|
||||
|
||||
/* Initialize thread attribute objects */
|
||||
scenar_init();
|
||||
|
||||
/* Initialize the signal state */
|
||||
ret = sigemptyset(&(td_parent.mask));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a signal set"); }
|
||||
|
||||
ret = sigemptyset(&(td_parent.pending));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a signal set"); }
|
||||
|
||||
/* Add SIGCONT, SIGUSR1 and SIGUSR2 to the set of blocked signals */
|
||||
ret = sigaddset(&(td_parent.mask), SIGUSR1);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to add SIGUSR1 to the signal set"); }
|
||||
|
||||
ret = sigaddset(&(td_parent.mask), SIGUSR2);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to add SIGUSR2 to the signal set"); }
|
||||
|
||||
/* Block those signals. */
|
||||
ret = pthread_sigmask(SIG_SETMASK, &(td_parent.mask), NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to mask the singals in main"); }
|
||||
|
||||
/* Raise those signals so they are now pending. */
|
||||
ret = raise(SIGUSR1);
|
||||
if (ret != 0) { UNRESOLVED(errno, "Failed to raise SIGUSR1"); }
|
||||
ret = raise(SIGUSR2);
|
||||
if (ret != 0) { UNRESOLVED(errno, "Failed to raise SIGUSR2"); }
|
||||
|
||||
/* Do the testing for each thread */
|
||||
for (sc=0; sc < NSCENAR; sc++)
|
||||
{
|
||||
#if VERBOSE > 0
|
||||
output("-----\n");
|
||||
output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr);
|
||||
#endif
|
||||
|
||||
/* (re)initialize thread signal sets */
|
||||
ret = sigemptyset(&(td_thread.mask));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a signal set"); }
|
||||
|
||||
ret = sigemptyset(&(td_thread.pending));
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a signal set"); }
|
||||
|
||||
|
||||
ret = pthread_create(&child, &scenarii[sc].ta, threaded, &td_thread);
|
||||
switch (scenarii[sc].result)
|
||||
{
|
||||
case 0: /* Operation was expected to succeed */
|
||||
if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); }
|
||||
break;
|
||||
|
||||
case 1: /* Operation was expected to fail */
|
||||
if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); }
|
||||
break;
|
||||
|
||||
case 2: /* We did not know the expected result */
|
||||
default:
|
||||
#if VERBOSE > 0
|
||||
if (ret == 0)
|
||||
{ output("Thread has been created successfully for this scenario\n"); }
|
||||
else
|
||||
{ output("Thread creation failed with the error: %s\n", strerror(ret)); }
|
||||
#endif
|
||||
}
|
||||
if (ret == 0) /* The new thread is running */
|
||||
{
|
||||
if (scenarii[sc].detached == 0)
|
||||
{
|
||||
ret = pthread_join(child, NULL);
|
||||
if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); }
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Just wait for the thread to terminate */
|
||||
do { ret = sem_wait(&scenarii[sc].sem); }
|
||||
while ((ret == -1) && (errno == EINTR));
|
||||
if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); }
|
||||
}
|
||||
|
||||
/* The thread has terminated its work, so we can now control */
|
||||
ret = sigismember(&(td_thread.mask), SIGUSR1);
|
||||
if (ret != 1)
|
||||
{
|
||||
if (ret == 0) { FAILED("The thread did not inherit the signal mask"); }
|
||||
/* else */
|
||||
UNRESOLVED(ret, "sigismember() failed");
|
||||
}
|
||||
|
||||
ret = sigismember(&(td_thread.mask), SIGUSR2);
|
||||
if (ret != 1)
|
||||
{
|
||||
if (ret == 0) { FAILED("The thread did not inherit the signal mask"); }
|
||||
/* else */
|
||||
UNRESOLVED(ret, "sigismember() failed");
|
||||
}
|
||||
|
||||
ret = sigismember(&(td_thread.pending), SIGUSR1);
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret == 1) { FAILED("The thread inherited the pending signal SIGUSR1"); }
|
||||
/* else */
|
||||
UNRESOLVED(ret, "sigismember() failed");
|
||||
}
|
||||
|
||||
ret = sigismember(&(td_thread.pending), SIGUSR2);
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret == 1) { FAILED("The thread inherited the pending signal SIGUSR2"); }
|
||||
/* else */
|
||||
UNRESOLVED(ret, "sigismember() failed");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
scenar_fini();
|
||||
#if VERBOSE > 0
|
||||
output("-----\n");
|
||||
output("All test data destroyed\n");
|
||||
output("Test PASSED\n");
|
||||
#endif
|
||||
|
||||
PASSED;
|
||||
}
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_create ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest pthread_create_1-1 : 1-1.c ;
|
||||
SimpleTest pthread_create_1-2 : 1-2.c ;
|
||||
SimpleTest pthread_create_1-3 : 1-3.c ;
|
||||
#SimpleTest pthread_create_1-4 : 1-4.c ;
|
||||
#SimpleTest pthread_create_1-5 : 1-5.c ;
|
||||
#SimpleTest pthread_create_1-6 : 1-6.c ;
|
||||
SimpleTest pthread_create_2-1 : 2-1.c ;
|
||||
SimpleTest pthread_create_3-1 : 3-1.c ;
|
||||
#SimpleTest pthread_create_3-2 : 3-2.c ;
|
||||
SimpleTest pthread_create_4-1 : 4-1.c ;
|
||||
SimpleTest pthread_create_5-1 : 5-1.c ;
|
||||
SimpleTest pthread_create_5-2 : 5-2.c ;
|
||||
SimpleTest pthread_create_8-1 : 8-1.c ;
|
||||
#SimpleTest pthread_create_8-2 : 8-2.c ;
|
||||
SimpleTest pthread_create_10-1 : 10-1.c ;
|
||||
#SimpleTest pthread_create_11-1 : 11-1.c ;
|
||||
SimpleTest pthread_create_12-1 : 12-1.c ;
|
||||
#SimpleTest pthread_create_14-1 : 14-1.c ;
|
||||
#SimpleTest pthread_create_15-1 : 15-1.c ;
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_getspecific()
|
||||
*
|
||||
* shall return the value currently bound to the specified key on behalf of the calling thread.
|
||||
* Calling pthread_getspecific() with a key value not obtained from pthread_key_create() or
|
||||
* after key has been deleted with pthread_key_delete() is undefined.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create NUM_OF_KEYS pthread_key_t objects
|
||||
* 2. Set each key to a thread-specific value with pthread_setspecific()
|
||||
* 3. Call pthread_getspecific() on each key and check that the value returned is correct.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUM_OF_KEYS 10
|
||||
#define KEY_VALUE 0
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_key_t keys[NUM_OF_KEYS];
|
||||
int i;
|
||||
void* rc;
|
||||
|
||||
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||
{
|
||||
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||
{
|
||||
printf("pthread_getspecific_1-1 Error: pthread_key_create() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
} else
|
||||
{
|
||||
if(pthread_setspecific(keys[i], (void *)(long)(i + KEY_VALUE)) != 0)
|
||||
{
|
||||
printf("pthread_getspecific_1-1 Error: pthread_setspecific() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0;i<NUM_OF_KEYS;++i)
|
||||
{
|
||||
rc = pthread_getspecific(keys[i]);
|
||||
if(rc != (void *)(long)(i + KEY_VALUE))
|
||||
{
|
||||
printf("pthread_getspecific_1-1 Test FAILED: Did not return correct value of thread-specific key, expected %d, but got %ld\n", (i + KEY_VALUE), (long)rc);
|
||||
return PTS_FAIL;
|
||||
} else
|
||||
{
|
||||
if(pthread_key_delete(keys[i]) != 0)
|
||||
{
|
||||
printf("pthread_getspecific_1-1 Error: pthread_key_delete() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%spthread_getspecific_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_getspecific()
|
||||
*
|
||||
* It shall return the thread-specific data value associated with the given 'key'. If no
|
||||
* thread-specific data value is associated with 'key, then the value NULL shall be returned.
|
||||
* It does not return any errors.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create pthread_key_t object and do no specify a key accociated with this key
|
||||
* 2. Call pthread_getspecific() and check that the value returns NULL.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_key_t key;
|
||||
void* rc;
|
||||
|
||||
if(pthread_key_create(&key, NULL) != 0)
|
||||
{
|
||||
printf("pthread_getspecific_3-1 Error: pthread_key_create() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
rc = pthread_getspecific(key);
|
||||
if(rc != NULL)
|
||||
{
|
||||
printf("pthread_getspecific_3-1 Test FAILED: Did not return correct value, expected NULL, but got %ld\n", (long)rc);
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
if(pthread_key_delete(key) != 0)
|
||||
{
|
||||
printf("pthread_getspecific_3-1 Error: pthread_key_delete() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("%spthread_getspecific_3-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_getspecific ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest pthread_getspecific_1-1 : 1-1.c ;
|
||||
SimpleTest pthread_getspecific_3-1 : 3-1.c ;
|
||||
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_key_create()
|
||||
*
|
||||
* shall create a thread-specific data key visible to all threaads in the process. Key values
|
||||
* provided by pthread_key_create() are opaque objects used to locate thread-specific data.
|
||||
* Although the same key value may be used by different threads, the values bound to the key
|
||||
* by pthread_setspecific() are maintained on a per-thread basis and persist for the life of
|
||||
* the calling thread.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Define an array of keys
|
||||
* 2. Use pthread_key_create() and create those keys
|
||||
* 3. Verify that you can set and get specific values for those keys without errors.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUM_OF_KEYS 10
|
||||
#define KEY_VALUE 0
|
||||
|
||||
pthread_key_t keys[NUM_OF_KEYS];
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
void* rc;
|
||||
|
||||
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||
{
|
||||
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||
{
|
||||
printf("pthread_key_create_1-1 Error: pthread_key_create() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
} else
|
||||
{
|
||||
if(pthread_setspecific(keys[i], (void *)(long)(i + KEY_VALUE)) != 0)
|
||||
{
|
||||
printf("pthread_key_create_1-1 Error: pthread_setspecific() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0;i<NUM_OF_KEYS;++i)
|
||||
{
|
||||
rc = pthread_getspecific(keys[i]);
|
||||
if(rc != (void *)(long)(i + KEY_VALUE))
|
||||
{
|
||||
printf("pthread_key_create_1-1 Test FAILED: Did not return correct value of thread-specific key, expected %ld, but got %ld\n", (long)(i + KEY_VALUE), (long)rc);
|
||||
return PTS_FAIL;
|
||||
} else
|
||||
{
|
||||
if(pthread_key_delete(keys[i]) != 0)
|
||||
{
|
||||
printf("pthread_key_create_1-1 Error: pthread_key_delete() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%spthread_key_create_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_key_create()
|
||||
*
|
||||
* shall create a thread-specific data key visible to all threaads in the process. Key values
|
||||
* provided by pthread_key_create() are opaque objects used to locate thread-specific data.
|
||||
* Although the same key value may be used by different threads, the values bound to the key
|
||||
* by pthread_setspecific() are maintained on a per-thread basis and persist for the life of
|
||||
* the calling thread.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Define and create a key
|
||||
* 2. Verify that you can create many threads with the same key value
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUM_OF_THREADS 10
|
||||
#define KEY_VALUE 1000
|
||||
pthread_key_t keys[NUM_OF_THREADS];
|
||||
int i;
|
||||
|
||||
/* Thread function that sets the key to KEY_VALUE */
|
||||
void *a_thread_func()
|
||||
{
|
||||
/* Set the key to KEY_VALUE */
|
||||
if(pthread_setspecific(keys[i], (void *)(KEY_VALUE)) != 0)
|
||||
{
|
||||
printf("pthread_key_create_1-2 Error: pthread_setspecific() failed\n");
|
||||
pthread_exit((void*)PTS_FAIL);
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
void *value_ptr;
|
||||
int error;
|
||||
|
||||
/* Create a key */
|
||||
for(i = 0;i<NUM_OF_THREADS;i++)
|
||||
{
|
||||
if((error = pthread_key_create(&keys[i], NULL)) != 0)
|
||||
{
|
||||
printf("pthread_key_create_1-2 Error: pthread_key_create() "
|
||||
"failed: %s\n", strerror(error));
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create NUM_OF_THREADS threads and in the thread_func, it will
|
||||
* use pthread_setspecific with the same KEY_VALUE */
|
||||
for(i = 0;i<NUM_OF_THREADS;i++)
|
||||
{
|
||||
/* Create a thread */
|
||||
if((error = pthread_create(&new_th, NULL, a_thread_func, NULL)) != 0)
|
||||
{
|
||||
printf("pthread_key_create_1-2 Error creating thread: %s\n",
|
||||
strerror(error));
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait for thread to end */
|
||||
if((error = pthread_join(new_th, &value_ptr)) != 0)
|
||||
{
|
||||
printf("pthread_key_create_1-2 Error in pthread_join: %s\n",
|
||||
strerror(error));
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if(value_ptr == (void*) PTS_FAIL)
|
||||
{
|
||||
printf("pthread_key_create_1-2: Test FAILED: Could not use a certain key value to set for many keys\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%spthread_key_create_1-2:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_key_create()
|
||||
*
|
||||
* Upon key creation, the value NULL shall be associated with the new key in all active threads.
|
||||
* Upon thread creation, the value NULL shall be associated with all defined keys in the new
|
||||
* thread.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a key
|
||||
* 2. Verify that the default value is NULL
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_key_t key;
|
||||
void* rc;
|
||||
|
||||
/* Verify that the value associated with "key" in a new thread is NULL */
|
||||
// rc = pthread_getspecific(key);
|
||||
// if(rc != NULL)
|
||||
// {
|
||||
// printf("pthread_key_create_2-1 Test FAILED\n");
|
||||
// return PTS_FAIL;
|
||||
// }
|
||||
|
||||
if(pthread_key_create(&key, NULL) != 0)
|
||||
{
|
||||
printf("pthread_key_create_2-1 pthread_key_create_2-1 Error: pthread_key_create() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
} else
|
||||
{
|
||||
/* Verify that the value associated with "key" after it is newly created is
|
||||
* NULL */
|
||||
rc = pthread_getspecific(key);
|
||||
if(rc != NULL)
|
||||
{
|
||||
printf("pthread_key_create_2-1 Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("%spthread_key_create_2-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-92
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_key_create()
|
||||
*
|
||||
* An optional destructor function may be associated with each key value. At thread exit, if
|
||||
* a key value has a non-NULL destructor pointer, and the thread has a non-NULL value associated
|
||||
* with that key, the value of the key is set to NULL, and then the function pointed to is called
|
||||
* with the previously associated value as its sole argument. The order of destructor calls is
|
||||
* unspecified if more than one destructor exists for a thread when it exits.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Define an array of keys
|
||||
* 2. Use pthread_key_create() and create those keys
|
||||
* 3. Verify that you can set and get specific values for those keys without errors.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define KEY_VALUE 1000
|
||||
|
||||
pthread_key_t key;
|
||||
int dest_cnt;
|
||||
|
||||
/* Destructor funciton */
|
||||
void dest_func(void *p)
|
||||
{
|
||||
dest_cnt++;
|
||||
}
|
||||
|
||||
/* Thread function */
|
||||
void *a_thread_func()
|
||||
{
|
||||
|
||||
/* Set the value of the key to a value */
|
||||
if(pthread_setspecific(key, (void *)(KEY_VALUE)) != 0)
|
||||
{
|
||||
printf("pthread_key_create_3-1 Error: pthread_setspecific() failed\n");
|
||||
pthread_exit((void*) PTS_UNRESOLVED);
|
||||
}
|
||||
|
||||
/* The thread ends here, the destructor for the key should now be called after this */
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
/* Inialize the destructor flag */
|
||||
dest_cnt = 0;
|
||||
|
||||
/* Create a key with a destructor function */
|
||||
if(pthread_key_create(&key, dest_func) != 0)
|
||||
{
|
||||
printf("pthread_key_create_3-1 Error: pthread_key_create() failed\n");
|
||||
pthread_exit((void*) PTS_UNRESOLVED);
|
||||
}
|
||||
|
||||
/* Create a thread */
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("pthread_key_create_3-1 Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait for the thread's return */
|
||||
if(pthread_join(new_th, NULL) != 0)
|
||||
{
|
||||
perror("pthread_key_create_3-1 Error in pthread_join()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Check if the destructor was called */
|
||||
if(dest_cnt == 0)
|
||||
{
|
||||
printf("pthread_key_create_3-1 Test FAILED: Destructor not called\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%spthread_key_create_3-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_create ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest pthread_key_create_1-1 : 1-1.c ;
|
||||
SimpleTest pthread_key_create_1-2 : 1-2.c ;
|
||||
SimpleTest pthread_key_create_2-1 : 2-1.c ;
|
||||
SimpleTest pthread_key_create_3-1 : 3-1.c ;
|
||||
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_key_delete()
|
||||
*
|
||||
* Shall delete a thread-specific data key previously returned by pthread_key_create. The
|
||||
* thread-specific data values specified data values associated with 'key' need not be NULL at
|
||||
* the time pthread_key_delete is called. It is the responsibility of the application to free
|
||||
* any application storage or perform any cleanup actions for data structures related to the
|
||||
* deleted key or associated thread-specific data in any threads; this cleanup can be done
|
||||
* either before or after pthread_key_delete is called. Any attempt to use 'key' following
|
||||
* the call to pthread_key_delete results in undefined behavior.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create many keys, and do not specify and value to them (default is NULL)
|
||||
* 2. Delete the keys with pthread_key_delete
|
||||
* 3. Verify that this will not result in an error
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUM_OF_KEYS 10
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_key_t keys[NUM_OF_KEYS];
|
||||
int i;
|
||||
|
||||
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||
{
|
||||
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||
{
|
||||
printf("pthread_key_delete_1-1 Error: pthread_key_create() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if(pthread_key_delete(keys[i]) != 0)
|
||||
{
|
||||
printf("pthread_key_delete_1-1 Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("%spthread_key_delete_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_key_delete()
|
||||
*
|
||||
* Shall delete a thread-specific data key previously returned by pthread_key_create. The
|
||||
* thread-specific data values specified data values associated with 'key' need not be NULL at
|
||||
* the time pthread_key_delete is called. It is the responsibility of the application to free
|
||||
* any application storage or perform any cleanup actions for data structures related to the
|
||||
* deleted key or associated thread-specific data in any threads; this cleanup can be done
|
||||
* either before or after pthread_key_delete is called. Any attempt to use 'key' following
|
||||
* the call to pthread_key_delete results in undefined behavior.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create many keys, and specify and value to them
|
||||
* 2. Delete the keys with pthread_key_delete
|
||||
* 3. Verify that this will not result in an error
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUM_OF_KEYS 10
|
||||
#define KEY_VALUE 100
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_key_t keys[NUM_OF_KEYS];
|
||||
int i;
|
||||
|
||||
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||
{
|
||||
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||
{
|
||||
printf("pthread_key_delete_1-2 Error: pthread_key_create() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if(pthread_setspecific(keys[i], (void*)(long)(KEY_VALUE + i)) != 0)
|
||||
{
|
||||
printf("pthread_key_delete_1-2 Error: pthread_setspecific failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if(pthread_key_delete(keys[i]) != 0)
|
||||
{
|
||||
printf("pthread_key_delete_1-2 Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%spthread_key_delete_1-2:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-103
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_key_delete()
|
||||
*
|
||||
pthread_key_delete function shall be callable from within destructor functions. No
|
||||
destructor functions shall be invoked by pthread_key_delete. Any destructor function
|
||||
that may have been associated with 'key' shall no longer be called up thread exit.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a key with a destructor function associated with it
|
||||
* 2. In the destructor function, call pthread_key_delete
|
||||
* 3. Verify that this can be done with no errors
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define KEY_VALUE 1000
|
||||
|
||||
pthread_key_t key;
|
||||
int dest_cnt;
|
||||
|
||||
/* Destructor funciton */
|
||||
void dest_func(void *p)
|
||||
{
|
||||
dest_cnt++;
|
||||
/* Delete the key and check if an error has occured */
|
||||
if(pthread_key_delete(key) != 0)
|
||||
{
|
||||
dest_cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Thread function */
|
||||
void *a_thread_func()
|
||||
{
|
||||
|
||||
/* Set the value of the key to a value */
|
||||
if(pthread_setspecific(key, (void *)(KEY_VALUE)) != 0)
|
||||
{
|
||||
printf("pthread_key_delete_2-1 Error: pthread_setspecific() failed\n");
|
||||
pthread_exit((void*) PTS_UNRESOLVED);
|
||||
}
|
||||
|
||||
/* The thread ends here, the destructor for the key should now be called after this */
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
/* Inialize the destructor flag */
|
||||
dest_cnt = 0;
|
||||
|
||||
/* Create a key with a destructor function */
|
||||
if(pthread_key_create(&key, dest_func) != 0)
|
||||
{
|
||||
printf("pthread_key_delete_2-1 Error: pthread_key_create() failed\n");
|
||||
pthread_exit((void*) PTS_UNRESOLVED);
|
||||
}
|
||||
|
||||
/* Create a thread */
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("pthread_key_delete_2-1 Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait for the thread's return */
|
||||
if(pthread_join(new_th, NULL) != 0)
|
||||
{
|
||||
perror("pthread_key_delete_2-1 Error in pthread_join()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Check if the destructor was called and if the pthread_key_delete function was
|
||||
* called successfully */
|
||||
if(dest_cnt != 1)
|
||||
{
|
||||
if(dest_cnt == 0)
|
||||
{
|
||||
printf("pthread_key_delete_2-1 Error calling the key destructor function\n");
|
||||
return PTS_UNRESOLVED;
|
||||
} else
|
||||
{
|
||||
printf("pthread_key_delete_2-1 Test FAILED: pthread_key_delete failed to be called from the destructor function\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%spthread_key_delete_2-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_delete ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest pthread_key_delete_1-1 : 1-1.c ;
|
||||
SimpleTest pthread_key_delete_1-2 : 1-2.c ;
|
||||
SimpleTest pthread_key_delete_2-1 : 2-1.c ;
|
||||
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_once()
|
||||
*
|
||||
* Dynamic package installation. Tihe first call to pthread_once() by any
|
||||
* thread in a process, with a given 'once_control', shall call the
|
||||
* 'init_routine' with no arguments. Subsequent calls of pthread_once()
|
||||
* with the same once_control shall not call the 'init_routine'. The
|
||||
* 'once_control' paramter shall determine whether the associated
|
||||
* initialization routine has been called.
|
||||
*
|
||||
* STEPS:
|
||||
* 1.Initialize a pthread_once object
|
||||
* 2.Call pthread_once passing it this object
|
||||
* 3.Call pthread_once again, this time, it shouldn't execute the function
|
||||
* passed to it. If it does, the test fails.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
/* Keeps track of how many times the init function has been called. */
|
||||
int init_flag;
|
||||
|
||||
/* The init function that pthread_once calls */
|
||||
void *an_init_func()
|
||||
{
|
||||
init_flag++;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
||||
|
||||
init_flag=0;
|
||||
|
||||
/* Call pthread_once, passing it the once_control */
|
||||
pthread_once(&once_control, (void*)an_init_func);
|
||||
|
||||
/* Call pthread_once again. The init function should not be
|
||||
* called. */
|
||||
pthread_once(&once_control, (void*)an_init_func);
|
||||
|
||||
if(init_flag != 1)
|
||||
{
|
||||
printf("Test FAILED\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%spthread_once_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
|
||||
}
|
||||
|
||||
|
||||
-118
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
*
|
||||
* In a process, the first call to pthread_once with a given once_control
|
||||
* calls the init routine.
|
||||
|
||||
* The steps are:
|
||||
* -> call pthread_once
|
||||
* -> check the init_routine executed
|
||||
|
||||
* The test fails if the init_routine has not been called after pthread_once
|
||||
* has returned.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* 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>
|
||||
|
||||
/********************************************************************************************/
|
||||
/****************************** 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 control;
|
||||
|
||||
void my_init( void )
|
||||
{
|
||||
|
||||
control = 1;
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
/* The main test function. */
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_once_t myctl = PTHREAD_ONCE_INIT;
|
||||
|
||||
/* Initialize output */
|
||||
output_init();
|
||||
|
||||
control = 0;
|
||||
|
||||
/* Call the initializer */
|
||||
ret = pthread_once( &myctl, my_init );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "pthread_once failed" );
|
||||
}
|
||||
|
||||
if ( control != 1 )
|
||||
{
|
||||
FAILED( "The initializer function did not execute" );
|
||||
}
|
||||
|
||||
printf("%spthread_once_1-2:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
}
|
||||
|
||||
|
||||
-183
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
*
|
||||
* Subsequent calls with the same once_control do not call init routine.
|
||||
|
||||
* The steps are:
|
||||
* -> Create several threads
|
||||
* -> each call pthread_once
|
||||
* -> check the init_routine executed once
|
||||
|
||||
* The test fails if the init_routine has not been called or has
|
||||
* been called several times.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* 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>
|
||||
|
||||
/********************************************************************************************/
|
||||
/****************************** 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
|
||||
|
||||
#define NTHREADS 30
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Test case *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
int control;
|
||||
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void my_init( void )
|
||||
{
|
||||
int ret = 0;
|
||||
ret = pthread_mutex_lock( &mtx );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Failed to lock mutex in initializer" );
|
||||
}
|
||||
|
||||
control++;
|
||||
|
||||
ret = pthread_mutex_unlock( &mtx );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Failed to unlock mutex in initializer" );
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
/* Thread function */
|
||||
void * threaded ( void * arg )
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = pthread_once( arg, my_init );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "pthread_once failed" );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The main test function. */
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
int ret, i;
|
||||
|
||||
pthread_once_t myctl = PTHREAD_ONCE_INIT;
|
||||
|
||||
pthread_t th[ NTHREADS ];
|
||||
|
||||
/* Initialize output */
|
||||
output_init();
|
||||
|
||||
control = 0;
|
||||
|
||||
/* Create the children */
|
||||
|
||||
for ( i = 0; i < NTHREADS; i++ )
|
||||
{
|
||||
ret = pthread_create( &th[ i ], NULL, threaded, &myctl );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Failed to create a thread" );
|
||||
}
|
||||
}
|
||||
|
||||
/* Then join */
|
||||
for ( i = 0; i < NTHREADS; i++ )
|
||||
{
|
||||
ret = pthread_join( th[ i ], NULL );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Failed to join a thread" );
|
||||
}
|
||||
}
|
||||
|
||||
/* Fetch the memory */
|
||||
ret = pthread_mutex_lock( &mtx );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Failed to lock mutex in initializer" );
|
||||
}
|
||||
|
||||
if ( control != 1 )
|
||||
{
|
||||
output( "Control: %d\n", control );
|
||||
FAILED( "The initializer function did not execute once" );
|
||||
}
|
||||
|
||||
ret = pthread_mutex_unlock( &mtx );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Failed to unlock mutex in initializer" );
|
||||
}
|
||||
|
||||
printf("%spthread_once_1-3:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
}
|
||||
|
||||
|
||||
-118
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* 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:
|
||||
*
|
||||
* pthread_once returns only when init routine has completed.
|
||||
|
||||
* The steps are:
|
||||
* -> call pthread_once (the init routine lasts for 1 second)
|
||||
* -> check the init_routine executed
|
||||
|
||||
* The test fails if the init_routine has not been completed when pthread_once
|
||||
* returns.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* 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>
|
||||
|
||||
/********************************************************************************************/
|
||||
/****************************** 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 control;
|
||||
|
||||
void my_init( void )
|
||||
{
|
||||
sleep( 1 );
|
||||
|
||||
control = 1;
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
/* The main test function. */
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_once_t myctl = PTHREAD_ONCE_INIT;
|
||||
|
||||
/* Initialize output */
|
||||
output_init();
|
||||
|
||||
control = 0;
|
||||
|
||||
/* Call the initializer */
|
||||
ret = pthread_once( &myctl, my_init );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "pthread_once failed" );
|
||||
}
|
||||
|
||||
if ( control != 1 )
|
||||
{
|
||||
FAILED( "The initializer function did not execute" );
|
||||
}
|
||||
|
||||
printf("%spthread_once_2-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
}
|
||||
|
||||
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
*
|
||||
* Test pthread_once()
|
||||
*
|
||||
* The pthread_once() function is not a cancelation point. However if
|
||||
* 'init_routine'is a cancelation point and is canceled, the effect on
|
||||
* 'once_control' shall be as if pthread_once() was never called.
|
||||
*
|
||||
* STEPS:
|
||||
* 1. Create a cancelable thread.
|
||||
* 2. In the thread routine, call pthread_once using a global pthread_once_t
|
||||
* object.
|
||||
* 3. Cancel the thread during the pthread_once init function
|
||||
* 4. Call pthread_once again with the same pthread once_t object
|
||||
* 5. This should call the pthread_once init function. If not, the test fails.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
/* Global pthread_once_t object */
|
||||
pthread_once_t once_control;
|
||||
|
||||
/* Keeps track of how many times the init function has been called. */
|
||||
int init_flag;
|
||||
|
||||
/* The init function that pthread_once calls */
|
||||
void *an_init_func()
|
||||
{
|
||||
/* Indicate to main() that the init function has been reached */
|
||||
init_flag=1;
|
||||
|
||||
/* Stay in a continuous loop until the thread that called
|
||||
* this function gets canceled */
|
||||
sleep(10);
|
||||
|
||||
/* The thread could not be canceled, timeout after 10 secs */
|
||||
perror("Init function timed out (10 secs), thread could not be canceled\n");
|
||||
init_flag=-1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Thread function */
|
||||
void *a_thread_func()
|
||||
{
|
||||
/* Make the thread cancelable immediately */
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
pthread_once(&once_control, (void*)an_init_func);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 2nd init function used by the 2nd call of pthread_once */
|
||||
void *an_init_func2()
|
||||
{
|
||||
/* Indicate to main() that this init function has been reached */
|
||||
init_flag=1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
once_control = PTHREAD_ONCE_INIT;
|
||||
init_flag=0;
|
||||
|
||||
/* Create a thread that will execute the first call to pthread_once() */
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
perror("Error creating thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait until the init function is reached to cancel the thread */
|
||||
while(init_flag==0)
|
||||
sleep(1);
|
||||
|
||||
/* Send cancel request to the thread*/
|
||||
if(pthread_cancel(new_th) != 0)
|
||||
{
|
||||
perror("Could send cancel request to thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait until the thread is canceled */
|
||||
pthread_join(new_th, NULL);
|
||||
|
||||
/* If the thread could not be canceled and timed out, send
|
||||
* an error */
|
||||
if (init_flag == -1)
|
||||
{
|
||||
perror("Error: could not cancel thread\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
init_flag=0;
|
||||
|
||||
/* Should be able to call pthread_once() again with the same
|
||||
* pthread_once_t object. */
|
||||
pthread_once(&once_control, (void*)an_init_func2);
|
||||
|
||||
/* If the init function from the 2nd call to pthread_once() was not
|
||||
* reached, the test fails. */
|
||||
if(init_flag != 1)
|
||||
{
|
||||
printf("Test FAILED\n: %d", init_flag);
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("Test PASSED\n");
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Test pthread_once()
|
||||
|
||||
*The constant PTHREAD_ONCE_INIT is defined in the pthread.h header.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
pthread_once_t dummy = PTHREAD_ONCE_INIT;
|
||||
|
||||
|
||||
-365
@@ -1,365 +0,0 @@
|
||||
/*
|
||||
* 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 function does not return EINTR
|
||||
|
||||
* The steps are:
|
||||
* -> kill a thread which calls pthread_once
|
||||
* -> check that EINTR is never returned
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* 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 <semaphore.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
|
||||
|
||||
#define WITH_SYNCHRO
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/*********************************** Test cases *****************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
char do_it = 1;
|
||||
unsigned long count_ope = 0;
|
||||
#ifdef WITH_SYNCHRO
|
||||
sem_t semsig1;
|
||||
sem_t semsig2;
|
||||
unsigned long count_sig = 0;
|
||||
#endif
|
||||
|
||||
sigset_t usersigs;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sig;
|
||||
#ifdef WITH_SYNCHRO
|
||||
sem_t *sem;
|
||||
#endif
|
||||
}
|
||||
|
||||
thestruct;
|
||||
|
||||
/* the following function keeps on sending the signal to the process */
|
||||
void * sendsig ( void * arg )
|
||||
{
|
||||
thestruct * thearg = ( thestruct * ) arg;
|
||||
int ret;
|
||||
pid_t process;
|
||||
|
||||
process = getpid();
|
||||
|
||||
/* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */
|
||||
ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread" );
|
||||
}
|
||||
|
||||
while ( do_it )
|
||||
{
|
||||
#ifdef WITH_SYNCHRO
|
||||
|
||||
if ( ( ret = sem_wait( thearg->sem ) ) )
|
||||
{
|
||||
UNRESOLVED( errno, "Sem_wait in sendsig" );
|
||||
}
|
||||
|
||||
count_sig++;
|
||||
#endif
|
||||
|
||||
ret = kill( process, thearg->sig );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( errno, "Kill in sendsig" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Next are the signal handlers. */
|
||||
/* This one is registered for signal SIGUSR1 */
|
||||
void sighdl1( int sig )
|
||||
{
|
||||
#ifdef WITH_SYNCHRO
|
||||
|
||||
if ( sem_post( &semsig1 ) )
|
||||
{
|
||||
UNRESOLVED( errno, "Sem_post in signal handler 1" );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This one is registered for signal SIGUSR2 */
|
||||
void sighdl2( int sig )
|
||||
{
|
||||
#ifdef WITH_SYNCHRO
|
||||
|
||||
if ( sem_post( &semsig2 ) )
|
||||
{
|
||||
UNRESOLVED( errno, "Sem_post in signal handler 2" );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int init_ctl;
|
||||
/* Init function */
|
||||
void initializer( void )
|
||||
{
|
||||
init_ctl++;
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
/* Test function -- calls pthread_equal() and checks that EINTR is never returned. */
|
||||
void * test( void * arg )
|
||||
{
|
||||
int ret = 0;
|
||||
pthread_once_t once_ctl;
|
||||
|
||||
/* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */
|
||||
ret = pthread_sigmask( SIG_UNBLOCK, &usersigs, NULL );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread" );
|
||||
}
|
||||
|
||||
|
||||
while ( do_it )
|
||||
{
|
||||
count_ope++;
|
||||
|
||||
once_ctl = PTHREAD_ONCE_INIT;
|
||||
init_ctl = 0;
|
||||
|
||||
ret = pthread_once( &once_ctl, initializer );
|
||||
|
||||
if ( ret == EINTR )
|
||||
{
|
||||
FAILED( "pthread_once returned EINTR" );
|
||||
}
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "pthread_once failed" );
|
||||
}
|
||||
|
||||
ret = pthread_once( &once_ctl, initializer );
|
||||
|
||||
if ( ret == EINTR )
|
||||
{
|
||||
FAILED( "pthread_once returned EINTR" );
|
||||
}
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "pthread_once failed" );
|
||||
}
|
||||
|
||||
if ( init_ctl != 1 )
|
||||
{
|
||||
output( "init_ctl:%d\n", init_ctl );
|
||||
FAILED( "The initializer did not execute as expected" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Main function */
|
||||
int main ( int argc, char * argv[] )
|
||||
{
|
||||
int ret;
|
||||
pthread_t th_work, th_sig1, th_sig2;
|
||||
thestruct arg1, arg2;
|
||||
|
||||
struct sigaction sa;
|
||||
|
||||
/* Initialize output routine */
|
||||
output_init();
|
||||
|
||||
/* We need to register the signal handlers for the PROCESS */
|
||||
sigemptyset ( &sa.sa_mask );
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = sighdl1;
|
||||
|
||||
if ( ( ret = sigaction ( SIGUSR1, &sa, NULL ) ) )
|
||||
{
|
||||
UNRESOLVED( ret, "Unable to register signal handler1" );
|
||||
}
|
||||
|
||||
sa.sa_handler = sighdl2;
|
||||
|
||||
if ( ( ret = sigaction ( SIGUSR2, &sa, NULL ) ) )
|
||||
{
|
||||
UNRESOLVED( ret, "Unable to register signal handler2" );
|
||||
}
|
||||
|
||||
/* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */
|
||||
sigemptyset( &usersigs );
|
||||
|
||||
ret = sigaddset( &usersigs, SIGUSR1 );
|
||||
|
||||
ret |= sigaddset( &usersigs, SIGUSR2 );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Unable to add SIGUSR1 or 2 to a signal set" );
|
||||
}
|
||||
|
||||
/* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */
|
||||
ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL );
|
||||
|
||||
if ( ret != 0 )
|
||||
{
|
||||
UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread" );
|
||||
}
|
||||
|
||||
#ifdef WITH_SYNCHRO
|
||||
if ( sem_init( &semsig1, 0, 1 ) )
|
||||
{
|
||||
UNRESOLVED( errno, "Semsig1 init" );
|
||||
}
|
||||
|
||||
if ( sem_init( &semsig2, 0, 1 ) )
|
||||
{
|
||||
UNRESOLVED( errno, "Semsig2 init" );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if ( ( ret = pthread_create( &th_work, NULL, test, NULL ) ) )
|
||||
{
|
||||
UNRESOLVED( ret, "Worker thread creation failed" );
|
||||
}
|
||||
|
||||
arg1.sig = SIGUSR1;
|
||||
arg2.sig = SIGUSR2;
|
||||
#ifdef WITH_SYNCHRO
|
||||
arg1.sem = &semsig1;
|
||||
arg2.sem = &semsig2;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if ( ( ret = pthread_create( &th_sig1, NULL, sendsig, ( void * ) & arg1 ) ) )
|
||||
{
|
||||
UNRESOLVED( ret, "Signal 1 sender thread creation failed" );
|
||||
}
|
||||
|
||||
if ( ( ret = pthread_create( &th_sig2, NULL, sendsig, ( void * ) & arg2 ) ) )
|
||||
{
|
||||
UNRESOLVED( ret, "Signal 2 sender thread creation failed" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Let's wait for a while now */
|
||||
sleep( 1 );
|
||||
|
||||
|
||||
/* Now stop the threads and join them */
|
||||
do
|
||||
{
|
||||
do_it = 0;
|
||||
}
|
||||
while ( do_it );
|
||||
|
||||
|
||||
if ( ( ret = pthread_join( th_sig1, NULL ) ) )
|
||||
{
|
||||
UNRESOLVED( ret, "Signal 1 sender thread join failed" );
|
||||
}
|
||||
|
||||
if ( ( ret = pthread_join( th_sig2, NULL ) ) )
|
||||
{
|
||||
UNRESOLVED( ret, "Signal 2 sender thread join failed" );
|
||||
}
|
||||
|
||||
|
||||
if ( ( ret = pthread_join( th_work, NULL ) ) )
|
||||
{
|
||||
UNRESOLVED( ret, "Worker thread join failed" );
|
||||
}
|
||||
|
||||
|
||||
#if VERBOSE > 0
|
||||
output( "Test executed successfully.\n" );
|
||||
|
||||
output( " %d initializations.\n", count_ope );
|
||||
|
||||
#ifdef WITH_SYNCHRO
|
||||
output( " %d signals were sent meanwhile.\n", count_sig );
|
||||
|
||||
#endif
|
||||
#endif
|
||||
PASSED;
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_once ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest pthread_once_1-1 : 1-1.c ;
|
||||
SimpleTest pthread_once_1-2 : 1-2.c ;
|
||||
SimpleTest pthread_once_1-3 : 1-3.c ;
|
||||
SimpleTest pthread_once_2-1 : 2-1.c ;
|
||||
#SimpleTest pthread_once_3-1 : 3-1.c ;
|
||||
#SimpleTest pthread_once_4-1 : 4-1.c ;
|
||||
#SimpleTest pthread_once_6-1 : 6-1.c ;
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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)
|
||||
static void output_init()
|
||||
{
|
||||
/* do nothing */
|
||||
return;
|
||||
}
|
||||
static 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);
|
||||
}
|
||||
static void output_fini()
|
||||
{
|
||||
/*do nothing */
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_setspecific()
|
||||
*
|
||||
* shall associate a thread-specific value with a key obtained via a previouse call to
|
||||
* pthread_key_create. Different threads may bind different values to the same key.
|
||||
* Calling pthread_setspecific with a key value not obtiained from pthread_key_create of after
|
||||
* the key has been deleted with pthread_key_delete is undefined.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create NUM_OF_KEYS pthread_key_t objects
|
||||
* 2. Set each key to a thread-specific value with pthread_setspecific()
|
||||
* 3. Call pthread_getspecific() on each key and check that the value returned is correct.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUM_OF_KEYS 10
|
||||
#define KEY_VALUE 0
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_key_t keys[NUM_OF_KEYS];
|
||||
int i;
|
||||
void* rc;
|
||||
|
||||
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||
{
|
||||
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||
{
|
||||
printf("pthread_setspecific_1-1 Error: pthread_key_create() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
} else
|
||||
{
|
||||
if(pthread_setspecific(keys[i], (void *)(long)(i + KEY_VALUE)) != 0)
|
||||
{
|
||||
printf("pthread_setspecific_1-1 Test FAILED: Could not set the value of the key to %d\n", (i + KEY_VALUE));
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0;i<NUM_OF_KEYS;++i)
|
||||
{
|
||||
rc = pthread_getspecific(keys[i]);
|
||||
if(rc != (void *)(long)(i + KEY_VALUE))
|
||||
{
|
||||
printf("pthread_setspecific_1-1 Test FAILED: Did not return correct value of thread-specific key, expected %ld, but got %ld\n", (long)(i + KEY_VALUE), (long)rc);
|
||||
return PTS_FAIL;
|
||||
} else
|
||||
{
|
||||
if(pthread_key_delete(keys[i]) != 0)
|
||||
{
|
||||
printf("pthread_setspecific_1-1 Error: pthread_key_delete() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%spthread_setspecific_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-103
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
* Test that pthread_setspecific()
|
||||
*
|
||||
* shall acssociate a thread-specific value with a key obtained via a previouse call to
|
||||
* pthread_key_create. Different threads may bind different values to the same key.
|
||||
* Calling pthread_setspecific with a key value not obtiained from pthread_key_create of after
|
||||
* the key has been deleted with pthread_key_delete is undefined.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a key
|
||||
* 2. Bind a value from the main thread to this key
|
||||
* 3. Create a thread and bind another value to this key
|
||||
* 4. Compare the values bound to the key between the main thread and the newly created thread,
|
||||
* they should be different and pertaining to what each thread set as the value.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define KEY_VALUE_1 100
|
||||
#define KEY_VALUE_2 200
|
||||
|
||||
pthread_key_t key;
|
||||
void* rc1;
|
||||
void* rc2;
|
||||
|
||||
void *a_thread_func()
|
||||
{
|
||||
/* Bind a value to key for this thread (this will be different from the value
|
||||
* that we bind for the main thread) */
|
||||
if(pthread_setspecific(key, (void *)(KEY_VALUE_2)) != 0)
|
||||
{
|
||||
printf("pthread_setspecific_1-2 Test FAILED: Could not set the value of the key to %d\n", (KEY_VALUE_2));
|
||||
pthread_exit((void*)PTS_FAIL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get the bound value of the key that we just set. */
|
||||
rc2 = pthread_getspecific(key);
|
||||
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t new_th;
|
||||
|
||||
/* Create the key */
|
||||
if(pthread_key_create(&key, NULL) != 0)
|
||||
{
|
||||
printf("pthread_setspecific_1-2 Error: pthread_key_create() failed\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Bind a value for this main thread */
|
||||
if(pthread_setspecific(key, (void *)(KEY_VALUE_1)) != 0)
|
||||
{
|
||||
printf("pthread_setspecific_1-2 Test FAILED: Could not set the value of the key to %d\n", (KEY_VALUE_1));
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
/* Create another thread. This thread will also bind a value to the key */
|
||||
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||
{
|
||||
printf("pthread_setspecific_1-2 Error: in pthread_create()\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* Wait for thread to end execution */
|
||||
pthread_join(new_th, NULL);
|
||||
|
||||
/* Get the value associated for the key in this main thread */
|
||||
rc1 = pthread_getspecific(key);
|
||||
|
||||
/* Compare this value with the value associated for the key in the newly created
|
||||
* thread, they should be different. */
|
||||
if(rc1 != (void *)(KEY_VALUE_1))
|
||||
{
|
||||
printf("pthread_setspecific_1-2 Test FAILED: Incorrect value bound to key, expected %d, got %ld\n", KEY_VALUE_1, (long)rc1);
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
if(rc2 != (void *)(KEY_VALUE_2))
|
||||
{
|
||||
printf("pthread_setspecific_1-2 Test FAILED: Incorrect value bound to key, expected %d, got %ld\n", KEY_VALUE_2, (long)rc2);
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%spthread_setspecific_1-2:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_setspecific ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest pthread_setspecific_1-1 : 1-1.c ;
|
||||
SimpleTest pthread_setspecific_1-2 : 1-2.c ;
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Steps:
|
||||
1. Set up a handler for signal SIGABRT, such that it is called if signal is ever raised.
|
||||
2. Call sighold on that SIGABRT.
|
||||
3. Raise a SIGABRT and verify that the signal handler was not called.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void handler(int signo)
|
||||
{
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
if (sigaction(SIGABRT, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (sighold(SIGABRT) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (raise(SIGABRT) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
if (handler_called) {
|
||||
printf("FAIL: Signal was not blocked\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%ssighold_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Simply, if sighold returns a 0 here, test passes.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
if ((int)sighold(SIGABRT) != 0) {
|
||||
perror("sighold failed -- returned -- test aborted");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
printf("%ssighold_2-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Testing passing an invalid signals to sighold().
|
||||
After sighold is called on an invalid signal, sighold() should return -1 and set
|
||||
errno to EINVAL
|
||||
|
||||
The invalid signal passed to sighold() depends on the argument passed to this program.
|
||||
There are currently 4 invalid signals.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
jmp_buf sig11_recover;
|
||||
void sig11_handler(int sig);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int signo, TEST_RETURN;
|
||||
struct sigaction sa, osa;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s [1|2|3|4]\n", argv[0]);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/*
|
||||
Various error conditions
|
||||
*/
|
||||
switch (argv[1][0]) {
|
||||
case '1':
|
||||
signo=-1;
|
||||
break;
|
||||
case '2':
|
||||
signo=-10000;
|
||||
break;
|
||||
case '3':
|
||||
signo=INT32_MIN+1;
|
||||
break;
|
||||
case '4':
|
||||
signo=INT32_MIN;
|
||||
break;
|
||||
default:
|
||||
printf("Usage: %s [1|2|3|4]\n", argv[0]);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* special sig11 case */
|
||||
sa.sa_handler = &sig11_handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
|
||||
sigaction(SIGSEGV, NULL, &osa);
|
||||
sigaction(SIGSEGV, &sa, NULL);
|
||||
|
||||
if (setjmp(sig11_recover)) {
|
||||
errno = EINVAL;
|
||||
TEST_RETURN=-2;
|
||||
} else {
|
||||
TEST_RETURN=sighold(signo);
|
||||
}
|
||||
sigaction(SIGSEGV, &osa, NULL);
|
||||
|
||||
if (TEST_RETURN == -1) {
|
||||
if (EINVAL == errno) {
|
||||
printf("%ssighold_3-core-buildonly%s:%s %s PASSED%s\n", boldOn, argv[1], boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
} else {
|
||||
printf ("errno not set to EINVAL\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
if (TEST_RETURN == -2) {
|
||||
printf ("test received SIGSEGV\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("sighold did not return -1\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
* sig11_handler() - our segfault recover hack
|
||||
******************************************************************/
|
||||
void
|
||||
sig11_handler(int sig)
|
||||
{
|
||||
longjmp(sig11_recover, 1);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sighold ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest sighold_1-1 : 1-1.c ;
|
||||
SimpleTest sighold_2-1 : 2-1.c ;
|
||||
SimpleTest sighold_3-core-buildonly : 3-core-buildonly.c ;
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Steps:
|
||||
1. Set up a handler for signal SIGABRT, such that it is called if
|
||||
signal is ever raised.
|
||||
2. Call sigignore on SIGABRT.
|
||||
3. Raise a SIGABRT and verify that the signal handler was not called.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void handler(int signo)
|
||||
{
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
if (sigaction(SIGABRT, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
sigignore(SIGABRT);
|
||||
|
||||
if (raise(SIGABRT) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (handler_called) {
|
||||
printf("FAIL: Signal was not ignored\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%ssigignore_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Simply, if sigignore returns a 0 here, test passes.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
if (sigignore(SIGABRT) != 0) {
|
||||
perror("sigignore failed -- returned -- test aborted");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
printf("%ssigignore_4-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Testing passing an invalid signals to sighold().
|
||||
After sighold is called on an invalid signal, sigignore() should
|
||||
return -1 and set errno to EINVAL
|
||||
|
||||
The invalid signal passed to sigignore() depends on the argument
|
||||
passed to this program. There are currently 4 invalid signals.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int signo;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s [1|2|3|4]\n", argv[0]);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/*
|
||||
Various error conditions
|
||||
*/
|
||||
switch (argv[1][0]) {
|
||||
case '1':
|
||||
signo=-1;
|
||||
break;
|
||||
case '2':
|
||||
signo=-10000;
|
||||
break;
|
||||
case '3':
|
||||
signo=INT32_MIN+1;
|
||||
break;
|
||||
case '4':
|
||||
signo=INT32_MIN;
|
||||
break;
|
||||
default:
|
||||
printf("Usage: %s [1|2|3|4]\n", argv[0]);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (sigignore(signo) == -1) {
|
||||
if (EINVAL == errno) {
|
||||
printf("%ssigignore_5-core-buildonly%s:%s%sPASSED%s\n", boldOn, argv[1], boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
} else {
|
||||
printf ("errno not set to EINVAL\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printf("sighold did not return -1\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Testing trying to ignore a signal that cannot be ignored.
|
||||
Line 1264 in Issue 6 of the Posix System Interfaces document says that
|
||||
the system shall not allow the signals SIGKILL or SIGSTOP
|
||||
to be ignored.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
if (sigignore(SIGKILL) == -1) {
|
||||
if (EINVAL == errno) {
|
||||
printf("%ssigignore_6-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
} else {
|
||||
printf ("errno not set to EINVAL\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printf("sigignore did not return -1\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Testing trying to ignore a signal that cannot be ignored.
|
||||
Line 1264 in Issue 6 of the Posix System Interfaces document says that
|
||||
the system shall not allow the signals SIGKILL or SIGSTOP
|
||||
to be ignored.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
if (sigignore(SIGSTOP) == -1) {
|
||||
if (EINVAL == errno) {
|
||||
printf("%ssigignore_6-2:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
} else {
|
||||
printf ("errno not set to EINVAL\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printf("sigignore did not return -1\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigignore ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest sigignore_1-1 : 1-1.c ;
|
||||
SimpleTest sigignore_4-1 : 4-1.c ;
|
||||
SimpleTest sigignore_5-core-buildonly : 5-core-buildonly.c ;
|
||||
SimpleTest sigignore_6-1 : 6-1.c ;
|
||||
SimpleTest sigignore_6-2 : 6-2.c ;
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the default handling of the
|
||||
signal shall occur if the value of the func parameter is SIG_DFL.
|
||||
|
||||
How this program tests this assertion by setting up a handler
|
||||
"myhandler" for SIGCHLD. Then another call to signal() is made about
|
||||
SIGCHLD, this time with SIG_DFL as the value of the func parameter.
|
||||
The default action for SIGCHLD is to be ignored, so unless myhandler
|
||||
gets called when SIGCHLD is raised, the test passess, otherwise
|
||||
returns failure.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
printf("signal_1-1: SIGCHLD called. Inside handler\n");
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (signal(SIGCHLD, myhandler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (signal(SIGCHLD,SIG_DFL) != myhandler) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
raise(SIGCHLD);
|
||||
|
||||
if (handler_called == 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssignal_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the signal shall be ignored
|
||||
if the value of the func parameter is SIG_IGN.
|
||||
|
||||
How this program tests this assertion is by setting up a handler
|
||||
"myhandler" for SIGCHLD. Then another call to signal() is made about
|
||||
SIGCHLD, this time with SIG_IGN as the value of the func parameter.
|
||||
SIGCHLD should be ignored now, so unless myhandler gets called when
|
||||
SIGCHLD is raised, the test passes, otherwise returns failure.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
printf("signal_2-1: SIGCHLD called. Inside handler\n");
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (signal(SIGCHLD, myhandler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (signal(SIGCHLD,SIG_IGN) != myhandler) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
raise(SIGCHLD);
|
||||
|
||||
if (handler_called == 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssignal_2-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the signal shall be ignored
|
||||
if the value of the func parameter is SIG_IGN.
|
||||
|
||||
How this program tests this assertion is by setting up a handler
|
||||
"myhandler" for SIGCHLD, and then raising that signal. If the
|
||||
handler_called variable is anything but 1, then fail, otherwise pass.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
/* printf("signal_3-1: SIGCHLD called. Inside handler\n"); */
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (signal(SIGCHLD, myhandler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
raise(SIGCHLD);
|
||||
|
||||
if (handler_called != 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssignal_3-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the signal function shall return
|
||||
the function name of the last signal handler that was associated with
|
||||
sig.
|
||||
|
||||
How this program tests this assertion is by setting up handlers
|
||||
SIGUSR1_handler and SIGUSR2_handler for signals SIGUSR1 and SIGUSR2
|
||||
respectively. A third call to signal() is made regarding signal SIGUSR1.
|
||||
If this call returns anything but SIGUSR1_handler, fail the test,
|
||||
otherwise the test passes.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void SIGUSR1_handler(int signo)
|
||||
{
|
||||
printf("signal_5-1: inside SIGUSR1_handler\n");
|
||||
}
|
||||
|
||||
void SIGUSR2_handler(int signo)
|
||||
{
|
||||
printf("signal_5-1: inside SIGUSR2_handler\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (signal(SIGUSR1, SIGUSR1_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (signal(SIGUSR2, SIGUSR2_handler) == SIG_ERR) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (signal(SIGUSR1,SIG_IGN) != SIGUSR1_handler) {
|
||||
printf("signal did not return the last handler that was associated with SIGUSR1\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssignal_5-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that signal() shall return SIG_ERR
|
||||
and set errno to a positive value if an invalid signal number was
|
||||
passed to it.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
printf("signal_6-1: inside handler\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
if (signal(-1, myhandler) != SIG_ERR) {
|
||||
printf("Test FAILED: signal() didn't return SIG_ERR even though invalid signal number was passed to it\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
if (errno != EINVAL) {
|
||||
printf("Test FAILED: errno wasn't set to EINVAL even though invalid signal number was passed to the signal() function\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssignal_6-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that signal() shall return SIG_ERR
|
||||
and set errno to a positive value if an invalid signal number was
|
||||
passed to it.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
printf("signal_7-1: inside handler\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
if (signal(SIGKILL, myhandler) != SIG_ERR) {
|
||||
printf("Test FAILED: signal() didn't return SIG_ERR even though a non-catchable signal was passed to it\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
if (errno != EINVAL) {
|
||||
printf("Test FAILED: errno wasn't set to EINVAL even though a non-catchable signal was passed to the signal() function\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%ssignal_7-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces signal ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest signal_1-1 : 1-1.c ;
|
||||
SimpleTest signal_2-1 : 2-1.c ;
|
||||
SimpleTest signal_3-1 : 3-1.c ;
|
||||
SimpleTest signal_5-1 : 5-1.c ;
|
||||
SimpleTest signal_6-1 : 6-1.c ;
|
||||
SimpleTest signal_7-1 : 7-1.c ;
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Steps:
|
||||
1. Set the signal mask to only having SIGABRT.
|
||||
2. Call sigprocmask again, this time with a randomly generated value of
|
||||
how that is checked to make sure it does not equal any of the three defined
|
||||
values of how which are SIG_SETMASK, SIG_BLOCK, or SIG_UNBLOCK. This should
|
||||
cause sigprocmask() to return -1. For the second parameter in the sigprocmask()
|
||||
function, use a set which contains SIGABRT and SIGALRM.
|
||||
3. Now verify using the is_changed() function that the only signal that is still
|
||||
in the signal mask is SIGABRT. Neither SIGALRM nor any other signal should be
|
||||
in the signal mask of the process.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUMSIGNALS 25
|
||||
|
||||
int is_changed(sigset_t set) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if (sigismember(&set, siglist[i]) != 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_rand() {
|
||||
|
||||
int r;
|
||||
r=rand();
|
||||
while ((r == SIG_BLOCK) || (r == SIG_SETMASK) || (r == SIG_UNBLOCK)) {
|
||||
r = get_rand();
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
int r=get_rand();
|
||||
sigset_t actl, oactl;
|
||||
|
||||
sigemptyset(&actl);
|
||||
sigemptyset(&oactl);
|
||||
sigaddset(&actl, SIGABRT);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &actl, NULL);
|
||||
|
||||
sigaddset(&actl, SIGALRM);
|
||||
if (sigprocmask(r, &actl, NULL) != -1) {
|
||||
perror("sigprocmask() did not fail even though invalid how parameter was passed to it.\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
sigprocmask(SIG_SETMASK, NULL, &oactl);
|
||||
|
||||
if (sigismember(&oactl, SIGABRT) != 1) {
|
||||
printf("FAIL: signal mask was changed. \n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
if (is_changed(oactl)) {
|
||||
printf("FAIL: signal mask was changed. \n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
printf("%ssigprocmask_12-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Steps:
|
||||
1. Add only SIGABRT to the signal mask.
|
||||
2. Make a call such as this: sigprocmask(SIG_BLOCK, NULL, &oactl). At
|
||||
this point, we have obtained the signal mask in oactl.
|
||||
3. Now call is_changed to make sure that SIGABRT is still in oactl, and
|
||||
that no other signal in the set is in oactl.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUMSIGNALS 26
|
||||
|
||||
int is_changed(sigset_t set, int sig) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
if (sigismember(&set, sig) != 1) {
|
||||
return 1;
|
||||
}
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if ((siglist[i] != sig)) {
|
||||
if (sigismember(&set, siglist[i]) != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
sigset_t actl, oactl;
|
||||
|
||||
sigemptyset(&actl);
|
||||
sigemptyset(&oactl);
|
||||
|
||||
sigaddset(&actl, SIGABRT);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &actl, NULL);
|
||||
sigprocmask(SIG_BLOCK, NULL, &oactl);
|
||||
|
||||
if (is_changed(oactl, SIGABRT)) {
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigprocmask_8-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Steps:
|
||||
1. Add only SIGABRT to the signal mask.
|
||||
2. Make a call such as this: sigprocmask(SIG_SETMASK, NULL, &oactl).
|
||||
At
|
||||
this point, we have obtained the signal mask in oactl.
|
||||
3. Now call is_changed to make sure that SIGABRT is still in oactl, and
|
||||
that no other signal in the set is in oactl.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUMSIGNALS 26
|
||||
|
||||
int is_changed(sigset_t set, int sig) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
if (sigismember(&set, sig) != 1) {
|
||||
return 1;
|
||||
}
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if ((siglist[i] != sig)) {
|
||||
if (sigismember(&set, siglist[i]) != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
sigset_t actl, oactl;
|
||||
|
||||
sigemptyset(&actl);
|
||||
sigemptyset(&oactl);
|
||||
|
||||
sigaddset(&actl, SIGABRT);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &actl, NULL);
|
||||
sigprocmask(SIG_SETMASK, NULL, &oactl);
|
||||
|
||||
if (is_changed(oactl, SIGABRT)) {
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigprocmask_8-2:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Steps:
|
||||
1. Add only SIGABRT to the signal mask.
|
||||
2. Make a call such as this: sigprocmask(SIG_UNBLOCK, NULL, &oactl). At
|
||||
this point, we have obtained the signal mask in oactl.
|
||||
3. Now call is_changed to make sure that SIGABRT is still in oactl, and
|
||||
that no other signal in the set is in oactl.
|
||||
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUMSIGNALS 26
|
||||
|
||||
int is_changed(sigset_t set, int sig) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
if (sigismember(&set, sig) != 1) {
|
||||
return 1;
|
||||
}
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if ((siglist[i] != sig)) {
|
||||
if (sigismember(&set, siglist[i]) != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
sigset_t actl, oactl;
|
||||
|
||||
sigemptyset(&actl);
|
||||
sigemptyset(&oactl);
|
||||
|
||||
sigaddset(&actl, SIGABRT);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &actl, NULL);
|
||||
sigprocmask(SIG_UNBLOCK, NULL, &oactl);
|
||||
|
||||
if (is_changed(oactl, SIGABRT)) {
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigprocmask_8-3:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigprocmask ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest sigprocmask_8-1 : 8-1.c ;
|
||||
SimpleTest sigprocmask_8-2 : 8-2.c ;
|
||||
SimpleTest sigprocmask_8-3 : 8-3.c ;
|
||||
SimpleTest sigprocmask_12-1 : 12-1.c ;
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Steps:
|
||||
1. Set up a handler for signal SIGABRT, such that it is called if
|
||||
signal is ever raised.
|
||||
2. Call sighold on that SIGABRT.
|
||||
3. Raise a SIGABRT and verify that the signal handler was not called.
|
||||
Otherwise, the test exits with unresolved results.
|
||||
4. Call sigrelse on SIGABRT.
|
||||
5. Verify that the handler gets called this time.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void handler(int signo)
|
||||
{
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = handler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
if (sigaction(SIGABRT, &act, 0) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
sighold(SIGABRT);
|
||||
|
||||
if (raise(SIGABRT) == -1) {
|
||||
perror("Unexpected error while attempting to setup test "
|
||||
"pre-conditions");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (handler_called) {
|
||||
printf("UNRESOLVED. possible problem in sigrelse\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (sigrelse(SIGABRT) == -1) {
|
||||
printf("UNRESOLVED. possible problem in sigrelse\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
if (handler_called) {
|
||||
printf("%ssigrelse_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
printf("FAIL\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Simply, if sigrelse returns a 0 here, test passes.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
if ((int)sigrelse(SIGABRT) != 0) {
|
||||
perror("sigrelse failed -- returned -- test aborted");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
printf("%ssigrelse_2-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
Testing passing an invalid signals to sigrelse().
|
||||
After sighold is called on an invalid signal, sigrelse() should
|
||||
return -1 and set errno to EINVAL
|
||||
|
||||
The invalid signal passed to sigrelse() depends on the argument
|
||||
passed to this program.
|
||||
There are currently 4 invalid signals.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
jmp_buf sig11_recover;
|
||||
void sig11_handler(int sig);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int signo, TEST_RETURN;
|
||||
struct sigaction sa, osa;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s [1|2|3|4]\n", argv[0]);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/*
|
||||
Various error conditions
|
||||
*/
|
||||
switch (argv[1][0]) {
|
||||
case '1':
|
||||
signo=-1;
|
||||
break;
|
||||
case '2':
|
||||
signo=-10000;
|
||||
break;
|
||||
case '3':
|
||||
signo=INT32_MIN+1;
|
||||
break;
|
||||
case '4':
|
||||
signo=INT32_MIN;
|
||||
break;
|
||||
default:
|
||||
printf("Usage: %s [1|2|3|4]\n", argv[0]);
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
/* special sig11 case */
|
||||
sa.sa_handler = &sig11_handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
|
||||
sigaction(SIGSEGV, NULL, &osa);
|
||||
sigaction(SIGSEGV, &sa, NULL);
|
||||
|
||||
if (setjmp(sig11_recover)) {
|
||||
errno = EINVAL;
|
||||
TEST_RETURN=-2;
|
||||
} else {
|
||||
TEST_RETURN=sigrelse(signo);
|
||||
}
|
||||
sigaction(SIGSEGV, &osa, NULL);
|
||||
|
||||
if (TEST_RETURN == -1) {
|
||||
if (EINVAL == errno) {
|
||||
printf("%ssigrelse_3-core-buildonly%s:%s %sPASSED%s\n", boldOn, argv[1], boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
} else {
|
||||
printf ("errno not set to EINVAL\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
}
|
||||
if (TEST_RETURN == -2) {
|
||||
printf ("test received SIGSEGV\n");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
printf("sigrelse did not return -1\n");
|
||||
return PTS_FAIL;
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
* sig11_handler() - our segfault recover hack
|
||||
******************************************************************/
|
||||
void
|
||||
sig11_handler(int sig)
|
||||
{
|
||||
longjmp(sig11_recover, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigrelse ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||
|
||||
SimpleTest sigrelse_1-1 : 1-1.c ;
|
||||
SimpleTest sigrelse_2-1 : 2-1.c ;
|
||||
SimpleTest sigrelse_3-core-buildonly : 3-core-buildonly.c ;
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the default handling of the
|
||||
signal shall occur if the value of the disp parameter is SIG_DFL.
|
||||
|
||||
How this program tests this assertion by setting up a handler
|
||||
"myhandler" for SIGCHLD. Then another call to sigset() is made about
|
||||
SIGCHLD, this time with SIG_DFL as the value of the func parameter.
|
||||
The default action for SIGCHLD is to be ignored, so unless myhandler
|
||||
gets called when SIGCHLD is raised, the test passess, otherwise
|
||||
returns failure.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
printf("sigset_1-1: SIGCHLD called. Inside handler\n");
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
struct sigaction act;
|
||||
act.sa_handler = myhandler;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(SIGCHLD, &act, 0) != 0) {
|
||||
perror("Unexpected error while using sigaction()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (sigset(SIGCHLD,SIG_DFL) != myhandler) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
raise(SIGCHLD);
|
||||
|
||||
if (handler_called == 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigset_1-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that when unsuccessful, SIG_ERROR
|
||||
shall be returned, and errno set to EINVAL.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
if (sigset(SIGKILL,SIG_IGN) == SIG_ERR) {
|
||||
if (errno != EINVAL) {
|
||||
printf("Test FAILED: sigset() returned SIG_ERR but didn't set errno to EINVAL\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
} else {
|
||||
printf("Test FAILED: sigset() didn't return SIG_ERROR even though SIGKILL was passed to it\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigset_10-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the signal shall be ignored
|
||||
if the value of the dist parameter is SIG_IGN.
|
||||
|
||||
How this program tests this assertion is by setting up a handler
|
||||
"myhandler" for SIGUSR1. Then another call to signal() is made about
|
||||
SIGUSR1, this time with SIG_IGN as the value of the func parameter.
|
||||
SIGUSR1 should be ignored now, so unless myhandler gets called when
|
||||
SIGUSR1 is raised, the test passes, otherwise returns failure.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
printf("sigset_2-1: SIGUSR1 called. Inside handler\n");
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sigaction act;
|
||||
act.sa_flags = 0;
|
||||
act.sa_handler = myhandler;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
if (sigaction(SIGUSR1, &act, 0) != 0) {
|
||||
perror("Unexpected error while using sigaction()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
if (sigset(SIGUSR1,SIG_IGN) != myhandler) {
|
||||
perror("Unexpected error while using signal()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
raise(SIGUSR1);
|
||||
|
||||
if (handler_called == 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigset_2-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the function shall be executed
|
||||
when the signal occurs if the disp parameter is the address of a function.
|
||||
|
||||
How this program tests this assertion is by setting up a handler
|
||||
"myhandler" for SIGCHLD, and then raising that signal. If the
|
||||
handler_called variable is anything but 1, then fail, otherwise pass.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int handler_called = 0;
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
/* printf("sigset_3-1: SIGCHLD called. Inside handler\n"); */
|
||||
handler_called = 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (sigset(SIGCHLD, myhandler) == SIG_ERR) {
|
||||
perror("Unexpected error while using sigset()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
raise(SIGCHLD);
|
||||
|
||||
if (handler_called != 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigset_3-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the signal will be added to the
|
||||
signal mask before its handler is executed.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
int signal_blocked = 0;
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
sigset_t mask;
|
||||
/* printf("sigset_4-1: SIGCHLD called. Inside handler\n"); */
|
||||
sigprocmask(SIG_SETMASK, NULL, &mask);
|
||||
if(sigismember(&mask, SIGCHLD)) {
|
||||
signal_blocked = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (sigset(SIGCHLD, myhandler) == SIG_ERR) {
|
||||
perror("Unexpected error while using sigset()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
raise(SIGCHLD);
|
||||
|
||||
if (signal_blocked != 1) {
|
||||
printf("Test FAILED: handler was called even though default was expected\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigset_4-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Intel Corporation. All rights reserved.
|
||||
* Created by: salwan.searty REMOVE-THIS AT intel DOT com
|
||||
* This file is licensed under the GPL license. For the full content
|
||||
* of this license, see the COPYING file at the top level of this
|
||||
* source tree.
|
||||
|
||||
This program tests the assertion that the process's signal mask will be
|
||||
restored to the state that it was in prior to the delivery of the signal
|
||||
|
||||
Steps:
|
||||
1. Empty the signal mask
|
||||
2. Deliver the signal
|
||||
3. When we return from the signal handler, verify that the signal mask
|
||||
is still empty, otherwise fail.
|
||||
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "posixtest.h"
|
||||
|
||||
#define NUMSIGNALS 26
|
||||
|
||||
int is_empty(sigset_t *set) {
|
||||
|
||||
int i;
|
||||
int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
|
||||
SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
|
||||
SIGPIPE, SIGQUIT, SIGSEGV,
|
||||
SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
|
||||
SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS,
|
||||
SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ };
|
||||
|
||||
for (i=0; i<NUMSIGNALS; i++) {
|
||||
if (sigismember(set, siglist[i]) != 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void myhandler(int signo)
|
||||
{
|
||||
/* printf("sigset_5-1: SIGCHLD called. Inside handler\n"); */
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
|
||||
sigprocmask(SIG_SETMASK, &mask, NULL);
|
||||
|
||||
if (sigset(SIGCHLD, myhandler) == SIG_ERR) {
|
||||
perror("Unexpected error while using sigset()");
|
||||
return PTS_UNRESOLVED;
|
||||
}
|
||||
|
||||
raise(SIGCHLD);
|
||||
sigprocmask(SIG_SETMASK, NULL, &mask);
|
||||
|
||||
if (is_empty(&mask) != 1) {
|
||||
printf("Test FAILED: signal mask should be empty\n");
|
||||
return PTS_FAIL;
|
||||
}
|
||||
printf("%ssigset_5-1:%s %sPASSED%s\n", boldOn, boldOff, green, normal);
|
||||
return PTS_PASS;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user