2 //=============================================================================
4 * @file Sigset_Ops_Test.cpp
6 * This program tests the correctness of following functions.
7 * sigfillset(), sigemptyset(), sigaddset(), sigdelset(),
10 * @author Nanbor Wang <nanbor@cs.wustl.edu>
12 //=============================================================================
15 #include "test_config.h"
16 #include "ace/OS_NS_signal.h"
17 #include "ace/OS_NS_errno.h"
21 siglistset (sigset_t x
, int *sigset
, int can_miss
= 0)
26 for (int i
= 1; i
< ACE_NSIG
; i
++)
28 result
= ACE_OS::sigismember (&x
, i
);
32 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT (" %d\n"), i
)) ;
38 ACE_TEXT ("Be careful... Signal %d is not valid\n"),
42 ACE_TEST_ASSERT ((sigset
[i
] ? result
> 0 : result
<= 0)) ;
46 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Empty!!\n\n"))) ;
48 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n\n"))) ;
52 run_main (int, ACE_TCHAR
*[])
54 ACE_START_TEST (ACE_TEXT ("Sigset_Ops_Test"));
56 #if defined (ACE_LACKS_SIGSET)
57 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%n uses ACE implementation of sigset* () functions.\n\n"))) ;
59 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%n uses platform's native sigset* () functions.\n\n"))) ;
62 sigset_t x
; // examined sigset
63 int sigset
[ACE_NSIG
] ; // a comparison sigset
65 int status
= 0; // 0 is success, else fail code
67 // Two test signal numbers. I choose these low value signals to
68 // avoid exceeding the ACE_NSIG range.
73 ACE_OS::sigfillset (&x
) ;
75 // fill the comparison set
76 for (i
= 0 ; i
< ACE_NSIG
; i
++)
79 // There's no guarantee that the valid signals are sequential without
80 // missed spots. For example, Red Hat Enterprise Linux 3 (any version
81 // with NPTL) does not include signal 32 in sigfillset() since it's
82 // reserved for kernel/nptl use. So, allow a miss in this check, but
83 // be prepared to check the log file for misses if signal capability seems
84 // odd if the test passes.
85 siglistset (x
, sigset
, 1) ;
87 // testing sigemptyset
88 ACE_OS::sigemptyset (&x
) ;
90 // empty the comparison set
91 for (i
= 0 ; i
< ACE_NSIG
; i
++)
94 siglistset (x
, sigset
) ;
96 // add the first signal into set
97 ACE_OS::sigaddset (&x
, tsig1
) ;
99 siglistset (x
, sigset
) ;
101 // add the second signal into set
102 ACE_OS::sigaddset (&x
, tsig2
) ;
104 siglistset (x
, sigset
) ;
107 ACE_OS::sigdelset (&x
, tsig1
) ;
109 siglistset (x
, sigset
) ;
111 // remove the second one
112 ACE_OS::sigdelset (&x
, tsig2
) ;
114 siglistset (x
, sigset
) ;
116 // Now testing out of bound signal
117 if (ACE_OS::sigismember (&x
, ACE_NSIG
) >= 0)
119 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Platform doesn't check for valid signal number.\n")));
122 else if (ACE_OS::last_error () != EINVAL
)
124 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("%p.\n"), ACE_TEXT ("Expected status EINVAL; got")));
128 /* Skip this test at this moment
129 // Test if platform can catch invalid sigset error Currently, I can
130 // only think of passing a NULL ptr If you know other situations
131 // that fall into this catagory, please let me know. Thanks.
132 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Now testing invalid sigset. If your platform gets a \nsegmentation fault, then it doesn't check the error properly.\n"))) ;
134 ACE_TEST_ASSERT (ACE_OS::sigfillset (0) < 0 && ACE_OS::last_error () == EFAULT) ;