summaryrefslogtreecommitdiff
path: root/bin
diff options
authorMaciej Kisielewski <maciej.kisielewski@canonical.com>2014-10-07 11:18:06 +0200
committerMaciej Kisielewski <maciej.kisielewski@canonical.com>2014-10-07 11:18:06 +0200
commit4e8446b930cc122629d58d26d76665cdf12cd6de (patch)
tree3fc3fdd0c6062accaae1df42161130cc98006b21 /bin
parent9ae2f69663da8a751e415ad803eed8a1f1c7faff (diff)
providers:checkbox: add option to automatically reduce size of test data
Add option for jobs using removable_storage_test to mame test data smaller if it will not fit target filesystem. Especially useful for testing legacy devices like small mmc cards.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/removable_storage_test27
1 files changed, 26 insertions, 1 deletions
diff --git a/bin/removable_storage_test b/bin/removable_storage_test
index 2d08cf0..5e8b7db 100755
--- a/bin/removable_storage_test
+++ b/bin/removable_storage_test
@@ -427,6 +427,11 @@ def main():
"You may use SI or IEC suffixes like: 'K', 'M',"
"'G', 'T', 'Ki', 'Mi', 'Gi', 'Ti', etc. Default"
" is %(default)s"))
+ parser.add_argument('--auto-reduce-size',
+ action='store_true',
+ default=False,
+ help=("Automatically reduce size to fit in the target"
+ "filesystem. Reducing until fits in 1MiB"))
parser.add_argument('-n', '--skip-not-mount',
action='store_true',
default=False,
@@ -521,9 +526,29 @@ def main():
>= int(args.min_speed)}
write_sizes = []
test_files = {}
+ disks_freespace = {}
+ for disk, path in disks_eligible.items():
+ stat = os.statvfs(path)
+ disks_freespace[disk] = stat.f_bfree * stat.f_bsize
+ smallest_freespace = min(disks_freespace.values())
+ desired_size = args.size
+ if desired_size > smallest_freespace:
+ if args.auto_reduce_size:
+ min_space = HumanReadableBytes("1MiB")
+ if smallest_freespace < min_space:
+ raise IOError("Not enough space. {} is required"
+ .format(min_space))
+ new_size = HumanReadableBytes(int(0.8 * smallest_freespace))
+ logging.warning("Automatically reducing test data size"
+ ". {} requested. Reducing to {}."
+ .format(desired_size, new_size))
+ desired_size = new_size
+ else:
+ raise IOError("Not enough space. {} is required"
+ .format(desired_size))
# Generate our data file(s)
for count in range(args.count):
- test_files[count] = RandomData(args.size)
+ test_files[count] = RandomData(desired_size)
write_sizes.append(os.path.getsize(
test_files[count].tfile.name))
total_write_size = sum(write_sizes)