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 |
|
| 11 | bool g_testAll = false;
|
| 12 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 13 | bool g_testSanity = false;
|
| 14 | bool g_testSpeed = false;
|
| 15 | bool g_testDiff = false;
|
| 16 | bool g_testAvalanche = false;
|
| 17 | bool g_testCyclic = false;
|
| 18 | bool g_testSparse = false;
|
| 19 | bool g_testPermutation = false;
|
| 20 | bool g_testWindow = false;
|
| 21 | bool g_testText = false;
|
| 22 | bool g_testZeroes = false;
|
| 23 | bool g_testSeed = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 24 |
|
tanjent@gmail.com | f67ce94 | 2011-03-14 09:11:18 +0000 | [diff] [blame] | 25 | //-----------------------------------------------------------------------------
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 26 |
|
| 27 | int64_t g_hashcount = 0;
|
| 28 | int64_t g_bytecount = 0;
|
| 29 |
|
| 30 | void counterhash ( const void * , const int len, const uint32_t , void * out )
|
| 31 | {
|
| 32 | g_hashcount++;
|
| 33 | g_bytecount += len;
|
| 34 |
|
| 35 | *(uint32_t*)out = rand_u32();
|
| 36 | }
|
| 37 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 38 | //-----------------------------------------------------------------------------
|
| 39 |
|
| 40 | struct HashInfo
|
| 41 | {
|
| 42 | pfHash hash;
|
| 43 | int hashbits;
|
| 44 | const char * name;
|
| 45 | const char * desc;
|
| 46 | };
|
| 47 |
|
| 48 | HashInfo g_hashes[] =
|
| 49 | {
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 50 | { counterhash, 32, "count", "Counts how many times the hash function is called" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 51 | { randhash_32, 32, "rand32", "Random number generator, 32-bit" },
|
| 52 | { randhash_64, 64, "rand64", "Random number generator, 64-bit" },
|
| 53 | { randhash_128, 128, "rand128", "Random number generator, 128-bit" },
|
| 54 |
|
| 55 | { crc32, 32, "crc32", "CRC-32" },
|
| 56 | { DoNothingHash, 32, "donothing32", "Do-Nothing Function (only valid for speed test comparison)" },
|
| 57 |
|
| 58 | { md5_32, 32, "md5_32a", "MD5, first 32 bits of result" },
|
| 59 | { sha1_32a, 32, "sha1_32a", "SHA1, first 32 bits of result" },
|
| 60 |
|
| 61 | { FNV, 32, "FNV", "Fowler-Noll-Vo hash, 32-bit" },
|
| 62 | { lookup3_test, 32, "lookup3", "Bob Jenkins' lookup3" },
|
| 63 | { SuperFastHash, 32, "superfast", "Paul Hsieh's SuperFastHash" },
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 64 | { MurmurOAAT, 32, "MurmurOAAT", "Murmur one-at-a-time" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 65 |
|
| 66 | // MurmurHash2
|
| 67 |
|
| 68 | { MurmurHash2_test, 32, "Murmur2", "MurmurHash2 for x86, 32-bit" },
|
| 69 | { MurmurHash2A_test, 32, "Murmur2A", "MurmurHash2A for x86, 32-bit" },
|
| 70 | { MurmurHash64A_test, 64, "Murmur2B", "MurmurHash2 for x64, 64-bit" },
|
| 71 | { MurmurHash64B_test, 64, "Murmur2C", "MurmurHash2 for x86, 64-bit" },
|
| 72 |
|
| 73 | // MurmurHash3
|
| 74 |
|
| 75 | { MurmurHash3_x86_32, 32, "Murmur3A", "MurmurHash3 for x86, 32-bit" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 76 | { MurmurHash3_x86_128, 128, "Murmur3C", "MurmurHash3 for x86, 128-bit" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 77 | { MurmurHash3_x64_128, 128, "Murmur3F", "MurmurHash3 for x64, 128-bit" },
|
| 78 |
|
| 79 | };
|
| 80 |
|
| 81 | HashInfo * findHash ( const char * name )
|
| 82 | {
|
| 83 | for(int i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
|
| 84 | {
|
| 85 | if(_stricmp(name,g_hashes[i].name) == 0) return &g_hashes[i];
|
| 86 | }
|
| 87 |
|
| 88 | return NULL;
|
| 89 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 90 |
|
| 91 | //----------------------------------------------------------------------------
|
| 92 |
|
| 93 | template < typename hashtype >
|
| 94 | void test ( hashfunc<hashtype> hash, const char * hashname )
|
| 95 | {
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 96 | const int hashbits = sizeof(hashtype) * 8;
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 97 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 98 | printf("-------------------------------------------------------------------------------\n");
|
| 99 | printf("--- Testing %s\n\n",hashname);
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 100 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 101 | //-----------------------------------------------------------------------------
|
| 102 | // Sanity tests
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 103 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 104 | if(g_testSanity || g_testAll)
|
| 105 | {
|
| 106 | printf("[[[ Sanity Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 107 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 108 | QuickBrownFox(hash,hashbits);
|
| 109 | SanityTest(hash,hashbits);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 110 | AppendedZeroesTest(hash,hashbits);
|
| 111 | printf("\n");
|
| 112 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 113 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 114 | //-----------------------------------------------------------------------------
|
| 115 | // Speed tests
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 116 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 117 | if(g_testSpeed || g_testAll)
|
| 118 | {
|
| 119 | printf("[[[ Speed Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 120 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 121 | BulkSpeedTest(hash);
|
| 122 | printf("\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 123 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 124 | for(int i = 1; i < 32; i++)
|
| 125 | {
|
| 126 | double cycles;
|
| 127 |
|
| 128 | TinySpeedTest(hash,sizeof(hashtype),i,true,cycles);
|
| 129 | }
|
| 130 |
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 131 | /*
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 132 | for(int i = 32; i <= 2048; i += 32)
|
| 133 | {
|
| 134 | double cycles;
|
| 135 |
|
| 136 |
|
| 137 | TinySpeedTest(hash,sizeof(hashtype),i,true,cycles);
|
| 138 | }
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 139 | */
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 140 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 141 | printf("\n");
|
| 142 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 143 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 144 | //-----------------------------------------------------------------------------
|
| 145 | // Differential tests
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 146 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 147 | if(g_testDiff || g_testAll)
|
| 148 | {
|
| 149 | printf("[[[ Differential Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 150 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 151 | bool result = true;
|
| 152 | bool dumpCollisions = false;
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 153 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 154 | result &= DiffTest< Blob<64>, hashtype >(hash,5,1000,dumpCollisions);
|
| 155 | result &= DiffTest< Blob<128>, hashtype >(hash,4,1000,dumpCollisions);
|
| 156 | result &= DiffTest< Blob<256>, hashtype >(hash,3,1000,dumpCollisions);
|
| 157 |
|
| 158 | if(!result) printf("*********FAIL*********\n");
|
| 159 | printf("\n");
|
| 160 | }
|
| 161 |
|
| 162 | //-----------------------------------------------------------------------------
|
| 163 | // Avalanche tests.
|
| 164 |
|
| 165 | // 2 million reps is enough to measure bias down to ~0.25%
|
| 166 |
|
| 167 | if(g_testAvalanche || g_testAll)
|
| 168 | {
|
| 169 | printf("[[[ Avalanche Tests ]]]\n\n");
|
| 170 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 171 | //const int hashbits = sizeof(hashtype) * 8;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 172 | bool result = true;
|
| 173 |
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 174 | /*
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 175 | result &= AvalancheTest< Blob< 32>, hashtype > (hash,300000);
|
| 176 | result &= AvalancheTest< Blob< 40>, hashtype > (hash,300000);
|
| 177 | result &= AvalancheTest< Blob< 48>, hashtype > (hash,300000);
|
| 178 | result &= AvalancheTest< Blob< 56>, hashtype > (hash,300000);
|
| 179 |
|
| 180 | result &= AvalancheTest< Blob< 64>, hashtype > (hash,300000);
|
| 181 | result &= AvalancheTest< Blob< 72>, hashtype > (hash,300000);
|
| 182 | result &= AvalancheTest< Blob< 80>, hashtype > (hash,300000);
|
| 183 | result &= AvalancheTest< Blob< 88>, hashtype > (hash,300000);
|
| 184 | result &= AvalancheTest< Blob< 96>, hashtype > (hash,300000);
|
| 185 | result &= AvalancheTest< Blob<104>, hashtype > (hash,300000);
|
| 186 | result &= AvalancheTest< Blob<112>, hashtype > (hash,300000);
|
| 187 | result &= AvalancheTest< Blob<120>, hashtype > (hash,300000);
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 188 | */
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 189 |
|
| 190 | result &= AvalancheTest< Blob<128>, hashtype > (hash,300000);
|
| 191 | result &= AvalancheTest< Blob<136>, hashtype > (hash,300000);
|
| 192 | result &= AvalancheTest< Blob<144>, hashtype > (hash,300000);
|
| 193 | result &= AvalancheTest< Blob<152>, hashtype > (hash,300000);
|
| 194 | result &= AvalancheTest< Blob<160>, hashtype > (hash,300000);
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 195 |
|
| 196 | /*
|
| 197 | result &= AvalancheTest< Blob<168>, hashtype > (hash,300000);
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 198 | result &= AvalancheTest< Blob<176>, hashtype > (hash,300000);
|
| 199 | result &= AvalancheTest< Blob<184>, hashtype > (hash,300000);
|
| 200 | result &= AvalancheTest< Blob<192>, hashtype > (hash,300000);
|
| 201 | result &= AvalancheTest< Blob<200>, hashtype > (hash,300000);
|
| 202 | result &= AvalancheTest< Blob<208>, hashtype > (hash,300000);
|
| 203 | result &= AvalancheTest< Blob<216>, hashtype > (hash,300000);
|
| 204 | result &= AvalancheTest< Blob<224>, hashtype > (hash,300000);
|
| 205 | result &= AvalancheTest< Blob<232>, hashtype > (hash,300000);
|
| 206 | result &= AvalancheTest< Blob<240>, hashtype > (hash,300000);
|
| 207 | result &= AvalancheTest< Blob<248>, hashtype > (hash,300000);
|
| 208 |
|
| 209 | result &= AvalancheTest< Blob<256>, hashtype > (hash,300000);
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 210 | */
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 211 |
|
| 212 | //result &= AvalancheTest< Blob<hashbits * 2>, hashtype > (hash,200000);
|
| 213 | //result &= AvalancheTest< Blob<768>, hashtype > (hash,2000000);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 214 |
|
| 215 | // The bit independence test is slow and not particularly useful...
|
| 216 | //result &= BicTest < Blob<hashbits * 2>, hashtype > ( hash, 1000000 );
|
| 217 |
|
| 218 | if(!result) printf("*********FAIL*********\n");
|
| 219 | printf("\n");
|
| 220 | }
|
| 221 |
|
| 222 | //-----------------------------------------------------------------------------
|
| 223 | // Keyset 'Cyclic'
|
| 224 |
|
| 225 | if(g_testCyclic || g_testAll)
|
| 226 | {
|
| 227 | printf("[[[ Keyset 'Cyclic' Tests ]]]\n\n");
|
| 228 |
|
| 229 | bool result = true;
|
| 230 | bool drawDiagram = false;
|
| 231 |
|
| 232 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+0,8,10000000,drawDiagram);
|
| 233 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+1,8,10000000,drawDiagram);
|
| 234 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+2,8,10000000,drawDiagram);
|
| 235 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+3,8,10000000,drawDiagram);
|
| 236 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+4,8,10000000,drawDiagram);
|
| 237 |
|
| 238 | if(!result) printf("*********FAIL*********\n");
|
| 239 | printf("\n");
|
| 240 | }
|
| 241 |
|
| 242 | //-----------------------------------------------------------------------------
|
| 243 | // Keyset 'Sparse'
|
| 244 |
|
| 245 | if(g_testSparse || g_testAll)
|
| 246 | {
|
| 247 | printf("[[[ Keyset 'Sparse' Tests ]]]\n\n");
|
| 248 |
|
| 249 | bool result = true;
|
| 250 | bool drawDiagram = false;
|
| 251 |
|
| 252 | result &= SparseKeyTest< 32,hashtype>(hash,6,true,true,true,drawDiagram);
|
| 253 | result &= SparseKeyTest< 40,hashtype>(hash,6,true,true,true,drawDiagram);
|
| 254 | result &= SparseKeyTest< 48,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 255 | result &= SparseKeyTest< 56,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 256 | result &= SparseKeyTest< 64,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 257 | result &= SparseKeyTest< 96,hashtype>(hash,4,true,true,true,drawDiagram);
|
| 258 | result &= SparseKeyTest< 256,hashtype>(hash,3,true,true,true,drawDiagram);
|
| 259 | result &= SparseKeyTest<2048,hashtype>(hash,2,true,true,true,drawDiagram);
|
| 260 |
|
| 261 | if(!result) printf("*********FAIL*********\n");
|
| 262 | printf("\n");
|
| 263 | }
|
| 264 |
|
| 265 | //-----------------------------------------------------------------------------
|
| 266 | // Keyset 'Permutation'
|
| 267 |
|
| 268 | if(g_testPermutation || g_testAll)
|
| 269 | {
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 270 | {
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 271 | // This one breaks lookup3, surprisingly
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 272 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 273 | printf("[[[ Keyset 'Combination Lowbits' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 274 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 275 | bool result = true;
|
| 276 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 277 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 278 | uint32_t blocks[] =
|
| 279 | {
|
| 280 | 0x00000000,
|
| 281 |
|
| 282 | 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007,
|
| 283 | };
|
| 284 |
|
| 285 | result &= CombinationKeyTest<hashtype>(hash,8,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 286 |
|
| 287 | if(!result) printf("*********FAIL*********\n");
|
| 288 | printf("\n");
|
| 289 | }
|
| 290 |
|
| 291 | {
|
| 292 | printf("[[[ Keyset 'Combination Highbits' Tests ]]]\n\n");
|
| 293 |
|
| 294 | bool result = true;
|
| 295 | bool drawDiagram = false;
|
| 296 |
|
| 297 | uint32_t blocks[] =
|
| 298 | {
|
| 299 | 0x00000000,
|
| 300 |
|
| 301 | 0x20000000, 0x40000000, 0x60000000, 0x80000000, 0xA0000000, 0xC0000000, 0xE0000000
|
| 302 | };
|
| 303 |
|
| 304 | result &= CombinationKeyTest<hashtype>(hash,8,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 305 |
|
| 306 | if(!result) printf("*********FAIL*********\n");
|
| 307 | printf("\n");
|
| 308 | }
|
| 309 |
|
| 310 | {
|
| 311 | printf("[[[ Keyset 'Combination 0x8000000' Tests ]]]\n\n");
|
| 312 |
|
| 313 | bool result = true;
|
| 314 | bool drawDiagram = false;
|
| 315 |
|
| 316 | uint32_t blocks[] =
|
| 317 | {
|
| 318 | 0x00000000,
|
| 319 |
|
| 320 | 0x80000000,
|
| 321 | };
|
| 322 |
|
| 323 | result &= CombinationKeyTest<hashtype>(hash,20,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 324 |
|
| 325 | if(!result) printf("*********FAIL*********\n");
|
| 326 | printf("\n");
|
| 327 | }
|
| 328 |
|
| 329 | {
|
| 330 | printf("[[[ Keyset 'Combination 0x0000001' Tests ]]]\n\n");
|
| 331 |
|
| 332 | bool result = true;
|
| 333 | bool drawDiagram = false;
|
| 334 |
|
| 335 | uint32_t blocks[] =
|
| 336 | {
|
| 337 | 0x00000000,
|
| 338 |
|
| 339 | 0x00000001,
|
| 340 | };
|
| 341 |
|
| 342 | result &= CombinationKeyTest<hashtype>(hash,20,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 343 |
|
| 344 | if(!result) printf("*********FAIL*********\n");
|
| 345 | printf("\n");
|
| 346 | }
|
| 347 |
|
| 348 | {
|
| 349 | printf("[[[ Keyset 'Combination Hi-Lo' Tests ]]]\n\n");
|
| 350 |
|
| 351 | bool result = true;
|
| 352 | bool drawDiagram = false;
|
| 353 |
|
| 354 | uint32_t blocks[] =
|
| 355 | {
|
| 356 | 0x00000000,
|
| 357 |
|
| 358 | 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007,
|
| 359 |
|
| 360 | 0x80000000, 0x40000000, 0xC0000000, 0x20000000, 0xA0000000, 0x60000000, 0xE0000000
|
| 361 | };
|
| 362 |
|
| 363 | result &= CombinationKeyTest<hashtype>(hash,6,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 364 |
|
| 365 | if(!result) printf("*********FAIL*********\n");
|
| 366 | printf("\n");
|
| 367 | }
|
| 368 |
|
| 369 | //----------
|
| 370 |
|
| 371 | /*
|
| 372 | {
|
| 373 | printf("[[[ Keyset 'Permutation' Tests ]]]\n\n");
|
| 374 |
|
| 375 | bool result = true;
|
| 376 | bool drawDiagram = false;
|
| 377 |
|
| 378 | // This very sparse set of blocks is particularly hard for SuperFastHash
|
| 379 |
|
| 380 | uint32_t blocks[] =
|
| 381 | {
|
| 382 | 0x00000000,
|
| 383 | 0x00000001,
|
| 384 | 0x00000002,
|
| 385 |
|
| 386 | 0x00000400,
|
| 387 | 0x00008000,
|
| 388 |
|
| 389 | 0x00080000,
|
| 390 | 0x00200000,
|
| 391 |
|
| 392 | 0x20000000,
|
| 393 | 0x40000000,
|
| 394 | 0x80000000,
|
| 395 | };
|
| 396 |
|
| 397 | result &= PermutationKeyTest<hashtype>(hash,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 398 |
|
| 399 | if(!result) printf("*********FAIL*********\n");
|
| 400 | printf("\n");
|
| 401 | }
|
| 402 | */
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 403 | }
|
| 404 |
|
| 405 | //-----------------------------------------------------------------------------
|
| 406 | // Keyset 'Window'
|
| 407 |
|
| 408 | // Skip distribution test for these - they're too easy to distribute well,
|
| 409 | // and it generates a _lot_ of testing
|
| 410 |
|
| 411 | if(g_testWindow || g_testAll)
|
| 412 | {
|
| 413 | printf("[[[ Keyset 'Window' Tests ]]]\n\n");
|
| 414 |
|
| 415 | bool result = true;
|
| 416 | bool testCollision = true;
|
| 417 | bool testDistribution = false;
|
| 418 | bool drawDiagram = false;
|
| 419 |
|
| 420 | result &= WindowedKeyTest< Blob<hashbits*2>, hashtype > ( hash, 20, testCollision, testDistribution, drawDiagram );
|
| 421 |
|
| 422 | if(!result) printf("*********FAIL*********\n");
|
| 423 | printf("\n");
|
| 424 | }
|
| 425 |
|
| 426 | //-----------------------------------------------------------------------------
|
| 427 | // Keyset 'Text'
|
| 428 |
|
| 429 | if(g_testText || g_testAll)
|
| 430 | {
|
| 431 | printf("[[[ Keyset 'Text' Tests ]]]\n\n");
|
| 432 |
|
| 433 | bool result = true;
|
| 434 | bool drawDiagram = false;
|
| 435 |
|
| 436 | const char * alnum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
| 437 |
|
| 438 | result &= TextKeyTest( hash, "Foo", alnum,4, "Bar", drawDiagram );
|
| 439 | result &= TextKeyTest( hash, "FooBar", alnum,4, "", drawDiagram );
|
| 440 | result &= TextKeyTest( hash, "", alnum,4, "FooBar", drawDiagram );
|
| 441 |
|
| 442 | if(!result) printf("*********FAIL*********\n");
|
| 443 | printf("\n");
|
| 444 | }
|
| 445 |
|
| 446 | //-----------------------------------------------------------------------------
|
| 447 | // Keyset 'Zeroes'
|
| 448 |
|
| 449 | if(g_testZeroes || g_testAll)
|
| 450 | {
|
| 451 | printf("[[[ Keyset 'Zeroes' Tests ]]]\n\n");
|
| 452 |
|
| 453 | bool result = true;
|
| 454 | bool drawDiagram = false;
|
| 455 |
|
| 456 | result &= ZeroKeyTest<hashtype>( hash, drawDiagram );
|
| 457 |
|
| 458 | if(!result) printf("*********FAIL*********\n");
|
| 459 | printf("\n");
|
| 460 | }
|
| 461 |
|
| 462 | //-----------------------------------------------------------------------------
|
| 463 | // Keyset 'Seed'
|
| 464 |
|
| 465 | if(g_testSeed || g_testAll)
|
| 466 | {
|
| 467 | printf("[[[ Keyset 'Seed' Tests ]]]\n\n");
|
| 468 |
|
| 469 | bool result = true;
|
| 470 | bool drawDiagram = false;
|
| 471 |
|
| 472 | result &= SeedTest<hashtype>( hash, 1000000, drawDiagram );
|
| 473 |
|
| 474 | if(!result) printf("*********FAIL*********\n");
|
| 475 | printf("\n");
|
| 476 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 477 | }
|
| 478 |
|
| 479 | //-----------------------------------------------------------------------------
|
| 480 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 481 | void testHash ( const char * name )
|
| 482 | {
|
| 483 | HashInfo * pInfo = findHash(name);
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 484 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 485 | if(pInfo == NULL)
|
| 486 | {
|
| 487 | printf("Invalid hash '%s' specified\n",name);
|
| 488 | return;
|
| 489 | }
|
| 490 | else
|
| 491 | {
|
| 492 | if(pInfo->hashbits == 32)
|
| 493 | {
|
| 494 | test<uint32_t>( pInfo->hash, pInfo->desc );
|
| 495 | }
|
| 496 | else if(pInfo->hashbits == 64)
|
| 497 | {
|
| 498 | test<uint64_t>( pInfo->hash, pInfo->desc );
|
| 499 | }
|
| 500 | else if(pInfo->hashbits == 128)
|
| 501 | {
|
| 502 | test<uint128_t>( pInfo->hash, pInfo->desc );
|
| 503 | }
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 504 | else if(pInfo->hashbits == 256)
|
| 505 | {
|
| 506 | test<uint256_t>( pInfo->hash, pInfo->desc );
|
| 507 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 508 | else
|
| 509 | {
|
| 510 | printf("Invalid hash bit width %d for hash '%s'",pInfo->hashbits,pInfo->name);
|
| 511 | }
|
| 512 | }
|
| 513 | }
|
| 514 | //-----------------------------------------------------------------------------
|
| 515 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 516 | int main ( int argc, char ** argv )
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 517 | {
|
tanjent@gmail.com | f67ce94 | 2011-03-14 09:11:18 +0000 | [diff] [blame] | 518 | SetAffinity(2);
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 519 |
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 520 | int timeBegin = clock();
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 521 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 522 | g_testAll = true;
|
| 523 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 524 | //g_testSanity = true;
|
| 525 | //g_testSpeed = true;
|
| 526 | //g_testAvalanche = true;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 527 | //g_testCyclic = true;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 528 | //g_testDiff = true;
|
| 529 | //g_testSparse = true;
|
| 530 | //g_testPermutation = true;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 531 | //g_testZeroes = true;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 532 |
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 533 | //testHash("count");
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 534 | //printf("Called the hash function %I64d times, %I64d bytes hashed\n",g_hashcount,g_bytecount);
|
| 535 |
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 536 | testHash("murmur3a");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 537 |
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 538 | //----------
|
| 539 |
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 540 | int timeEnd = clock();
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 541 |
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 542 | printf("\n");
|
| 543 | printf("Testing took %f seconds\n",double(timeEnd-timeBegin)/double(CLOCKS_PER_SEC));
|
| 544 | printf("-------------------------------------------------------------------------------\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 545 | return 0;
|
tanjent@gmail.com | 2aa29c3 | 2011-03-19 08:53:53 +0000 | [diff] [blame^] | 546 | }
|