nptl: Convert tst-setuid2 to test-driver
Use <support/test-driver.c> and replace pthread calls to its xpthread equivalents. Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
parent
3bea50ccbc
commit
365b3af67e
|
@ -20,6 +20,7 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <support/xthread.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -36,30 +37,21 @@ static pthread_cond_t cond_recv;
|
||||||
static void *
|
static void *
|
||||||
thread_func (void *ctx __attribute__ ((unused)))
|
thread_func (void *ctx __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
int ret = pthread_mutex_lock (&mutex);
|
xpthread_mutex_lock (&mutex);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_mutex_lock (thread): %d", ret);
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (func_sent != NULL)
|
if (func_sent != NULL)
|
||||||
{
|
{
|
||||||
void (*func) (void) = func_sent;
|
void (*func) (void) = func_sent;
|
||||||
ret = pthread_mutex_unlock (&mutex);
|
xpthread_mutex_unlock (&mutex);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_mutex_unlock (thread): %d", ret);
|
|
||||||
func ();
|
func ();
|
||||||
ret = pthread_mutex_lock (&mutex);
|
|
||||||
if (ret != 0)
|
xpthread_mutex_lock (&mutex);
|
||||||
FAIL ("pthread_mutex_lock (thread): %d", ret);
|
|
||||||
func_sent = NULL;
|
func_sent = NULL;
|
||||||
ret = pthread_cond_signal (&cond_recv);
|
xpthread_cond_signal (&cond_recv);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_cond_signal (recv): %d", ret);
|
|
||||||
}
|
}
|
||||||
ret = pthread_cond_wait (&cond_send, &mutex);
|
xpthread_cond_wait (&cond_send, &mutex);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_cond_wait (send): %d", ret);
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -67,31 +59,18 @@ thread_func (void *ctx __attribute__ ((unused)))
|
||||||
static void
|
static void
|
||||||
run_on_thread (void (*func) (void))
|
run_on_thread (void (*func) (void))
|
||||||
{
|
{
|
||||||
int ret = pthread_mutex_lock (&mutex);
|
xpthread_mutex_lock (&mutex);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_mutex_lock (%s): %d", __func__, ret);
|
|
||||||
func_sent = func;
|
func_sent = func;
|
||||||
ret = pthread_mutex_unlock (&mutex);
|
xpthread_mutex_unlock (&mutex);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_mutex_unlock (%s): %d", __func__, ret);
|
|
||||||
|
|
||||||
ret = pthread_cond_signal (&cond_send);
|
xpthread_cond_signal (&cond_send);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_mutex_lock (%s): %d", __func__, ret);
|
|
||||||
|
|
||||||
ret = pthread_mutex_lock (&mutex);
|
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_mutex_lock (%s): %d", __func__, ret);
|
|
||||||
|
|
||||||
|
xpthread_mutex_lock (&mutex);
|
||||||
while (func_sent != NULL)
|
while (func_sent != NULL)
|
||||||
{
|
{
|
||||||
ret = pthread_cond_wait (&cond_recv, &mutex);
|
xpthread_cond_wait (&cond_recv, &mutex);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_mutex_wait (%s): %d", __func__, ret);
|
|
||||||
}
|
}
|
||||||
ret = pthread_mutex_unlock (&mutex);
|
xpthread_mutex_unlock (&mutex);
|
||||||
if (ret != 0)
|
|
||||||
FAIL ("pthread_mutex_unlock (%s): %d", __func__, ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -141,5 +120,4 @@ do_test (void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_FUNCTION do_test ()
|
#include <support/test-driver.c>
|
||||||
#include "../test-skeleton.c"
|
|
||||||
|
|
Loading…
Reference in New Issue