Skip to content

Commit

Permalink
zdtm: add checksum tests
Browse files Browse the repository at this point in the history
This adds 6 tests:
1. The last byte of the file is altered after dump and before restore,
causing restore to fail (checksum-full)

2. checksum, checksum-parameter = 10485800 (First 10485800 bytes are
checksummed)

3. checksum-period, checksum-parameter = 10485800 (Every 10485800th byte
is checksummed)

4. checksum, checksum-parameter = 10485700 (First 10485700 bytes are
checksummed)

5. checksum-period, checksum-parameter = 10485700 (Every 10485700th byte
is checksummed)

6. The last byte of a file of size 10485800 bytes is altered after dump
and before restore, causing restore to fail
checksum, checksum-parameter = 10485800 (First 10485800 bytes are
checksummed)

Signed-off-by: Ajay Bharadwaj <ajayrbharadwaj@gmail.com>
  • Loading branch information
AnorexicAtticusFinch committed Aug 30, 2020
1 parent ee9ded1 commit 2ef7543
Show file tree
Hide file tree
Showing 19 changed files with 467 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/zdtm/static/Makefile
Expand Up @@ -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 \
Expand Down
50 changes: 50 additions & 0 deletions test/zdtm/static/file-validation-chksm00.c
@@ -0,0 +1,50 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#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 <ajayrbharadwaj@gmail.com>";

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;
}
1 change: 1 addition & 0 deletions test/zdtm/static/file-validation-chksm00.desc
@@ -0,0 +1 @@
{'opts': '--file-validation checksum-full', 'flags': 'crfail-restore'}
16 changes: 16 additions & 0 deletions 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
74 changes: 74 additions & 0 deletions test/zdtm/static/file-validation-chksm01.c
@@ -0,0 +1,74 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#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 <ajayrbharadwaj@gmail.com>";

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;
}
1 change: 1 addition & 0 deletions test/zdtm/static/file-validation-chksm01.desc
@@ -0,0 +1 @@
{'opts': '--file-validation checksum --checksum-parameter 10485800'}
5 changes: 5 additions & 0 deletions test/zdtm/static/file-validation-chksm01.hook
@@ -0,0 +1,5 @@
#!/bin/bash

[ "$1" == "--clean" ] || exit 0

rm "${0%.*}.test"
74 changes: 74 additions & 0 deletions test/zdtm/static/file-validation-chksm02.c
@@ -0,0 +1,74 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#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 <ajayrbharadwaj@gmail.com>";

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;
}
1 change: 1 addition & 0 deletions test/zdtm/static/file-validation-chksm02.desc
@@ -0,0 +1 @@
{'opts': '--file-validation checksum-period --checksum-parameter 10485800'}
5 changes: 5 additions & 0 deletions test/zdtm/static/file-validation-chksm02.hook
@@ -0,0 +1,5 @@
#!/bin/bash

[ "$1" == "--clean" ] || exit 0

rm "${0%.*}.test"
74 changes: 74 additions & 0 deletions test/zdtm/static/file-validation-chksm03.c
@@ -0,0 +1,74 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#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 <ajayrbharadwaj@gmail.com>";

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;
}
1 change: 1 addition & 0 deletions test/zdtm/static/file-validation-chksm03.desc
@@ -0,0 +1 @@
{'opts': '--file-validation checksum --checksum-parameter 10485700'}
5 changes: 5 additions & 0 deletions test/zdtm/static/file-validation-chksm03.hook
@@ -0,0 +1,5 @@
#!/bin/bash

[ "$1" == "--clean" ] || exit 0

rm "${0%.*}.test"

0 comments on commit 2ef7543

Please sign in to comment.