From e1d10bea5d9fc94ba800ade1de430c7f3c0ccacd Mon Sep 17 00:00:00 2001 From: Jan Sucan Date: Sun, 6 Mar 2022 05:59:49 +0100 Subject: tests: Unify naming of the test files --- tests/300-incorrect-reference-file.sh | 37 ---------------------- tests/300-incorrect_reference_file.sh | 37 ++++++++++++++++++++++ tests/400-successful-backup-restore.sh | 56 ---------------------------------- tests/400-successful_backup_restore.sh | 56 ++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 93 deletions(-) delete mode 100644 tests/300-incorrect-reference-file.sh create mode 100644 tests/300-incorrect_reference_file.sh delete mode 100644 tests/400-successful-backup-restore.sh create mode 100644 tests/400-successful_backup_restore.sh (limited to 'tests') diff --git a/tests/300-incorrect-reference-file.sh b/tests/300-incorrect-reference-file.sh deleted file mode 100644 index b3de8c0..0000000 --- a/tests/300-incorrect-reference-file.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -source ./assert.sh - -PROGRAM_EXEC="$1" - -rm -f ref out -touch ref out -assert_error "reference file is empty" $PROGRAM_EXEC ref out - -dd if=/dev/zero of=ref bs=513 count=1 1>/dev/null 2>&1 -assert_error "reference file has size that cannot contain valid diff data" \ - $PROGRAM_EXEC -s 512 ref out - -rm -f ref out -dd if=/dev/zero of=out bs=512 count=2 1>/dev/null 2>&1 -# Create a two-sector backup file -dd if=/dev/zero of=ref bs=$(( 512 + 8 )) count=2 1>/dev/null 2>&1 -# The first offset will be 2 -printf '\x02' | dd of=ref bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1 -# The second offset will be 1 -printf '\x01' | dd of=ref bs=1 count=1 seek=520 conv=notrunc 1>/dev/null 2>&1 -assert_error "a sector offset points behind the previous offset" \ - $PROGRAM_EXEC -s 512 ref out - -rm -f ref out -dd if=/dev/zero of=out bs=512 count=1 1>/dev/null 2>&1 -# Create a one-sector backup file -dd if=/dev/zero of=ref bs=$(( 512 + 8 )) count=2 1>/dev/null 2>&1 -# The first offset will be 1 -printf '\x01' | dd of=ref bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1 -assert_error "a sector offset points past the end of the output file" \ - $PROGRAM_EXEC -s 512 ref out - -rm -f ref out - -exit 0 diff --git a/tests/300-incorrect_reference_file.sh b/tests/300-incorrect_reference_file.sh new file mode 100644 index 0000000..b3de8c0 --- /dev/null +++ b/tests/300-incorrect_reference_file.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +source ./assert.sh + +PROGRAM_EXEC="$1" + +rm -f ref out +touch ref out +assert_error "reference file is empty" $PROGRAM_EXEC ref out + +dd if=/dev/zero of=ref bs=513 count=1 1>/dev/null 2>&1 +assert_error "reference file has size that cannot contain valid diff data" \ + $PROGRAM_EXEC -s 512 ref out + +rm -f ref out +dd if=/dev/zero of=out bs=512 count=2 1>/dev/null 2>&1 +# Create a two-sector backup file +dd if=/dev/zero of=ref bs=$(( 512 + 8 )) count=2 1>/dev/null 2>&1 +# The first offset will be 2 +printf '\x02' | dd of=ref bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1 +# The second offset will be 1 +printf '\x01' | dd of=ref bs=1 count=1 seek=520 conv=notrunc 1>/dev/null 2>&1 +assert_error "a sector offset points behind the previous offset" \ + $PROGRAM_EXEC -s 512 ref out + +rm -f ref out +dd if=/dev/zero of=out bs=512 count=1 1>/dev/null 2>&1 +# Create a one-sector backup file +dd if=/dev/zero of=ref bs=$(( 512 + 8 )) count=2 1>/dev/null 2>&1 +# The first offset will be 1 +printf '\x01' | dd of=ref bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1 +assert_error "a sector offset points past the end of the output file" \ + $PROGRAM_EXEC -s 512 ref out + +rm -f ref out + +exit 0 diff --git a/tests/400-successful-backup-restore.sh b/tests/400-successful-backup-restore.sh deleted file mode 100644 index ce5949a..0000000 --- a/tests/400-successful-backup-restore.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -source ./assert.sh - -PROGRAM_EXEC="$1" - -function files_are_the_same() -{ - [ -z "$(diff "$1" "$2")" ] -} - -rm -f input backedup_input ref out - -# Create a four-sector reference file (the original file) -dd if=/dev/zero of=ref bs=512 count=4 1>/dev/null 2>&1 - -# Change the orignal file to make it an input file for differential backup -# There will be four different sectors in the input file -cp ref input - -# The first sector will have the 0th byte chaged -printf '\xFF' | dd of=input bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1 - -# The second sector will have no changes - -# The third sector will have the last byte changed -printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 3) - 1 )) conv=notrunc 1>/dev/null 2>&1 - -# The fourth sector will have the middle byte changed -printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 4) - (512 / 2) )) conv=notrunc 1>/dev/null 2>&1 - -assert_success $PROGRAM_EXEC -s 512 input ref out - -if ! files_are_the_same out 400-expected_backup_output.bin; then - echo "assert: Backup output file differs from the expected one" - exit 1 -fi - -# Modify the file to backup (the input file used in the backup phase) -cp input backedup_input -cp ref input -if ! files_are_the_same ref input; then - echo "assert: The input file must be the same as the reference one before restoring it" - exit 1 -fi - -assert_success $PROGRAM_EXEC -s 512 out input - -if ! files_are_the_same input backedup_input; then - echo "assert: Cannot restore the backup" - exit 1 -fi - -rm -f input backedup_input ref out - -exit 0 diff --git a/tests/400-successful_backup_restore.sh b/tests/400-successful_backup_restore.sh new file mode 100644 index 0000000..ce5949a --- /dev/null +++ b/tests/400-successful_backup_restore.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +source ./assert.sh + +PROGRAM_EXEC="$1" + +function files_are_the_same() +{ + [ -z "$(diff "$1" "$2")" ] +} + +rm -f input backedup_input ref out + +# Create a four-sector reference file (the original file) +dd if=/dev/zero of=ref bs=512 count=4 1>/dev/null 2>&1 + +# Change the orignal file to make it an input file for differential backup +# There will be four different sectors in the input file +cp ref input + +# The first sector will have the 0th byte chaged +printf '\xFF' | dd of=input bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1 + +# The second sector will have no changes + +# The third sector will have the last byte changed +printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 3) - 1 )) conv=notrunc 1>/dev/null 2>&1 + +# The fourth sector will have the middle byte changed +printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 4) - (512 / 2) )) conv=notrunc 1>/dev/null 2>&1 + +assert_success $PROGRAM_EXEC -s 512 input ref out + +if ! files_are_the_same out 400-expected_backup_output.bin; then + echo "assert: Backup output file differs from the expected one" + exit 1 +fi + +# Modify the file to backup (the input file used in the backup phase) +cp input backedup_input +cp ref input +if ! files_are_the_same ref input; then + echo "assert: The input file must be the same as the reference one before restoring it" + exit 1 +fi + +assert_success $PROGRAM_EXEC -s 512 out input + +if ! files_are_the_same input backedup_input; then + echo "assert: Cannot restore the backup" + exit 1 +fi + +rm -f input backedup_input ref out + +exit 0 -- cgit v1.2.3