From 72b25b22fa170f4d4aa07b073ff9d2af6557f74d Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 16 Jun 2020 14:49:57 +0000 Subject: [PATCH] .autotest git-svn-id: svn://ultimatepp.org/upp/trunk@14599 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- autotest/Mem/Mem.cpp | 81 ++++++++++++++++++++++++++++++++++++-- autotest/String/String.cpp | 1 + 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/autotest/Mem/Mem.cpp b/autotest/Mem/Mem.cpp index dadac6224..d15d0a954 100644 --- a/autotest/Mem/Mem.cpp +++ b/autotest/Mem/Mem.cpp @@ -11,7 +11,7 @@ void CheckEq(FN eq) { LOG("CheckEq " << sizeof(T)); T a[2000], b[2000]; - auto Rnd = [] { return (T)Random(26) + 'A'; }; + auto Rnd = [] { return (T)(Random(26) + 'A'); }; for(int i = 0; i < 100000; i++) { if(i % 10000 == 0) LOG(i); @@ -79,7 +79,7 @@ void CheckFill(FN fill) for(int i = 0; i < 500000; i++) { int pos = Random(200); int len = Random(decode(pass, 0, 20, 1, 200, 2, 2000, 9999)); - fill(~b1 + pos, i, len); + fill(~b1 + pos, (T)i, len); for(int j = 0; j < len; j++) b2[pos + j] = i; if(memcmp(b1, b2, sizeof(T) * 20000)) { @@ -98,7 +98,7 @@ void CheckFill(FN fill) for(int i = 0; i < 100; i++) { int pos = Random(200); int len = 1024*1024*7 + Random(200); - fill(~b1 + pos, i, len); + fill(~b1 + pos, (T)i, len); for(int j = 0; j < len; j++) b2[pos + j] = i; if(memcmp(b1, b2, sizeof(T) * 1024*1024*16)) { @@ -115,10 +115,82 @@ void CheckFill(FN fill) } } +void CheckMemHash() +{ + Buffer b(2000); + for(int i = 0; i < 2000; i++) + b[i] = (byte)Random(256); + + int worst = 0; + for(int pos = 10; pos < 40; pos++) { + for(int len = 0; len < 200; len++) { + auto Hash = [&] { return memhash(~b + pos, len); }; + hash_t h = Hash(); + for(int i = 0; i < 8; i++) { + b[pos - i - 1]++; + if(h != Hash()) { + RDUMP(pos); + RDUMP(len); + RDUMP(pos - i - 1); + Panic("Failed"); + } + b[pos - i - 1]++; + b[pos + len]++; + if(h != Hash()) { + RDUMP(pos); + RDUMP(len); + RDUMP(pos + len); + Panic("Failed"); + } + b[pos + len]--; + } + for(int i = 0; i < len; i++) { + int ii = pos + i; + byte bak = b[ii]; + bool ok = false; + for(int v = 0; v < 256; v++) { + b[ii] = v; + if(h != Hash()) { + ok = true; + worst = max(worst, v); + break; + } + } + if(!ok) { + RDUMP(pos); + RDUMP(len); + RDUMP(ii); + RDUMP(worst); + RDUMP(ii - pos); + LOGHEXDUMP(~b + pos, len); + b[ii] = bak; + LOGHEXDUMP(~b + pos, len); + Panic("Failed"); + } + b[ii] = bak; + } + } + } + LOG("CheckMemHash worst: " << worst); +} + +struct m128n : m128 { + m128n(int i) { i64[0] = i, i64[1] = 0; } + m128n() {} + + operator byte() const { return (byte)i64[0]; } +}; + CONSOLE_APP_MAIN { StdLogSetup(LOG_COUT|LOG_FILE); + SeedRandom(0); + + CheckEq(memeq128); + + CheckMemHash(); + CheckEq(memeq8); CheckEq(memeq16); CheckEq(memeq32); @@ -128,13 +200,14 @@ CONSOLE_APP_MAIN CheckFill(memset16); CheckFill(memset32); CheckFill(memset64); + CheckFill(memset128); struct dqword { qword x[2]; }; CheckCopy(memcpy8); CheckCopy(memcpy16); CheckCopy(memcpy32); CheckCopy(memcpy64); - CheckCopy(memcpy128); + CheckCopy(memcpy128); LOG("============= OK"); } diff --git a/autotest/String/String.cpp b/autotest/String/String.cpp index d091d37a7..17a524e02 100644 --- a/autotest/String/String.cpp +++ b/autotest/String/String.cpp @@ -265,6 +265,7 @@ void UnitTest() ASSERT(memcmp(cns.Begin(), css.Begin(), sizeof(tchar) * cns.GetCount() + 1) == 0); ASSERT(GetHashValue(ns) == GetHashValue(NewString(~ns, ns.GetCount()))); ASSERT(ns.IsVoid() == ss.IsVoid()); + ASSERT(ns == ~ns); } Cout() << "Passed"; RLOG("Test passed");