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"
22 siglistset (sigset_t x
, int *sigset
, int can_miss
= 0)
27 for (int i
= 1; i
< ACE_NSIG
; i
++)
29 result
= ACE_OS::sigismember (&x
, i
);
33 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT (" %d\n"), i
)) ;
39 ACE_TEXT ("Be careful... Signal %d is not valid\n"),
43 ACE_TEST_ASSERT ((sigset
[i
] ? result
> 0 : result
<= 0)) ;
47 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Empty!!\n\n"))) ;
49 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n\n"))) ;
53 run_main (int, ACE_TCHAR
*[])
55 ACE_START_TEST (ACE_TEXT ("Sigset_Ops_Test"));
57 #if defined (ACE_LACKS_SIGSET)
58 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%n uses ACE implementation of sigset* () functions.\n\n"))) ;
60 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%n uses platform's native sigset* () functions.\n\n"))) ;
63 sigset_t x
; // examined sigset
64 int sigset
[ACE_NSIG
] ; // a comparison sigset
66 int status
= 0; // 0 is success, else fail code
68 // Two test signal numbers. I choose these low value signals to
69 // avoid exceeding the ACE_NSIG range.
74 ACE_OS::sigfillset (&x
) ;
76 // fill the comparison set
77 for (i
= 0 ; i
< ACE_NSIG
; i
++)
80 // There's no guarantee that the valid signals are sequential without
81 // missed spots. For example, Red Hat Enterprise Linux 3 (any version
82 // with NPTL) does not include signal 32 in sigfillset() since it's
83 // reserved for kernel/nptl use. So, allow a miss in this check, but
84 // be prepared to check the log file for misses if signal capability seems
85 // odd if the test passes.
86 siglistset (x
, sigset
, 1) ;
88 // testing sigemptyset
89 ACE_OS::sigemptyset (&x
) ;
91 // empty the comparison set
92 for (i
= 0 ; i
< ACE_NSIG
; i
++)
95 siglistset (x
, sigset
) ;
97 // add the first signal into set
98 ACE_OS::sigaddset (&x
, tsig1
) ;
100 siglistset (x
, sigset
) ;
102 // add the second signal into set
103 ACE_OS::sigaddset (&x
, tsig2
) ;
105 siglistset (x
, sigset
) ;
108 ACE_OS::sigdelset (&x
, tsig1
) ;
110 siglistset (x
, sigset
) ;
112 // remove the second one
113 ACE_OS::sigdelset (&x
, tsig2
) ;
115 siglistset (x
, sigset
) ;
117 // Now testing out of bound signal
118 if (ACE_OS::sigismember (&x
, ACE_NSIG
) >= 0)
120 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Platform doesn't check for valid signal number.\n")));
123 else if (ACE_OS::last_error () != EINVAL
)
125 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("%p.\n"), ACE_TEXT ("Expected status EINVAL; got")));
129 /* Skip this test at this moment
130 // Test if platform can catch invalid sigset error Currently, I can
131 // only think of passing a NULL ptr If you know other situations
132 // that fall into this catagory, please let me know. Thanks.
133 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"))) ;
135 ACE_TEST_ASSERT (ACE_OS::sigfillset (0) < 0 && ACE_OS::last_error () == EFAULT) ;