From 20e1d773af8cb664d267d04478a03e06436cfb28 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 15 Aug 2017 15:38:17 +0200 Subject: [PATCH] add test corrupting an entire volume Zero out the first volume: None of the content can be restored. This includes the file extending from the first into the second volume. --- runtests.py | 11 ++++++++--- testing/test_recover.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/runtests.py b/runtests.py index 56046d2..eb81a83 100755 --- a/runtests.py +++ b/runtests.py @@ -46,7 +46,10 @@ from testing.test_recover import \ , RecoverCorruptTrailingDataGZSingleTest \ , RecoverCorruptTrailingDataGZMultiTest \ , RecoverCorruptTrailingDataGZAESSingleTest \ - , RecoverCorruptTrailingDataGZAESMultiTest + , RecoverCorruptTrailingDataGZAESMultiTest \ + , RecoverCorruptVolumeTest \ + , RecoverCorruptVolumeGZTest \ + , RecoverCorruptVolumeGZAESTest from testing.test_rescue_tar import RescueTarTest from testing.test_encryption import EncryptionTest from testing.test_deltatar import (DeltaTarTest, DeltaTar2Test, @@ -80,8 +83,8 @@ if __name__ == "__main__": , DeltaTarGzipAes128ConcatTest , DeltaTarAes128ConcatTest , HeaderTest, AESGCMTest - # testing.test_recover + # testing.test_recover , RecoverCorruptPayloadSingleTest , RecoverCorruptPayloadMultiTest , RecoverCorruptPayloadGZSingleTest @@ -105,7 +108,9 @@ if __name__ == "__main__": , RecoverCorruptTrailingDataGZSingleTest , RecoverCorruptTrailingDataGZMultiTest , RecoverCorruptTrailingDataGZAESSingleTest - , RecoverCorruptTrailingDataGZAESMultiTest + , RecoverCorruptVolumeTest + , RecoverCorruptVolumeGZTest + , RecoverCorruptVolumeGZAESTest ]: try: t = group (n) diff --git a/testing/test_recover.py b/testing/test_recover.py index e2a6292..e936e89 100644 --- a/testing/test_recover.py +++ b/testing/test_recover.py @@ -13,6 +13,7 @@ TEST_VOLSIZ = 2 # MB TEST_FILESPERVOL = 3 VOLUME_OVERHEAD = 1.4 # account for tar overhead when fitting files into # volumes; this is black magic +TEST_BLOCKSIZE = 4096 ############################################################################### ## helpers ## @@ -132,6 +133,21 @@ def corrupt_trailing_data (_, fname, compress, encrypt): os.close (fd) +def corrupt_volume (_, fname, compress, encrypt): + """ + Zero out an entire volume. + """ + fd = os.open (fname, os.O_WRONLY) + size = os.lseek (fd, 0, os.SEEK_END) + assert os.lseek (fd, 0, os.SEEK_SET) == 0 + zeros = bytes (b'\x00' * TEST_BLOCKSIZE) + while size > 0: + todo = min (size, TEST_BLOCKSIZE) + os.write (fd, zeros [:todo]) + size -= todo + os.close (fd) + + ############################################################################### ## tests ## ############################################################################### @@ -476,3 +492,28 @@ class RecoverCorruptTrailingDataGZAESSingleTest (RecoverCorruptTrailingDataGZAES class RecoverCorruptTrailingDataGZAESMultiTest (RecoverCorruptTrailingDataGZAESTestBase): VOLUMES = 3 + +class RecoverCorruptVolumeBaseTest (RecoverTest): + COMPRESSION = None + PASSWORD = None + FAILURES = 8 + CORRUPT = corrupt_volume + VOLUMES = 3 + +class RecoverCorruptVolumeTest (RecoverCorruptVolumeBaseTest): + pass + +class RecoverCorruptVolumeGZTest (RecoverTest): + COMPRESSION = "#gz" + PASSWORD = None + FAILURES = 8 + CORRUPT = corrupt_volume + VOLUMES = 3 + +class RecoverCorruptVolumeGZAESTest (RecoverTest): + COMPRESSION = "#gz" + PASSWORD = TEST_PASSWORD + FAILURES = 8 + CORRUPT = corrupt_volume + VOLUMES = 3 + -- 1.7.1