mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-24 18:49:44 +00:00
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>
78 lines
1.4 KiB
C
78 lines
1.4 KiB
C
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <sys/mount.h>
|
|
#include <sys/stat.h>
|
|
#include <linux/limits.h>
|
|
|
|
#include "zdtmtst.h"
|
|
|
|
const char *test_doc = "Check read-only tmpfs mount";
|
|
const char *test_author = "Andrew Vagin <avagin@openvz.org>";
|
|
|
|
char *dirname;
|
|
TEST_OPTION(dirname, string, "directory name", 1);
|
|
|
|
#define TEST_WORD "testtest"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int fd, ret = 1;
|
|
char buf[1024], fname[PATH_MAX];
|
|
|
|
test_init(argc, argv);
|
|
|
|
mkdir(dirname, 0700);
|
|
if (mount("none", dirname, "tmpfs", 0, "") < 0) {
|
|
fail("Can't mount tmpfs");
|
|
return 1;
|
|
}
|
|
|
|
snprintf(fname, sizeof(buf), "%s/test.file", dirname);
|
|
fd = open(fname, O_RDWR | O_CREAT, 0644);
|
|
if (fd < 0) {
|
|
pr_perror("open failed");
|
|
goto err;
|
|
}
|
|
|
|
if (write(fd, TEST_WORD, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
|
|
pr_perror("write() failed");
|
|
goto err;
|
|
}
|
|
close(fd);
|
|
|
|
if (mount(NULL, dirname, "tmpfs", MS_REMOUNT | MS_RDONLY, NULL) < 0) {
|
|
fail("Can't mount tmpfs");
|
|
return 1;
|
|
}
|
|
|
|
test_daemon();
|
|
test_waitsig();
|
|
|
|
|
|
fd = open(fname, O_RDONLY);
|
|
if (fd < 0) {
|
|
pr_perror("open failed");
|
|
goto err;
|
|
}
|
|
|
|
buf[sizeof(TEST_WORD) + 1] = '\0';
|
|
if (read(fd, buf, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
|
|
fail("Read failed");
|
|
goto err;
|
|
}
|
|
close(fd);
|
|
|
|
if (strcmp(buf, TEST_WORD)) {
|
|
fail("File corrupted");
|
|
goto err;
|
|
}
|
|
|
|
pass();
|
|
ret = 0;
|
|
err:
|
|
umount2(dirname, MNT_DETACH);
|
|
rmdir(dirname);
|
|
return ret;
|
|
}
|