4 // ============================================================================
8 * This file factors out common macros and other utilities used by the
9 * ACE automated regression tests.
11 * @author Prashant Jain <pjain@cs.wustl.edu>
12 * @author Tim Harrison <harrison@cs.wustl.edu>
13 * @author David Levine <levine@cs.wustl.edu>
15 // ============================================================================
17 #ifndef ACE_TEST_CONFIG_H
18 #define ACE_TEST_CONFIG_H
20 #include "ace/config-all.h"
22 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 #if defined (ACE_NLOGGING)
27 // ACE_NLOGGING must not be set if the tests are to produce any output.
29 #endif /* ACE_NLOGGING */
31 // This first #undef protects against command-line definitions.
33 #include "ace/streams.h"
34 #include "ace/Singleton.h"
35 #include "ace/Synch.h"
36 #include "ace/Log_Msg.h"
39 // The second #undef protects against being reset in a config.h file.
42 #if defined (ACE_WIN32)
43 # define ACE_LOG_DIRECTORY ACE_TEXT ("log\\")
44 # define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\.\\pipe\\"#X)
46 # define ACE_LOG_DIRECTORY ACE_TEXT ("log/")
47 # define MAKE_PIPE_NAME(X) ACE_TEXT (X)
48 #endif /* ACE_WIN32 */
50 #define ACE_LOG_FILE_EXT_NAME ACE_TEXT (".log")
52 const size_t ACE_MAX_CLIENTS
= 30;
53 const size_t ACE_NS_MAX_ENTRIES
= 1000;
54 const size_t ACE_DEFAULT_USECS
= 1000;
55 const size_t ACE_MAX_TIMERS
= 4;
56 const size_t ACE_MAX_DELAY
= 10;
57 const size_t ACE_MAX_INTERVAL
= 0;
58 const size_t ACE_MAX_ITERATIONS
= 10;
59 const size_t ACE_MAX_PROCESSES
= 10;
60 const size_t ACE_MAX_THREADS
= 4;
62 #define ACE_START_TEST(NAME) \
63 const ACE_TCHAR *program = NAME; \
64 ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM | ACE_Log_Msg::VERBOSE_LITE); \
65 if (ace_file_stream::instance()->set_output (program) != 0) \
66 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_output failed")), -1); \
67 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\n"), program))
69 #define ACE_END_TEST \
70 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n"), program)); \
71 ace_file_stream::instance()->close ()
73 #define ACE_CLOSE_TEST_LOG ace_file_stream::instance()->close ()
75 #if !defined (ACE_WIN32)
76 #define ACE_APPEND_LOG(NAME) \
77 const ACE_TCHAR *program = NAME; \
78 ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM | ACE_Log_Msg::VERBOSE_LITE); \
79 ace_file_stream::instance()->close (); \
80 if (ace_file_stream::instance()->set_output (program, 1) != 0) \
81 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_output failed")), -1); \
82 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\n"), program));
84 #define ACE_APPEND_LOG(NAME) \
85 const ACE_TCHAR *program = NAME; \
86 ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM | ACE_Log_Msg::VERBOSE_LITE); \
87 if (ace_file_stream::instance()->set_output (program, 1) != 0) \
88 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_output failed")), -1); \
89 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\n"), program));
90 #endif /* ACE_WIN32 */
93 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n\n"), program)); \
94 ACE_LOG_MSG->set_flags(ACE_Log_Msg::SILENT); \
95 ace_file_stream::instance()->close ();
98 // This is the only way I could figure out to avoid an error
99 // about attempting to unlink a non-existent file.
100 #define ACE_INIT_LOG(NAME) \
101 ACE_TCHAR temp[MAXPATHLEN]; \
102 ACE_OS::sprintf (temp, ACE_TEXT ("%s%s%s"), \
104 ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \
105 ACE_LOG_FILE_EXT_NAME); \
106 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Deleting old log file %s (if any)\n\n"), temp)); \
108 if ((fd_init_log = ACE_OS::open (temp, \
110 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) != ERROR) \
112 ACE_OS::close (fd_init_log); \
113 ACE_OS::unlink (temp); \
117 # // Rename main to ace_main for compatibility with run_tests.vxworks.
119 # define ACE_MAIN ace_main
121 #else /* ! VXWORKS */
122 #define ACE_INIT_LOG(NAME) \
123 ACE_TCHAR temp[MAXPATHLEN]; \
124 ACE_OS::sprintf (temp, ACE_TEXT ("%s%s%s"), \
126 ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \
127 ACE_LOG_FILE_EXT_NAME); \
128 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Deleting old log file %s (if any)\n\n"), temp)); \
129 ACE_OS::unlink (temp);
130 #endif /* ! VXWORKS */
132 #if defined (ACE_LACKS_IOSTREAM_TOTALLY)
133 #define OFSTREAM FILE
135 #define OFSTREAM ofstream
136 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
138 class ACE_Test_Output
143 int set_output (const ACE_TCHAR
*filename
, int append
= 0);
144 OFSTREAM
*output_file ();
148 OFSTREAM
*output_file_
;
151 inline ACE_Test_Output::ACE_Test_Output ()
154 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
155 this->output_file_
= new OFSTREAM
;
156 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
159 inline ACE_Test_Output::~ACE_Test_Output ()
161 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
162 ACE_LOG_MSG
->msg_ostream (&cerr
);
163 #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */
165 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::OSTREAM
);
166 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::STDERR
);
168 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
169 delete this->output_file_
;
170 #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */
174 ACE_Test_Output::output_file ()
176 return this->output_file_
;
180 ACE_Test_Output::set_output (const ACE_TCHAR
*filename
, int append
)
182 ACE_TCHAR temp
[MAXPATHLEN
];
183 // Ignore the error value since the directory may already exist.
184 const ACE_TCHAR
*test_dir
{};
186 test_dir
= ACE_OS::getenv (ACE_TEXT ("ACE_TEST_DIR"));
189 test_dir
= ACE_TEXT ("");
191 ACE_OS::sprintf (temp
,
192 ACE_TEXT ("%s%s%s%s"),
195 ACE::basename (filename
, ACE_DIRECTORY_SEPARATOR_CHAR
),
196 ACE_LOG_FILE_EXT_NAME
);
198 #if defined (VXWORKS)
199 // This is the only way I could figure out to avoid a console
200 // warning about opening an existing file (w/o O_CREAT), or
201 // attempting to unlink a non-existent one.
202 ACE_HANDLE fd
= ACE_OS::open (temp
,
204 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
);
208 ACE_OS::unlink (temp
);
210 # else /* ! VXWORKS */
211 // This doesn't seem to work on VxWorks if the directory doesn't
212 // exist: it creates a plain file instead of a directory. If the
213 // directory does exist, it causes a weird console error message
214 // about "cat: input error on standard input: Is a directory". So,
215 // VxWorks users must create the directory manually.
216 ACE_OS::mkdir (ACE_LOG_DIRECTORY
);
217 # endif /* ! VXWORKS */
219 # if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
220 this->output_file_
->open (ACE_TEXT_ALWAYS_CHAR (temp
),
221 ios::out
| (append
? ios::app
: ios::trunc
));
222 if (this->output_file_
->bad ())
224 #else /* when ACE_LACKS_IOSTREAM_TOTALLY */
225 ACE_TCHAR
*fmode
= 0;
227 fmode
= ACE_TEXT ("a");
229 fmode
= ACE_TEXT ("w");
230 this->output_file_
= ACE_OS::fopen (temp
, fmode
);
231 # endif /* ACE_LACKS_IOSTREAM_TOTALLY */
233 ACE_LOG_MSG
->msg_ostream (this->output_file ());
234 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::STDERR
| ACE_Log_Msg::LOGGER
);
235 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::OSTREAM
);
241 ACE_Test_Output::close ()
243 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
244 this->output_file_
->flush ();
245 this->output_file_
->close ();
247 ACE_OS::fflush (this->output_file_
);
248 ACE_OS::fclose (this->output_file_
);
249 #endif /* !ACE_LACKS_IOSTREAM_TOTALLY */
250 ACE_LOG_MSG
->msg_ostream (0);
254 randomize (int array
[], size_t size
)
258 for (i
= 0; i
< size
; i
++)
259 array
[i
] = static_cast<int> (i
);
261 // See with a fixed number so that we can produce "repeatable"
265 // Generate an array of random numbers from 0 .. size - 1.
267 for (i
= 0; i
< size
; i
++)
269 size_t index
= ACE_OS::rand() % size
--;
270 int temp
= array
[index
];
271 array
[index
] = array
[size
];
276 typedef ACE_Singleton
<ACE_Test_Output
, ACE_Null_Mutex
> ace_file_stream
;
278 #if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION)
279 template ACE_Singleton
<ACE_Test_Output
, ACE_Null_Mutex
> *
280 ACE_Singleton
<ACE_Test_Output
, ACE_Null_Mutex
>::singleton_
;
281 #endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */
283 #endif /* ACE_TEST_CONFIG_H */