ostest: remove printf & sem_wait in sigaction
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
d1e46c2d3e
commit
7f11c91054
@ -47,7 +47,6 @@ static sem_t sem1;
|
|||||||
static sem_t sem2;
|
static sem_t sem2;
|
||||||
static bool sigreceived = false;
|
static bool sigreceived = false;
|
||||||
static bool thread1exited = false;
|
static bool thread1exited = false;
|
||||||
static bool thread2exited = false;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
@ -86,15 +85,12 @@ static void wakeup_action(int signo, siginfo_t *info, void *ucontext)
|
|||||||
|
|
||||||
/* Use of printf in a signal handler is NOT safe! It can cause deadlocks! */
|
/* Use of printf in a signal handler is NOT safe! It can cause deadlocks! */
|
||||||
|
|
||||||
printf("wakeup_action: Received signal %d\n" , signo);
|
|
||||||
|
|
||||||
sigreceived = true;
|
sigreceived = true;
|
||||||
|
|
||||||
/* Check signo */
|
/* Check signo */
|
||||||
|
|
||||||
if (signo != WAKEUP_SIGNAL)
|
if (signo != WAKEUP_SIGNAL)
|
||||||
{
|
{
|
||||||
printf("wakeup_action: ERROR expected signo=%d\n" , WAKEUP_SIGNAL);
|
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,59 +98,27 @@ static void wakeup_action(int signo, siginfo_t *info, void *ucontext)
|
|||||||
|
|
||||||
if (info->si_value.sival_int != SIGVALUE_INT)
|
if (info->si_value.sival_int != SIGVALUE_INT)
|
||||||
{
|
{
|
||||||
printf("wakeup_action: ERROR sival_int=%d expected %d\n",
|
|
||||||
info->si_value.sival_int, SIGVALUE_INT);
|
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("wakeup_action: sival_int=%d\n" , info->si_value.sival_int);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info->si_signo != WAKEUP_SIGNAL)
|
if (info->si_signo != WAKEUP_SIGNAL)
|
||||||
{
|
{
|
||||||
printf("wakeup_action: ERROR expected si_signo=%d, got=%d\n",
|
|
||||||
WAKEUP_SIGNAL, info->si_signo);
|
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("wakeup_action: si_code=%d\n" , info->si_code);
|
|
||||||
|
|
||||||
/* Check ucontext_t */
|
|
||||||
|
|
||||||
printf("wakeup_action: ucontext=%p\n" , ucontext);
|
|
||||||
|
|
||||||
/* Check sigprocmask */
|
/* Check sigprocmask */
|
||||||
|
|
||||||
sigfillset(&allsigs);
|
sigfillset(&allsigs);
|
||||||
status = sigprocmask(SIG_SETMASK, NULL, &oldset);
|
status = sigprocmask(SIG_SETMASK, NULL, &oldset);
|
||||||
if (status != OK)
|
if (status != OK)
|
||||||
{
|
{
|
||||||
printf("wakeup_action: ERROR sigprocmask failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldset != allsigs)
|
if (oldset != allsigs)
|
||||||
{
|
{
|
||||||
printf("wakeup_action: ERROR sigprocmask=%jx expected=%jx\n",
|
|
||||||
(uintmax_t)oldset, (uintmax_t)allsigs);
|
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Checkout sem_wait */
|
|
||||||
|
|
||||||
status = sem_wait(&sem2);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
int error = errno;
|
|
||||||
printf("wakeup_action: ERROR sem_wait failed, errno=%d\n" , error);
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("wakeup_action: sem_wait() successfully!\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int waiter_main(int argc, char *argv[])
|
static int waiter_main(int argc, char *argv[])
|
||||||
@ -235,27 +199,6 @@ static int waiter_main(int argc, char *argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int poster_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
|
|
||||||
printf("poster_main: Poster started\n");
|
|
||||||
|
|
||||||
status = sem_post(&sem2);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
int error = errno;
|
|
||||||
printf("poster_main: sem_post failed error=%d\n", error);
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("poster_main: done\n");
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
thread2exited = true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -269,7 +212,7 @@ void sighand_test(void)
|
|||||||
#endif
|
#endif
|
||||||
struct sched_param param;
|
struct sched_param param;
|
||||||
union sigval sigvalue;
|
union sigval sigvalue;
|
||||||
pid_t waiterpid, posterpid;
|
pid_t waiterpid;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
printf("sighand_test: Initializing semaphore to 0\n");
|
printf("sighand_test: Initializing semaphore to 0\n");
|
||||||
@ -346,20 +289,6 @@ void sighand_test(void)
|
|||||||
task_delete(waiterpid);
|
task_delete(waiterpid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start poster thread */
|
|
||||||
|
|
||||||
posterpid = task_create("poster", param.sched_priority,
|
|
||||||
STACKSIZE, poster_main, NULL);
|
|
||||||
if (posterpid == ERROR)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR failed to start poster_main\n");
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("sighand_test: Started poster_main pid=%d\n", posterpid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a bit */
|
/* Wait a bit */
|
||||||
|
|
||||||
FFLUSH();
|
FFLUSH();
|
||||||
@ -377,12 +306,6 @@ void sighand_test(void)
|
|||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!thread2exited)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR poster task did not exit\n");
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sigreceived)
|
if (!sigreceived)
|
||||||
{
|
{
|
||||||
printf("sighand_test: ERROR signal handler did not run\n");
|
printf("sighand_test: ERROR signal handler did not run\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user