1#! /usr/bin/env python 2 3# Generate random IO patterns for the txg_integrity test 4# We do this statically and embed the results into the code so that the 5# Testing will be more repeatable compared to generating the tables at runtime 6 7import random 8 9CLUSTERSIZE = (1 << 16) 10NUM_CHUNKS = 64 11 12 13def rand_partition(): 14 partitions = [] 15 while len(partitions) != NUM_CHUNKS: 16 # We don't want any duplicates, so we make a set and then check that 17 # its length is correct 18 partitions = sorted( 19 list( 20 set( 21 [random.randrange(0, 22 2**31, 23 (2**31) * 8 / (NUM_CHUNKS * CLUSTERSIZE)) 24 for i in range(NUM_CHUNKS - 1)] + [2**31]))) 25 return partitions 26 27 28def rand_permutation(): 29 perm = range(NUM_CHUNKS) 30 random.shuffle(perm) 31 return perm 32 33 34def rand_follower_bitmap(): 35 bmp = 0 36 chunks = random.sample(range(NUM_CHUNKS), NUM_CHUNKS / 2) 37 for chunk in chunks: 38 bmp |= (1 << chunk) 39 return bmp 40 41 42def print_pattern(n): 43 print "const pattern_t pat%d = {" % n 44 print " {", 45 for p in rand_partition(): 46 print "%#x, " % p, 47 print " }," 48 print " {", 49 for p in rand_permutation(): 50 print "%d, " % p, 51 print " }," 52 print " %#x" % rand_follower_bitmap() 53 print "};" 54 55 56for n in range(32): 57 print_pattern(n) 58