3 //=============================================================================
7 * @author Prashant Jain <pjain@cs.wustl.edu>
8 * @author Tim Harrison <harrison@cs.wustl.edu>
9 * @author and David Levine <levine@cs.wustl.edu>
11 //=============================================================================
14 #ifndef ACE_TEST_CONFIG_H
15 #define ACE_TEST_CONFIG_H
18 #include "ace/Log_Msg.h"
19 #include "ace/OS_main.h"
20 #include "ace/OS_NS_stdio.h"
21 #include "ace/OS_NS_time.h"
22 #include "ace/OS_NS_sys_stat.h"
23 #include "ace/OS_NS_stdlib.h"
25 // FUZZ: disable check_for_streams_include
26 #include "ace/streams.h"
28 #if defined (ACE_WIN32)
30 #define ACE_DEFAULT_TEST_FILE ACE_TEXT ("C:\\temp\\ace_test_file")
31 #define ACE_TEMP_FILE_NAME ACE_TEXT ("C:\\temp\\ace_temp_file")
32 #define ACE_LOG_DIRECTORY ACE_TEXT ("C:\\temp\\log\\")
33 #define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\.\\pipe\\"#X)
37 #define ACE_DEFAULT_TEST_FILE ACE_TEXT ("/tmp/ace_test_file")
38 #define ACE_TEMP_FILE_NAME ACE_TEXT ("/tmp/ace_temp_file")
39 #define ACE_LOG_DIRECTORY ACE_TEXT ("log/")
40 #define MAKE_PIPE_NAME(X) ACE_TEXT (X)
42 #endif /* ACE_WIN32 */
44 #ifndef ACE_START_TEST
45 #define ACE_START_TEST(NAME) \
46 const ACE_TCHAR *program = NAME; \
47 ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM); \
48 if (ace_file_stream.set_output (program) != 0) \
49 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_output failed")), -1); \
50 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) starting %s test at %D\n"), program));
51 #endif /* ACE_START_TEST */
54 #define ACE_END_TEST \
55 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n"), program)); \
56 ace_file_stream.close ();
57 #endif /* ACE_END_TEST */
59 #define ACE_NEW_THREAD \
61 ACE_LOG_MSG->msg_ostream (ace_file_stream.output_file ()); \
62 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR | ACE_Log_Msg::LOGGER); \
63 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); \
66 #define ACE_APPEND_LOG(NAME) \
67 const ACE_TCHAR *program = NAME; \
68 ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM); \
69 if (ace_file_stream.set_output (program, 1) != 0) \
70 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("set_output failed")), -1); \
71 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\n"), program));
74 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\n\n"), program)); \
75 ace_file_stream.close ();
77 #define ACE_INIT_LOG(NAME) \
79 ACE_OS::sprintf (temp, "%s%s%s", \
80 ACE_TEXT_ALWAYS_CHAR (ACE_LOG_DIRECTORY), \
81 ACE_TEXT_ALWAYS_CHAR (ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR)), \
83 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Deleting old log file %C (if any)\n\n"), temp)); \
84 ACE_OS::unlink (temp);
87 const int ACE_NS_MAX_ENTRIES
= 1000;
88 const int ACE_MAX_TIMERS
= 4;
89 const int ACE_MAX_THREADS
= 4;
90 const int ACE_MAX_DELAY
= 10;
91 const int ACE_MAX_INTERVAL
= 0;
92 const int ACE_MAX_ITERATIONS
= 10;
93 const int ACE_MAX_PROCESSES
= 10;
95 char ACE_ALPHABET
[] = "abcdefghijklmnopqrstuvwxyz";
102 int set_output (const ACE_TCHAR
*filename
, int append
= 0);
103 ofstream
*output_file ();
107 ofstream output_file_
;
110 static ACE_Test_Output ace_file_stream
;
112 ACE_Test_Output::ACE_Test_Output ()
116 ACE_Test_Output::~ACE_Test_Output ()
121 ACE_Test_Output::set_output (const ACE_TCHAR
*filename
, int append
)
124 // Ignore the error value since the directory may already exist.
125 ACE_OS::mkdir (ACE_LOG_DIRECTORY
);
126 ACE_OS::sprintf (temp
, "%s%s%s",
127 ACE_TEXT_ALWAYS_CHAR (ACE_LOG_DIRECTORY
),
128 ACE_TEXT_ALWAYS_CHAR (ACE::basename (filename
, ACE_DIRECTORY_SEPARATOR_CHAR
)),
131 this->output_file_
.open (temp
, ios::out
| (append
? ios::app
: ios::trunc
));
132 if (this->output_file_
.bad ())
135 ACE_LOG_MSG
->msg_ostream (ace_file_stream
.output_file ());
136 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::STDERR
| ACE_Log_Msg::LOGGER
);
137 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::OSTREAM
);
143 ACE_Test_Output::output_file ()
145 return &this->output_file_
;
149 ACE_Test_Output::close ()
151 this->output_file_
.flush ();
152 this->output_file_
.close ();
156 randomize (int array
[], size_t size
)
160 for (i
= 0; i
< size
; i
++)
161 array
[i
] = static_cast<int> (i
);
163 ACE_OS::srand ((u_int
) ACE_OS::time (0L));
165 // Generate an array of random numbers from 0 .. size - 1.
167 for (i
= 0; i
< size
; i
++)
169 int index
= ACE_OS::rand() % static_cast<int> (size
);
171 int temp
= array
[index
];
172 array
[index
] = array
[size
];
177 #endif /* ACE_TEST_CONFIG_H */