diff options
Diffstat (limited to 'test/harness/util.py')
-rw-r--r-- | test/harness/util.py | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/test/harness/util.py b/test/harness/util.py index d2a7b63..d7c64a2 100644 --- a/test/harness/util.py +++ b/test/harness/util.py @@ -42,6 +42,13 @@ class Global: # XXX we should really look how many subtests there are, but there's # no good way to detect that. subtest_list = [i+1 for i in range(16)] + # for timing + fio_time = 0.0 + sgdisk_time = 0.0 + dd_time = 0.0 + bonnie_time = 0.0 + mkfs_time = 0.0 + sleep_time = 0.0 def dprint(*args): @@ -261,7 +268,7 @@ def run_fio(): Return zero for success. Return non-zero for failure and a failure reason. - Uses Globals: device, blocksize + Uses Globals: partition, blocksize """ if Global.blocksize is not None: dprint('Found a block size passed in: %s' % Global.blocksize) @@ -272,37 +279,41 @@ def run_fio(): '16k', '32k', '75536', '128k', '1000000'] # for each block size, do a read test, then a write test for bs in blocksizes: - vprint('Running "fio" read test: 8 threads, bs=%s' % bs) + vprint('Running "fio" read/write/verify tests with 8/8/1 threads, bs=%s' % bs) # only support direct IO with aligned reads if bs.endswith('k'): direct=1 else: direct=0 + ts = time.time() res = run_cmd(['fio', '--name=read-test', '--readwrite=randread', '--runtime=2s', '--numjobs=8', '--blocksize=%s' % bs, - '--direct=%d' % direct, '--filename=%s' % Global.device]) + '--offset=256k', + '--direct=%d' % direct, '--filename=%s' % Global.partition]) if res != 0: return (res, 'fio failed') - vprint('Running "fio" write test: 8 threads, bs=%s' % bs) res = run_cmd(['fio', '--name=write-test', '--readwrite=randwrite', '--runtime=2s', '--numjobs=8', '--blocksize=%s' % bs, - '--direct=%d' % direct, '--filename=%s' % Global.device]) + '--offset=256k', + '--direct=%d' % direct, '--filename=%s' % Global.partition]) if res != 0: return (res, 'fio failed') - vprint('Running "fio" verify test: 1 thread, bs=%s' % bs) res = run_cmd(['fio', '--name=verify-test', '--readwrite=randwrite', '--runtime=2s', '--numjobs=1', '--blocksize=%s' % bs, - '--direct=%d' % direct, '--filename=%s' % Global.device, + '--direct=%d' % direct, '--filename=%s' % Global.partition, + '--offset=256k', '--verify=md5', '--verify_state_save=0']) if res != 0: return (res, 'fio failed') + te = time.time() + Global.fio_time += (te - ts) return (0, 'Success') def wait_for_path(path, present=True, amt=10): """Wait until a path exists or is gone""" dprint("Looking for path=%s, present=%s" % (path, present)) for i in range(amt): - time.sleep(1) + sleep_some(1) if os.path.exists(path) == present: dprint("We are Happy :) present=%s, cnt=%d" % (present, i)) return True @@ -318,13 +329,27 @@ def wipe_disc(): """ # zero out the label and parition table vprint('Running "sgdisk" and "dd" to wipe disc label, partitions, and filesystem') - time.sleep(1) - res = run_cmd(['sgdisk', '-Z', Global.device]) + sleep_some(1) + ts = time.time() + res = run_cmd(['sgdisk', '--clear', Global.device]) + te = time.time() + Global.sgdisk_time += (te - ts) if res != 0: - return (res, '%s: could not zero out label: %d' % (Global.device, res)) + if res == 4: + dprint("Oh oh -- 'clear' failed! trying one more time ...") + ts = time.time() + res = run_cmd(['sgdisk', '--clear', Global.device]) + te = time.time() + if res != 0: + return (res, '%s: could not zero out label after two tries: %d' % \ + (Global.device, res)) + Global.sgdisk_time += (te - ts) + ts = time.time() res = run_cmd(['dd', 'if=/dev/zero', 'of=%s' % Global.device, 'bs=256k', 'count=20', 'oflag=direct']) + te = time.time() if res != 0: return (res, '%s: could not zero out filesystem: %d' % (Global.device, res)) + Global.dd_time += (te - ts) return (0, 'Success') def run_parted(): @@ -339,7 +364,7 @@ def run_parted(): """ (res, reason) = wipe_disc() if res != 0: - return (res, resason) + return (res, reason) # ensure our partition file is not there, to be safe if not wait_for_path(Global.partition, present=False, amt=30): return (1, '%s: Partition already exists?' % Global.partition) @@ -359,25 +384,39 @@ def run_parted(): def run_mkfs(): vprint('Running "mkfs" to to create filesystem') + ts = time.time() res = run_cmd(Global.MKFSCMD + [ Global.partition ] ) + te = time.time() if res != 0: return (res, '%s: mkfs failed (%d)' % (Global.partition, res)) + Global.mkfs_time += (te - ts) return (0, 'Success') def run_bonnie(): # make a temp dir and mount the device there with tempfile.TemporaryDirectory() as tmp_dir: - vprint('Mounting the filesystem') + vprint('Running "mount" to mount the filesystem') res = run_cmd(['mount'] + Global.MOUNTOPTIONS + [Global.partition, tmp_dir]) if res != 0: return (res, '%s: mount failed (%d)' % (Global.partition, res)) # run bonnie++ on the new directory vprint('Running "bonnie++" on the filesystem') + ts = time.time() res = run_cmd(['bonnie++'] + Global.BONNIEPARAMS + ['-d', tmp_dir]) + te = time.time() if res != 0: return (res, '%s: umount failed (%d)' % (tmp_dir, res)) + Global.bonnie_time += (te - ts) # unmount the device and remove the temp dir + vprint('Running "umount" to unmount the filesystem') res = run_cmd(['umount', tmp_dir]) if res != 0: return (res, '%s: umount failed (%d)' % (tmp_dir, res)) return (0, 'Success') + +def sleep_some(s): + # sleep s seconds + ts = time.time() + time.sleep(s) + te = time.time() + Global.sleep_time += (te - ts) |