Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Sigset_Ops_Test.cpp
blob9402ab7f0cc13623604ff7a28774a1ff786e3290
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"
20 void
21 siglistset (sigset_t x, int *sigset, int can_miss = 0)
23 bool empty = true;
24 int result = 0;
26 for (int i = 1; i < ACE_NSIG; i++)
28 result = ACE_OS::sigismember (&x, i);
30 if (result > 0)
32 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" %d\n"), i)) ;
33 empty = false;
35 else if (can_miss)
37 ACE_DEBUG ((LM_DEBUG,
38 ACE_TEXT ("Be careful... Signal %d is not valid\n"),
39 i));
40 result = 1;
42 ACE_TEST_ASSERT ((sigset [i] ? result > 0 : result <= 0)) ;
45 if (empty)
46 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Empty!!\n\n"))) ;
47 else
48 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n\n"))) ;
51 int
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"))) ;
58 #else
59 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%n uses platform's native sigset* () functions.\n\n"))) ;
60 #endif
62 sigset_t x ; // examined sigset
63 int sigset [ACE_NSIG] ; // a comparison sigset
64 int i ;
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.
69 const int tsig1 = 5 ;
70 const int tsig2 = 8 ;
72 // Testing sigfillset
73 ACE_OS::sigfillset (&x) ;
75 // fill the comparison set
76 for (i = 0 ; i < ACE_NSIG ; i++)
77 sigset [i] = 1 ;
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++)
92 sigset [i] = 0 ;
94 siglistset (x, sigset) ;
96 // add the first signal into set
97 ACE_OS::sigaddset (&x, tsig1) ;
98 sigset [tsig1] = 1 ;
99 siglistset (x, sigset) ;
101 // add the second signal into set
102 ACE_OS::sigaddset (&x, tsig2) ;
103 sigset [tsig2] = 1 ;
104 siglistset (x, sigset) ;
106 // then remove it
107 ACE_OS::sigdelset (&x, tsig1) ;
108 sigset [tsig1] = 0 ;
109 siglistset (x, sigset) ;
111 // remove the second one
112 ACE_OS::sigdelset (&x, tsig2) ;
113 sigset [tsig2] = 0 ;
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")));
120 status = 1;
122 else if (ACE_OS::last_error () != EINVAL)
124 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p.\n"), ACE_TEXT ("Expected status EINVAL; got")));
125 status = 1;
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) ;
137 ACE_END_TEST;
138 return status;