]> gitweb.hamatoma.de Git - crepublib/commitdiff
ReMD5 works, CUnit clean
authorhama <hama@siduction.net>
Mon, 9 Feb 2015 23:42:53 +0000 (00:42 +0100)
committerhama <hama@siduction.net>
Mon, 9 Feb 2015 23:42:53 +0000 (00:42 +0100)
cunit/cuReMD5.cpp
cunit/cuReRandomizer.cpp
math/ReMD5.cpp
os/ReDirTools.cpp

index 22559c55760a28bd0b0ed1911b0a4c1e995d880e..9b32c4a70a6dbd1c5281ef41ad548baba307099f 100644 (file)
@@ -6,15 +6,6 @@
  * No warranties and disclaimer of any damages.
  * The latest sources: https://github.com/republib
  */
-/*
- * cuReMatcher.hpp
- *
- * License: Public domain
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * The latest sources: https://github.com/republib
- */
-
 
 #include "base/rebase.hpp"
 #include "math/remath.hpp"
 
 class TestReMd5 : public ReTestUnit {
 public:
-       TestReMd5() : ReTestUnit("ReMatcher", __FILE__){
+       TestReMd5() : ReTestUnit("ReMD5", __FILE__){
                run();
        }
 private:
        void run(){
-               testOld();
+               testSpeed();
+               testLong();
+               testBig();
+               //testOld();
                testBase();
        }
        void testOld(){
@@ -60,6 +54,73 @@ private:
                checkEqu("d41d8cd98f00b204e9800998ecf8427e",
                        md5.hexDigest().str());
        }
+       int testOneLong(ReByteBuffer& text, int seed2 = 0){
+               ReMD5 md5;
+               int rc = 0;
+               ReShiftRandom random;
+               random.setSeed(text.length() + seed2);
+
+               md5.update((uint8_t*) text.str(), text.length());
+               ReByteBuffer digest(md5.hexDigest());
+               md5.reset();
+               int max2 = text.length() / 20;
+               if (max2 < 1)
+                       max2 = random.nextInt(20);
+               while(text.length() > 0){
+                       int part = random.nextInt(32, 32 + 1 + max2);
+                       if (part > text.length())
+                               part = text.length();
+                       md5.update((uint8_t*) text.str(), part);
+                       text.remove(0, part);
+                       rc++;
+               }
+               checkEqu(digest.str(), md5.hexDigest().str());
+               return rc;
+       }
+       void testLong(){
+               ReByteBuffer text("01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ0123456789001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ01234567890\n");
+               for (int ii = 178 - 69 + 1; ii > 0; ii--){
+                       text.setLength(ii);
+                       testOneLong(text, 200 * ii + 0x47111);
+               }
+       }
+       void testBig(){
+               ReByteBuffer text;
+               ReShiftRandom random;
+               int64_t start = timer();
+               int count = 1000;
+               int parts = 0;
+               int sumLength = 0;
+               for (int ii = 0; ii < count; ii++){
+                       random.nextString(10, 20000, text);
+                       sumLength += text.length();
+                       parts += testOneLong(text, 333 * ii + 0x55221);
+               }
+               printf("count: %d updates: %d avg length: %d duration: %s\n",
+                       count, parts, sumLength / count,
+                ReByteBuffer("").appendMilliSec(milliSecSince(start)).str());
+       }
+       void testSpeed(){
+               int max = 1024*1024*50;
+               ReByteBuffer buffer;
+               buffer.ensureSize(max);
+               buffer.setLength(max - 1);
+               buffer.fill('x', max - 1);
+               ReMD5 md5;
+               int passes = 2;
+               int64_t start = timer();
+               for (int ii = 0; ii < passes; ii++){
+                       md5.reset();
+                       md5.update((uint8_t*) buffer.str(), max - 1);
+               }
+               int duration = milliSecSince(start);
+               if (duration == 0)
+                       duration = 1;
+               printf("size: %.3f MiByte count: %d rate: %.3f MiB/sec duration: %s\n",
+                       max / 1024.0 / 1024, passes,
+                       max / 1024.0 / 1024 * 1000 * passes / duration,
+                       ReByteBuffer("").appendMilliSec(duration).str());
+       }
 };
 extern void testReMD5(void);
 
index 6615e7b49d91a70f9c1afd4a458c7e3784231b0a..666c46ebac42ca8b01a3be3699502379f9f4da29 100644 (file)
@@ -26,25 +26,28 @@ private:
                ReCongruentialGenerator rand;
                const int MAX = 16;
                time_t start = time(NULL);
-               ReRandomizer::seed_t field[MAX];
+               int64_t field[MAX];
                for (int ix = 0; ix < MAX; ix++)
                        field[ix] = rand.nextInt64();
                rand.reset();
                for (int ix = 0; ix < MAX; ix++){
-                       checkEqu(field[ix], rand.nextInt64(ix + 10));
+                       int64_t current = rand.nextInt64();
+                       if (field[ix] != current)
+                               checkEqu(field[ix], current);
                }
        }
        void testNextInt64(){
                ReCongruentialGenerator rand;
                const int MAX = 16;
                time_t start = time(NULL);
-               ReRandomizer::seed_t field[MAX];
+               int64_t field[MAX];
                for (int ix = 0; ix < MAX; ix++)
                        field[ix] = rand.nextInt64(ix + 10);
                rand.reset();
                for (int ix = 0; ix < MAX; ix++){
                        checkEqu(field[ix], rand.nextInt64(ix + 10));
-                       checkT(field[ix] >= 0 && field[ix] < ix + 10);
+                       if (! (field[ix] >= 0 && field[ix] <= ix + 10))
+                               checkT(false);
                }
                time_t diff = time(NULL) - start;
        }
index 2f89478884b3aa35c2671dd8cc6282fb145ce4a9..375a91c153439c20a44aee66f3ac8bf36e91b9ae 100644 (file)
@@ -174,7 +174,6 @@ void ReMD5::processChunk(const uint8_t block[64]){
 #else
 #      error "missing __LITTLE_ENDIAN__ or __BIG_ENDIAN__"
 #endif
-
        //Initialize hash value for this chunk:
        uint32_t A = m_a0;
        uint32_t B = m_b0;
@@ -183,12 +182,13 @@ void ReMD5::processChunk(const uint8_t block[64]){
        //Main loop:
 
        int F, g;
-#define TRACE_MD5
+//#define TRACE_MD5
 #if defined TRACE_MD5
        printf("neu: (%s)\n", block);
 #endif
        for (int i = 0; i < 64; i++){
 #if defined TRACE_MD5
+               if (i > 60)
                printf("%2d: A: %08x B: %08x C: %08x D%08x\n", i, A, B, C, D);
 #endif
                if (i < 16){
@@ -212,6 +212,7 @@ void ReMD5::processChunk(const uint8_t block[64]){
                        g = (7*i) % 16;
                }
 #if defined TRACE_MD5
+               if (i > 60)
                printf("    K[%2d]: %08x M[%2d]: %08x shift: %02d\n",
                                        i, m_K[i], g, M[g], m_s[i]);
 #endif
@@ -272,19 +273,15 @@ void ReMD5::update(const uint8_t* block, int blockLength){
                }
        }
        // process full 512 bit chunks (64 byte blocks):
-       if (blockLength > 0){
-               if (blockLength > 64){
-                       for (int ix = blockLength / 64; ix >= 0; ix--){
-                               processChunk(block);
-                               block += 64;
-                       }
-               }
-               blockLength %= 64;
-               if (blockLength != 0){
-                       assert(m_lengthWaiting == 0);
-                       memcpy(m_waiting, block, blockLength);
-                       m_lengthWaiting = blockLength;
-               }
+       for (int ix = blockLength / 64; ix > 0; ix--){
+               processChunk(block);
+               block += 64;
+       }
+       blockLength %= 64;
+       if (blockLength != 0){
+               assert(m_lengthWaiting == 0);
+               memcpy(m_waiting, block, blockLength);
+               m_lengthWaiting = blockLength;
        }
 }
 
index d865cf9f83b84dd53f52acf9ede0ee28fea3208f..10553ebcccf97acaf2164126fdc99ac38ca5d79e 100644 (file)
@@ -447,13 +447,20 @@ void ReDirOptions::help(const char* errorMessage, const char* message2) const{
  */\r
 void ReDirOptions::checkStandardFilterOptions(){\r
     ReByteBuffer buffer;\r
-    checkDate(m_programArgs.getString("older", buffer));\r
-    checkDate(m_programArgs.getString("younger", buffer));\r
-    checkType(m_programArgs.getString("types", buffer));\r
-    checkSize(m_programArgs.getString("maxsize", buffer));\r
-    checkSize(m_programArgs.getString("minsize", buffer));\r
-    checkPatternList(m_programArgs.getString("nodepattern", buffer));    \r
-    checkPatternList(m_programArgs.getString("pathpattern", buffer));\r
+    if (m_programArgs.getString("older", buffer)[0] != '\0')\r
+        checkDate(buffer.str());\r
+    if (m_programArgs.getString("younger", buffer)[0] != '\0')\r
+        checkDate(buffer.str());\r
+    if (m_programArgs.getString("type", buffer)[0] != '\0')\r
+        checkType(buffer.str());\r
+    if (m_programArgs.getString("maxsize", buffer)[0] != '\0')\r
+        checkSize(buffer.str());\r
+    if (m_programArgs.getString("minsize", buffer)[0] != '\0')\r
+        checkSize(buffer.str());\r
+    if (m_programArgs.getString("nodepattern", buffer)[0] != '\0')\r
+        checkPatternList(buffer.str());\r
+    if (m_programArgs.getString("pathpattern", buffer)[0] != '\0')\r
+        checkPatternList(buffer.str());\r
        if (m_programArgs.getString("verbose", buffer)[0] != '\0'){\r
                unsigned level = V_NORMAL;\r
                if (ReStringUtils::lengthOfUnsigned(buffer.str(), -1, &level)\r