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