]> arthur.barton.de Git - bup.git/commitdiff
cmd/memtest: add a --existing option to test with existing objects.
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 27 Aug 2010 02:16:34 +0000 (19:16 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 27 Aug 2010 02:19:06 +0000 (19:19 -0700)
This is useful for testing behaviour when we're looking for objects
that *do* exist.  Of course, it just goes through the objects in order, so
it's not actually that realistic.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
cmd/memtest-cmd.py
t/test.sh

index faad3f0b0d259096cc974f18e0dae20d62e54c46..0005e67d3dc78fde985918e1e4289fee92e61aa8 100755 (executable)
@@ -37,6 +37,7 @@ bup memtest [-n elements] [-c cycles]
 n,number=  number of objects per cycle [10000]
 c,cycles=  number of cycles to run [100]
 ignore-midx  ignore .midx files, use only .idx files
+existing   test with existing objects instead of fake ones
 """
 o = options.Options('bup memtest', optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
@@ -53,19 +54,30 @@ report(-1)
 f = open('/dev/urandom')
 a = mmap.mmap(-1, 20)
 report(0)
+
+if opt.existing:
+    def foreverit(mi):
+        while 1:
+            for e in mi:
+                yield e
+    objit = iter(foreverit(m))
+    
 for c in xrange(opt.cycles):
     for n in xrange(opt.number):
-        b = f.read(3)
-        if 0:
-            bytes = list(struct.unpack('!BBB', b)) + [0]*17
-            bytes[2] &= 0xf0
-            bin = struct.pack('!20s', s_from_bytes(bytes))
+        if opt.existing:
+            bin = objit.next()
+            assert(m.exists(bin))
         else:
+            b = f.read(3)
             a[0:2] = b[0:2]
             a[2] = chr(ord(b[2]) & 0xf0)
             bin = str(a[0:20])
-        #print bin.encode('hex')
-        m.exists(bin)
+
+            # technically, a randomly generated object id might exist.
+            # but the likelihood of that is the likelihood of finding
+            # a collision in sha-1 by accident, which is so unlikely that
+            # we don't care.
+            assert(not m.exists(bin))
     report((c+1)*opt.number)
 
 print 'Total time: %.3fs' % (time.time() - start)
index 565afcd47236d237ecfba717b2477e61a70eb5be..e654255c90497cfaa673854bdf740fbfe65decd5 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -139,6 +139,9 @@ WVFAIL diff -q tags2t.tmp tags2tf.tmp
 wc -c t/testfile1 t/testfile2
 wc -l tags1.tmp tags2.tmp
 
+WVPASS bup memtest -c1 -n100
+WVPASS bup memtest -c1 -n100 --existing
+
 WVSTART "join"
 WVPASS bup join $(cat tags1.tmp) >out1.tmp
 WVPASS bup join <tags2.tmp >out2.tmp