tanjent@gmail.com | f67ce94 | 2011-03-14 09:11:18 +0000 | [diff] [blame] | 1 | #include "Platform.h"
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame] | 2 | #include "Hashes.h"
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 3 | #include "KeysetTest.h"
|
| 4 | #include "SpeedTest.h"
|
| 5 | #include "AvalancheTest.h"
|
| 6 | #include "DifferentialTest.h"
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 7 |
|
tanjent@gmail.com | f67ce94 | 2011-03-14 09:11:18 +0000 | [diff] [blame] | 8 | #include <stdio.h>
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 9 | #include <time.h>
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 10 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 11 | //-----------------------------------------------------------------------------
|
| 12 | // Configuration. TODO - move these to command-line flags
|
| 13 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 14 | bool g_testAll = false;
|
| 15 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 16 | bool g_testSanity = false;
|
| 17 | bool g_testSpeed = false;
|
| 18 | bool g_testDiff = false;
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 19 | bool g_testDiffDist = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 20 | bool g_testAvalanche = false;
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 21 | bool g_testBIC = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 22 | bool g_testCyclic = false;
|
tanjent@gmail.com | 96601f2 | 2011-03-31 02:41:29 +0000 | [diff] [blame] | 23 | bool g_testTwoBytes = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 24 | bool g_testSparse = false;
|
| 25 | bool g_testPermutation = false;
|
| 26 | bool g_testWindow = false;
|
| 27 | bool g_testText = false;
|
| 28 | bool g_testZeroes = false;
|
| 29 | bool g_testSeed = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 30 |
|
tanjent@gmail.com | f67ce94 | 2011-03-14 09:11:18 +0000 | [diff] [blame] | 31 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 32 | // This is the list of all hashes that SMHasher can test.
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 33 |
|
| 34 | struct HashInfo
|
| 35 | {
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 36 | pfHash hash;
|
| 37 | int hashbits;
|
| 38 | uint32_t verification;
|
| 39 | const char * name;
|
| 40 | const char * desc;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 41 | };
|
| 42 |
|
| 43 | HashInfo g_hashes[] =
|
| 44 | {
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 45 | { DoNothingHash, 32, 0x00000000, "donothing32", "Do-Nothing function (only valid for measuring call overhead)" },
|
| 46 | { DoNothingHash, 64, 0x00000000, "donothing64", "Do-Nothing function (only valid for measuring call overhead)" },
|
| 47 | { DoNothingHash, 128, 0x00000000, "donothing128", "Do-Nothing function (only valid for measuring call overhead)" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 48 |
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 49 | { crc32, 32, 0x3719DB20, "crc32", "CRC-32" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 50 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 51 | { md5_32, 32, 0xC10C356B, "md5_32a", "MD5, first 32 bits of result" },
|
| 52 | { sha1_32a, 32, 0xF9376EA7, "sha1_32a", "SHA1, first 32 bits of result" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 53 |
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 54 | { FNV, 32, 0xE3CBBE91, "FNV", "Fowler-Noll-Vo hash, 32-bit" },
|
| 55 | { lookup3_test, 32, 0x3D83917A, "lookup3", "Bob Jenkins' lookup3" },
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 56 | { SuperFastHash, 32, 0x980ACD1D, "superfast", "Paul Hsieh's SuperFastHash" },
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 57 | { MurmurOAAT_test, 32, 0x5363BD98, "MurmurOAAT", "Murmur one-at-a-time" },
|
| 58 | { Crap8_test, 32, 0x743E97A1, "Crap8", "Crap8" },
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 59 |
|
| 60 | // MurmurHash2
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 61 |
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 62 | { MurmurHash2_test, 32, 0x27864C1E, "Murmur2", "MurmurHash2 for x86, 32-bit" },
|
| 63 | { MurmurHash2A_test, 32, 0x7FBD4396, "Murmur2A", "MurmurHash2A for x86, 32-bit" },
|
| 64 | { MurmurHash64A_test, 64, 0x1F0D3804, "Murmur2B", "MurmurHash2 for x64, 64-bit" },
|
| 65 | { MurmurHash64B_test, 64, 0xDD537C05, "Murmur2C", "MurmurHash2 for x86, 64-bit" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 66 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 67 | // MurmurHash3
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 68 |
|
tanjent@gmail.com | 2ff5e9b | 2011-04-03 06:30:51 +0000 | [diff] [blame] | 69 | { MurmurHash3_x86_32, 32, 0x3252D141, "Murmur3A", "MurmurHash3 for x86, 32-bit" },
|
tanjent@gmail.com | 0f37bbd | 2011-04-04 23:05:26 +0000 | [diff] [blame] | 70 | { MurmurHash3_x86_128, 128, 0xB3ECE62A, "Murmur3C", "MurmurHash3 for x86, 128-bit" },
|
| 71 | { MurmurHash3_x64_128, 128, 0x833607F9, "Murmur3F", "MurmurHash3 for x64, 128-bit" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 72 |
|
| 73 | };
|
| 74 |
|
| 75 | HashInfo * findHash ( const char * name )
|
| 76 | {
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 77 | for(int i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
|
| 78 | {
|
| 79 | if(_stricmp(name,g_hashes[i].name) == 0) return &g_hashes[i];
|
| 80 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 81 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 82 | return NULL;
|
| 83 | }
|
| 84 |
|
| 85 | //-----------------------------------------------------------------------------
|
| 86 | // Self-test on startup - verify that all installed hashes work correctly.
|
| 87 |
|
| 88 | void SelfTest ( void )
|
| 89 | {
|
| 90 | bool pass = true;
|
| 91 |
|
| 92 | for(int i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
|
| 93 | {
|
| 94 | HashInfo * info = & g_hashes[i];
|
| 95 |
|
| 96 | pass &= VerificationTest(info->hash,info->hashbits,info->verification,false);
|
| 97 | }
|
| 98 |
|
| 99 | if(!pass)
|
| 100 | {
|
| 101 | printf("Self-test FAILED!\n");
|
| 102 |
|
| 103 | for(int i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
|
| 104 | {
|
| 105 | HashInfo * info = & g_hashes[i];
|
| 106 |
|
| 107 | pass &= VerificationTest(info->hash,info->hashbits,info->verification,true);
|
| 108 | }
|
| 109 |
|
| 110 | exit(1);
|
| 111 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 112 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 113 |
|
| 114 | //----------------------------------------------------------------------------
|
| 115 |
|
| 116 | template < typename hashtype >
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 117 | void test ( hashfunc<hashtype> hash, HashInfo * info )
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 118 | {
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 119 | const int hashbits = sizeof(hashtype) * 8;
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 120 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 121 | printf("-------------------------------------------------------------------------------\n");
|
tanjent@gmail.com | 2ff5e9b | 2011-04-03 06:30:51 +0000 | [diff] [blame] | 122 | printf("--- Testing %s (%s)\n\n",info->name,info->desc);
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 123 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 124 | //-----------------------------------------------------------------------------
|
| 125 | // Sanity tests
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 126 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 127 | if(g_testSanity || g_testAll)
|
| 128 | {
|
| 129 | printf("[[[ Sanity Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 130 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 131 | VerificationTest(hash,hashbits,info->verification,true);
|
| 132 | SanityTest(hash,hashbits);
|
| 133 | AppendedZeroesTest(hash,hashbits);
|
| 134 | printf("\n");
|
| 135 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 136 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 137 | //-----------------------------------------------------------------------------
|
| 138 | // Speed tests
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 139 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 140 | if(g_testSpeed || g_testAll)
|
| 141 | {
|
| 142 | printf("[[[ Speed Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 143 |
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 144 | BulkSpeedTest(info->hash,info->verification);
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 145 | printf("\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 146 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 147 | for(int i = 1; i < 32; i++)
|
| 148 | {
|
| 149 | double cycles;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 150 |
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 151 | TinySpeedTest(hashfunc<hashtype>(info->hash),sizeof(hashtype),i,info->verification,true,cycles);
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 152 | }
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 153 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 154 | printf("\n");
|
| 155 | }
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 156 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 157 | //-----------------------------------------------------------------------------
|
| 158 | // Differential tests
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 159 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 160 | if(g_testDiff || g_testAll)
|
| 161 | {
|
| 162 | printf("[[[ Differential Tests ]]]\n\n");
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 163 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 164 | bool result = true;
|
| 165 | bool dumpCollisions = false;
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 166 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 167 | result &= DiffTest< Blob<64>, hashtype >(hash,5,1000,dumpCollisions);
|
| 168 | result &= DiffTest< Blob<128>, hashtype >(hash,4,1000,dumpCollisions);
|
| 169 | result &= DiffTest< Blob<256>, hashtype >(hash,3,1000,dumpCollisions);
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 170 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 171 | if(!result) printf("*********FAIL*********\n");
|
| 172 | printf("\n");
|
| 173 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 174 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 175 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 176 | // Differential-distribution tests
|
| 177 |
|
| 178 | if(g_testDiffDist /*|| g_testAll*/)
|
| 179 | {
|
| 180 | printf("[[[ Differential Distribution Tests ]]]\n\n");
|
| 181 |
|
| 182 | bool result = true;
|
| 183 |
|
| 184 | result &= DiffDistTest2<uint64_t,hashtype>(hash);
|
| 185 |
|
| 186 | printf("\n");
|
| 187 | }
|
| 188 |
|
| 189 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 190 | // Avalanche tests
|
| 191 |
|
| 192 | if(g_testAvalanche || g_testAll)
|
| 193 | {
|
| 194 | printf("[[[ Avalanche Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 195 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 196 | bool result = true;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 197 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 198 | result &= AvalancheTest< Blob< 32>, hashtype > (hash,300000);
|
| 199 | result &= AvalancheTest< Blob< 40>, hashtype > (hash,300000);
|
| 200 | result &= AvalancheTest< Blob< 48>, hashtype > (hash,300000);
|
| 201 | result &= AvalancheTest< Blob< 56>, hashtype > (hash,300000);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 202 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 203 | result &= AvalancheTest< Blob< 64>, hashtype > (hash,300000);
|
| 204 | result &= AvalancheTest< Blob< 72>, hashtype > (hash,300000);
|
| 205 | result &= AvalancheTest< Blob< 80>, hashtype > (hash,300000);
|
| 206 | result &= AvalancheTest< Blob< 88>, hashtype > (hash,300000);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 207 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 208 | result &= AvalancheTest< Blob< 96>, hashtype > (hash,300000);
|
| 209 | result &= AvalancheTest< Blob<104>, hashtype > (hash,300000);
|
| 210 | result &= AvalancheTest< Blob<112>, hashtype > (hash,300000);
|
| 211 | result &= AvalancheTest< Blob<120>, hashtype > (hash,300000);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 212 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 213 | result &= AvalancheTest< Blob<128>, hashtype > (hash,300000);
|
| 214 | result &= AvalancheTest< Blob<136>, hashtype > (hash,300000);
|
| 215 | result &= AvalancheTest< Blob<144>, hashtype > (hash,300000);
|
| 216 | result &= AvalancheTest< Blob<152>, hashtype > (hash,300000);
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 217 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 218 | if(!result) printf("*********FAIL*********\n");
|
| 219 | printf("\n");
|
| 220 | }
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 221 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 222 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 223 | // Bit Independence Criteria. Interesting, but doesn't tell us much about
|
| 224 | // collision or distribution.
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 225 |
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 226 | if(g_testBIC)
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 227 | {
|
| 228 | printf("[[[ Bit Independence Criteria ]]]\n\n");
|
| 229 |
|
| 230 | bool result = true;
|
| 231 |
|
| 232 | //result &= BicTest<uint64_t,hashtype>(hash,2000000);
|
| 233 | BicTest3<Blob<88>,hashtype>(hash,2000000);
|
| 234 |
|
| 235 | if(!result) printf("*********FAIL*********\n");
|
| 236 | printf("\n");
|
| 237 | }
|
| 238 |
|
| 239 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 240 | // Keyset 'Cyclic' - keys of the form "abcdabcdabcd..."
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame] | 241 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 242 | if(g_testCyclic || g_testAll)
|
| 243 | {
|
| 244 | printf("[[[ Keyset 'Cyclic' Tests ]]]\n\n");
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 245 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 246 | bool result = true;
|
| 247 | bool drawDiagram = false;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 248 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 249 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+0,8,10000000,drawDiagram);
|
| 250 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+1,8,10000000,drawDiagram);
|
| 251 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+2,8,10000000,drawDiagram);
|
| 252 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+3,8,10000000,drawDiagram);
|
| 253 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+4,8,10000000,drawDiagram);
|
| 254 |
|
| 255 | if(!result) printf("*********FAIL*********\n");
|
| 256 | printf("\n");
|
| 257 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 258 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 259 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 260 | // Keyset 'TwoBytes' - all keys up to N bytes containing two non-zero bytes
|
tanjent@gmail.com | 96601f2 | 2011-03-31 02:41:29 +0000 | [diff] [blame] | 261 |
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 262 | // This generates some huge keysets, 128-bit tests will take ~1.3 gigs of RAM.
|
| 263 |
|
| 264 | if(g_testTwoBytes || g_testAll)
|
tanjent@gmail.com | 96601f2 | 2011-03-31 02:41:29 +0000 | [diff] [blame] | 265 | {
|
| 266 | printf("[[[ Keyset 'TwoBytes' Tests ]]]\n\n");
|
| 267 |
|
| 268 | bool result = true;
|
| 269 | bool drawDiagram = false;
|
| 270 |
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 271 | for(int i = 4; i <= 20; i += 4)
|
| 272 | {
|
| 273 | result &= TwoBytesTest2<hashtype>(hash,i,drawDiagram);
|
| 274 | }
|
tanjent@gmail.com | 96601f2 | 2011-03-31 02:41:29 +0000 | [diff] [blame] | 275 |
|
| 276 | if(!result) printf("*********FAIL*********\n");
|
| 277 | printf("\n");
|
| 278 | }
|
| 279 |
|
| 280 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 281 | // Keyset 'Sparse' - keys with all bits 0 except a few
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 282 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 283 | if(g_testSparse || g_testAll)
|
| 284 | {
|
| 285 | printf("[[[ Keyset 'Sparse' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 286 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 287 | bool result = true;
|
| 288 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 289 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 290 | result &= SparseKeyTest< 32,hashtype>(hash,6,true,true,true,drawDiagram);
|
| 291 | result &= SparseKeyTest< 40,hashtype>(hash,6,true,true,true,drawDiagram);
|
| 292 | result &= SparseKeyTest< 48,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 293 | result &= SparseKeyTest< 56,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 294 | result &= SparseKeyTest< 64,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 295 | result &= SparseKeyTest< 96,hashtype>(hash,4,true,true,true,drawDiagram);
|
| 296 | result &= SparseKeyTest< 256,hashtype>(hash,3,true,true,true,drawDiagram);
|
| 297 | result &= SparseKeyTest<2048,hashtype>(hash,2,true,true,true,drawDiagram);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 298 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 299 | if(!result) printf("*********FAIL*********\n");
|
| 300 | printf("\n");
|
| 301 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 302 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 303 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 304 | // Keyset 'Permutation' - all possible combinations of a set of blocks
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 305 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 306 | if(g_testPermutation || g_testAll)
|
| 307 | {
|
| 308 | {
|
| 309 | // This one breaks lookup3, surprisingly
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 310 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 311 | printf("[[[ Keyset 'Combination Lowbits' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 312 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 313 | bool result = true;
|
| 314 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 315 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 316 | uint32_t blocks[] =
|
| 317 | {
|
| 318 | 0x00000000,
|
| 319 |
|
| 320 | 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007,
|
| 321 | };
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 322 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 323 | result &= CombinationKeyTest<hashtype>(hash,8,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 324 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 325 | if(!result) printf("*********FAIL*********\n");
|
| 326 | printf("\n");
|
| 327 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 328 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 329 | {
|
| 330 | printf("[[[ Keyset 'Combination Highbits' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 331 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 332 | bool result = true;
|
| 333 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 334 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 335 | uint32_t blocks[] =
|
| 336 | {
|
| 337 | 0x00000000,
|
| 338 |
|
| 339 | 0x20000000, 0x40000000, 0x60000000, 0x80000000, 0xA0000000, 0xC0000000, 0xE0000000
|
| 340 | };
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 341 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 342 | result &= CombinationKeyTest<hashtype>(hash,8,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 343 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 344 | if(!result) printf("*********FAIL*********\n");
|
| 345 | printf("\n");
|
| 346 | }
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 347 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 348 | {
|
| 349 | printf("[[[ Keyset 'Combination 0x8000000' Tests ]]]\n\n");
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 350 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 351 | bool result = true;
|
| 352 | bool drawDiagram = false;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 353 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 354 | uint32_t blocks[] =
|
| 355 | {
|
| 356 | 0x00000000,
|
| 357 |
|
| 358 | 0x80000000,
|
| 359 | };
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 360 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 361 | result &= CombinationKeyTest<hashtype>(hash,20,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 362 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 363 | if(!result) printf("*********FAIL*********\n");
|
| 364 | printf("\n");
|
| 365 | }
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 366 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 367 | {
|
| 368 | printf("[[[ Keyset 'Combination 0x0000001' Tests ]]]\n\n");
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 369 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 370 | bool result = true;
|
| 371 | bool drawDiagram = false;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 372 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 373 | uint32_t blocks[] =
|
| 374 | {
|
| 375 | 0x00000000,
|
| 376 |
|
| 377 | 0x00000001,
|
| 378 | };
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 379 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 380 | result &= CombinationKeyTest<hashtype>(hash,20,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 381 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 382 | if(!result) printf("*********FAIL*********\n");
|
| 383 | printf("\n");
|
| 384 | }
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 385 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 386 | {
|
| 387 | printf("[[[ Keyset 'Combination Hi-Lo' Tests ]]]\n\n");
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 388 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 389 | bool result = true;
|
| 390 | bool drawDiagram = false;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 391 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 392 | uint32_t blocks[] =
|
| 393 | {
|
| 394 | 0x00000000,
|
| 395 |
|
| 396 | 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007,
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 397 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 398 | 0x80000000, 0x40000000, 0xC0000000, 0x20000000, 0xA0000000, 0x60000000, 0xE0000000
|
| 399 | };
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 400 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 401 | result &= CombinationKeyTest<hashtype>(hash,6,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 402 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 403 | if(!result) printf("*********FAIL*********\n");
|
| 404 | printf("\n");
|
| 405 | }
|
| 406 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 407 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 408 | //-----------------------------------------------------------------------------
|
| 409 | // Keyset 'Window'
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 410 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 411 | // Skip distribution test for these - they're too easy to distribute well,
|
| 412 | // and it generates a _lot_ of testing
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 413 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 414 | if(g_testWindow || g_testAll)
|
| 415 | {
|
| 416 | printf("[[[ Keyset 'Window' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 417 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 418 | bool result = true;
|
| 419 | bool testCollision = true;
|
| 420 | bool testDistribution = false;
|
| 421 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 422 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 423 | result &= WindowedKeyTest< Blob<hashbits*2>, hashtype > ( hash, 20, testCollision, testDistribution, drawDiagram );
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 424 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 425 | if(!result) printf("*********FAIL*********\n");
|
| 426 | printf("\n");
|
| 427 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 428 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 429 | //-----------------------------------------------------------------------------
|
| 430 | // Keyset 'Text'
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 431 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 432 | if(g_testText || g_testAll)
|
| 433 | {
|
| 434 | printf("[[[ Keyset 'Text' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 435 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 436 | bool result = true;
|
| 437 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 438 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 439 | const char * alnum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 440 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 441 | result &= TextKeyTest( hash, "Foo", alnum,4, "Bar", drawDiagram );
|
| 442 | result &= TextKeyTest( hash, "FooBar", alnum,4, "", drawDiagram );
|
| 443 | result &= TextKeyTest( hash, "", alnum,4, "FooBar", drawDiagram );
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 444 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 445 | if(!result) printf("*********FAIL*********\n");
|
| 446 | printf("\n");
|
| 447 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 448 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 449 | //-----------------------------------------------------------------------------
|
| 450 | // Keyset 'Zeroes'
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 451 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 452 | if(g_testZeroes || g_testAll)
|
| 453 | {
|
| 454 | printf("[[[ Keyset 'Zeroes' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 455 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 456 | bool result = true;
|
| 457 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 458 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 459 | result &= ZeroKeyTest<hashtype>( hash, drawDiagram );
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 460 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 461 | if(!result) printf("*********FAIL*********\n");
|
| 462 | printf("\n");
|
| 463 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 464 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 465 | //-----------------------------------------------------------------------------
|
| 466 | // Keyset 'Seed'
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 467 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 468 | if(g_testSeed || g_testAll)
|
| 469 | {
|
| 470 | printf("[[[ Keyset 'Seed' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 471 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 472 | bool result = true;
|
| 473 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 474 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 475 | result &= SeedTest<hashtype>( hash, 1000000, drawDiagram );
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 476 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 477 | if(!result) printf("*********FAIL*********\n");
|
| 478 | printf("\n");
|
| 479 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 480 | }
|
| 481 |
|
| 482 | //-----------------------------------------------------------------------------
|
| 483 |
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 484 | uint32_t g_inputVCode = 1;
|
| 485 | uint32_t g_outputVCode = 1;
|
| 486 | uint32_t g_resultVCode = 1;
|
| 487 |
|
| 488 | HashInfo * g_hashUnderTest = NULL;
|
| 489 |
|
| 490 | void VerifyHash ( const void * key, int len, uint32_t seed, void * out )
|
| 491 | {
|
| 492 | g_inputVCode = MurmurOAAT(key,len,g_inputVCode);
|
| 493 | g_inputVCode = MurmurOAAT(&seed,sizeof(uint32_t),g_inputVCode);
|
| 494 |
|
| 495 | g_hashUnderTest->hash(key,len,seed,out);
|
| 496 |
|
| 497 | g_outputVCode = MurmurOAAT(out,g_hashUnderTest->hashbits/8,g_outputVCode);
|
| 498 | }
|
| 499 |
|
| 500 | //-----------------------------------------------------------------------------
|
| 501 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 502 | void testHash ( const char * name )
|
| 503 | {
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 504 | HashInfo * pInfo = findHash(name);
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 505 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 506 | if(pInfo == NULL)
|
| 507 | {
|
| 508 | printf("Invalid hash '%s' specified\n",name);
|
| 509 | return;
|
| 510 | }
|
| 511 | else
|
| 512 | {
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 513 | g_hashUnderTest = pInfo;
|
| 514 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 515 | if(pInfo->hashbits == 32)
|
| 516 | {
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 517 | test<uint32_t>( VerifyHash, pInfo );
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 518 | }
|
| 519 | else if(pInfo->hashbits == 64)
|
| 520 | {
|
| 521 | test<uint64_t>( pInfo->hash, pInfo );
|
| 522 | }
|
| 523 | else if(pInfo->hashbits == 128)
|
| 524 | {
|
| 525 | test<uint128_t>( pInfo->hash, pInfo );
|
| 526 | }
|
| 527 | else if(pInfo->hashbits == 256)
|
| 528 | {
|
| 529 | test<uint256_t>( pInfo->hash, pInfo );
|
| 530 | }
|
| 531 | else
|
| 532 | {
|
| 533 | printf("Invalid hash bit width %d for hash '%s'",pInfo->hashbits,pInfo->name);
|
| 534 | }
|
| 535 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 536 | }
|
| 537 | //-----------------------------------------------------------------------------
|
| 538 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 539 | int main ( int argc, char ** argv )
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 540 | {
|
tanjent@gmail.com | 2ff5e9b | 2011-04-03 06:30:51 +0000 | [diff] [blame] | 541 | const char * hashToTest = "murmur3a";
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 542 |
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 543 | if(argc < 2)
|
| 544 | {
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 545 | printf("(No test hash given on command line, testing Murmur3_x86_32.)\n");
|
| 546 | }
|
| 547 | else
|
| 548 | {
|
| 549 | hashToTest = argv[1];
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 550 | }
|
| 551 |
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 552 | SetAffinity(3);
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 553 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 554 | SelfTest();
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 555 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 556 | int timeBegin = clock();
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 557 |
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 558 | g_testAll = true;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 559 |
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 560 | //g_testSanity = true;
|
| 561 | //g_testSpeed = true;
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 562 | //g_testAvalanche = true;
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 563 | //g_testBIC = true;
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 564 | //g_testCyclic = true;
|
tanjent@gmail.com | 96601f2 | 2011-03-31 02:41:29 +0000 | [diff] [blame] | 565 | //g_testTwoBytes = true;
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 566 | //g_testDiff = true;
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 567 | //g_testDiffDist = true;
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 568 | //g_testSparse = true;
|
| 569 | //g_testPermutation = true;
|
tanjent@gmail.com | 603c878 | 2011-04-01 08:50:06 +0000 | [diff] [blame] | 570 | //g_testWindow = true;
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 571 | //g_testZeroes = true;
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 572 |
|
tanjent@gmail.com | 623590d | 2011-03-28 18:19:31 +0000 | [diff] [blame] | 573 | testHash(hashToTest);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 574 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 575 | //----------
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 576 |
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 577 | int timeEnd = clock();
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 578 |
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame] | 579 | printf("\n");
|
aappleby@google.com | 7f20a31 | 2011-03-21 20:55:06 +0000 | [diff] [blame] | 580 | printf("Input vcode 0x%08x, Output vcode 0x%08x, Result vcode 0x%08x\n",g_inputVCode,g_outputVCode,g_resultVCode);
|
tanjent@gmail.com | 3ee4561 | 2011-03-21 19:33:01 +0000 | [diff] [blame] | 581 | printf("Verification value is 0x%08x - Testing took %f seconds\n",g_verify,double(timeEnd-timeBegin)/double(CLOCKS_PER_SEC));
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame] | 582 | printf("-------------------------------------------------------------------------------\n");
|
tanjent@gmail.com | 6ffe010 | 2011-03-19 21:28:26 +0000 | [diff] [blame] | 583 | return 0;
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame] | 584 | }
|