1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Data Differential YATL (i.e. libtest) library
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <libtest/common.h>
50 #include <sys/types.h>
56 #ifndef __INTEL_COMPILER
57 #pragma GCC diagnostic ignored "-Wold-style-cast"
60 using namespace libtest
;
62 static void stats_print(libtest::Framework
*frame
)
64 if (frame
->failed() == 0 and frame
->success() == 0)
70 Out
<< "Collections\t\t\t\t\t" << frame
->total();
71 Out
<< "\tFailed\t\t\t\t\t" << frame
->failed();
72 Out
<< "\tSkipped\t\t\t\t\t" << frame
->skipped();
73 Out
<< "\tSucceeded\t\t\t\t" << frame
->success();
75 Out
<< "Tests\t\t\t\t\t" << frame
->sum_total();
76 Out
<< "\tFailed\t\t\t\t" << frame
->sum_failed();
77 Out
<< "\tSkipped\t\t\t\t" << frame
->sum_skipped();
78 Out
<< "\tSucceeded\t\t\t" << frame
->sum_success();
84 int main(int argc
, char *argv
[])
86 Out
<< "BEGIN:" << argv
[0];
87 bool opt_massive
= false;
88 unsigned long int opt_repeat
= 1; // Run all tests once
89 bool opt_quiet
= false;
90 std::string collection_to_run
;
92 std::string binary_name
;
94 const char *just_filename
= rindex(argv
[0], '/');
101 just_filename
= argv
[0];
104 if (just_filename
[0] == 'l' and just_filename
[1] == 't' and just_filename
[2] == '-')
108 binary_name
.append(just_filename
);
111 Valgrind does not currently work reliably, or sometimes at all, on OSX
112 - Fri Jun 15 11:24:07 EDT 2012
114 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
115 if (valgrind_is_caller())
125 OPT_LIBYATL_MATCH_COLLECTION
,
128 OPT_LIBYATL_MATCH_WILDCARD
,
132 static struct option long_options
[]=
134 { "version", no_argument
, NULL
, OPT_LIBYATL_VERSION
},
135 { "quiet", no_argument
, NULL
, OPT_LIBYATL_QUIET
},
136 { "repeat", no_argument
, NULL
, OPT_LIBYATL_REPEAT
},
137 { "collection", required_argument
, NULL
, OPT_LIBYATL_MATCH_COLLECTION
},
138 { "wildcard", required_argument
, NULL
, OPT_LIBYATL_MATCH_WILDCARD
},
139 { "massive", no_argument
, NULL
, OPT_LIBYATL_MASSIVE
},
146 int option_rv
= getopt_long(argc
, argv
, "", long_options
, &option_index
);
154 case OPT_LIBYATL_VERSION
:
157 case OPT_LIBYATL_QUIET
:
161 case OPT_LIBYATL_REPEAT
:
162 opt_repeat
= strtoul(optarg
, (char **) NULL
, 10);
165 case OPT_LIBYATL_MATCH_COLLECTION
:
166 collection_to_run
= optarg
;
169 case OPT_LIBYATL_MATCH_WILDCARD
:
173 case OPT_LIBYATL_MASSIVE
:
178 /* getopt_long already printed an error message. */
179 Error
<< "unknown option to getopt_long()";
188 srandom((unsigned int)time(NULL
));
190 if (bool(getenv("YATL_REPEAT")) and (strtoul(getenv("YATL_REPEAT"), (char **) NULL
, 10) > 1))
192 opt_repeat
= strtoul(getenv("YATL_REPEAT"), (char **) NULL
, 10);
195 if ((bool(getenv("YATL_QUIET")) and (strcmp(getenv("YATL_QUIET"), "0") == 0)) or opt_quiet
)
199 else if (getenv("JENKINS_URL"))
201 if (bool(getenv("YATL_QUIET")) and (strcmp(getenv("YATL_QUIET"), "1") == 0))
209 if ((bool(getenv("YATL_RUN_MASSIVE_TESTS"))) or opt_massive
)
216 close(STDOUT_FILENO
);
221 is_massive(opt_massive
);
224 char tmp_directory
[1024];
225 if (getenv("LIBTEST_TMP"))
227 snprintf(tmp_directory
, sizeof(tmp_directory
), "%s", getenv("LIBTEST_TMP"));
231 snprintf(tmp_directory
, sizeof(tmp_directory
), "%s", LIBTEST_TEMP
);
234 if (chdir(tmp_directory
) == -1)
236 char getcwd_buffer
[1024];
237 char *dir
= getcwd(getcwd_buffer
, sizeof(getcwd_buffer
));
239 Error
<< "Unable to chdir() from " << dir
<< " to " << tmp_directory
<< " errno:" << strerror(errno
);
243 if (libtest::libtool() == NULL
)
245 Error
<< "Failed to locate libtool";
249 if (getenv("YATL_COLLECTION_TO_RUN"))
251 if (strlen(getenv("YATL_COLLECTION_TO_RUN")))
253 collection_to_run
= getenv("YATL_COLLECTION_TO_RUN");
257 if (collection_to_run
.compare("none") == 0)
262 if (collection_to_run
.empty() == false)
264 Out
<< "Only testing " << collection_to_run
;
273 exit_code
= EXIT_SUCCESS
;
274 fatal_assert(sigignore(SIGPIPE
) == 0);
276 libtest::SignalThread signal
;
277 if (signal
.setup() == false)
279 Error
<< "Failed to setup signals";
283 std::auto_ptr
<libtest::Framework
> frame(new libtest::Framework(signal
, binary_name
, collection_to_run
, wildcard
));
285 // Run create(), bail on error.
287 switch (frame
->create())
296 std::cerr
<< __FILE__
<< ":" << __LINE__
<< ": " << "frame->create()" << std::endl
;
303 if (signal
.is_shutdown() == false)
305 signal
.set_shutdown(SHUTDOWN_GRACEFUL
);
308 shutdown_t status
= signal
.get_shutdown();
309 if (status
== SHUTDOWN_FORCED
)
311 Out
<< "Tests were aborted.";
312 exit_code
= EXIT_FAILURE
;
314 else if (frame
->failed())
316 Out
<< "Some test failed.";
317 exit_code
= EXIT_FAILURE
;
319 else if (frame
->skipped() and frame
->failed() and frame
->success())
321 Out
<< "Some tests were skipped.";
323 else if (frame
->success() and (frame
->failed() == 0))
326 Out
<< "All tests completed successfully.";
329 stats_print(frame
.get());
331 std::ofstream xml_file
;
332 std::string file_name
;
333 file_name
.append(tmp_directory
);
334 file_name
.append(frame
->name());
335 file_name
.append(".xml");
336 xml_file
.open(file_name
.c_str(), std::ios::trunc
);
337 libtest::Formatter::xml(*frame
, xml_file
);
339 Outn(); // Generate a blank to break up the messages if make check/test has been run
340 } while (exit_code
== EXIT_SUCCESS
and --opt_repeat
);
342 catch (libtest::fatal
& e
)
344 std::cerr
<< __FILE__
<< ":" << __LINE__
<< ": " << "FATAL:" << e
.what() << std::endl
;
345 exit_code
= EXIT_FAILURE
;
347 catch (libtest::disconnected
& e
)
349 std::cerr
<< __FILE__
<< ":" << __LINE__
<< ": " << "Unhandled disconnection occurred:" << e
.what() << std::endl
;
350 exit_code
= EXIT_FAILURE
;
352 catch (std::exception
& e
)
354 std::cerr
<< __FILE__
<< ":" << __LINE__
<< ": " << "std::exception:" << e
.what() << std::endl
;
355 exit_code
= EXIT_FAILURE
;
359 std::cerr
<< __FILE__
<< ":" << __LINE__
<< ": " << "Exception:" << std::endl
;
360 exit_code
= EXIT_FAILURE
;
364 std::cerr
<< __FILE__
<< ":" << __LINE__
<< ": " << "Unknown exception halted execution." << std::endl
;
365 exit_code
= EXIT_FAILURE
;
368 Out
<< "END:" << argv
[0];