gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/rtmp r9944: add corrupt() methods to rando


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9944: add corrupt() methods to randomly corrupt data in a Buffer for stress testing.
Date: Sun, 18 Jan 2009 08:01:31 -0000
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9944
committer: address@hidden
branch nick: rtmp
timestamp: Thu 2009-01-01 12:00:41 -0700
message:
  add corrupt() methods to randomly corrupt data in a Buffer for stress testing.
modified:
  libamf/buffer.cpp
  libamf/buffer.h
=== modified file 'libamf/buffer.cpp'
--- a/libamf/buffer.cpp 2008-12-28 19:47:57 +0000
+++ b/libamf/buffer.cpp 2009-01-01 19:00:41 +0000
@@ -22,6 +22,8 @@
 
 #include <boost/cstdint.hpp>
 #include <iostream>
+#include <boost/random/uniform_int.hpp>
+#include <boost/random/mersenne_twister.hpp>
 
 #include "buffer.h"
 #include "amf.h"
@@ -731,14 +733,51 @@
 Buffer::dump(std::ostream& os) const
 {
     os << "Buffer is " << _seekptr-_data.get() << "/" << _nbytes << " bytes at 
" << (void *)_data.get() << endl;
-    if (_nbytes < 0xffff) {
+    if (_data) {
        const size_t bytes = _seekptr - _data.get();
        os << gnash::hexify((unsigned char *)_data.get(), bytes, false) << endl;
        os << gnash::hexify((unsigned char *)_data.get(), bytes, true) << endl;
     } else {
        os << "ERROR: Buffer size out of range!" << endl;
-       abort();
-    }
+    }
+}
+
+/// \brief Corrupt a buffer with random errors.
+///            This is used only for testing to make sure we can cleanly
+///            handle corruption of the packets.
+///
+/// @param factor A divisor to adjust how many errors are created.
+///
+/// @return nothing
+int
+Buffer::corrupt()
+{
+    corrupt(10);
+}
+
+int
+Buffer::corrupt(int factor)
+{
+    boost::mt19937 seed;
+    // Pick the number of errors to create based on the Buffer's data size
+    boost::uniform_int<> errs(1, (_nbytes/factor));
+    int errors = errs(seed);
+    log_debug("Creating %d errors in the buffer", errors);
+    
+    for (int i=0; i<errors; i++) {
+       // find a location someplace within the file.
+       boost::uniform_int<> location(0, _nbytes);
+       int pos = location(seed);
+       
+       log_debug("Creating error at %d in the buffer", pos);
+       // Create a random new value for the byte
+       boost::uniform_int<> shift(1, 256);
+       int newval = shift(seed);
+       // stomp the old value for our new one.
+       _data[pos] = newval;
+    }
+
+    return errors;
 }
 
 } // end of amf namespace

=== modified file 'libamf/buffer.h'
--- a/libamf/buffer.h   2008-12-27 16:51:48 +0000
+++ b/libamf/buffer.h   2009-01-01 19:00:41 +0000
@@ -70,6 +70,16 @@
     /// Delete the memory allocated for this Buffer
     ~Buffer();
 
+    /// \brief Corrupt a buffer with random errors.
+    ///                This is used only for testing to make sure we can 
cleanly
+    ///                handle corruption of the packets.
+    ///
+    /// @param factor A divisor to adjust how many errors are created.
+    ///
+    /// @return The number or errors that were created.
+    int corrupt();
+    int corrupt(int factor);
+    
     /// \brief Encode a Buffer from a hex string.
     ///
     /// @param str A hex string.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]