test merge RC_1_2 into RC_2_0
This commit is contained in:
7
.github/workflows/python.yml
vendored
7
.github/workflows/python.yml
vendored
@ -53,7 +53,7 @@ jobs:
|
||||
if: runner.os == 'Windows'
|
||||
shell: cmd
|
||||
run: |
|
||||
git clone --depth=1 --recurse-submodules -j10 --branch=boost-1.72.0 https://github.com/boostorg/boost.git
|
||||
git clone --depth=1 --recurse-submodules -j10 --branch=boost-1.78.0 https://github.com/boostorg/boost.git
|
||||
cd boost
|
||||
bootstrap.bat
|
||||
|
||||
@ -68,7 +68,8 @@ jobs:
|
||||
if: runner.os == 'Windows'
|
||||
uses: nick-invision/retry@v2
|
||||
with:
|
||||
timeout_minutes: 30
|
||||
shell: cmd
|
||||
timeout_minutes: 5
|
||||
retry_wait_seconds: 4
|
||||
max_attempts: 3
|
||||
command: choco install openssl --limitoutput --no-progress
|
||||
@ -108,4 +109,4 @@ jobs:
|
||||
if: runner.os != 'Windows'
|
||||
run: |
|
||||
cd bindings/python
|
||||
python3 test.py
|
||||
python3 test.py
|
||||
|
2
.github/workflows/windows.yml
vendored
2
.github/workflows/windows.yml
vendored
@ -43,7 +43,7 @@ jobs:
|
||||
|
||||
- name: install boost
|
||||
run: |
|
||||
git clone --depth=1 --recurse-submodules -j10 --branch=boost-1.72.0 https://github.com/boostorg/boost.git
|
||||
git clone --depth=1 --recurse-submodules -j10 --branch=boost-1.78.0 https://github.com/boostorg/boost.git
|
||||
cd boost
|
||||
bootstrap.bat
|
||||
|
||||
|
3
Jamfile
3
Jamfile
@ -312,9 +312,8 @@ rule building ( properties * )
|
||||
{
|
||||
# allow larger .obj files (with more sections)
|
||||
result += <cxxflags>/bigobj ;
|
||||
result += <cflags>/bigobj ;
|
||||
# https://docs.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170
|
||||
result += <cflags>/utf-8 ;
|
||||
result += <cxxflags>/utf-8 ;
|
||||
}
|
||||
|
||||
if <toolset>gcc in $(properties) && <target-os>windows in $(properties)
|
||||
|
@ -14,11 +14,11 @@ project client_test
|
||||
<threading>multi <library>/torrent//torrent
|
||||
<toolset>darwin:<cflags>-Wno-unused-command-line-argument
|
||||
# disable warning C4275: non DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
|
||||
<toolset>msvc:<cflags>/wd4275
|
||||
<toolset>msvc:<cxxflags>/wd4275
|
||||
# C4268: 'identifier' : 'const' static/global data initialized
|
||||
# with compiler generated default constructor fills the object with zeros
|
||||
<toolset>msvc:<cflags>/wd4268
|
||||
<toolset>msvc:<cflags>/wd4373
|
||||
<toolset>msvc:<cxxflags>/wd4268
|
||||
<toolset>msvc:<cxxflags>/wd4373
|
||||
<toolset>clang:<cflags>-Wno-implicit-int-float-conversion
|
||||
<conditional>@warnings
|
||||
: default-build
|
||||
|
@ -18,9 +18,9 @@ project
|
||||
<source>utils.cpp
|
||||
<source>disk_io.cpp
|
||||
<source>transfer_sim.cpp
|
||||
<toolset>msvc:<cflags>/wd4275
|
||||
<toolset>msvc:<cflags>/wd4005
|
||||
<toolset>msvc:<cflags>/wd4268
|
||||
<toolset>msvc:<cxxflags>/wd4275
|
||||
<toolset>msvc:<cxxflags>/wd4005
|
||||
<toolset>msvc:<cxxflags>/wd4268
|
||||
: default-build
|
||||
<threading>multi
|
||||
<invariant-checks>full
|
||||
|
@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
std::string save_path(int idx)
|
||||
{
|
||||
int const swarm_id = test_counter();
|
||||
int const swarm_id = unit_test::test_counter();
|
||||
char path[200];
|
||||
std::snprintf(path, sizeof(path), "swarm-%04d-peer-%02d"
|
||||
, swarm_id, idx);
|
||||
@ -53,7 +53,7 @@ lt::add_torrent_params create_torrent(int const idx, bool const seed
|
||||
// TODO: if we want non-seeding torrents, that could be a bit cheaper to
|
||||
// create
|
||||
lt::add_torrent_params params;
|
||||
int swarm_id = test_counter();
|
||||
int swarm_id = unit_test::test_counter();
|
||||
char name[200];
|
||||
std::snprintf(name, sizeof(name), "temp-%02d", swarm_id);
|
||||
std::string path = save_path(idx);
|
||||
|
@ -210,7 +210,7 @@ void setup_swarm(int num_nodes
|
||||
lt::deadline_timer timer(ios);
|
||||
|
||||
lt::error_code ec;
|
||||
int const swarm_id = test_counter();
|
||||
int const swarm_id = unit_test::test_counter();
|
||||
std::string path = save_path(swarm_id, 0);
|
||||
|
||||
std::shared_ptr<lt::torrent_info> ti;
|
||||
|
@ -196,7 +196,7 @@ TORRENT_TEST(error_handling)
|
||||
// this will clear the history of all output we've printed so far.
|
||||
// if we encounter an error from now on, we'll only print the relevant
|
||||
// iteration
|
||||
reset_output();
|
||||
unit_test::reset_output();
|
||||
|
||||
// re-seed the random engine each iteration, to make the runs
|
||||
// deterministic
|
||||
|
@ -885,7 +885,7 @@ TORRENT_TEST(pex)
|
||||
lt::deadline_timer timer(ios);
|
||||
|
||||
lt::error_code ec;
|
||||
int const swarm_id = test_counter();
|
||||
int const swarm_id = unit_test::test_counter();
|
||||
std::string path = save_path(swarm_id, 0);
|
||||
|
||||
lt::create_directory(path, ec);
|
||||
|
@ -84,14 +84,14 @@ TORRENT_TEST(transfer_matrix)
|
||||
// this will clear the history of all output we've printed so far.
|
||||
// if we encounter an error from now on, we'll only print the relevant
|
||||
// iteration
|
||||
reset_output();
|
||||
::unit_test::reset_output();
|
||||
|
||||
// re-seed the random engine each iteration, to make the runs
|
||||
// deterministic
|
||||
lt::aux::random_engine().seed(0x23563a7f);
|
||||
|
||||
run_matrix_test(piece_size | bt_version | magnet | multi_file, files, corruption);
|
||||
if (g_test_failures > 0) return;
|
||||
if (::unit_test::g_test_failures > 0) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,14 +64,14 @@ project
|
||||
<library>libtorrent_test
|
||||
<library>/torrent//torrent
|
||||
# C4127: conditional expression is constant
|
||||
<toolset>msvc:<cflags>/wd4127
|
||||
<toolset>msvc:<cxxflags>/wd4127
|
||||
# C4309: 'conversion' : truncation of constant value
|
||||
<toolset>msvc:<cflags>/wd4309
|
||||
<toolset>msvc:<cxxflags>/wd4309
|
||||
# C4310: cast truncates constant value
|
||||
<toolset>msvc:<cflags>/wd4310
|
||||
<toolset>msvc:<cxxflags>/wd4310
|
||||
# C4268: 'identifier' : 'const' static/global data initialized
|
||||
# with compiler generated default constructor fills the object with zeros
|
||||
<toolset>msvc:<cflags>/wd4268
|
||||
<toolset>msvc:<cxxflags>/wd4268
|
||||
<toolset>clang:<cflags>-Wno-implicit-int-float-conversion
|
||||
<conditional>@warnings
|
||||
<export-extra>on
|
||||
|
@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <cstdlib> // for exit()
|
||||
#include "libtorrent/address.hpp"
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include "setup_transfer.hpp" // for g_test_failures
|
||||
#include "setup_transfer.hpp" // for unit_test::g_test_failures
|
||||
#include "test.hpp"
|
||||
#include "dht_server.hpp" // for stop_dht
|
||||
#include "peer_server.hpp" // for stop_peer
|
||||
@ -86,7 +86,7 @@ bool redirect_stderr = false;
|
||||
bool keep_files = false;
|
||||
|
||||
// the current tests file descriptor
|
||||
unit_test_t* current_test = nullptr;
|
||||
unit_test::unit_test_t* current_test = nullptr;
|
||||
|
||||
void output_test_log_to_terminal()
|
||||
{
|
||||
@ -297,6 +297,8 @@ private:
|
||||
std::string dir;
|
||||
};
|
||||
|
||||
namespace unit_test {
|
||||
|
||||
void EXPORT reset_output()
|
||||
{
|
||||
if (current_test == nullptr || current_test->output == nullptr) return;
|
||||
@ -315,6 +317,8 @@ void EXPORT reset_output()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int EXPORT main(int argc, char const* argv[])
|
||||
{
|
||||
char const* executable = argv[0];
|
||||
@ -334,9 +338,9 @@ int EXPORT main(int argc, char const* argv[])
|
||||
if (argv[0] == "-l"_sv || argv[0] == "--list"_sv)
|
||||
{
|
||||
std::printf("TESTS:\n");
|
||||
for (int i = 0; i < g_num_unit_tests; ++i)
|
||||
for (int i = 0; i < ::unit_test::g_num_unit_tests; ++i)
|
||||
{
|
||||
std::printf(" - %s\n", g_unit_tests[i].name);
|
||||
std::printf(" - %s\n", ::unit_test::g_unit_tests[i].name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -418,7 +422,7 @@ int EXPORT main(int argc, char const* argv[])
|
||||
std::string const unit_dir_prefix = combine_path(root_dir, "test_tmp_" + std::to_string(process_id) + "_");
|
||||
std::printf("test: %s\ncwd_prefix = \"%s\"\n", executable, unit_dir_prefix.c_str());
|
||||
|
||||
if (g_num_unit_tests == 0)
|
||||
if (unit_test::g_num_unit_tests == 0)
|
||||
{
|
||||
std::printf("\x1b[31mTEST_ERROR: no unit tests registered\x1b[0m\n");
|
||||
return 1;
|
||||
@ -428,9 +432,9 @@ int EXPORT main(int argc, char const* argv[])
|
||||
if (redirect_stderr) old_stderr = dup(fileno(stderr));
|
||||
|
||||
int num_run = 0;
|
||||
for (int i = 0; i < g_num_unit_tests; ++i)
|
||||
for (int i = 0; i < unit_test::g_num_unit_tests; ++i)
|
||||
{
|
||||
if (filter && tests_to_run.count(g_unit_tests[i].name) == 0)
|
||||
if (filter && tests_to_run.count(unit_test::g_unit_tests[i].name) == 0)
|
||||
continue;
|
||||
|
||||
std::string const unit_dir = unit_dir_prefix + std::to_string(i);
|
||||
@ -451,7 +455,7 @@ int EXPORT main(int argc, char const* argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
unit_test_t& t = g_unit_tests[i];
|
||||
auto& t = ::unit_test::g_unit_tests[i];
|
||||
|
||||
if (redirect_stdout || redirect_stderr)
|
||||
{
|
||||
@ -504,7 +508,7 @@ int EXPORT main(int argc, char const* argv[])
|
||||
setbuf(stdout, nullptr);
|
||||
setbuf(stderr, nullptr);
|
||||
|
||||
g_test_idx = i;
|
||||
::unit_test::g_test_idx = i;
|
||||
current_test = &t;
|
||||
|
||||
std::printf("cwd: %s\n", unit_dir.c_str());
|
||||
@ -521,7 +525,7 @@ int EXPORT main(int argc, char const* argv[])
|
||||
std::srand(unsigned(std::hash<std::string>{}(executable)) + unsigned(i));
|
||||
lt::aux::random_engine().seed(0x82daf973);
|
||||
|
||||
g_test_failures = 0;
|
||||
::unit_test::g_test_failures = 0;
|
||||
(*t.fun)();
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
@ -532,28 +536,28 @@ int EXPORT main(int argc, char const* argv[])
|
||||
, e.code().value()
|
||||
, e.code().category().name()
|
||||
, e.code().message().c_str());
|
||||
report_failure(buf, __FILE__, __LINE__);
|
||||
unit_test::report_failure(buf, __FILE__, __LINE__);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
char buf[200];
|
||||
std::snprintf(buf, sizeof(buf), "TEST_ERROR: Terminated with exception: \"%s\"", e.what());
|
||||
report_failure(buf, __FILE__, __LINE__);
|
||||
unit_test::report_failure(buf, __FILE__, __LINE__);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
report_failure("TEST_ERROR: Terminated with unknown exception", __FILE__, __LINE__);
|
||||
unit_test::report_failure("TEST_ERROR: Terminated with unknown exception", __FILE__, __LINE__);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!tests_to_run.empty()) tests_to_run.erase(t.name);
|
||||
|
||||
if (g_test_failures > 0)
|
||||
if (::unit_test::g_test_failures > 0)
|
||||
{
|
||||
output_test_log_to_terminal();
|
||||
}
|
||||
|
||||
t.num_failures = g_test_failures;
|
||||
t.num_failures = ::unit_test::g_test_failures;
|
||||
t.run = true;
|
||||
++num_run;
|
||||
|
||||
@ -592,6 +596,6 @@ int EXPORT main(int argc, char const* argv[])
|
||||
if (redirect_stdout) fflush(stdout);
|
||||
if (redirect_stderr) fflush(stderr);
|
||||
|
||||
return print_failures() ? 333 : 0;
|
||||
return unit_test::print_failures() ? 333 : 0;
|
||||
}
|
||||
|
||||
|
@ -716,7 +716,7 @@ std::vector<std::string> get_python()
|
||||
|
||||
int find_available_port()
|
||||
{
|
||||
int port = 2000 + (std::int64_t(::getpid()) + g_test_idx + std::rand()) % 60000;
|
||||
int port = 2000 + (std::int64_t(::getpid()) + ::unit_test::g_test_idx + std::rand()) % 60000;
|
||||
error_code ec;
|
||||
io_context ios;
|
||||
|
||||
|
@ -46,13 +46,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
EXPORT std::shared_ptr<lt::torrent_info> generate_torrent(bool with_files = false, bool with_hashes = false);
|
||||
|
||||
EXPORT int print_failures();
|
||||
|
||||
EXPORT int load_file(std::string const& filename, std::vector<char>& v
|
||||
, lt::error_code& ec, int limit = 8000000);
|
||||
|
||||
EXPORT void report_failure(char const* err, char const* file, int line);
|
||||
|
||||
EXPORT void init_rand_address();
|
||||
EXPORT lt::address rand_v4();
|
||||
EXPORT lt::address rand_v6();
|
||||
|
@ -35,12 +35,16 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
namespace unit_test {
|
||||
|
||||
unit_test_t g_unit_tests[1024];
|
||||
int g_num_unit_tests = 0;
|
||||
int g_test_failures = 0; // flushed at start of every unit
|
||||
int g_test_idx = 0;
|
||||
|
||||
static std::vector<std::string> failure_strings;
|
||||
namespace {
|
||||
std::vector<std::string> failure_strings;
|
||||
}
|
||||
|
||||
int test_counter()
|
||||
{
|
||||
@ -95,3 +99,4 @@ int print_failures()
|
||||
return total_num_failures;
|
||||
}
|
||||
|
||||
} // unit_test
|
||||
|
@ -62,6 +62,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace unit_test {
|
||||
|
||||
void EXPORT report_failure(char const* err, char const* file, int line);
|
||||
int EXPORT print_failures();
|
||||
int EXPORT test_counter();
|
||||
@ -83,23 +85,25 @@ extern int EXPORT g_num_unit_tests;
|
||||
extern int EXPORT g_test_failures;
|
||||
extern int g_test_idx;
|
||||
|
||||
} // unit_test
|
||||
|
||||
#define TORRENT_TEST(test_name) \
|
||||
static void BOOST_PP_CAT(unit_test_, test_name)(); \
|
||||
static struct BOOST_PP_CAT(register_class_, test_name) { \
|
||||
BOOST_PP_CAT(register_class_, test_name) () { \
|
||||
unit_test_t& t = g_unit_tests[g_num_unit_tests]; \
|
||||
auto& t = ::unit_test::g_unit_tests[::unit_test::g_num_unit_tests]; \
|
||||
t.fun = &BOOST_PP_CAT(unit_test_, test_name); \
|
||||
t.name = __FILE__ "." #test_name; \
|
||||
t.num_failures = 0; \
|
||||
t.run = false; \
|
||||
t.output = nullptr; \
|
||||
g_num_unit_tests++; \
|
||||
::unit_test::g_num_unit_tests++; \
|
||||
} \
|
||||
} BOOST_PP_CAT(_static_registrar_, test_name); \
|
||||
} BOOST_PP_CAT(g_static_registrar_for, test_name); \
|
||||
static void BOOST_PP_CAT(unit_test_, test_name)()
|
||||
|
||||
#define TEST_REPORT_AUX(x, line, file) \
|
||||
report_failure(x, line, file)
|
||||
unit_test::report_failure(x, line, file)
|
||||
|
||||
#ifdef BOOST_NO_EXCEPTIONS
|
||||
#define TEST_CHECK(x) \
|
||||
@ -108,15 +112,15 @@ extern int g_test_idx;
|
||||
} while (false)
|
||||
#define TEST_EQUAL(x, y) \
|
||||
do if ((x) != (y)) { \
|
||||
std::stringstream s__; \
|
||||
s__ << "TEST_ERROR: equal check failed:\n" #x ": " << (x) << "\nexpected: " << (y); \
|
||||
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
|
||||
std::stringstream _s_; \
|
||||
_s_ << "TEST_ERROR: equal check failed:\n" #x ": " << (x) << "\nexpected: " << (y); \
|
||||
TEST_REPORT_AUX(_s_.str().c_str(), __FILE__, __LINE__); \
|
||||
} while (false)
|
||||
#define TEST_NE(x, y) \
|
||||
do if ((x) == (y)) { \
|
||||
std::stringstream s__; \
|
||||
s__ << "TEST_ERROR: not equal check failed:\n" #x ": " << (x) << "\nexpected not equal to: " << (y); \
|
||||
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
|
||||
std::stringstream _s_; \
|
||||
_s_ << "TEST_ERROR: not equal check failed:\n" #x ": " << (x) << "\nexpected not equal to: " << (y); \
|
||||
TEST_REPORT_AUX(_s_.str().c_str(), __FILE__, __LINE__); \
|
||||
} while (false)
|
||||
#else
|
||||
#define TEST_CHECK(x) \
|
||||
@ -137,9 +141,9 @@ extern int g_test_idx;
|
||||
#define TEST_EQUAL(x, y) \
|
||||
do try { \
|
||||
if ((x) != (y)) { \
|
||||
std::stringstream s__; \
|
||||
s__ << "TEST_ERROR: " #x ": " << (x) << " expected: " << (y); \
|
||||
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
|
||||
std::stringstream _s_; \
|
||||
_s_ << "TEST_ERROR: " #x ": " << (x) << " expected: " << (y); \
|
||||
TEST_REPORT_AUX(_s_.str().c_str(), __FILE__, __LINE__); \
|
||||
} \
|
||||
} \
|
||||
catch (std::exception const& _e) \
|
||||
@ -153,9 +157,9 @@ extern int g_test_idx;
|
||||
#define TEST_NE(x, y) \
|
||||
do try { \
|
||||
if ((x) == (y)) { \
|
||||
std::stringstream s__; \
|
||||
s__ << "TEST_ERROR: " #x ": " << (x) << " expected not equal to: " << (y); \
|
||||
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
|
||||
std::stringstream _s_; \
|
||||
_s_ << "TEST_ERROR: " #x ": " << (x) << " expected not equal to: " << (y); \
|
||||
TEST_REPORT_AUX(_s_.str().c_str(), __FILE__, __LINE__); \
|
||||
} \
|
||||
} \
|
||||
catch (std::exception const& _e) \
|
||||
|
@ -29,10 +29,10 @@ project tools
|
||||
: requirements
|
||||
<threading>multi
|
||||
# disable warning C4275: non DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
|
||||
<toolset>msvc:<cflags>/wd4275
|
||||
<toolset>msvc:<cxxflags>/wd4275
|
||||
# C4268: 'identifier' : 'const' static/global data initialized
|
||||
# with compiler generated default constructor fills the object with zeros
|
||||
<toolset>msvc:<cflags>/wd4268
|
||||
<toolset>msvc:<cxxflags>/wd4268
|
||||
<conditional>@link_libtorrent
|
||||
: default-build
|
||||
<link>static
|
||||
|
Reference in New Issue
Block a user