diff --git a/src/assert.cpp b/src/assert.cpp index 800cfd738..0157e0a81 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -266,7 +266,7 @@ TORRENT_NO_RETURN TORRENT_EXPORT void assert_fail(char const* expr, int line message = "A precondition of a libtorrent function has been violated.\n" "This indicates a bug in the client application using libtorrent\n"; } - + assert_print("%s\n" #ifdef TORRENT_PRODUCTION_ASSERTS "#: %d\n" @@ -288,10 +288,10 @@ TORRENT_NO_RETURN TORRENT_EXPORT void assert_fail(char const* expr, int line // if production asserts are defined, don't abort, just print the error #ifndef TORRENT_PRODUCTION_ASSERTS - // send SIGINT to the current process - // to break into the debugger - raise(SIGINT); - abort(); + // send SIGINT to the current process + // to break into the debugger + raise(SIGINT); + abort(); #endif } diff --git a/test/main.cpp b/test/main.cpp index cbb165d32..6e22815fb 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -58,6 +58,34 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; +// these are global so we can restore them on abnormal exits and print stuff +// out, such as the log +int old_stdout = -1; +int old_stderr = -1; + +// the current tests file descriptor +unit_test_t* current_test = NULL; + +void output_test_log_to_terminal() +{ + if (current_test == NULL || old_stdout == -1 || old_stderr == -1) + return; + + fflush(stdout); + fflush(stderr); + dup2(old_stdout, fileno(stdout)); + dup2(old_stderr, fileno(stderr)); + + fseek(current_test->output, 0, SEEK_SET); + fprintf(stderr, "\x1b[1m[%s]\x1b[0m\n\n", current_test->name); + char buf[4096]; + int size = 0; + do { + size = fread(buf, 1, sizeof(buf), current_test->output); + if (size > 0) fwrite(buf, 1, size, stderr); + } while (size > 0); +} + void sig_handler(int sig) { char stack_text[10000]; @@ -90,6 +118,9 @@ void sig_handler(int sig) #undef SIG }; fprintf(stderr, "signal: %s caught:\n%s\n", sig_name, stack_text); + + output_test_log_to_terminal(); + exit(138); } @@ -159,6 +190,7 @@ int main(int argc, char const* argv[]) signal(SIGBUS, &sig_handler); #endif signal(SIGILL, &sig_handler); + signal(SIGINT, &sig_handler); signal(SIGABRT, &sig_handler); signal(SIGFPE, &sig_handler); #ifdef SIGSYS @@ -190,8 +222,8 @@ int main(int argc, char const* argv[]) return 1; } - int old_stdout = dup(fileno(stdout)); - int old_stderr = dup(fileno(stderr)); + old_stdout = dup(fileno(stdout)); + old_stderr = dup(fileno(stderr)); int num_run = 0; for (int i = 0; i < _g_num_unit_tests; ++i) @@ -215,6 +247,8 @@ int main(int argc, char const* argv[]) continue; } + current_test = &t; + #ifndef BOOST_NO_EXCEPTIONS try { @@ -240,19 +274,7 @@ int main(int argc, char const* argv[]) if (_g_test_failures > 0) { - fflush(stdout); - fflush(stderr); - dup2(old_stdout, fileno(stdout)); - dup2(old_stderr, fileno(stderr)); - - fseek(t.output, 0, SEEK_SET); - fprintf(stderr, "\x1b[1m[%s]\x1b[0m\n\n", t.name); - char buf[4096]; - int size = 0; - do { - size = fread(buf, 1, sizeof(buf), t.output); - if (size > 0) fwrite(buf, 1, size, stderr); - } while (size > 0); + output_test_log_to_terminal(); } t.num_failures = _g_test_failures; diff --git a/test/test.cpp b/test/test.cpp index 61b4439e9..c9c92e01b 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -66,12 +66,12 @@ int print_failures() if (_g_unit_tests[i].num_failures == 0) { - fprintf(stderr, "\x1b[32m[%*s] ***PASS***\n" + fprintf(stderr, "\x1b[32m[%-*s] ***PASS***\n" , longest_name, _g_unit_tests[i].name); } else { - fprintf(stderr, "\x1b[31m[%*s] %d FAILURES\n" + fprintf(stderr, "\x1b[31m[%-*s] %d FAILURES\n" , longest_name , _g_unit_tests[i].name , _g_unit_tests[i].num_failures); diff --git a/test/test.hpp b/test/test.hpp index 22a4378a1..77e48cd79 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -71,7 +71,7 @@ extern int EXPORT _g_num_unit_tests; extern int EXPORT _g_test_failures; #define TORRENT_TEST(test_name) \ - void BOOST_PP_CAT(unit_test_, test_name)(); \ + static void BOOST_PP_CAT(unit_test_, test_name)(); \ static struct BOOST_PP_CAT(register_class, __LINE__) { \ BOOST_PP_CAT(register_class, __LINE__) () { \ unit_test_t& t = _g_unit_tests[_g_num_unit_tests]; \ diff --git a/test/test_web_seed.cpp b/test/test_web_seed.cpp index 362584013..e3ba37de6 100644 --- a/test/test_web_seed.cpp +++ b/test/test_web_seed.cpp @@ -38,11 +38,15 @@ using namespace libtorrent; const int proxy = libtorrent::settings_pack::none; +#ifdef TORRENT_USE_OPENSSL +TORRENT_TEST(web_seed_ssl) +{ + run_http_suite(proxy, "https", false); +} +#endif + TORRENT_TEST(web_seed) { -#ifdef TORRENT_USE_OPENSSL - run_http_suite(proxy, "https", false); -#endif run_http_suite(proxy, "http", false); } diff --git a/test/test_web_seed_http.cpp b/test/test_web_seed_http.cpp index f33c829c3..802bd7586 100644 --- a/test/test_web_seed_http.cpp +++ b/test/test_web_seed_http.cpp @@ -40,12 +40,23 @@ const int proxy = libtorrent::settings_pack::http; TORRENT_TEST(web_seed_http) { - for (int url_seed = 0; url_seed < 2; ++url_seed) - { -#ifdef TORRENT_USE_OPENSSL - run_http_suite(proxy, "https", url_seed); -#endif - run_http_suite(proxy, "http", url_seed); - } + run_http_suite(proxy, "http", false); } +TORRENT_TEST(url_seed_http) +{ + run_http_suite(proxy, "http", true); +} + +#ifdef TORRENT_USE_OPENSSL +TORRENT_TEST(web_seed_https) +{ + run_http_suite(proxy, "https", false); +} + +TORRENT_TEST(url_seed_https) +{ + run_http_suite(proxy, "https", true); +} +#endif + diff --git a/test/test_web_seed_http_pw.cpp b/test/test_web_seed_http_pw.cpp index 9805e9733..067f5e34c 100644 --- a/test/test_web_seed_http_pw.cpp +++ b/test/test_web_seed_http_pw.cpp @@ -40,12 +40,23 @@ const int proxy = libtorrent::settings_pack::http_pw; TORRENT_TEST(web_seed_http_pw) { - for (int url_seed = 0; url_seed < 2; ++url_seed) - { -#ifdef TORRENT_USE_OPENSSL - run_http_suite(proxy, "https", url_seed); -#endif - run_http_suite(proxy, "http", url_seed); - } + run_http_suite(proxy, "http", false); } +TORRENT_TEST(url_seed_http_pw) +{ + run_http_suite(proxy, "http", true); +} + +#ifdef TORRENT_USE_OPENSSL +TORRENT_TEST(web_seed_http_pw_ssl) +{ + run_http_suite(proxy, "https", false); +} + +TORRENT_TEST(url_seed_http_pw_ssl) +{ + run_http_suite(proxy, "https", true); +} +#endif +