diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index b65e33c71..0818067c8 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -629,6 +629,8 @@ int snprintf(char* buf, int len, char const* fmt, ...) // GCC requires the user to enable SSE support in order for // the program to have access to the intrinsics, this is // indicated by the __SSE4_1__ macro +#ifndef TORRENT_HAS_SSE + #if (defined _M_AMD64 || defined _M_IX86 || defined _M_X64 \ || defined __amd64__ || defined __i386 || defined __i386__ \ || defined __x86_64__ || defined __x86_64) \ @@ -638,6 +640,8 @@ int snprintf(char* buf, int len, char const* fmt, ...) #define TORRENT_HAS_SSE 0 #endif +#endif // TORRENT_HAS_SSE + #endif // TORRENT_CONFIG_HPP_INCLUDED diff --git a/include/libtorrent/cpuid.hpp b/include/libtorrent/cpuid.hpp index 768170c1b..a4174e56a 100644 --- a/include/libtorrent/cpuid.hpp +++ b/include/libtorrent/cpuid.hpp @@ -54,7 +54,7 @@ namespace libtorrent : "a" (type), "c" (0)); #else // for non-x86 and non-amd64, just return zeroes - std::memset(info, 0, sizeof(info)); + std::memset(&info[0], 0, sizeof(unsigned int) * 4); #endif } } diff --git a/test/Jamfile b/test/Jamfile index f1b996be9..b5c924601 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -90,6 +90,7 @@ feature launcher : none valgrind : composite ; feature.compose valgrind : "valgrind --tool=memcheck -v --num-callers=20 --read-var-info=yes --track-origins=yes --error-exitcode=222 --suppressions=valgrind_suppressions.txt" on ; test-suite libtorrent : + [ run test_crc32.cpp ] [ run test_resume.cpp ] [ run test_sliding_average.cpp ] [ run test_socket_io.cpp ] diff --git a/test/Makefile.am b/test/Makefile.am index 88393d2f0..ac3a28a5b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,6 +2,7 @@ AUTOMAKE_OPTIONS = subdir-objects test_programs = \ test_bitfield \ + test_crc32 \ test_torrent_info \ test_recheck \ test_stat_cache \ @@ -135,6 +136,7 @@ libtest_la_SOURCES = main.cpp \ swarm_suite.cpp test_bitfield_SOURCES = test_bitfield.cpp +test_crc32_SOURCES = test_crc32.cpp test_torrent_info_SOURCES = test_torrent_info.cpp test_recheck_SOURCES = test_recheck.cpp test_stat_cache_SOURCES = test_stat_cache.cpp diff --git a/test/test_crc32.cpp b/test/test_crc32.cpp new file mode 100644 index 000000000..aa6dadb2a --- /dev/null +++ b/test/test_crc32.cpp @@ -0,0 +1,65 @@ +/* + +Copyright (c) 2014, 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/crc32c.hpp" +#include "test.hpp" + +int test_main() +{ + using namespace libtorrent; + + boost::uint32_t out; + + boost::uint32_t in1 = 0x5aa5feef; + out = crc32c_32(in1); + + TEST_EQUAL(out, htonl(0xd5b9e35e)); + + boost::uint64_t buf[4]; + memcpy(buf, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32); + + out = crc32c(buf, 4); + TEST_EQUAL(out, htonl(0xaa36918a)); + + memcpy(buf, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 32); + out = crc32c(buf, 4); + TEST_EQUAL(out, htonl(0x43aba862)); + + memcpy(buf, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32); + out = crc32c(buf, 4); + TEST_EQUAL(out, htonl(0x4e79dd46)); + return 0; +} +