Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / Sigset_Ops_Test.cpp
blobe29272100e1026ae119fa66d1197fcfab1a86920
2 //=============================================================================
3 /**
4 * @file Sigset_Ops_Test.cpp
6 * This program tests the correctness of following functions.
7 * sigfillset(), sigemptyset(), sigaddset(), sigdelset(),
8 * sigismember().
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 void
22 siglistset (sigset_t x, int *sigset, int can_miss = 0)
24 bool empty = true;
25 int result = 0;
27 for (int i = 1; i < ACE_NSIG; i++)
29 result = ACE_OS::sigismember (&x, i);
31 if (result > 0)
33 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" %d\n"), i)) ;
34 empty = false;
36 else if (can_miss)
38 ACE_DEBUG ((LM_DEBUG,
39 ACE_TEXT ("Be careful... Signal %d is not valid\n"),
40 i));
41 result = 1;
43 ACE_TEST_ASSERT ((sigset [i] ? result > 0 : result <= 0)) ;
46 if (empty)
47 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Empty!!\n\n"))) ;
48 else
49 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n\n"))) ;
52 int
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"))) ;
59 #else
60 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%n uses platform's native sigset* () functions.\n\n"))) ;
61 #endif
63 sigset_t x ; // examined sigset
64 int sigset [ACE_NSIG] ; // a comparison sigset
65 int i ;
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.
70 const int tsig1 = 5 ;
71 const int tsig2 = 8 ;
73 // Testing sigfillset
74 ACE_OS::sigfillset (&x) ;
76 // fill the comparison set
77 for (i = 0 ; i < ACE_NSIG ; i++)
78 sigset [i] = 1 ;
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++)
93 sigset [i] = 0 ;
95 siglistset (x, sigset) ;
97 // add the first signal into set
98 ACE_OS::sigaddset (&x, tsig1) ;
99 sigset [tsig1] = 1 ;
100 siglistset (x, sigset) ;
102 // add the second signal into set
103 ACE_OS::sigaddset (&x, tsig2) ;
104 sigset [tsig2] = 1 ;
105 siglistset (x, sigset) ;
107 // then remove it
108 ACE_OS::sigdelset (&x, tsig1) ;
109 sigset [tsig1] = 0 ;
110 siglistset (x, sigset) ;
112 // remove the second one
113 ACE_OS::sigdelset (&x, tsig2) ;
114 sigset [tsig2] = 0 ;
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")));
121 status = 1;
123 else if (ACE_OS::last_error () != EINVAL)
125 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p.\n"), ACE_TEXT ("Expected status EINVAL; got")));
126 status = 1;
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) ;
138 ACE_END_TEST;
139 return status;