diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index e687a425f5..61846a3589 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -313,6 +313,12 @@ TST_FILE = \ file-validation-buildid01 \ file-validation-buildid02 \ file-validation-buildid03 \ + file-validation-chksm00 \ + file-validation-chksm01 \ + file-validation-chksm02 \ + file-validation-chksm03 \ + file-validation-chksm04 \ + file-validation-chksm05 \ TST_DIR = \ cwd00 \ diff --git a/test/zdtm/static/file-validation-chksm00.c b/test/zdtm/static/file-validation-chksm00.c new file mode 100644 index 0000000000..6814df4c9e --- /dev/null +++ b/test/zdtm/static/file-validation-chksm00.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "File validation test for checksum (Should fail during restore, uses checksum-full)"; +const char *test_author = "Ajay Bharadwaj "; + +char *filename; +TEST_OPTION(filename, string, "file name", 1); + +#define BUF_SIZE 1024 + +int main(int argc, char **argv) +{ + int fd; + uint8_t buf[BUF_SIZE]; + uint32_t crc; + + test_init(argc, argv); + + fd = open(filename, O_RDWR | O_CREAT, 0666); + if (fd < 0) { + pr_perror("Can't open %s", filename); + return 1; + } + + crc = ~0; + datagen(buf, BUF_SIZE, &crc); + if (write_data(fd, buf, BUF_SIZE)) { + pr_perror("write() failed"); + return 1; + } + + test_daemon(); + test_waitsig(); + + if (close(fd) < 0) { + pr_perror("Can't close %s", filename); + return 1; + } + + fail("Restore passed even though file was altered\n"); + return 0; +} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm00.desc b/test/zdtm/static/file-validation-chksm00.desc new file mode 100644 index 0000000000..0daaba7b0c --- /dev/null +++ b/test/zdtm/static/file-validation-chksm00.desc @@ -0,0 +1 @@ +{'opts': '--file-validation checksum-full', 'flags': 'crfail-restore'} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm00.hook b/test/zdtm/static/file-validation-chksm00.hook new file mode 100755 index 0000000000..d8257b4def --- /dev/null +++ b/test/zdtm/static/file-validation-chksm00.hook @@ -0,0 +1,16 @@ +#!/bin/bash + +[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0 + +filename="${0%.*}.test" + +if [ "$1" == "--pre-restore" ] +then + set -e -- $(ls -l $filename) + pos=$(( $5 - 1 )) + data=$(od -j "$pos" -t u1 -A n "$9") + invdata=$(printf '%02x' $(( data ^ 0xff ))) + printf "\\x${invdata}" | dd of="$9" obs="$pos" seek=1 +else + rm $filename +fi \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm01.c b/test/zdtm/static/file-validation-chksm01.c new file mode 100644 index 0000000000..3573f8ee63 --- /dev/null +++ b/test/zdtm/static/file-validation-chksm01.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "File validation test for checksum (checksum-first) with checksum parameter greater than CHSKM_CHUNK_SIZE (10MB)"; +const char *test_author = "Ajay Bharadwaj "; + +char *filename; +TEST_OPTION(filename, string, "file name", 1); + +#define BUF_SIZE 104857600 + +int main(int argc, char **argv) +{ + int fd; + void *buf; + uint32_t crc; + + test_init(argc, argv); + + fd = open(filename, O_RDWR | O_CREAT, 0666); + if (fd < 0) { + pr_perror("Can't open %s", filename); + return 1; + } + + buf = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buf == MAP_FAILED) { + pr_perror("mmap() failed"); + return 1; + } + + crc = ~0; + datagen(buf, BUF_SIZE, &crc); + if (write_data(fd, buf, BUF_SIZE)) { + pr_perror("write() failed"); + return 1; + } + + test_daemon(); + test_waitsig(); + + if (lseek(fd, 0, SEEK_SET) < 0) + { + pr_perror("lseek() failed"); + return -1; + } + + if (read_data(fd, buf, BUF_SIZE)) { + pr_perror("read() failed"); + return 1; + } + + crc = ~0; + if (datachk(buf, BUF_SIZE, &crc)) { + fail("Data in file has been changed\n"); + return 1; + } + + if (close(fd) < 0) { + pr_perror("Can't close %s", filename); + return 1; + } + + pass(); + return 0; +} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm01.desc b/test/zdtm/static/file-validation-chksm01.desc new file mode 100644 index 0000000000..c751d056d3 --- /dev/null +++ b/test/zdtm/static/file-validation-chksm01.desc @@ -0,0 +1 @@ +{'opts': '--file-validation checksum --checksum-parameter 10485800'} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm01.hook b/test/zdtm/static/file-validation-chksm01.hook new file mode 100755 index 0000000000..5cf62cdafa --- /dev/null +++ b/test/zdtm/static/file-validation-chksm01.hook @@ -0,0 +1,5 @@ +#!/bin/bash + +[ "$1" == "--clean" ] || exit 0 + +rm "${0%.*}.test" \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm02.c b/test/zdtm/static/file-validation-chksm02.c new file mode 100644 index 0000000000..7178c534ad --- /dev/null +++ b/test/zdtm/static/file-validation-chksm02.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "File validation test for checksum (checksum-period) with checksum parameter greater than CHSKM_CHUNK_SIZE (10MB)"; +const char *test_author = "Ajay Bharadwaj "; + +char *filename; +TEST_OPTION(filename, string, "file name", 1); + +#define BUF_SIZE 104857600 + +int main(int argc, char **argv) +{ + int fd; + void *buf; + uint32_t crc; + + test_init(argc, argv); + + fd = open(filename, O_RDWR | O_CREAT, 0666); + if (fd < 0) { + pr_perror("Can't open %s", filename); + return 1; + } + + buf = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buf == MAP_FAILED) { + pr_perror("mmap() failed"); + return 1; + } + + crc = ~0; + datagen(buf, BUF_SIZE, &crc); + if (write_data(fd, buf, BUF_SIZE)) { + pr_perror("write() failed"); + return 1; + } + + test_daemon(); + test_waitsig(); + + if (lseek(fd, 0, SEEK_SET) < 0) + { + pr_perror("lseek() failed"); + return -1; + } + + if (read_data(fd, buf, BUF_SIZE)) { + pr_perror("read() failed"); + return 1; + } + + crc = ~0; + if (datachk(buf, BUF_SIZE, &crc)) { + fail("Data in file has been changed\n"); + return 1; + } + + if (close(fd) < 0) { + pr_perror("Can't close %s", filename); + return 1; + } + + pass(); + return 0; +} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm02.desc b/test/zdtm/static/file-validation-chksm02.desc new file mode 100644 index 0000000000..36a8421026 --- /dev/null +++ b/test/zdtm/static/file-validation-chksm02.desc @@ -0,0 +1 @@ +{'opts': '--file-validation checksum-period --checksum-parameter 10485800'} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm02.hook b/test/zdtm/static/file-validation-chksm02.hook new file mode 100755 index 0000000000..5cf62cdafa --- /dev/null +++ b/test/zdtm/static/file-validation-chksm02.hook @@ -0,0 +1,5 @@ +#!/bin/bash + +[ "$1" == "--clean" ] || exit 0 + +rm "${0%.*}.test" \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm03.c b/test/zdtm/static/file-validation-chksm03.c new file mode 100644 index 0000000000..6d7cdfe943 --- /dev/null +++ b/test/zdtm/static/file-validation-chksm03.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "File validation test for checksum (checksum-first) with checksum parameter less than CHSKM_CHUNK_SIZE (10MB)"; +const char *test_author = "Ajay Bharadwaj "; + +char *filename; +TEST_OPTION(filename, string, "file name", 1); + +#define BUF_SIZE 104857600 + +int main(int argc, char **argv) +{ + int fd; + void *buf; + uint32_t crc; + + test_init(argc, argv); + + fd = open(filename, O_RDWR | O_CREAT, 0666); + if (fd < 0) { + pr_perror("Can't open %s", filename); + return 1; + } + + buf = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buf == MAP_FAILED) { + pr_perror("mmap() failed"); + return 1; + } + + crc = ~0; + datagen(buf, BUF_SIZE, &crc); + if (write_data(fd, buf, BUF_SIZE)) { + pr_perror("write() failed"); + return 1; + } + + test_daemon(); + test_waitsig(); + + if (lseek(fd, 0, SEEK_SET) < 0) + { + pr_perror("lseek() failed"); + return -1; + } + + if (read_data(fd, buf, BUF_SIZE)) { + pr_perror("read() failed"); + return 1; + } + + crc = ~0; + if (datachk(buf, BUF_SIZE, &crc)) { + fail("Data in file has been changed\n"); + return 1; + } + + if (close(fd) < 0) { + pr_perror("Can't close %s", filename); + return 1; + } + + pass(); + return 0; +} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm03.desc b/test/zdtm/static/file-validation-chksm03.desc new file mode 100644 index 0000000000..1bd341f667 --- /dev/null +++ b/test/zdtm/static/file-validation-chksm03.desc @@ -0,0 +1 @@ +{'opts': '--file-validation checksum --checksum-parameter 10485700'} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm03.hook b/test/zdtm/static/file-validation-chksm03.hook new file mode 100755 index 0000000000..5cf62cdafa --- /dev/null +++ b/test/zdtm/static/file-validation-chksm03.hook @@ -0,0 +1,5 @@ +#!/bin/bash + +[ "$1" == "--clean" ] || exit 0 + +rm "${0%.*}.test" \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm04.c b/test/zdtm/static/file-validation-chksm04.c new file mode 100644 index 0000000000..d7e671ac0a --- /dev/null +++ b/test/zdtm/static/file-validation-chksm04.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "File validation test for checksum (checksum-period) with checksum parameter less than CHSKM_CHUNK_SIZE (10MB)"; +const char *test_author = "Ajay Bharadwaj "; + +char *filename; +TEST_OPTION(filename, string, "file name", 1); + +#define BUF_SIZE 104857600 + +int main(int argc, char **argv) +{ + int fd; + void *buf; + uint32_t crc; + + test_init(argc, argv); + + fd = open(filename, O_RDWR | O_CREAT, 0666); + if (fd < 0) { + pr_perror("Can't open %s", filename); + return 1; + } + + buf = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buf == MAP_FAILED) { + pr_perror("mmap() failed"); + return 1; + } + + crc = ~0; + datagen(buf, BUF_SIZE, &crc); + if (write_data(fd, buf, BUF_SIZE)) { + pr_perror("write() failed"); + return 1; + } + + test_daemon(); + test_waitsig(); + + if (lseek(fd, 0, SEEK_SET) < 0) + { + pr_perror("lseek() failed"); + return -1; + } + + if (read_data(fd, buf, BUF_SIZE)) { + pr_perror("read() failed"); + return 1; + } + + crc = ~0; + if (datachk(buf, BUF_SIZE, &crc)) { + fail("Data in file has been changed\n"); + return 1; + } + + if (close(fd) < 0) { + pr_perror("Can't close %s", filename); + return 1; + } + + pass(); + return 0; +} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm04.desc b/test/zdtm/static/file-validation-chksm04.desc new file mode 100644 index 0000000000..0a6970206e --- /dev/null +++ b/test/zdtm/static/file-validation-chksm04.desc @@ -0,0 +1 @@ +{'opts': '--file-validation checksum-period --checksum-parameter 10485700'} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm04.hook b/test/zdtm/static/file-validation-chksm04.hook new file mode 100755 index 0000000000..5cf62cdafa --- /dev/null +++ b/test/zdtm/static/file-validation-chksm04.hook @@ -0,0 +1,5 @@ +#!/bin/bash + +[ "$1" == "--clean" ] || exit 0 + +rm "${0%.*}.test" \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm05.c b/test/zdtm/static/file-validation-chksm05.c new file mode 100644 index 0000000000..72b14fffe6 --- /dev/null +++ b/test/zdtm/static/file-validation-chksm05.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "File validation test for checksum (checksum-first) with checksum parameter and file size equal to 10485800 (Should fail during restore)"; +const char *test_author = "Ajay Bharadwaj "; + +char *filename; +TEST_OPTION(filename, string, "file name", 1); + +#define BUF_SIZE 10485800 + +int main(int argc, char **argv) +{ + int fd; + void *buf; + uint32_t crc; + + test_init(argc, argv); + + fd = open(filename, O_RDWR | O_CREAT, 0666); + if (fd < 0) { + pr_perror("Can't open %s", filename); + return 1; + } + + buf = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buf == MAP_FAILED) { + pr_perror("mmap() failed"); + return 1; + } + + crc = ~0; + datagen(buf, BUF_SIZE, &crc); + if (write_data(fd, buf, BUF_SIZE)) { + pr_perror("write() failed"); + return 1; + } + + test_daemon(); + test_waitsig(); + + if (close(fd) < 0) { + pr_perror("Can't close %s", filename); + return 1; + } + + fail("Restore passed even though file was altered\n"); + return 0; +} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm05.desc b/test/zdtm/static/file-validation-chksm05.desc new file mode 100644 index 0000000000..61d043bd8e --- /dev/null +++ b/test/zdtm/static/file-validation-chksm05.desc @@ -0,0 +1 @@ +{'opts': '--file-validation checksum --checksum-parameter 10485800', 'flags': 'crfail-restore'} \ No newline at end of file diff --git a/test/zdtm/static/file-validation-chksm05.hook b/test/zdtm/static/file-validation-chksm05.hook new file mode 100755 index 0000000000..d8257b4def --- /dev/null +++ b/test/zdtm/static/file-validation-chksm05.hook @@ -0,0 +1,16 @@ +#!/bin/bash + +[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0 + +filename="${0%.*}.test" + +if [ "$1" == "--pre-restore" ] +then + set -e -- $(ls -l $filename) + pos=$(( $5 - 1 )) + data=$(od -j "$pos" -t u1 -A n "$9") + invdata=$(printf '%02x' $(( data ^ 0xff ))) + printf "\\x${invdata}" | dd of="$9" obs="$pos" seek=1 +else + rm $filename +fi \ No newline at end of file