Removed tests that tested undefined behavior:

* Calling pthread_{join,detach}() on non-joinable threads.
* Calling mutexattr_setpshared() on uninitialized object.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36050 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-04-06 18:44:18 +00:00
parent 185b8ae6b0
commit 2b76954997
4 changed files with 0 additions and 310 deletions
@@ -1,84 +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_setdetachstate()
*
* If the thread is created detached, then use of the ID of the newly created
* thread by the pthread_detach() or pthread_join() function is an error.
*
* Steps:
* 1. Initialize a pthread_attr_t object using pthread_attr_init().
* 2. Using pthread_attr_setdetachstate(), set the detachstate to
* PTHREAD_CREATE_DETACHED.
* 3. Create a thread with this attribute.
* 4. Call pthread_detach() and pthread_join() on this thread, it should give
* an error.
*
*/
#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_val;
/* Initialize attribute */
if(pthread_attr_init(&new_attr) != 0)
{
perror("Cannot initialize attribute object\n");
return PTS_UNRESOLVED;
}
/* Set the attribute object to PTHREAD_CREATE_DETACHED. */
if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_DETACHED) != 0)
{
perror("Error in pthread_attr_setdetachstate()\n");
return PTS_UNRESOLVED;
}
/* Create a new thread passing it the new attribute object */
if(pthread_create(&new_th, &new_attr, a_thread_func, NULL) != 0)
{
perror("Error creating thread\n");
return PTS_UNRESOLVED;
}
/* If pthread_join() or pthread_detach fail, that means that the
* test fails as well. */
ret_val=pthread_join(new_th, NULL);
if(ret_val != EINVAL)
{
printf("Test FAILED\n");
return PTS_FAIL;
}
ret_val=pthread_detach(new_th);
if(ret_val != EINVAL)
{
printf("Test FAILED\n");
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
@@ -1,97 +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_detach()
*
* shall detach a thread. It shall indicate to the implementation that storage
* for 'thread' can be reclaimed when that thread terminates.
*
* STEPS:
* 1. Create a joinable thread
* 2. Detach that thread with pthread_detach()
* 3. Try and join the thread to main() using pthread_join()
* 4. An error should return from the pthread_join() function saying that the
* thread is detched. The test passes.
* 5. Else, if pthread_join is successful, the test fails.
*/
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include "posixtest.h"
void *a_thread_func()
{
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
/* If the thread wasn't canceled in 10 seconds, time out */
sleep(10);
perror("Thread couldn't be canceled (at cleanup time), timing out\n");
pthread_exit(0);
return NULL;
}
int main()
{
pthread_attr_t new_attr;
pthread_t new_th;
int ret;
/* Initialize attribute */
if(pthread_attr_init(&new_attr) != 0)
{
perror("Cannot initialize attribute object\n");
return PTS_UNRESOLVED;
}
/* Set the attribute object to be joinable */
if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_JOINABLE) != 0)
{
perror("Error in pthread_attr_setdetachstate()\n");
return PTS_UNRESOLVED;
}
/* Create the thread */
if(pthread_create(&new_th, &new_attr, a_thread_func, NULL) != 0)
{
perror("Error creating thread\n");
return PTS_UNRESOLVED;
}
/* Detach the thread. */
if(pthread_detach(new_th) != 0)
{
printf("Error detaching thread\n");
return PTS_FAIL;
}
/* Now try and join it. This should fail. */
ret=pthread_join(new_th, NULL);
/* Cleanup: Cancel the thread */
pthread_cancel(new_th);
if(ret == 0)
{
printf("Test FAILED\n");
return PTS_FAIL;
}else if(ret == EINVAL)
{
printf("Test PASSED\n");
return PTS_PASS;
}else
{
perror("Error in pthread_join\n");
return PTS_UNRESOLVED;
}
}
@@ -1,74 +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_join()
*
* pthread_join() SHALL fail if:
*
* -[ESRCH] No thread could be found corresponding to that thread ID
*
* pthread_join() MAY fail if:
* -[EINVAL] The implementation has detected that the value specified by
* 'thread' does not refer to a joinable thread.
* -[EDEADLK] A deadlock was detected or the value of 'thread' specifies the
* calling thread.
* It shall not return an error code of [EINTR]
*
* Testing EINVAL
*
* Steps:
* 1. Create a new thread that is non-joinable (i.e. detached state attribute is
* PTHREAD_CREATE_DETACHED.
* 2. Call pthread_join() in main. It should return EINVAL. If not, the test fails.
*
*/
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include "posixtest.h"
/* Thread's function. */
void *a_thread_func()
{
pthread_exit(0);
return NULL;
}
int main()
{
pthread_t new_th;
pthread_attr_t attr;
int ret;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
/* Create a new thread. */
if(pthread_create(&new_th, &attr, a_thread_func, NULL) != 0)
{
perror("Error creating thread\n");
return PTS_UNRESOLVED;
}
/* Wait for thread to return */
ret=pthread_join(new_th, NULL);
if(ret != EINVAL)
{
printf("Test FAILED: Return code should be EINVAL, but is: %d instead.\n", ret);
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
@@ -1,55 +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_mutexattr_setpshared()
*
* It MAY fail if:
*
* [EINVAL] - 'attr' is invalid.
*
* Steps:
*
* 1. Pass to pthread_mutexattr_setpshared() an uninitialized attributes object.
* 2. It may return the value of EINVAL.
*
*/
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include "posixtest.h"
int main()
{
/* Make sure there is process-shared capability. */
#ifndef PTHREAD_PROCESS_SHARED
fprintf(stderr,"process-shared attribute is not available for testing\n");
return PTS_UNRESOLVED;
#endif
pthread_mutexattr_t mta;
int ret;
/* Set the attribute to PTHREAD_PROCESS_PRIVATE. */
ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_PRIVATE);
if(ret != 0)
{
if(ret == EINVAL)
{
printf("Test PASSED\n");
return PTS_PASS;
}
printf("Test FAILED: Expected return code 0 or EINVAL, got: %d", ret);
return PTS_FAIL;
}
printf("Test PASSED: NOTE*: Returned 0 on error, though standard states 'may' fail.\n");
return PTS_PASS;
}