don't print color output from tests (to make it work with some of the regression testing tools)

This commit is contained in:
Arvid Norberg 2013-06-14 16:38:26 +00:00
parent 3823b74586
commit f91d83434b
9 changed files with 45 additions and 108 deletions

View File

@ -67,17 +67,7 @@ bool tests_failure = false;
void report_failure(char const* err, char const* file, int line)
{
#if defined TORRENT_WINDOWS
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(out, FOREGROUND_RED);
char buffer[1024];
int len = snprintf(buffer, sizeof(buffer), "\n**** %s:%d \"%s\" ****\n\n", file, line, err);
DWORD written;
WriteFile(out, buffer, len, &written, NULL);
SetConsoleTextAttribute(out, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
#else
fprintf(stderr, "\033[31m %s:%d \"%s\"\033[0m\n", file, line, err);
#endif
fprintf(stderr, "\n***** %s:%d \"%s\" *****\n\n", file, line, err);
tests_failure = true;
}
@ -150,6 +140,33 @@ void wait_for_listen(libtorrent::session& ses, char const* name)
} while (a);
}
void print_ses_rate(libtorrent::torrent_status const* st1
, libtorrent::torrent_status const* st2
, libtorrent::torrent_status const* st3)
{
std::cerr
<< int(st1->download_payload_rate / 1000.f) << "kB/s "
<< int(st1->upload_payload_rate / 1000.f) << "kB/s "
<< int(st1->progress * 100) << "% "
<< st1->num_peers;
if (st2)
std::cerr << " : "
<< int(st2->download_payload_rate / 1000.f) << "kB/s "
<< int(st2->upload_payload_rate / 1000.f) << "kB/s "
<< int(st2->progress * 100) << "% "
<< st2->num_peers
<< " cc: " << st2->connect_candidates;
if (st3)
std::cerr << " : "
<< int(st3->download_payload_rate / 1000.f) << "kB/s "
<< int(st3->upload_payload_rate / 1000.f) << "kB/s "
<< int(st3->progress * 100) << "% "
<< st3->num_peers
<< " cc: " << st3->connect_candidates;
std::cerr << std::endl;
}
void test_sleep(int millisec)
{
libtorrent::sleep(millisec);

View File

@ -40,8 +40,13 @@ namespace libtorrent
{
class alert;
struct add_torrent_params;
struct session_status;
}
void print_ses_rate(libtorrent::torrent_status const* st1
, libtorrent::torrent_status const* st2
, libtorrent::torrent_status const* st3 = NULL);
bool print_alerts(libtorrent::session& ses, char const* name
, bool allow_disconnects = false
, bool allow_no_torrents = false

View File

@ -103,18 +103,7 @@ void test_swarm()
torrent_status st2 = tor2.status();
torrent_status st3 = tor3.status();
std::cerr
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< st1.num_peers << " " << st.allowed_upload_slots << ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers << " - "
<< "\033[32m" << int(st3.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st3.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st3.progress * 100) << "% "
<< st3.num_peers
<< std::endl;
print_ses_rate(&st1, &st2, &st3);
test_sleep(1000);
}

View File

@ -69,12 +69,7 @@ void test_lsd()
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
std::cerr
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< std::endl;
print_ses_rate(&st1, &st2);
if (st2.is_seeding /*&& st3.is_seeding*/) break;
test_sleep(1000);

View File

@ -94,14 +94,7 @@ void test_transfer(bool clear_files, bool disconnect
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
std::cerr
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< st1.num_peers << ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers
<< std::endl;
print_ses_rate(&st1, &st2);
if (st2.is_seeding) break;
test_sleep(1000);
}

View File

@ -118,18 +118,7 @@ void test_pex()
st2 = tor2.status();
st3 = tor3.status();
std::cerr
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< st1.num_peers << ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers << " - "
<< "\033[32m" << int(st3.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st3.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st3.progress * 100) << "% "
<< st3.num_peers
<< std::endl;
print_ses_rate(&st1, &st2, &st3);
// this is the success condition
if (st1.num_peers == 2 && st2.num_peers == 2 && st3.num_peers == 2)

View File

@ -131,18 +131,7 @@ void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode
++count_dl_rates3;
}
std::cerr
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< st1.num_peers << ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers << " - "
<< "\033[32m" << int(st3.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st3.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st3.progress * 100) << "% "
<< st3.num_peers
<< std::endl;
print_ses_rate(&st1, &st2, &st3);
if (st2.is_seeding && st3.is_seeding) break;
test_sleep(1000);

View File

@ -91,13 +91,7 @@ void test_rate()
torrent_status st2 = tor2.status();
if (i % 10 == 0)
{
std::cerr
<< "up: \033[33m" << st1.upload_payload_rate / 1000000.f << "MB/s "
<< " down: \033[32m" << st2.download_payload_rate / 1000000.f << "MB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< std::endl;
}
print_ses_rate(&st1, &st2);
if (st2.is_seeding) break;
test_sleep(100);
@ -370,18 +364,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
if (i % 10 == 0)
{
std::cerr
<< "\033[32m" << int(st1.download_payload_rate / 1000.f) << "kB/s "
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st1.progress * 100) << "% "
<< st1.num_peers
<< ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers
<< " cc: " << st2.connect_candidates
<< std::endl;
print_ses_rate(&st1, &st2);
}
if (!test_move_storage && st2.progress > 0.25f)
@ -439,7 +422,9 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
print_alerts(ses2, "ses2");
torrent_status st2 = tor2.status();
if (i % 10 == 0)
std::cerr << "\033[0m" << int(st2.progress * 100) << "% " << std::endl;
{
std::cerr << int(st2.progress * 100) << "% " << std::endl;
}
if (st2.state != torrent_status::checking_files) break;
}
@ -450,7 +435,6 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
{
print_alerts(ses2, "ses2");
torrent_status st2 = tor2.status();
// std::cerr << "\033[0m" << int(st2.progress * 100) << "% " << std::endl;
TEST_CHECK(st2.state == torrent_status::finished);
test_sleep(100);
}
@ -552,20 +536,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
torrent_status st2 = tor2.status();
if (i % 10 == 0)
{
std::cerr
<< "\033[32m" << int(st1.download_payload_rate / 1000.f) << "kB/s "
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st1.progress * 100) << "% "
<< st1.num_peers
<< ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers
<< " cc: " << st2.connect_candidates
<< std::endl;
}
print_ses_rate(&st1, &st2);
if (tor2.status().is_finished) break;

View File

@ -115,18 +115,7 @@ void test_transfer()
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
std::cerr
<< "\033[32m" << int(st1.download_payload_rate / 1000.f) << "kB/s "
<< "\033[33m" << int(st1.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st1.progress * 100) << "% "
<< st1.num_peers
<< ": "
<< "\033[32m" << int(st2.download_payload_rate / 1000.f) << "kB/s "
<< "\033[31m" << int(st2.upload_payload_rate / 1000.f) << "kB/s "
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers
<< " cc: " << st2.connect_candidates
<< std::endl;
print_ses_rate(&st1, &st2);
if (st2.is_finished) break;