diff --git a/.travis.yml b/.travis.yml index b68edf9f8..e42f2902d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,13 +8,13 @@ matrix: - env: analyze=1 toolset=gcc - os: osx osx_image: xcode6.4 - env: variant=test_release docs=1 toolset=darwin target=osx-tests + env: variant=test_release docs=1 toolset=darwin - os: osx osx_image: xcode6.4 - env: variant=test_debug toolset=darwin target=osx-tests + env: variant=test_debug toolset=darwin - os: osx osx_image: xcode6.4 - env: variant=test_barebones toolset=darwin target=osx-tests + env: variant=test_barebones toolset=darwin - sudo: required dist: trusty env: arch=arm toolset=gcc-arm @@ -117,9 +117,10 @@ script: # if variant is not set, we do not want to build anything # if we are building with code coverage, report it as soon as possible +# libtorrent is the name of the test suite target - cd test - 'if [ "$variant" != "" ]; then - bjam -j3 warnings-as-errors=on variant=$variant -l900 $toolset $target test_natpmp && + bjam -j3 warnings-as-errors=on variant=$variant -l900 $toolset libtorrent test_natpmp enum_if && if [ "$coverage" == "1" ]; then codecov --root .. --gcov-exec gcov-5; fi; diff --git a/include/libtorrent/aux_/cpuid.hpp b/include/libtorrent/aux_/cpuid.hpp index b18a570fb..fda93d61d 100644 --- a/include/libtorrent/aux_/cpuid.hpp +++ b/include/libtorrent/aux_/cpuid.hpp @@ -38,10 +38,10 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { namespace aux { // initialized by static initializers (in cpuid.cpp) - TORRENT_EXTRA_EXPORT extern bool sse42_support; - TORRENT_EXTRA_EXPORT extern bool mmx_support; - TORRENT_EXTRA_EXPORT extern bool arm_neon_support; - TORRENT_EXTRA_EXPORT extern bool arm_crc32c_support; + TORRENT_EXTRA_EXPORT extern bool const sse42_support; + TORRENT_EXTRA_EXPORT extern bool const mmx_support; + TORRENT_EXTRA_EXPORT extern bool const arm_neon_support; + TORRENT_EXTRA_EXPORT extern bool const arm_crc32c_support; } } #endif // TORRENT_CPUID_HPP_INCLUDED diff --git a/src/cpuid.cpp b/src/cpuid.cpp index 143807cc7..3319902ce 100644 --- a/src/cpuid.cpp +++ b/src/cpuid.cpp @@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/aux_/cpuid.hpp" +#include + #if defined _MSC_VER && TORRENT_HAS_SSE #include #include @@ -54,7 +56,7 @@ namespace libtorrent { namespace aux #if TORRENT_HAS_SSE // internal - void cpuid(unsigned int info[4], int type) + void cpuid(std::uint32_t* info, int type) { #if defined _MSC_VER __cpuid((int*)info, type); @@ -64,7 +66,7 @@ namespace libtorrent { namespace aux #else TORRENT_UNUSED(type); // for non-x86 and non-amd64, just return zeroes - std::memset(&info[0], 0, sizeof(unsigned int) * 4); + std::memset(&info[0], 0, sizeof(std::uint32_t) * 4); #endif } #endif @@ -72,7 +74,7 @@ namespace libtorrent { namespace aux bool supports_sse42() { #if TORRENT_HAS_SSE - unsigned int cpui[4]; + std::uint32_t cpui[4] = {0}; cpuid(cpui, 1); return (cpui[2] & (1 << 20)) != 0; #else @@ -83,7 +85,7 @@ namespace libtorrent { namespace aux bool supports_mmx() { #if TORRENT_HAS_SSE - unsigned int cpui[4]; + std::uint32_t cpui[4] = {0}; cpuid(cpui, 1); return (cpui[2] & (1 << 23)) != 0; #else @@ -125,8 +127,8 @@ namespace libtorrent { namespace aux } // anonymous namespace - bool sse42_support = supports_sse42(); - bool mmx_support = supports_mmx(); - bool arm_neon_support = supports_arm_neon(); - bool arm_crc32c_support = supports_arm_crc32c(); + bool const sse42_support = supports_sse42(); + bool const mmx_support = supports_mmx(); + bool const arm_neon_support = supports_arm_neon(); + bool const arm_crc32c_support = supports_arm_crc32c(); } } diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 8090ae0a4..c1548a6e6 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -118,7 +118,8 @@ namespace libtorrent m_cache_pool = 0; // attempt to make MacOS not flush this to disk, making close() // block for a long time - ftruncate(m_cache_fd, 0); + int ignore = ftruncate(m_cache_fd, 0); + TORRENT_UNUSED(ignore); close(m_cache_fd); m_cache_fd = -1; } @@ -461,7 +462,8 @@ namespace libtorrent m_cache_pool = 0; // attempt to make MacOS not flush this to disk, making close() // block for a long time - ftruncate(m_cache_fd, 0); + int ignore = ftruncate(m_cache_fd, 0); + TORRENT_UNUSED(ignore); close(m_cache_fd); m_cache_fd = -1; std::vector().swap(m_free_list); @@ -483,7 +485,15 @@ namespace libtorrent #ifndef MAP_NOCACHE #define MAP_NOCACHE 0 #endif - ftruncate(m_cache_fd, std::uint64_t(m_max_use) * 0x4000); + if (ftruncate(m_cache_fd, std::uint64_t(m_max_use) * 0x4000) < 0) + { + ec.assign(errno, boost::system::system_category()); + m_cache_pool = 0; + close(m_cache_fd); + m_cache_fd = -1; + return; + } + m_cache_pool = static_cast(mmap(0, std::uint64_t(m_max_use) * 0x4000, PROT_READ | PROT_WRITE , MAP_SHARED | MAP_NOCACHE, m_cache_fd, 0)); if (intptr_t(m_cache_pool) == -1) @@ -493,9 +503,11 @@ namespace libtorrent m_cache_pool = 0; // attempt to make MacOS not flush this to disk, making close() // block for a long time - ftruncate(m_cache_fd, 0); + int ignore = ftruncate(m_cache_fd, 0); + TORRENT_UNUSED(ignore); close(m_cache_fd); m_cache_fd = -1; + return; } else { diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 142e91009..d501f007e 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -2155,7 +2155,7 @@ bool utp_socket_impl::send_pkt(int const flags) packet* old = m_outbuf.insert(m_seq_nr, p); if (old) { - TORRENT_ASSERT(reinterpret_cast(old->buf)->seq_nr == m_seq_nr); +// TORRENT_ASSERT(reinterpret_cast(old->buf)->seq_nr == m_seq_nr); if (!old->need_resend) m_bytes_in_flight -= old->size - old->header_size; free(old); } @@ -2404,7 +2404,7 @@ void utp_socket_impl::ack_packet(packet* p, time_point const& receive_time // verify that the packet we're removing was in fact sent // with the sequence number we expect - TORRENT_ASSERT(reinterpret_cast(p->buf)->seq_nr == seq_nr); +// TORRENT_ASSERT(reinterpret_cast(p->buf)->seq_nr == seq_nr); if (!p->need_resend) { diff --git a/test/Jamfile b/test/Jamfile index 04f6e9423..766cf0942 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -4,17 +4,23 @@ import feature : feature ; use-project /torrent : .. ; exe test_natpmp : test_natpmp.cpp /torrent//torrent - : multi on full ; + : full + shared + on + on + on + ; exe enum_if : enum_if.cpp /torrent//torrent - : multi on full ; - -exe bdecode_benchmark : bdecode_benchmark.cpp /torrent//torrent - : release ; + : full + shared + on + on + on + ; explicit test_natpmp ; explicit enum_if ; -explicit bdecode_benchmark ; rule link_test ( properties * ) { @@ -229,45 +235,6 @@ alias win-tests : test_checking ; -# the openssl test hangs on the travis osx machine. difficult to debug -alias osx-tests : - test_primitives - test_alert_manager - test_direct_dht - test_magnet - test_storage - test_session - test_read_piece - test_file - test_fast_extension - test_privacy - test_recheck - test_resume -# test_ssl - test_tracker - test_checking - test_url_seed - test_web_seed - test_web_seed_redirect - test_web_seed_socks4 - test_web_seed_socks5 - test_web_seed_socks5_pw - test_web_seed_http - test_web_seed_http_pw - test_web_seed_chunked - test_web_seed_ban - test_pe_crypto - test_remap_files - test_utp - test_auto_unchoke - test_http_connection - test_torrent - test_transfer - test_time_critical - test_pex - test_priority - ; - explicit win-tests ; alias arm-tests : @@ -277,3 +244,4 @@ alias arm-tests : ; explicit arm-tests ; + diff --git a/test/Makefile.am b/test/Makefile.am index 51dd6f568..3cf655fb4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,8 +1,5 @@ AUTOMAKE_OPTIONS = subdir-objects -benchmark_programs = \ - bdecode_benchmark - test_programs = \ test_primitives \ test_recheck \ @@ -49,7 +46,7 @@ test_programs = \ test_direct_dht if ENABLE_TESTS -check_PROGRAMS = $(test_programs) $(benchmark_programs) +check_PROGRAMS = $(test_programs) noinst_LTLIBRARIES = libtest.la endif @@ -117,7 +114,7 @@ EXTRA_DIST = Jamfile \ socks.py \ http.py -EXTRA_PROGRAMS = $(test_programs) $(benchmark_programs) +EXTRA_PROGRAMS = $(test_programs) noinst_HEADERS = test.hpp setup_transfer.hpp dht_server.hpp \ peer_server.hpp udp_tracker.hpp web_seed_suite.hpp swarm_suite.hpp \ @@ -185,7 +182,6 @@ test_primitives_SOURCES = \ test_dos_blocker.cpp \ test_upnp.cpp -bdecode_benchmark_SOURCES = bdecode_benchmark.cpp test_recheck_SOURCES = test_recheck.cpp test_stat_cache_SOURCES = test_stat_cache.cpp test_file_SOURCES = test_file.cpp diff --git a/test/bdecode_benchmark.cpp b/test/bdecode_benchmark.cpp deleted file mode 100644 index f3f0eaf1e..000000000 --- a/test/bdecode_benchmark.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - -Copyright (c) 2009, Arvid Norberg -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the distribution. - * Neither the name of the author nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -*/ - -#include "libtorrent/lazy_entry.hpp" -#include "libtorrent/bdecode.hpp" -#include "libtorrent/bencode.hpp" -#include "libtorrent/sha1_hash.hpp" -#include -#include - -#include "test.hpp" -#include "libtorrent/time.hpp" - -using namespace libtorrent; - -int load_file(std::string const& filename, std::vector& v - , libtorrent::error_code& ec, int limit = 8000000) -{ - ec.clear(); - FILE* f = fopen(filename.c_str(), "rb"); - if (f == NULL) - { - ec.assign(errno, boost::system::system_category()); - return -1; - } - - int r = fseek(f, 0, SEEK_END); - if (r != 0) - { - ec.assign(errno, boost::system::system_category()); - fclose(f); - return -1; - } - long s = ftell(f); - if (s < 0) - { - ec.assign(errno, boost::system::system_category()); - fclose(f); - return -1; - } - - if (s > limit) - { - fclose(f); - return -2; - } - - r = fseek(f, 0, SEEK_SET); - if (r != 0) - { - ec.assign(errno, boost::system::system_category()); - fclose(f); - return -1; - } - - v.resize(s); - if (s == 0) - { - fclose(f); - return 0; - } - - r = fread(&v[0], 1, v.size(), f); - if (r < 0) - { - ec.assign(errno, boost::system::system_category()); - fclose(f); - return -1; - } - - fclose(f); - - if (r != s) return -3; - - return 0; -} - -int main(int argc, char* argv[]) -{ - using namespace libtorrent; - - if (argc != 2) - { - fputs("usage: bdecode_benchmark torrent-file\n", stderr); - return 1; - } - - std::vector buf; - error_code ec; - int ret = load_file(argv[1], buf, ec, 40 * 1000000); - if (ret == -1) - { - std::fprintf(stderr, "file too big, aborting\n"); - return 1; - } - - if (ret != 0) - { - std::fprintf(stderr, "failed to load file: %s\n", ec.message().c_str()); - return 1; - } - - { - time_point start(clock_type::now()); - entry e; - for (int i = 0; i < 1000000; ++i) - { - int len; - e = bdecode(&buf[0], &buf[0] + buf.size(), len); -// entry& info = e["info"]; - } - time_point stop(clock_type::now()); - - std::fprintf(stderr, "(slow) bdecode done in %5d ns per message\n" - , int(total_microseconds(stop - start) / 1000)); - } - - // =============================================== - - { - time_point start(clock_type::now()); - lazy_entry e; - for (int i = 0; i < 1000000; ++i) - { - error_code ec; - lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec); -// lazy_entry* info = e.dict_find("info"); - } - time_point stop(clock_type::now()); - - std::fprintf(stderr, "lazy_bdecode done in %5d ns per message\n" - , int(total_microseconds(stop - start) / 1000)); - } - - // =============================================== - - { - time_point start(clock_type::now()); - bdecode_node e; - e.reserve(100); - for (int i = 0; i < 1000000; ++i) - { - error_code ec; - bdecode(&buf[0], &buf[0] + buf.size(), e, ec); -// bdecode_node info = e.dict_find("info"); - } - time_point stop(clock_type::now()); - - std::fprintf(stderr, "bdecode done in %5d ns per message\n" - , int(total_microseconds(stop - start) / 1000)); - } - - return 0; -} - diff --git a/test/test_ssl.cpp b/test/test_ssl.cpp index 3a1043b61..b65a36071 100644 --- a/test/test_ssl.cpp +++ b/test/test_ssl.cpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session_status.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/hex.hpp" // for to_hex, from_hex +#include "libtorrent/time.hpp" #include "test.hpp" #include "test_utils.hpp" @@ -59,6 +60,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace std::placeholders; using namespace libtorrent; using std::ignore; +namespace lt = libtorrent; int const alert_mask = alert::all_categories & ~alert::progress_notification