Hack asdcplib to make its RNG repeatable when we are testing.
authorCarl Hetherington <cth@carlh.net>
Tue, 17 Jul 2012 14:14:14 +0000 (15:14 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 17 Jul 2012 14:14:14 +0000 (15:14 +0100)
asdcplib/src/KM_prng.cpp
asdcplib/src/KM_prng.h
run-tests.sh
src/util.cc
src/util.h
test/tests.cc

index 5212595f8b4669725b1f1ddcfe361e618138220b..3c64bdcc6a3cb2ca5ad21ab64148d93d37609835 100755 (executable)
@@ -48,6 +48,7 @@ using namespace Kumu;
 const char* DEV_URANDOM = "/dev/urandom";
 #endif // KM_WIN32
 
+bool Kumu::libdcp_test = false;
 
 const ui32_t RNG_KEY_SIZE = 512UL;
 const ui32_t RNG_KEY_SIZE_BITS = 256UL;
@@ -64,6 +65,7 @@ public:
   AES_KEY   m_Context;
   byte_t    m_ctr_buf[RNG_BLOCK_SIZE];
   Mutex     m_Lock;
+  unsigned int m_libdcp_test_rng_state;
 
   h__RNG()
   {
@@ -97,6 +99,8 @@ public:
     } // end AutoMutex context
 
     set_key(rng_key);
+
+    m_libdcp_test_rng_state = 1;
   }
        
   //
@@ -138,6 +142,12 @@ public:
        AES_encrypt(m_ctr_buf, tmp, &m_Context);
        memcpy(buf + gen_count, tmp, len - gen_count);
       }
+
+    if (libdcp_test)
+      {    
+        for (unsigned int i = 0; i < len; ++i)
+         buf[i] = rand_r(&m_libdcp_test_rng_state);
+      }
   }
 };
 
index 2a909d6f472950df5a4d7033886381e12b14fd10..a1f232884ad64492709935dbe808d9e6f39e7b10 100755 (executable)
@@ -51,6 +51,7 @@ namespace Kumu
   // key_len must be <= 64 (larger values will be truncated)
   void Gen_FIPS_186_Value(const byte_t* key_in, ui32_t key_len, byte_t* buf, ui32_t buf_len);
 
+  extern bool libdcp_test;
 } // namespace Kumu
 
 
index 08db5a85498db7cf7408fd9929d8ed06043f3312..a44ccea09ea9dbc1b321719c3e02ba4f45986aa5 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-LD_LIBRARY_PATH=build/src
+LD_LIBRARY_PATH=build/src:build/asdcplib/src
 build/test/tests
-diff -ur build/test/foo test/ref/DCP
+#diff -ur build/test/foo test/ref/DCP
  
\ No newline at end of file
index aab2e184ad2654e819950e9bc1fc13a31da20056..e805f3eb876010c61e6c4b57678b2c87f714f7a6 100644 (file)
@@ -28,8 +28,6 @@
 
 using namespace std;
 
-bool libdcp::libdcp_test = false;
-
 /** Create a UUID.
  *  @return UUID.
  */
@@ -38,20 +36,7 @@ libdcp::make_uuid ()
 {
        char buffer[64];
        Kumu::UUID id;
-
-       if (libdcp_test) {
-               static int N = 0;
-               byte_t t[16];
-               for (int i = 0; i < 16; ++i) {
-                       t[i] = N;
-               }
-               ++N;
-               
-               id = Kumu::UUID (t);
-       } else {
-               Kumu::GenRandomValue (id);
-       }
-       
+       Kumu::GenRandomValue (id);
        id.EncodeHex (buffer, 64);
        return string (buffer);
 }
index fcb6d739eb8eb06d8e6927d9024ad3aaf97efc0b..0a5292c00bfb68656976f5325cd124853232ec75 100644 (file)
@@ -23,6 +23,5 @@ namespace libdcp {
        
 extern std::string make_uuid ();
 extern std::string make_digest (std::string);
-extern bool libdcp_test;
 
 }
index dd9ed07dd18ce245e809755093e91b97e5d2c60c..ec7cc6883adebf84e418c1a0181213d0f2e74814 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include <boost/filesystem.hpp>
+#include "KM_prng.h"
 #include "dcp.h"
 #include "util.h"
 #include "tags.h"
@@ -31,8 +32,8 @@ using namespace boost;
 
 BOOST_AUTO_TEST_CASE (dcp_test)
 {
-       libdcp::libdcp_test = true;
-
+       Kumu::libdcp_test = true;
+       
        libdcp::Tags* t = libdcp::Tags::instance ();
        t->issuer = "OpenDCP 0.0.25";
        t->creator = "OpenDCP 0.0.25";