X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fmain.cc;h=80ffa769344d5ac89c5d72283c0c37cfa3a23b1b;hb=457e8cd000fa47f002c20af7a8227b7444ab1b42;hp=3ae8ff988ebe14e0662dd9cd49b99ee582dab703;hpb=1be0350e7ae7a566896a9fe52863dcc22433fc8a;p=awesomized%2Flibmemcached diff --git a/libtest/main.cc b/libtest/main.cc index 3ae8ff98..80ffa769 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -34,7 +34,7 @@ * */ -#include +#include "libtest/yatlcon.h" #include #include @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,7 @@ using namespace libtest; -static void stats_print(Framework *frame) +static void stats_print(libtest::Framework *frame) { if (frame->failed() == 0 and frame->success() == 0) { @@ -87,6 +88,34 @@ int main(int argc, char *argv[]) bool opt_quiet= false; std::string collection_to_run; std::string wildcard; + std::string binary_name; + + const char *just_filename= rindex(argv[0], '/'); + if (just_filename) + { + just_filename++; + } + else + { + just_filename= argv[0]; + } + + if (just_filename[0] == 'l' and just_filename[1] == 't' and just_filename[2] == '-') + { + just_filename+= 3; + } + binary_name.append(just_filename); + + /* + Valgrind does not currently work reliably, or sometimes at all, on OSX + - Fri Jun 15 11:24:07 EDT 2012 + */ +#if defined(TARGET_OS_OSX) && TARGET_OS_OSX + if (valgrind_is_caller()) + { + return EXIT_SKIP; + } +#endif // Options parsing { @@ -103,7 +132,7 @@ int main(int argc, char *argv[]) { { "version", no_argument, NULL, OPT_LIBYATL_VERSION }, { "quiet", no_argument, NULL, OPT_LIBYATL_QUIET }, - { "repeat", no_argument, NULL, OPT_LIBYATL_REPEAT }, + { "repeat", required_argument, NULL, OPT_LIBYATL_REPEAT }, { "collection", required_argument, NULL, OPT_LIBYATL_MATCH_COLLECTION }, { "wildcard", required_argument, NULL, OPT_LIBYATL_MATCH_WILDCARD }, { "massive", no_argument, NULL, OPT_LIBYATL_MASSIVE }, @@ -129,7 +158,14 @@ int main(int argc, char *argv[]) break; case OPT_LIBYATL_REPEAT: + errno= 0; opt_repeat= strtoul(optarg, (char **) NULL, 10); + if (errno != 0) + { + Error << "unknown value passed to --repeat: `" << optarg << "`"; + exit(EXIT_FAILURE); + } + break; case OPT_LIBYATL_MATCH_COLLECTION: @@ -157,9 +193,16 @@ int main(int argc, char *argv[]) srandom((unsigned int)time(NULL)); - if (bool(getenv("YATL_REPEAT")) and (strtoul(getenv("YATL_REPEAT"), (char **) NULL, 10) > 1)) + errno= 0; + if (bool(getenv("YATL_REPEAT"))) { + errno= 0; opt_repeat= strtoul(getenv("YATL_REPEAT"), (char **) NULL, 10); + if (errno != 0) + { + Error << "ENV YATL_REPEAT passed an invalid value: `" << getenv("YATL_REPEAT") << "`"; + exit(EXIT_FAILURE); + } } if ((bool(getenv("YATL_QUIET")) and (strcmp(getenv("YATL_QUIET"), "0") == 0)) or opt_quiet) @@ -176,27 +219,39 @@ int main(int argc, char *argv[]) } } + if ((bool(getenv("YATL_RUN_MASSIVE_TESTS"))) or opt_massive) + { + opt_massive= true; + } + if (opt_quiet) { close(STDOUT_FILENO); } - char buffer[1024]; + if (opt_massive) + { + is_massive(opt_massive); + } + + libtest::vchar_t tmp_directory; + tmp_directory.resize(1024); if (getenv("LIBTEST_TMP")) { - snprintf(buffer, sizeof(buffer), "%s", getenv("LIBTEST_TMP")); + snprintf(&tmp_directory[0], tmp_directory.size(), "%s", getenv("LIBTEST_TMP")); } else { - snprintf(buffer, sizeof(buffer), "%s", LIBTEST_TEMP); + snprintf(&tmp_directory[0], tmp_directory.size(), "%s", LIBTEST_TEMP); } - if (chdir(buffer) == -1) + if (chdir(&tmp_directory[0]) == -1) { - char getcwd_buffer[1024]; - char *dir= getcwd(getcwd_buffer, sizeof(getcwd_buffer)); + libtest::vchar_t getcwd_buffer; + getcwd_buffer.resize(1024); + char *dir= getcwd(&getcwd_buffer[0], getcwd_buffer.size()); - Error << "Unable to chdir() from " << dir << " to " << buffer << " errno:" << strerror(errno); + Error << "Unable to chdir() from " << dir << " to " << &tmp_directory[0] << " errno:" << strerror(errno); return EXIT_FAILURE; } @@ -240,9 +295,10 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - std::auto_ptr frame(new Framework(signal, collection_to_run, wildcard)); + std::auto_ptr frame(new libtest::Framework(signal, binary_name, collection_to_run, wildcard)); // Run create(), bail on error. + try { switch (frame->create()) { @@ -250,13 +306,17 @@ int main(int argc, char *argv[]) break; case TEST_SKIPPED: - Out << "SKIP " << argv[0]; - return EXIT_SUCCESS; + return EXIT_SKIP; case TEST_FAILURE: + std::cerr << "Could not call frame->create()" << std::endl; return EXIT_FAILURE; } } + catch (const libtest::__skipped& e) + { + return EXIT_SKIP; + } frame->exec(); @@ -282,27 +342,50 @@ int main(int argc, char *argv[]) } else if (frame->success() and (frame->failed() == 0)) { + Out; Out << "All tests completed successfully."; } stats_print(frame.get()); + std::ofstream xml_file; + std::string file_name; + file_name.append(&tmp_directory[0]); + file_name.append(frame->name()); + file_name.append(".xml"); + xml_file.open(file_name.c_str(), std::ios::trunc); + libtest::Formatter::xml(*frame, xml_file); + Outn(); // Generate a blank to break up the messages if make check/test has been run } while (exit_code == EXIT_SUCCESS and --opt_repeat); } - catch (libtest::fatal& e) + catch (const libtest::__skipped& e) { - std::cerr << e.what() << std::endl; + return EXIT_SKIP; + } + catch (const libtest::__failure& e) + { + libtest::stream::make_cout(e.file(), e.line(), e.func()) << e.what(); + exit_code= EXIT_FAILURE; + } + catch (const libtest::fatal& e) + { + std::cerr << "FATAL:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (libtest::disconnected& e) + catch (const libtest::disconnected& e) { std::cerr << "Unhandled disconnection occurred:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } - catch (std::exception& e) + catch (const std::exception& e) + { + std::cerr << "std::exception:" << e.what() << std::endl; + exit_code= EXIT_FAILURE; + } + catch (char const*) { - std::cerr << e.what() << std::endl; + std::cerr << "Exception:" << std::endl; exit_code= EXIT_FAILURE; } catch (...)