diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-04-13 09:54:05 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-04-13 10:13:13 -0700 |
commit | b7365f0545b1a6862e3277b2b2139ee0d5aee1cf (patch) | |
tree | e28b9adb622f0e7ee1ec89d125ed7d7f71b069e7 /src/test | |
parent | eab00d96dfe93db894358787e1b34252d8c23206 (diff) | |
parent | f9c88079df8b78b8fab75e0903ca395654f2d360 (diff) |
Merge #9480: De-duplicate SignatureCacheHasher
f9c8807 Deduplicate SignatureCacheHasher (Jeremy Rubin)
Tree-SHA512: 714a0f39d1c836fedd1868369b4ebf1096cd800cc544d57b54101da338c80c627a3e59c6644b3268054efe85053cf1a7be508af935f624491e7acfae61123994
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/cuckoocache_tests.cpp | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/test/cuckoocache_tests.cpp b/src/test/cuckoocache_tests.cpp index ccd7155627..8cae4e66e8 100644 --- a/src/test/cuckoocache_tests.cpp +++ b/src/test/cuckoocache_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <boost/test/unit_test.hpp> #include "cuckoocache.h" +#include "script/sigcache.h" #include "test/test_bitcoin.h" #include "random.h" #include <thread> @@ -36,20 +37,6 @@ void insecure_GetRandHash(uint256& t) *(ptr++) = insecure_rand.rand32(); } -/** Definition copied from /src/script/sigcache.cpp - */ -class uint256Hasher -{ -public: - template <uint8_t hash_select> - uint32_t operator()(const uint256& key) const - { - static_assert(hash_select <8, "SignatureCacheHasher only has 8 hashes available."); - uint32_t u; - std::memcpy(&u, key.begin() + 4 * hash_select, 4); - return u; - } -}; /* Test that no values not inserted into the cache are read out of it. @@ -59,7 +46,7 @@ public: BOOST_AUTO_TEST_CASE(test_cuckoocache_no_fakes) { insecure_rand = FastRandomContext(true); - CuckooCache::cache<uint256, uint256Hasher> cc{}; + CuckooCache::cache<uint256, SignatureCacheHasher> cc{}; size_t megabytes = 4; cc.setup_bytes(megabytes << 20); uint256 v; @@ -138,7 +125,7 @@ BOOST_AUTO_TEST_CASE(cuckoocache_hit_rate_ok) double HitRateThresh = 0.98; size_t megabytes = 4; for (double load = 0.1; load < 2; load *= 2) { - double hits = test_cache<CuckooCache::cache<uint256, uint256Hasher>>(megabytes, load); + double hits = test_cache<CuckooCache::cache<uint256, SignatureCacheHasher>>(megabytes, load); BOOST_CHECK(normalize_hit_rate(hits, load) > HitRateThresh); } } @@ -206,7 +193,7 @@ void test_cache_erase(size_t megabytes) BOOST_AUTO_TEST_CASE(cuckoocache_erase_ok) { size_t megabytes = 4; - test_cache_erase<CuckooCache::cache<uint256, uint256Hasher>>(megabytes); + test_cache_erase<CuckooCache::cache<uint256, SignatureCacheHasher>>(megabytes); } template <typename Cache> @@ -293,7 +280,7 @@ void test_cache_erase_parallel(size_t megabytes) BOOST_AUTO_TEST_CASE(cuckoocache_erase_parallel_ok) { size_t megabytes = 4; - test_cache_erase_parallel<CuckooCache::cache<uint256, uint256Hasher>>(megabytes); + test_cache_erase_parallel<CuckooCache::cache<uint256, SignatureCacheHasher>>(megabytes); } @@ -389,7 +376,7 @@ void test_cache_generations() } BOOST_AUTO_TEST_CASE(cuckoocache_generations) { - test_cache_generations<CuckooCache::cache<uint256, uint256Hasher>>(); + test_cache_generations<CuckooCache::cache<uint256, SignatureCacheHasher>>(); } BOOST_AUTO_TEST_SUITE_END(); |