#: tolerances of volume sizes
-SIZE_TOLERANCE_GZ = 32*1024 # 32 KiB due to Gzip/Bzip2 compression object buffer
-SIZE_TOLERANCE_BZ2 = 1024*1024 # 1MB!
-SIZE_TOLERANCE_XZ = 72*1024
-SIZE_TOLERANCE_NONE = 5*BLOCKSIZE
+KiB = 1024
+MiB = KiB * KiB
+SIZE_TOLERANCE_GZ = 32*KiB # Gzip compression object buffer
+SIZE_TOLERANCE_BZ2 = MiB
+SIZE_TOLERANCE_XZ = 72*KiB
+SIZE_TOLERANCE_NONE = 3*BLOCKSIZE # should be little
#: variables for find_random_files
DIR_RETURN_MIN_REC = 5
clean_up_if_error=False, debug_level=0):
""" create TarFile with given vol_size, add vol_size*input_size
- :param volume_size: in MB
+ :param volume_size: in MiB
:param str prefix: optional output prefix
:param str mode: compression mode for TarFile's mode argument
:param bool clean_up_if_error: True will ensure there are no files left;
:returns: True if test failed (some size wrong, file missing, ...)
"""
- input_size = volume_size * input_size_factor * 1e6
+ input_size = volume_size * input_size_factor * MiB
something_strange = False
if 'gz' in mode:
if debug_level:
print(prefix + 'tarfile: ' + temp_name)
- volume_prefix = prefix + 'vol={}MB, in=*{}, mode={}: ' \
+ volume_prefix = prefix + 'vol={}MiB, in=*{}, mode={}: ' \
.format(volume_size, input_size_factor, mode)
def vol_handler(a,b,c):
return new_volume_handler(a,b,c, volume_prefix, debug_level)
# create tar object
tarobj = TarFile.open(temp_name, mode=mode,
- max_volume_size=volume_size*1.e6,
+ max_volume_size=volume_size*MiB,
new_volume_handler=vol_handler,
password='test1234', debug=debug_level)
if file_name.startswith(base_name):
continue # do not accidentally add self
new_size = os.lstat(file_name).st_size
- if new_size > max(volume_size*1.e6, input_size-added_size):
+ if new_size > max(volume_size*MiB, input_size-added_size):
continue # add at most one volume_size too much
new_name = '{}_{:04d}_{}_{:09d}' \
.format(base_name, count,
files_added.append(new_name)
added_size += new_size
if debug_level > 2:
- print('{}vol={}MB, in=*{}, mode={}: added {:.1f}MB/{:.1f}MB'
+ print('{}vol={}MiB, in=*{}, mode={}: added {:.1f}MiB/{:.1f}MiB'
.format(prefix, volume_size, input_size_factor, mode,
- added_size/1e6, input_size/1e6))
+ added_size/MiB, input_size/MiB))
if added_size > input_size:
break
tarobj.close()
volume_size_sum += vol_size
if debug_level:
print('{} - {}: {:.3f}'.format(prefix, file_name,
- vol_size/1.e6))
- if abs(vol_size - volume_size*1e6) > size_tolerance:
+ vol_size/MiB))
+ if abs(vol_size - volume_size*MiB) > size_tolerance:
n_wrong_size += 1
if debug_level:
:retuns: number of failed tests
"""
- # volume sizes in MB
+ # volume sizes in MiB
volume_sizes = 10, 100
# input size factor (multiplied with volume size)