[Libtorrent-commits] SF.net SVN: libtorrent:[11135] trunk
Brought to you by:
arvidn
From: <ar...@us...> - 2015-05-31 16:14:49
|
Revision: 11135 http://sourceforge.net/p/libtorrent/code/11135 Author: arvidn Date: 2015-05-31 16:14:46 +0000 (Sun, 31 May 2015) Log Message: ----------- some test fixes Modified Paths: -------------- trunk/src/assert.cpp trunk/test/main.cpp trunk/test/test.cpp trunk/test/test.hpp trunk/test/test_web_seed.cpp trunk/test/test_web_seed_http.cpp trunk/test/test_web_seed_http_pw.cpp Modified: trunk/src/assert.cpp =================================================================== --- trunk/src/assert.cpp 2015-05-31 12:21:16 UTC (rev 11134) +++ trunk/src/assert.cpp 2015-05-31 16:14:46 UTC (rev 11135) @@ -266,7 +266,7 @@ 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 @@ // 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 } Modified: trunk/test/main.cpp =================================================================== --- trunk/test/main.cpp 2015-05-31 12:21:16 UTC (rev 11134) +++ trunk/test/main.cpp 2015-05-31 16:14:46 UTC (rev 11135) @@ -58,6 +58,34 @@ 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 @@ #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 @@ 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 @@ 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 @@ continue; } + current_test = &t; + #ifndef BOOST_NO_EXCEPTIONS try { @@ -240,19 +274,7 @@ 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; Modified: trunk/test/test.cpp =================================================================== --- trunk/test/test.cpp 2015-05-31 12:21:16 UTC (rev 11134) +++ trunk/test/test.cpp 2015-05-31 16:14:46 UTC (rev 11135) @@ -66,12 +66,12 @@ 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); Modified: trunk/test/test.hpp =================================================================== --- trunk/test/test.hpp 2015-05-31 12:21:16 UTC (rev 11134) +++ trunk/test/test.hpp 2015-05-31 16:14:46 UTC (rev 11135) @@ -71,7 +71,7 @@ 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]; \ Modified: trunk/test/test_web_seed.cpp =================================================================== --- trunk/test/test_web_seed.cpp 2015-05-31 12:21:16 UTC (rev 11134) +++ trunk/test/test_web_seed.cpp 2015-05-31 16:14:46 UTC (rev 11135) @@ -38,11 +38,15 @@ const int proxy = libtorrent::settings_pack::none; -TORRENT_TEST(web_seed) +#ifdef TORRENT_USE_OPENSSL +TORRENT_TEST(web_seed_ssl) { -#ifdef TORRENT_USE_OPENSSL run_http_suite(proxy, "https", false); +} #endif + +TORRENT_TEST(web_seed) +{ run_http_suite(proxy, "http", false); } Modified: trunk/test/test_web_seed_http.cpp =================================================================== --- trunk/test/test_web_seed_http.cpp 2015-05-31 12:21:16 UTC (rev 11134) +++ trunk/test/test_web_seed_http.cpp 2015-05-31 16:14:46 UTC (rev 11135) @@ -40,12 +40,23 @@ TORRENT_TEST(web_seed_http) { - for (int url_seed = 0; url_seed < 2; ++url_seed) - { + run_http_suite(proxy, "http", false); +} + +TORRENT_TEST(url_seed_http) +{ + run_http_suite(proxy, "http", true); +} + #ifdef TORRENT_USE_OPENSSL - run_http_suite(proxy, "https", url_seed); -#endif - run_http_suite(proxy, "http", url_seed); - } +TORRENT_TEST(web_seed_https) +{ + run_http_suite(proxy, "https", false); } +TORRENT_TEST(url_seed_https) +{ + run_http_suite(proxy, "https", true); +} +#endif + Modified: trunk/test/test_web_seed_http_pw.cpp =================================================================== --- trunk/test/test_web_seed_http_pw.cpp 2015-05-31 12:21:16 UTC (rev 11134) +++ trunk/test/test_web_seed_http_pw.cpp 2015-05-31 16:14:46 UTC (rev 11135) @@ -40,12 +40,23 @@ TORRENT_TEST(web_seed_http_pw) { - for (int url_seed = 0; url_seed < 2; ++url_seed) - { + run_http_suite(proxy, "http", false); +} + +TORRENT_TEST(url_seed_http_pw) +{ + run_http_suite(proxy, "http", true); +} + #ifdef TORRENT_USE_OPENSSL - run_http_suite(proxy, "https", url_seed); -#endif - run_http_suite(proxy, "http", url_seed); - } +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 + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |