optimized unit tests

This commit is contained in:
Arvid Norberg 2009-04-10 08:40:13 +00:00
parent efbb3a5861
commit bc9e58962b
7 changed files with 41 additions and 29 deletions

View File

@ -2,32 +2,31 @@ use-project /torrent : .. ;
lib test_common
:
main.cpp
setup_transfer.cpp
:
<link>static
<library>/torrent//torrent
<threading>multi
:
<link>static
<threading>multi
<library>/torrent//torrent
;
exe test_upnp : test_upnp.cpp /torrent//torrent
: <link>shared <threading>multi <debug-iterators>on <invariant-checks>full ;
exe test_natpmp : test_natpmp.cpp /torrent//torrent
: <link>shared <threading>multi <debug-iterators>on <invariant-checks>full ;
project
: requirements
<library>test_common
<library>/torrent//torrent
<source>main.cpp
: default-build
<threading>multi
<invariant-checks>full
<debug-iterators>on
;
exe test_upnp : test_upnp.cpp /torrent//torrent
: <link>static <threading>multi <debug-iterators>on <invariant-checks>full ;
exe test_natpmp : test_natpmp.cpp /torrent//torrent
: <link>static <threading>multi <debug-iterators>on <invariant-checks>full ;
test-suite libtorrent :
[ run test_auto_unchoke.cpp ]
[ run test_http_connection.cpp ]

View File

@ -35,13 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
int test_main();
bool tests_failure = false;
void report_failure(char const* err, char const* file, int line)
{
std::cerr << "\033[31m" << file << ":" << line << " \"" << err << "\"\033[0m\n";
tests_failure = true;
}
extern bool tests_failure;
int main()
{

View File

@ -51,6 +51,14 @@ using boost::filesystem::create_directory;
using namespace libtorrent;
namespace sf = boost::filesystem;
bool tests_failure = false;
void report_failure(char const* err, char const* file, int line)
{
std::cerr << "\033[31m" << file << ":" << line << " \"" << err << "\"\033[0m\n";
tests_failure = true;
}
bool print_alerts(libtorrent::session& ses, char const* name
, bool allow_disconnects, bool allow_no_torrents, bool allow_failed_fastresume
, bool (*predicate)(libtorrent::alert*))
@ -253,6 +261,12 @@ setup_transfer(session* ses1, session* ses2, session* ses3
assert(ses1);
assert(ses2);
session_settings sess_set;
sess_set.ignore_limits_on_local_network = false;
ses1->set_settings(sess_set);
ses2->set_settings(sess_set);
if (ses3) ses3->set_settings(sess_set);
std::srand(time(0));
peer_id pid;
std::generate(&pid[0], &pid[0] + 20, std::rand);
@ -272,7 +286,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3
{
create_directory("./tmp1" + suffix);
std::ofstream file(("./tmp1" + suffix + "/temporary").c_str());
t = ::create_torrent(&file, piece_size, 1024 / 8);
t = ::create_torrent(&file, piece_size, 19);
file.close();
if (clear_files)
{

View File

@ -50,7 +50,7 @@ bool print_alerts(libtorrent::session& ses, char const* name
void test_sleep(int millisec);
boost::intrusive_ptr<libtorrent::torrent_info> create_torrent(std::ostream* file = 0, int piece_size = 16 * 1024, int num_pieces = 1024 / 8);
boost::intrusive_ptr<libtorrent::torrent_info> create_torrent(std::ostream* file = 0, int piece_size = 16 * 1024, int num_pieces = 13);
boost::tuple<libtorrent::torrent_handle
, libtorrent::torrent_handle

View File

@ -136,7 +136,7 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
int test_main()
{
using namespace libtorrent;
int repcount = 1024;
int repcount = 128;
for (int rep = 0; rep < repcount; ++rep)
{

View File

@ -643,9 +643,9 @@ int test_main()
using namespace libtorrent::dht;
for (int i = 0; i < 160; i += 4)
for (int i = 0; i < 160; i += 8)
{
for (int j = 0; j < 160; j += 4)
for (int j = 0; j < 160; j += 8)
{
node_id a(0);
a[(159-i) / 8] = 1 << (i & 7);
@ -656,7 +656,7 @@ int test_main()
TEST_CHECK(dist >= 0 && dist < 160);
TEST_CHECK(dist == ((i == j)?0:(std::max)(i, j)));
for (int k = 0; k < 160; k += 4)
for (int k = 0; k < 160; k += 8)
{
node_id c(0);
c[(159-k) / 8] = 1 << (k & 7);
@ -676,7 +676,7 @@ int test_main()
node_id tmp;
node_id diff = to_hash("00001f7459456a9453f8719b09547c11d5f34064");
std::vector<node_entry> nodes;
for (int i = 0; i < 10000; ++i)
for (int i = 0; i < 1000; ++i)
{
table.node_seen(tmp, udp::endpoint(address_v4::any(), rand()));
add_and_replace(tmp, diff);

View File

@ -59,7 +59,7 @@ void test_rate()
create_directory("./tmp1_transfer");
std::ofstream file("./tmp1_transfer/temporary");
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file, 4 * 1024 * 1024, 50);
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file, 4 * 1024 * 1024, 7);
file.close();
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0
@ -134,13 +134,18 @@ void test_transfer()
// set half of the pieces to priority 0
int num_pieces = tor2.get_torrent_info().num_pieces();
std::vector<int> priorities(num_pieces, 1);
std::fill(priorities.begin(), priorities.begin() + num_pieces / 2, 0);
std::fill(priorities.begin(), priorities.begin() + (num_pieces / 2), 0);
tor2.prioritize_pieces(priorities);
std::cerr << "setting priorities: ";
std::copy(priorities.begin(), priorities.end(), std::ostream_iterator<int>(std::cerr, ", "));
std::cerr << std::endl;
ses1.set_alert_mask(alert::all_categories & ~alert::progress_notification);
ses2.set_alert_mask(alert::all_categories & ~alert::progress_notification);
ses1.set_alert_dispatch(&print_alert);
ses2.set_download_rate_limit(tor2.get_torrent_info().piece_length() / 2);
// also test to move the storage of the downloader and the uploader
// to make sure it can handle switching paths
bool test_move_storage = false;
@ -165,8 +170,6 @@ void test_transfer()
<< st2.num_peers
<< std::endl;
if (tor2.is_finished()) break;
if (!test_move_storage && st2.progress > 0.25f)
{
test_move_storage = true;
@ -175,6 +178,8 @@ void test_transfer()
std::cerr << "moving storage" << std::endl;
}
if (tor2.is_finished()) break;
TEST_CHECK(st1.state == torrent_status::seeding
|| st1.state == torrent_status::checking_files);
TEST_CHECK(st2.state == torrent_status::downloading);