diff options
author | tanjent@gmail.com <tanjent@gmail.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a> | 2011-03-21 19:33:01 +0000 |
---|---|---|
committer | tanjent@gmail.com <tanjent@gmail.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a> | 2011-03-21 19:33:01 +0000 |
commit | 3ee4561b1347b8ad7a6cda7210c640d9288df957 (patch) | |
tree | c4ea0fe6327187ed98dd91355995b2b00d8a89b7 | |
parent | f14506757829d5d9cae7f510b71d826fecc55f3f (diff) | |
download | src-3ee4561b1347b8ad7a6cda7210c640d9288df957.tar.gz |
Start work on verification codes
git-svn-id: http://smhasher.googlecode.com/svn/trunk@95 77a7d1d3-4c08-bdc2-d393-d5859734b01a
-rw-r--r-- | DifferentialTest.h | 5 | ||||
-rw-r--r-- | Hashes.cpp | 12 | ||||
-rw-r--r-- | Hashes.h | 4 | ||||
-rw-r--r-- | Types.cpp | 9 | ||||
-rw-r--r-- | Types.h | 13 | ||||
-rw-r--r-- | main.cpp | 8 |
6 files changed, 40 insertions, 11 deletions
diff --git a/DifferentialTest.h b/DifferentialTest.h index 0894c0a..b0b1231 100644 --- a/DifferentialTest.h +++ b/DifferentialTest.h @@ -7,6 +7,7 @@ #include "Types.h"
#include "Stats.h" // for chooseUpToK
#include "KeysetTest.h" // for SparseKeygenRecurse
+#include "Random.h"
#include <vector>
#include <algorithm>
@@ -138,6 +139,8 @@ bool DiffTest ( pfHash hash, int diffbits, int reps, bool dumpCollisions ) double testcount = (diffcount * double(reps));
double expected = testcount / pow(2.0,double(hashbits));
+ Rand r(100);
+
std::vector<keytype> diffs;
keytype k1,k2;
@@ -150,7 +153,7 @@ bool DiffTest ( pfHash hash, int diffbits, int reps, bool dumpCollisions ) {
if(i % (reps/10) == 0) printf(".");
- rand_p(&k1,sizeof(k1));
+ r.rand_p(&k1,sizeof(keytype));
k2 = k1;
hash(&k1,sizeof(k1),0,(uint32_t*)&h1);
@@ -63,11 +63,11 @@ void DoNothingHash ( const void *, int, uint32_t, void * ) //-----------------------------------------------------------------------------
// One-byte-at-a-time hash based on Murmur's mix
-void MurmurOAAT ( const void * key, int len, uint32_t seed, void * out )
+uint32_t MurmurOAAT ( const void * key, int len, uint32_t seed )
{
const uint8_t * data = (const uint8_t*)key;
- uint32_t h = seed ^ len;
+ uint32_t h = seed;
for(int i = 0; i < len; i++)
{
@@ -76,10 +76,12 @@ void MurmurOAAT ( const void * key, int len, uint32_t seed, void * out ) h ^= h >> 15;
}
- h *= 0x5bd1e995;
- h ^= h >> 15;
+ return h;
+}
- *(uint32_t*)out = h;
+void MurmurOAAT_test ( const void * key, int len, uint32_t seed, void * out )
+{
+ *(uint32_t*)out = MurmurOAAT(key,len,seed);
}
//----------------------------------------------------------------------------
@@ -31,7 +31,9 @@ void sha1_32a ( const void * key, int len, uint32_t seed, void * ou void FNV ( const void * key, int len, uint32_t seed, void * out );
void SuperFastHash ( const void * key, int len, uint32_t seed, void * out );
void lookup3_test ( const void * key, int len, uint32_t seed, void * out );
-void MurmurOAAT ( const void * key, int len, uint32_t seed, void * out );
+void MurmurOAAT_test ( const void * key, int len, uint32_t seed, void * out );
+
+uint32_t MurmurOAAT ( const void * key, int len, uint32_t seed );
//----------
// MurmurHash2
@@ -1,5 +1,7 @@ #include "Types.h"
+uint32_t MurmurOAAT ( const void * blob, int len, uint32_t seed );
+
//-----------------------------------------------------------------------------
#pragma optimize( "", off )
@@ -15,4 +17,11 @@ uint32_t whitehole ( void ) #pragma optimize( "", on )
+uint32_t g_verify = 1;
+
+void MixVCode ( const void * blob, int len )
+{
+ g_verify = MurmurOAAT(blob,len,g_verify);
+}
+
//-----------------------------------------------------------------------------
@@ -14,6 +14,19 @@ void blackhole ( uint32_t x ); uint32_t whitehole ( void );
//-----------------------------------------------------------------------------
+// We want to verify that every test produces the same result on every platform
+// To do this, we hash the results of every test to produce an overall
+// verification value for the whole test suite. If two runs produce the same
+// verification value, then every test in both run produced the same results
+
+extern uint32_t g_verify;
+
+// Mix the given blob of data into the verification code
+
+void MixVCode ( const void * blob, int len );
+
+
+//-----------------------------------------------------------------------------
typedef void (*pfHash) ( const void * blob, const int len, const uint32_t seed, void * out );
@@ -51,7 +51,7 @@ HashInfo g_hashes[] = { FNV, 32, 0x2B377407, "FNV", "Fowler-Noll-Vo hash, 32-bit" },
{ lookup3_test, 32, 0xDEC6FD2F, "lookup3", "Bob Jenkins' lookup3" },
{ SuperFastHash, 32, 0x980ACD1D, "superfast", "Paul Hsieh's SuperFastHash" },
- { MurmurOAAT, 32, 0x5F424541, "MurmurOAAT", "Murmur one-at-a-time" },
+ { MurmurOAAT_test, 32, 0xF5AC8D0D, "MurmurOAAT", "Murmur one-at-a-time" },
// MurmurHash2
@@ -468,11 +468,11 @@ int main ( int argc, char ** argv ) int timeBegin = clock();
- g_testAll = true;
+ g_testAll = false;
//g_testSanity = true;
//g_testSpeed = true;
- //g_testAvalanche = true;
+ g_testAvalanche = true;
//g_testCyclic = true;
//g_testDiff = true;
//g_testSparse = true;
@@ -486,7 +486,7 @@ int main ( int argc, char ** argv ) int timeEnd = clock();
printf("\n");
- printf("Testing took %f seconds\n",double(timeEnd-timeBegin)/double(CLOCKS_PER_SEC));
+ printf("Verification value is 0x%08x - Testing took %f seconds\n",g_verify,double(timeEnd-timeBegin)/double(CLOCKS_PER_SEC));
printf("-------------------------------------------------------------------------------\n");
return 0;
}
|