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