optimized unit tests
This commit is contained in:
19
test/Jamfile
19
test/Jamfile
@@ -2,32 +2,31 @@ use-project /torrent : .. ;
|
|||||||
|
|
||||||
lib test_common
|
lib test_common
|
||||||
:
|
:
|
||||||
main.cpp
|
|
||||||
setup_transfer.cpp
|
setup_transfer.cpp
|
||||||
:
|
:
|
||||||
<link>static
|
<library>/torrent//torrent
|
||||||
<threading>multi
|
<threading>multi
|
||||||
:
|
:
|
||||||
<link>static
|
|
||||||
<threading>multi
|
<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
|
project
|
||||||
: requirements
|
: requirements
|
||||||
<library>test_common
|
<library>test_common
|
||||||
|
<library>/torrent//torrent
|
||||||
|
<source>main.cpp
|
||||||
: default-build
|
: default-build
|
||||||
<threading>multi
|
<threading>multi
|
||||||
<invariant-checks>full
|
<invariant-checks>full
|
||||||
<debug-iterators>on
|
<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 :
|
test-suite libtorrent :
|
||||||
[ run test_auto_unchoke.cpp ]
|
[ run test_auto_unchoke.cpp ]
|
||||||
[ run test_http_connection.cpp ]
|
[ run test_http_connection.cpp ]
|
||||||
|
@@ -35,13 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
int test_main();
|
int test_main();
|
||||||
|
|
||||||
bool tests_failure = false;
|
extern bool tests_failure;
|
||||||
|
|
||||||
void report_failure(char const* err, char const* file, int line)
|
|
||||||
{
|
|
||||||
std::cerr << "\033[31m" << file << ":" << line << " \"" << err << "\"\033[0m\n";
|
|
||||||
tests_failure = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@@ -51,6 +51,14 @@ using boost::filesystem::create_directory;
|
|||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
namespace sf = boost::filesystem;
|
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 print_alerts(libtorrent::session& ses, char const* name
|
||||||
, bool allow_disconnects, bool allow_no_torrents, bool allow_failed_fastresume
|
, bool allow_disconnects, bool allow_no_torrents, bool allow_failed_fastresume
|
||||||
, bool (*predicate)(libtorrent::alert*))
|
, bool (*predicate)(libtorrent::alert*))
|
||||||
@@ -253,6 +261,12 @@ setup_transfer(session* ses1, session* ses2, session* ses3
|
|||||||
assert(ses1);
|
assert(ses1);
|
||||||
assert(ses2);
|
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));
|
std::srand(time(0));
|
||||||
peer_id pid;
|
peer_id pid;
|
||||||
std::generate(&pid[0], &pid[0] + 20, std::rand);
|
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);
|
create_directory("./tmp1" + suffix);
|
||||||
std::ofstream file(("./tmp1" + suffix + "/temporary").c_str());
|
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();
|
file.close();
|
||||||
if (clear_files)
|
if (clear_files)
|
||||||
{
|
{
|
||||||
|
@@ -50,7 +50,7 @@ bool print_alerts(libtorrent::session& ses, char const* name
|
|||||||
|
|
||||||
void test_sleep(int millisec);
|
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
|
boost::tuple<libtorrent::torrent_handle
|
||||||
, libtorrent::torrent_handle
|
, libtorrent::torrent_handle
|
||||||
|
@@ -136,7 +136,7 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
|
|||||||
int test_main()
|
int test_main()
|
||||||
{
|
{
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
int repcount = 1024;
|
int repcount = 128;
|
||||||
|
|
||||||
for (int rep = 0; rep < repcount; ++rep)
|
for (int rep = 0; rep < repcount; ++rep)
|
||||||
{
|
{
|
||||||
|
@@ -643,9 +643,9 @@ int test_main()
|
|||||||
|
|
||||||
using namespace libtorrent::dht;
|
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);
|
node_id a(0);
|
||||||
a[(159-i) / 8] = 1 << (i & 7);
|
a[(159-i) / 8] = 1 << (i & 7);
|
||||||
@@ -656,7 +656,7 @@ int test_main()
|
|||||||
TEST_CHECK(dist >= 0 && dist < 160);
|
TEST_CHECK(dist >= 0 && dist < 160);
|
||||||
TEST_CHECK(dist == ((i == j)?0:(std::max)(i, j)));
|
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);
|
node_id c(0);
|
||||||
c[(159-k) / 8] = 1 << (k & 7);
|
c[(159-k) / 8] = 1 << (k & 7);
|
||||||
@@ -676,7 +676,7 @@ int test_main()
|
|||||||
node_id tmp;
|
node_id tmp;
|
||||||
node_id diff = to_hash("00001f7459456a9453f8719b09547c11d5f34064");
|
node_id diff = to_hash("00001f7459456a9453f8719b09547c11d5f34064");
|
||||||
std::vector<node_entry> nodes;
|
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()));
|
table.node_seen(tmp, udp::endpoint(address_v4::any(), rand()));
|
||||||
add_and_replace(tmp, diff);
|
add_and_replace(tmp, diff);
|
||||||
|
@@ -59,7 +59,7 @@ void test_rate()
|
|||||||
|
|
||||||
create_directory("./tmp1_transfer");
|
create_directory("./tmp1_transfer");
|
||||||
std::ofstream file("./tmp1_transfer/temporary");
|
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();
|
file.close();
|
||||||
|
|
||||||
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0
|
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
|
// set half of the pieces to priority 0
|
||||||
int num_pieces = tor2.get_torrent_info().num_pieces();
|
int num_pieces = tor2.get_torrent_info().num_pieces();
|
||||||
std::vector<int> priorities(num_pieces, 1);
|
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);
|
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);
|
ses1.set_alert_mask(alert::all_categories & ~alert::progress_notification);
|
||||||
ses2.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);
|
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
|
// also test to move the storage of the downloader and the uploader
|
||||||
// to make sure it can handle switching paths
|
// to make sure it can handle switching paths
|
||||||
bool test_move_storage = false;
|
bool test_move_storage = false;
|
||||||
@@ -165,8 +170,6 @@ void test_transfer()
|
|||||||
<< st2.num_peers
|
<< st2.num_peers
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
if (tor2.is_finished()) break;
|
|
||||||
|
|
||||||
if (!test_move_storage && st2.progress > 0.25f)
|
if (!test_move_storage && st2.progress > 0.25f)
|
||||||
{
|
{
|
||||||
test_move_storage = true;
|
test_move_storage = true;
|
||||||
@@ -175,6 +178,8 @@ void test_transfer()
|
|||||||
std::cerr << "moving storage" << std::endl;
|
std::cerr << "moving storage" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tor2.is_finished()) break;
|
||||||
|
|
||||||
TEST_CHECK(st1.state == torrent_status::seeding
|
TEST_CHECK(st1.state == torrent_status::seeding
|
||||||
|| st1.state == torrent_status::checking_files);
|
|| st1.state == torrent_status::checking_files);
|
||||||
TEST_CHECK(st2.state == torrent_status::downloading);
|
TEST_CHECK(st2.state == torrent_status::downloading);
|
||||||
|
Reference in New Issue
Block a user