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