criu/test/zdtm/static/mem-touch.c
Pavel Emelyanov 2e13f1f029 test: Get rid of live directory
Move static and transition into zdtm top. We can't move all the micro
tests themselves, as we need to distinguish static from non static (zdtm.py
makes additional checks on static ones).

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-02-20 13:40:52 +03:00

62 lines
1.3 KiB
C

#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
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;
struct timespec req = { .tv_sec = 0, .tv_nsec = 100000, };
pfn = random() % MEM_PAGES;
*(unsigned *)(mem + pfn * PAGE_SIZE) = rover;
backup[pfn] = rover;
test_msg("t %u %u\n", pfn, rover);
rover++;
nanosleep(&req, NULL);
}
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;
}