minor improvements
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 27 Jul 2016 07:49:26 +0000 (09:49 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 12 Nov 2020 14:04:34 +0000 (15:04 +0100)
testing/test_volume_split.py

index 2c96631..0f1660b 100755 (executable)
@@ -49,7 +49,7 @@ N_BLOCKS_PER_RECORD = RECORDSIZE // BLOCKSIZE
 MAX_VOLUME_BLOCKS = N_BLOCKS_PER_RECORD + 1
 
 #: size of big file: fits into first volume even if not compressed
-BIG_SIZE = (MAX_VOLUME_BLOCKS-3) * BLOCKSIZE
+BIG_SIZE = (MAX_VOLUME_BLOCKS-4) * BLOCKSIZE
 
 #: max size of small files
 SMALL_MAX_SIZE = 2 * BLOCKSIZE
@@ -64,7 +64,7 @@ SEED_BITS = int(log2(sys.maxsize+1))
 HASH_BUF_SIZE = 4096
 
 #: modes for tar file creation
-CREATE_MODES = 'w:tar', 'w|tar', 'w|gz', 'w|bz2', 'w#gz'
+CREATE_MODES = 'w:tar', 'w|tar', 'w|gz', 'w|bz2', 'w#gz', \
                #'w#gz.aes128', 'w#gz.aes256', 'w#aes128', 'w#aes256'
                # not currently working: 'w:gz', 'w:bz2',
 
@@ -150,7 +150,7 @@ def do_test(seed, create_mode, extract_mode, temp_dir, print_everything=False):
     output = []
     if print_everything:
         print('-' * 72)
-        prefix = '{:9d}: '.format(seed)
+        prefix = '{:10d}: '.format(seed)
         dprnt = lambda val: print(prefix + val)
     else:
         dprnt = output.append
@@ -207,7 +207,7 @@ def do_test(seed, create_mode, extract_mode, temp_dir, print_everything=False):
 
             # add big file
             big_name, big_hash, file_info = create_file(BIG_SIZE, temp_dir)
-            files[big_name] = big_hash
+            files[big_name] = (big_hash, BIG_SIZE)
             dprnt('adding big file {} of size {}, info {} with hash {}'
                   .format(big_name, BIG_SIZE, file_info, big_hash))
             tarobj.add(big_name, arcname=basename(big_name))
@@ -226,7 +226,7 @@ def do_test(seed, create_mode, extract_mode, temp_dir, print_everything=False):
                 small_size = random.randint(0, SMALL_MAX_SIZE)
                 small_name, small_hash, file_info = create_file(small_size,
                                                                 temp_dir)
-                files[small_name] = small_hash
+                files[small_name] = (small_hash, small_size)
                 dprnt('adding small file {} of size {}, info {} with hash {}'
                       .format(small_name, small_size, file_info, small_hash))
                 tarobj.add(small_name, arcname=basename(small_name))
@@ -269,12 +269,18 @@ def do_test(seed, create_mode, extract_mode, temp_dir, print_everything=False):
             for file_name in os.listdir(temp_dir):
                 dprnt('listdir: {}'.format(file_name))
 
-        for file_name, file_hash in files.items():
+        for file_name, (file_hash, file_size) in files.items():
             if not os.path.exists(file_name):
                 everything_ok = False
                 dprnt('failed to find file {} after extraction'
                       .format(file_name))
                 continue
+            if os.stat(file_name).st_size != file_size:
+                everything_ok = False
+                dprnt('wrong size for file {} after extraction: {} != {}'
+                      .format(file_name, os.stat(file_name).st_size,
+                              file_size))
+                continue
             if hash_file(file_name) != file_hash:
                 everything_ok = False
                 dprnt('wrong hash for file {} after extraction: {} != {}'
@@ -296,7 +302,7 @@ def do_test(seed, create_mode, extract_mode, temp_dir, print_everything=False):
                 pass
 
     if (not print_everything) and (not everything_ok):
-        prefix = '{:9d}: '.format(seed)
+        prefix = '{:10d}: '.format(seed)
         for line in output:
             print(prefix + line)
     elif print_everything and everything_ok: