add unit test for crc32c and fix cpuid warning

This commit is contained in:
Arvid Norberg 2014-11-10 02:05:46 +00:00
parent e526355d24
commit f7221e277f
5 changed files with 73 additions and 1 deletions

View File

@ -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

View File

@ -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
}
}

View File

@ -90,6 +90,7 @@ feature launcher : none valgrind : composite ;
feature.compose <launcher>valgrind : <testing.launcher>"valgrind --tool=memcheck -v --num-callers=20 --read-var-info=yes --track-origins=yes --error-exitcode=222 --suppressions=valgrind_suppressions.txt" <use-valgrind>on ;
test-suite libtorrent :
[ run test_crc32.cpp ]
[ run test_resume.cpp ]
[ run test_sliding_average.cpp ]
[ run test_socket_io.cpp ]

View File

@ -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

65
test/test_crc32.cpp Normal file
View File

@ -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;
}