From 39169dd9e497d4c052b056acd813d145503d0a8c Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Tue, 19 Jul 2016 10:58:00 +0200 Subject: [PATCH] some fine-tuning: clarify documentation, add variables for easier debugging --- testing/volume_size_accuracy.py | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/testing/volume_size_accuracy.py b/testing/volume_size_accuracy.py index fb32748..820499b 100755 --- a/testing/volume_size_accuracy.py +++ b/testing/volume_size_accuracy.py @@ -11,14 +11,10 @@ By doing the following: - add a file that nearly fills the volume - add a small file that should just fit in or not - check expected number and size of volumes -- repeat with max_volume_size +1, -1, +2, -2, +10, -10 - -Repeat with compressed/encrypted data; for this have to find some random data -that is repeatable (--> :py:mod:`create_pseudo_random_files`) and experiment a -bit for suitable seeds and sizes - -e.g. for max_volume_size = RECORDSIZE + 1 * BLOCKSIZE +- repeat with max_volume_size +1, +2, +10, ... +- repeat with file sizes -1, -2, -10, ... +e.g. for max_volume_size = RECORDSIZE + 1 * BLOCKSIZE: File 0 has Info0 and blocks Dat00, Dat01, ... Dat0K, (Dat0L, Dat0M, Dat0N) File 1 has Info1 and blocks Dat10, (Dat11) end of end of @@ -34,10 +30,12 @@ vol0: | Info0 | Dat00 | Dat01 | ... | Dat0K | Info1 | Dat10 | 0 | 0 | +-------+-------+-------+ ... +-------+-------+-------+-------+-------+ 2: file0 needs next block: blocks = [MAX_VOLUME_BLOCKS-4, 1] + --> will add one block of zeros after end of volume vol0: | Info0 | Dat00 | Dat01 | ... | Dat0K | Dat0L | Info1 | Dat10 | 0 | 0 +-------+-------+-------+ ... +-------+-------+-------+-------+-------+ 3: file0 needs 2 more blocks: blocks = [MAX_VOLUME_BLOCKS-3, 1] + --> will add two blocks of zeros after end of volume vol0: | Info0 | Dat00 | Dat01 | ... | Dat0K | Dat0L | Dat0M | Info1 | Dat10 |00 +-------+-------+-------+ ... +-------+-------+-------+-------+-------+ @@ -53,12 +51,12 @@ vol1: | VOL | Dat11 | 0 | 0 | | | | | | 6: both need next block: blocks = [MAX_VOLUME_BLOCKS-4, 2] vol0: | Info0 | Dat00 | Dat01 | ... | Dat0K | Dat0L | Info1 | Dat10 | | -vol1: | VOL | Dat11 | 0 | 0 | | | | | | +vol1: | VOL | Dat11 | 0 |0|...| | | | | | +-------+-------+-------+ ... +-------+-------+-------+-------+-------+ -single huge file: blocks = [MAX_VOLUME_BLOCKS * 3,] +(not tested: single huge file) vol0: | Info0 | Dat00 | Dat01 | ... | Dat02 | Dat03 | Dat04 | wasted space | -vol1: | VOL | Dat05 | Dat06 | Dat07 | ... | Dat08 | Dat09 | wasted space | +vol1: | VOL | Dat05 | Dat06 | ... | Dat07 | Dat08 | Dat09 | wasted space | vol2: | ... | | | | | | | | | +-------+-------+-------+ ... +-------+-------+-------+-------+-------+ @@ -89,6 +87,9 @@ N_BLOCKS_PER_RECORD = RECORDSIZE // BLOCKSIZE #: number of blocks per tar volume file MAX_VOLUME_BLOCKS = N_BLOCKS_PER_RECORD + 1 +#: always print all test output; will produce ~10 lines of text for each of the +#: ~48000 tests --> not recommended +ALWAYS_PRINT_EVERYTHING = False def fill_file(file_handle, data_size): """ fill given file handle with nonsense data of given size """ @@ -117,11 +118,12 @@ def test(temp_dir, file_blocks, volume_blocks_arg, offset_blocks, file_size_offsets=(0, 0), volume_size_offset=0): """ create TarFile with given configuration """ - # use "delayed" print dprnt, that only prints if necessary (i.e. something - # went wrong) + # use delayed + conditional print dprnt, that only prints if necessary + # (i.e. if something went wrong) output = [] dprnt = output.append + dprnt('-' * 72) dprnt('testing with {} file blocks, expect {} volume blocks' .format(file_blocks, volume_blocks_arg)) dprnt('expect offsets to be {} blocks'.format(offset_blocks)) @@ -238,7 +240,7 @@ def test(temp_dir, file_blocks, volume_blocks_arg, offset_blocks, size_str(expected_blocks * BLOCKSIZE))) # print output only if something went wrong - if not everything_ok: + if (not everything_ok) or ALWAYS_PRINT_EVERYTHING: for line in output: print(line) @@ -272,12 +274,12 @@ def main(): n_errs = 0 n_tests = 0 n_tests_overall = len(tests) * len(size_offsets)**3 - with TemporaryDirectory() as temp_dir: + with TemporaryDirectory(prefix='deltatar_test_') as temp_dir: for size_comb_idx, (file_sizes, vol_sizes, offsets) \ in enumerate(tests): if fast_fail and n_errs > 0: break - print('-' * 72) + print('=' * 72) print('size combination {}: ({}, {})' .format(size_comb_idx, *file_sizes)) for volume_size_offset in size_offsets: @@ -300,6 +302,9 @@ def main(): volume_size_offset=volume_size_offset) if not test_succeeded: n_errs += 1 + if fast_fail: + print('stopping after test {} (fast-fail set)' + .format(n_tests)) return n_errs -- 1.7.1