Commit ea5b03ce authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm: Test for manual (for now) testing

This guy touches a random page once per second and backs-up
what was touched. At the end it checks whether everything is
OK. It can be used to test how snapshots work -- take several
snapshots with several seconds pauses in betweem and restore
form the last.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent af03e7d5
......@@ -92,6 +92,7 @@ TST_NOFILE = \
posix_timers \
sigpending \
sk-netlink \
mem-touch \
# jobctl00 \
TST_FILE = \
......
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/mman.h>
#include "zdtmtst.h"
const char *test_doc = "Check changing memory";
const char *test_author = "Pavel Emelyanov <xemul@parallels.com>";
#define MEM_PAGES 16
#define PAGE_SIZE 4096
int main(int argc, char **argv)
{
void *mem;
int i, fail = 0;
unsigned rover = 1;
unsigned backup[MEM_PAGES] = {};
srand(time(NULL));
test_init(argc, argv);
mem = mmap(NULL, MEM_PAGES * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0);
if (mem == MAP_FAILED)
return 1;
test_msg("mem %p backup %p\n", mem, backup);
test_daemon();
while (test_go()) {
unsigned pfn;
pfn = random() % MEM_PAGES;
*(unsigned *)(mem + pfn * PAGE_SIZE) = rover;
backup[pfn] = rover;
test_msg("t %u %u\n", pfn, rover);
rover++;
sleep(1);
}
test_waitsig();
test_msg("final rover %u\n", rover);
for (i = 0; i < MEM_PAGES; i++)
if (backup[i] != *(unsigned *)(mem + i * PAGE_SIZE)) {
test_msg("Page %u differs want %u has %u\n", i,
backup[i], *(unsigned *)(mem + i * PAGE_SIZE));
fail = 1;
} else
test_msg("Page %u matches %u\n", i, backup[i]);
if (fail)
fail("Memory corruption\n");
else
pass();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment