* Included Files
****************************************************************************/
#include <tinyara/config.h>
+#include <errno.h>
#include <stdio.h>
#include <signal.h>
+#include <time.h>
#include "tc_internal.h"
#define SIG1 SIGUSR1
TC_SUCCESS_RESULT();
}
+/**
+* @fn :tc_libc_signal_sigignore
+* @brief :tc_libc_signal_sigignore test sigignore function
+* @scenario :If sig > MAX_SIGNO, it returns ERROR.
+* Else if sig is the member of sigset, it will set the disposition of sig to SIG_IGN & return 0
+* API's covered :sigignore()
+* Preconditions :none
+* Preconditions :none
+* @return :void
+*/
+
+static void tc_libc_signal_sigignore(void)
+{
+ int ret_chk;
+
+ ret_chk = sigignore(MAX_SIGNO + 1);
+ TC_ASSERT_EQ("sigignore", ret_chk, ERROR);
+
+ ret_chk = sigignore(SIG1);
+ TC_ASSERT_EQ("sigignore", ret_chk, OK);
+
+ ret_chk = sigignore(SIG2);
+ TC_ASSERT_EQ("sigignore", ret_chk, OK);
+
+ TC_SUCCESS_RESULT();
+}
+
+/**
+* @fn :tc_libc_signal_sigpause
+* @brief :tc_libc_signal_sigpause test sigpause function
+* @scenario :If sig > MAX_SIGNO, it returns ERROR.
+* Else if a sigset member, it will remove sig from the calling process' signal mask & suspend the calling process until a signal is received
+* It will restore the process' signal mask to its original state before returning
+* API's covered :sigpause()
+* Preconditions :none
+* Preconditions :none
+* @return :void
+*/
+
+static void tc_libc_signal_sigpause(void)
+{
+ int ret_chk;
+ timer_t timer_id;
+ clockid_t clockid = 0; /*CLOCK_REALTIME*/
+ struct sigevent st_sigevent;
+ struct itimerspec st_timer_spec_val;
+
+ ret_chk = sigpause(MAX_SIGNO + 1);
+ TC_ASSERT_EQ("sigpause", ret_chk, ERROR);
+
+ /* Set and enable alarm */
+ st_sigevent.sigev_notify = 1; /*SIGEV_SIGNAL*/
+ st_sigevent.sigev_signo = SIGRTMIN;
+ st_sigevent.sigev_value.sival_ptr = &timer_id;
+
+ ret_chk = timer_create(clockid, &st_sigevent, &timer_id);
+ TC_ASSERT_NEQ("timer_create", ret_chk, ERROR);
+
+ st_timer_spec_val.it_value.tv_sec = 2;
+
+ ret_chk = timer_settime(timer_id, 0, &st_timer_spec_val, NULL);
+ TC_ASSERT_NEQ_CLEANUP("timer_settime", ret_chk, ERROR, errno, timer_delete(timer_id));
+
+ printf("sigpause test : Before Pause\n");
+ ret_chk = sigpause(SIG1);
+ TC_ASSERT_EQ("sigpause", ret_chk, ERROR);
+
+ printf("sigpause test : 2 sec After Pause\n");
+
+ TC_SUCCESS_RESULT();
+}
+
+/**
+* @fn :tc_libc_signal_sigset
+* @brief :tc_libc_signal_sigset test sigset function
+* @scenario :If sig is the member of sigset, it will modify signal dispositions
+* It will return SIG_HOLD if signal had been blocked & the signal's previous disposition if it had not been blocked else SIG_ERR will be returned
+* API's covered :sigset()
+* Preconditions :none
+* Preconditions :none
+* @return :void
+*/
+
+static void tc_libc_signal_sigset(void)
+{
+ int ret_chk;
+
+ ret_chk = (int)sigset(MAX_SIGNO + 1, SIG_DFL);
+ TC_ASSERT_EQ("sigset", ret_chk, ERROR);
+
+ ret_chk = (int)sigset(SIG1, SIG_DFL);
+ TC_ASSERT_EQ("sigset", ret_chk, OK);
+
+ ret_chk = (int)sigset(SIG2, SIG_IGN);
+ TC_ASSERT_EQ("sigset", ret_chk, OK);
+
+ TC_SUCCESS_RESULT();
+}
+
+/**
+* @fn :tc_libc_signal_signal
+* @brief :tc_libc_signal_signal test signal function
+* @scenario :If sig is the member of sigset, it will modify signal dispositions
+* It will return the previous disposition of the signal handling else SIG_ERR will be returned
+* API's covered :signal()
+* Preconditions :none
+* Preconditions :none
+* @return :void
+*/
+
+static void tc_libc_signal_signal(void)
+{
+ int ret_chk;
+
+ ret_chk = (int)signal(MAX_SIGNO + 1, SIG_DFL);
+ TC_ASSERT_EQ("signal", ret_chk, ERROR);
+
+ ret_chk = (int)signal(SIG1, SIG_DFL);
+ TC_ASSERT_EQ("signal", ret_chk, OK);
+
+ ret_chk = (int)signal(SIG2, SIG_IGN);
+ TC_ASSERT_EQ("signal", ret_chk, OK);
+
+ TC_SUCCESS_RESULT();
+}
+
+/**
+* @fn :tc_libc_signal_raise
+* @brief :tc_libc_signal_raise test sigraise function
+* @scenario :If sig > MAX_SIGNO, it returns ERROR.
+* Else if sig is the member of sigset, it will send the signal sig to the executing thread or process
+* API's covered :raise()
+* Preconditions :none
+* Preconditions :none
+* @return :void
+*/
+
+static void tc_libc_signal_raise(void)
+{
+ int ret_chk;
+
+ ret_chk = raise(MAX_SIGNO + 1);
+ TC_ASSERT_EQ("raise", ret_chk, ERROR);
+
+ ret_chk = raise(SIG1);
+ TC_ASSERT_EQ("raise", ret_chk, OK);
+
+ ret_chk = raise(SIG2);
+ TC_ASSERT_EQ("raise", ret_chk, OK);
+
+ TC_SUCCESS_RESULT();
+}
+
/****************************************************************************
* Name: libc_signal
****************************************************************************/
tc_libc_signal_sigaddset();
tc_libc_signal_sigdelset();
tc_libc_signal_sigismember();
+ tc_libc_signal_sigignore();
+ tc_libc_signal_raise();
+ tc_libc_signal_sigset();
+ tc_libc_signal_signal();
+ tc_libc_signal_sigpause();
return 0;
}