Example #1
0
int main(int argc, char **argv)
{
    int fd, fd2;

    test_init(argc, argv);

    fd = open(filename, O_CREAT | O_RDWR, 0600);
    if (fd < 0) {
        pr_perror("No file");
        return -1;
    }

    fd2 = open(filename, O_RDWR);
    if (fd2 < 0) {
        pr_perror("No file2");
        return -1;
    }

    flock(fd, LOCK_SH);

    test_daemon();
    test_waitsig();

    if (flock(fd2, LOCK_SH) == 0)
        pass();
    else
        fail("Flock file locks check failed (%d)", errno);

    close(fd);
    close(fd2);
    unlink(filename);

    return 0;
}
Example #2
0
int main(int argc, char **argv)
{
	char *start_addr, *addr1, *addr2;

	test_init(argc, argv);

	start_addr = mmap(NULL, PAGE_SIZE * 10, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
	if (start_addr == MAP_FAILED) {
		err("Can't mal a new region");
		return 1;
	}
	munmap(start_addr, PAGE_SIZE * 10);

	addr1 = mmap(start_addr + PAGE_SIZE * 5, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0);
	addr2 = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0);

	err("%p %p\n", addr1, addr2);

	test_daemon();
	test_waitsig();

	pass();

	return 0;
}
Example #3
0
int main(int argc, char **argv)
{
	int fd_rd = -1, fd_wr = -1;

	test_init(argc, argv);

	snprintf(filename_rd, sizeof(filename_rd), "%s.0", filename);
	snprintf(filename_wr, sizeof(filename_wr), "%s.1", filename);

	if (open_files(&fd_rd, &fd_wr)) {
		pr_err("Can't open files\n");
		return -1;
	}
	if (fcntl(fd_rd, F_SETLEASE, F_RDLCK) < 0 ||
		fcntl(fd_wr, F_SETLEASE, F_WRLCK) < 0) {
		pr_perror("Can't set leases\n");
		close_files(fd_rd, fd_wr);
		return -1;
	}

	test_daemon();
	test_waitsig();

	if (check_lease_type(fd_rd, F_RDLCK))
		fail("Read lease check failed\n");
	else if (check_lease_type(fd_wr, F_WRLCK))
		fail("Write lease check failed\n");
	else
		pass();

	close_files(fd_rd, fd_wr);
	return 0;
}
Example #4
0
int main(int argc, char **argv)
{
	char *env;

	test_init(argc, argv);

	if (setenv(envname, test_author, 1)) {
		pr_perror("Can't set env var \"%s\" to \"%s\"", envname, test_author);
		exit(1);
	}

	test_daemon();
	test_waitsig();

	env = getenv(envname);
	if (!env) {
		fail("can't get env var \"%s\": %m\n", envname);
		goto out;
	}

	if (strcmp(env, test_author))
		fail("%s != %s\n", env, test_author);
	else
		pass();
out:
	return 0;
}
Example #5
0
static int test_fn(int argc, char **argv)
{
	char cmd[128];

	if (system("iptables -A INPUT -t filter --protocol icmp -j DROP")) {
		pr_perror("Can't set input rule");
		return -1;
	}

	sprintf(cmd, "iptables -L > pre-%s", filename);
	if (system(cmd)) {
		pr_perror("Can't save iptables");
		return -1;
	}

	test_daemon();
	test_waitsig();

	sprintf(cmd, "iptables -L > post-%s", filename);
	if (system(cmd)) {
		fail("Can't get iptables");
		return -1;
	}

	sprintf(cmd, "diff pre-%s post-%s", filename, filename);
	if (system(cmd)) {
		fail("Iptables differ");
		return -1;
	}

	pass();
	return 0;
}
Example #6
0
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", MS_RDONLY, "") < 0) {
		fail("Can't mount tmpfs");
		return 1;
	}

	snprintf(fname, sizeof(buf), "%s/test.file", dirname);

	test_daemon();
	test_waitsig();


	fd = open(fname, O_RDWR | O_CREAT, 0777);
	if (fd >= 0 || errno != EROFS) {
		pr_perror("open failed -> %d", fd);
		goto err;
	}

	pass();
	ret = 0;
err:
	umount2(dirname, MNT_DETACH);
	rmdir(dirname);
	return ret;
}
Example #7
0
int main(int argc, char **argv)
{
	char *val;
	int max_nr = 1024, i;

	val = getenv("ZDTM_THREAD_BOMB");
	if (val)
		max_nr = atoi(val);

	test_msg("%d\n", max_nr);

	test_init(argc, argv);

	for (i = 0; i < max_nr; i++) {
		pthread_t p;
		pthread_create(&p, NULL, thread_fn, NULL);
	}

	test_daemon();
	test_waitsig();

	pass();

	return 0;
}
Example #8
0
int main(int argc, char **argv)
{
	test_init(argc, argv);

	if (mount("/proc/sys/", "/proc/sys", NULL, MS_BIND, NULL)) {
		pr_perror("Unable to bind-mount  /proc/sys");
		return 1;
	}
	if (mount("/proc/sys/net", "/proc/sys/net", NULL, MS_BIND, NULL)) {
		pr_perror("Unable to bind-mount /proc/sys/net");
		return 1;
	}
	if (mount("/proc/sys/", "/proc/sys", NULL, MS_RDONLY|MS_BIND|MS_REMOUNT, NULL)) {
		pr_perror("Unable to remount  /proc/sys");
		return 1;
	}

	test_daemon();
	test_waitsig();

	if (access("/proc/sys/net/unix/max_dgram_qlen", W_OK)) {
		fail("Unable to access /proc/sys/net/core/wmem_max");
		return 1;
	}

	if (access("/proc/sys/kernel/pid_max", W_OK) != -1 || errno != EROFS) {
		fail("Unable to access /proc/sys/kernel/pid_max");
		return 1;
	}

	pass();

	return 0;
}
Example #9
0
int main(int argc, char ** argv)
{
	int fdmaster, fdslave;
	pid_t jobs[JOBS_MAX] = {};

	test_init(argc, argv);

	if (num_jobs > JOBS_MAX) {
		err("%d jobs is too many", num_jobs);
		exit(1);
	}

	if (make_pty_pair(&fdmaster, &fdslave) < 0) {
		err("can't make pty pair: %m");
		exit(1);
	}

	sleep(30);

	if (start_jobs(jobs, num_jobs, fdmaster, fdslave)) {
		err("failed to start jobs");
		exit(1);
	}

	test_daemon();
	test_waitsig();

	if (finish_jobs(jobs, num_jobs, fdmaster, fdslave))
		fail("failed to finish jobs");
	else
		pass();

	return 0;
}
Example #10
0
int main(int argc, char **argv)
{
	test_init(argc, argv);
	unsigned char *mem;

	test_msg("Alloc huge VMA\n");
	mem = (void *)mmap(NULL, (10L << 30), PROT_READ | PROT_WRITE,
			   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	if ((void *)mem == MAP_FAILED) {
		pr_perror("mmap failed");
		return -1;
	}

	mem[4L << 30] = 1;
	mem[8L << 30] = 2;

	test_daemon();
	test_waitsig();

	test_msg("Testing restored data\n");

	if (mem[4L << 30] != 1 || mem[8L << 30] != 2) {
		fail("Data corrupted!\n");
		exit(1);
	}

	pass();

	return 0;
}
Example #11
0
int main(int argc, char **argv)
{
	int sks[2], ret;
	char buf[1024];

	test_init(argc, argv);

	if (socketpair(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0, sks) < 0) {
		pr_perror("socketpair");
		return 1;
	}

	if (write(sks[1], MSG, sizeof(MSG)) != sizeof(MSG)) {
		pr_perror("write");
		return 1;
	}
	close(sks[1]);

	test_daemon();
	test_waitsig();

	ret = read(sks[0], buf, sizeof(MSG));
	buf[ret > 0 ? ret : 0] = 0;
	if (ret != sizeof(MSG)) {
		fail("%d: %s", ret, buf);
		return 1;
	}

	pass();
	return 0;
}
Example #12
0
int main(int argc, char **argv)
{
	int ret;

	lo.dir = LO_CONF_DIR_PATH;
	def.dir = DEF_CONF_DIR_PATH;

	test_init(argc, argv);

	ret = for_each_option_do(save_and_set, &lo);
	if (ret < 0)
		return -1;

	ret = for_each_option_do(save_and_set, &def);
	if (ret < 0)
		return -1;

	test_daemon();
	test_waitsig();

	ret = for_each_option_do(check_and_restore, &lo);
	if (ret < 0)
		return -1;

	ret = for_each_option_do(check_and_restore, &def);
	if (ret < 0)
		return -1;

	pass();
	return 0;
}
Example #13
0
int main(int argc, char **argv)
{
	int rv, i;
	int counter = 0;

	test_init(argc, argv);

	if (scale > MAX_SCALE) {
		err("Too many children specified\n");
		exit(-1);
	}

	if (signal(SIGUSR2, do_stop) == SIG_ERR) {
		err("Can't setup handler\n");
		exit(-1);
	}

	for (i = 0; i < scale; i++) {
		rv = test_fork();
		if (rv == -1) {
			err("Can't fork\n");
			killall();
			exit(-1);
		}
		if (rv == 0)
			chew_some_file(i);
		pids[i] = rv;
	}

	test_daemon();
	test_waitsig();

	killall();
	for (i = 0; i < scale; i++) {
		if (waitpid(pids[i], &rv, 0) == -1) {
			fail("Can't wipe up the kid\n");
			counter++;
			continue;
		}
		if (!WIFEXITED(rv)) {
			fail("Kid was killed\n");
			counter++;
		} else {
			rv = WEXITSTATUS(rv);
			if (rv < MAX_EXIT_CODE_VAL && rv > SUCCESS) {
				fail("Kid failed: %s (%d)\n",
						kids_fail_reasons[rv], rv);
				counter++;
			} else if (rv != SUCCESS) {
				fail("Unknow exitcode from kid: %d\n", rv);
				counter++;
			}
		}
	}

	if (counter == 0)
		pass();
	return 0;
}
Example #14
0
int main(int argc, char **argv)
{
	pid_t pid;

	test_init(argc, argv);

	pid = fork();
	if (pid < 0) {
		fail("fork() failed");
		return -1;
	}

	if (pid == 0) {
		test_msg("child is %d\n", pid);
		/* Child process just sleeps until it is killed. All we need
		 * here is a process to open the mountinfo of. */
		while(1)
			sleep(10);
	} else {
		int fd, ret;
		char path[PATH_MAX];
		pid_t result;

		sprintf(path, "/proc/%d/mountinfo", pid);
		fd = open(path, O_RDONLY);
		if (fd < 0) {
			fail("failed to open fd");
			return -1;
		}

		/* no matter what, we should kill the child */
		kill(pid, SIGKILL);
		result = waitpid(pid, NULL, 0);
		if (result < 0) {
			fail("failed waitpid()");
			return -1;
		}

		if (fd < 0) {
			fail("failed opening %s", path);
			return -1;
		}

		test_daemon();
		test_waitsig();

		ret = fcntl(fd, F_GETFD);
		close(fd);

		if (ret) {
			fail("bad fd after restore");
			return -1;
		}
	}

	pass();
	return 0;
}
Example #15
0
File: futex.c Project: OSLL/pmover
int main(int argc, char **argv)
{
	int i;
	pthread_t thr[num_threads];
	pthread_mutex_t m;

	test_init(argc, argv);

	if (num_threads > MAX_NUM_THREADS) {
		err("%d threads it too much. max is %d\n",
				num_threads, MAX_NUM_THREADS);
		goto out;
	}

	pthread_mutex_init(&m, NULL);
	pthread_mutex_lock(&m);

	for (i = 0; i < num_threads; i++)
		if (pthread_create(&thr[i], NULL, thread_fn, &m)) {
			err("Can't create %d'th thread\n", i + 1);
			goto out_kill;
		}

	kid_passed = 0;

	test_daemon();
	test_waitsig();

	sleep(1);
	if (kid_passed != 0)
		fail("some kids broke through\n");

	pthread_mutex_unlock(&m);
	for (i = 0; i < num_threads; i++)
		pthread_join(thr[i], NULL);

	if (pthread_mutex_trylock(&m)) {
		if (errno == EBUSY)
			fail("kids left my mutex locked\n");
		else
			err("kids spoiled my mutex\n");
	}

	if (kid_passed != num_threads)
		fail("some kids died during migration\n");

	pass();
out:
	return 0;

out_kill:
	for (i--; i >= 0; i--) {
		pthread_kill(thr[i], SIGKILL);
		pthread_join(thr[i], NULL);
	}
	goto out;
}
Example #16
0
int main(int argc, char **argv)
{
	char *start_addr, *fake_grow_down, *test_addr, *grow_down;
	test_init(argc, argv);

	start_addr = mmap(NULL, PAGE_SIZE * 10, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
	if (start_addr == MAP_FAILED) {
		err("Can't mal a new region");
		return 1;
	}
	munmap(start_addr, PAGE_SIZE * 10);

	fake_grow_down = mmap(start_addr + PAGE_SIZE * 5, PAGE_SIZE,
			 PROT_READ | PROT_WRITE,
			 MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED | MAP_GROWSDOWN, -1, 0);
	if (fake_grow_down == MAP_FAILED) {
		err("Can't mal a new region");
		return 1;
	}

	fake_grow_down[0] = 'c';
	*(fake_grow_down - 1) = 'b';

	/* overlap the guard page of fake_grow_down */
	test_addr = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE,
			 PROT_READ | PROT_WRITE,
			 MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
	if (test_addr == MAP_FAILED) {
		err("Can't mal a new region");
		return 1;
	}

	grow_down = mmap(start_addr + PAGE_SIZE * 2, PAGE_SIZE,
			 PROT_READ | PROT_WRITE,
			 MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED | MAP_GROWSDOWN, -1, 0);
	if (grow_down == MAP_FAILED) {
		err("Can't mal a new region");
		return 1;
	}

	test_daemon();
	test_waitsig();

	munmap(test_addr, PAGE_SIZE);
	if (fake_grow_down[0] != 'c' || *(fake_grow_down - 1) != 'b') {
		fail("%c %c\n", fake_grow_down[0], *(fake_grow_down - 1));
		return 1;
	}

	grow_down[0] = 'z';
	*(grow_down - 1) = 'x';

	pass();

	return 0;
}
Example #17
0
int main(int argc, char **argv)
{
	int fd;
	char path[256];

	test_init(argc, argv);

	if (snprintf(path, sizeof(path), "%s/foo", dirname) >= sizeof(path)) {
		pr_perror("directory name \"%s\"is too long", dirname);
		exit(1);
	}

	if (mkdir(dirname, 0700)) {
		pr_perror("can't make directory %s", dirname);
		exit(1);
	}

	fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
	if (fd < 0) {
		pr_perror("can't open %s", path);
		goto rmdir;
	}

	if (mount("rien", dirname, "tmpfs", 0, 0) < 0) {
		pr_perror("can't mount tmpfs over %s", dirname);
		goto cleanup;
	}

	test_daemon();
	test_waitsig();

	if (umount(dirname) < 0) {
		fail("can't umount %s: %m", dirname);
		goto cleanup;
	}

	if (close(fd) < 0) {
		fail("can't close %s: %m", path);
		goto unlink;
	}

	if (unlink(path) < 0) {
		fail("can't unlink %s: %m", path);
		goto rmdir;
	}

	pass();
	goto rmdir;
cleanup:
	close(fd);
unlink:
	unlink(path);
rmdir:
	rmdir(dirname);
	return 0;
}
Example #18
0
int main(int argc, char **argv)
{
	int fd, pf[2], pid;

	test_init(argc, argv);

	pipe(pf);

	fd = open(filename, O_CREAT | O_RDWR, 0600);
	if (fd < 0) {
		err("No file");
		return -1;
	}

	flock(fd, LOCK_EX);

	pid = fork();
	if (pid == 0) {
		close(pf[1]);
		read(pf[0], &pid, sizeof(pid));
		exit(0);
	}

	close(pf[0]);
	close(fd);

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		err("No file 2");
		close(pf[1]);
		waitpid(pid, NULL, 0);
		return -1;
	}

	if (flock(fd, LOCK_EX | LOCK_NB) == 0) {
		err("Bogus locks");
		close(pf[1]);
		waitpid(pid, NULL, 0);
		return -1;
	}

	test_daemon();
	test_waitsig();

	if (check_file_locks(pid, fd))
		pass();
	else
		fail("Flock file locks check failed");

	close(pf[1]);
	waitpid(pid, NULL, 0);
	close(fd);
	unlink(filename);

	return 0;
}
Example #19
0
int main(int argc, char **argv)
{
	int sk[2], p[2];
#define MSG "HELLO"
	char buf[8]; /* bigger than the MSG to check boundaries */

	test_init(argc, argv);

	if (socketpair(PF_UNIX, SOCK_DGRAM, 0, sk) < 0) {
		pr_perror("Can't make unix pair");
		exit(1);
	}

	if (pipe(p) < 0) {
		pr_perror("Can't make pipe");
		exit(1);
	}

	if (send_fd(sk[0], p[0], p[1]) < 0) {
		pr_perror("Can't send descriptor");
		exit(1);
	}

	close(p[0]);
	close(p[1]);
	p[0] = p[1] = -1;

	test_daemon();
	test_waitsig();

	if (recv_fd(sk[1], &p[0], &p[1]) < 0) {
		fail("Can't recv pipes back");
		goto out;
	}

	if (write(p[1], MSG, sizeof(MSG)) != sizeof(MSG)) {
		fail("Pipe write-broken");
		goto out;
	}

	if (read(p[0], buf, sizeof(buf)) != sizeof(MSG)) {
		fail("Pipe read-broken");
		goto out;
	}

	if (strcmp(buf, MSG)) {
		buf[sizeof(buf) - 1] = '\0';
		fail("Pipe read-broken (%s)", buf);
		goto out;
	}

	pass();
out:
	return 0;
}
Example #20
0
int main(int argc, char *argv[])
{
	char cmdline_orig[4096];
	char cmdline[4096];
	char env_orig[4096];
	char env[4096];
	char auxv_orig[1024];
	char auxv[1024];

	memset(cmdline_orig,	0, sizeof(cmdline_orig));
	memset(cmdline,		0, sizeof(cmdline));
	memset(env_orig,	0, sizeof(env_orig));
	memset(env,		0, sizeof(env));
	memset(auxv_orig,	0, sizeof(auxv_orig));
	memset(auxv,		0, sizeof(auxv));

	test_init(argc, argv);

	read_from_proc("/proc/self/cmdline", cmdline_orig, sizeof(cmdline_orig));
	read_from_proc("/proc/self/environ", env_orig, sizeof(env_orig));
	read_from_proc("/proc/self/auxv", auxv_orig, sizeof(auxv_orig));

	test_msg("old cmdline: %s\n", cmdline_orig);
	test_msg("old environ: %s\n", env_orig);

	test_daemon();
	test_waitsig();

	read_from_proc("/proc/self/cmdline", cmdline, sizeof(cmdline));
	read_from_proc("/proc/self/environ", env, sizeof(env));
	read_from_proc("/proc/self/auxv", auxv, sizeof(auxv));

	test_msg("new cmdline: %s\n", cmdline);
	test_msg("new environ: %s\n", env);

	if (strncmp(cmdline_orig, cmdline, sizeof(cmdline_orig))) {
		fail("cmdline corrupted on restore");
		exit(1);
	}

	if (strncmp(env_orig, env, sizeof(env_orig))) {
		fail("envirion corrupted on restore");
		exit(1);
	}

	if (memcmp(auxv_orig, auxv, sizeof(auxv_orig))) {
		fail("auxv corrupted on restore");
		exit(1);
	}

	pass();

	return 0;
}
Example #21
0
int main(int argc, char ** argv)
{
	int sk, skc;
	int ret, len;
	char path[PATH_MAX];
	struct sockaddr_un addr;
	socklen_t addrlen;

	test_init(argc, argv);

	sk = socket(AF_UNIX, SOCK_STREAM, 0);
	if (sk == -1) {
		pr_perror("socket");
		return 1;
	}

	skc = socket(AF_UNIX, SOCK_STREAM, 0);
	if (skc == -1) {
		pr_perror("socket");
		return 1;
	}

	len = snprintf(path, sizeof(path), "X/zdtm-%s-%d/X", argv[0], getpid());

	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, path, sizeof(addr.sun_path));
	addrlen = sizeof(addr.sun_family) + len;
	addr.sun_path[0] = 0;
	addr.sun_path[len - 1] = 0;

	ret = bind(sk, (struct sockaddr *) &addr, addrlen);
	if (ret) {
		fail("bind\n");
		return 1;
	}

	test_daemon();

	test_waitsig();

	if (listen(sk, 1) == -1) {
		pr_perror("listen");
		return 1;
	}

	if (connect(skc, (struct sockaddr *) &addr, addrlen) == -1) {
		fail("Unable to connect");
		return 1;
	}

	pass();

	return 0;
}
Example #22
0
int main(int argc, char ** argv)
{
	test_init(argc, argv);

	test_daemon();
	test_waitsig();

	pass();

	return 0;
}
Example #23
0
int main(int argc, char ** argv)
{
	char src[PATH_MAX], dst[PATH_MAX], *root;
	char *dname = "/tmp/zdtm_ext_auto.XXXXXX";
	int status;
	pid_t pid;

	root = getenv("ZDTM_ROOT");
	if (root == NULL) {
		pr_perror("root");
		return 1;
	}

	sprintf(dst, "%s/ext_mounts", getenv("ZDTM_ROOT"));

	if (strcmp(getenv("ZDTM_NEWNS"), "1"))
		goto test;

	pid = fork();
	if (pid < 0)
		return 1;
	if (pid == 0) {
		test_ext_init(argc, argv);

		mkdir(dname, 755);
		sprintf(src, "%s/test", dname);
		if (mount("zdtm_auto_ext_mnt", dname, "tmpfs", 0, NULL)) {
			pr_perror("mount");
			return 1;
		}
		mkdir(src, 755);
		mkdir(dst, 755);
		if (mount(src, dst, NULL, MS_BIND, NULL)) {
			pr_perror("bind");
			return 1;
		}
		return 0;
	}

	wait(&status);
	if (status != 0)
		return 1;

test:
	test_init(argc, argv);

	test_daemon();
	test_waitsig();


	pass();

	return 0;
}
Example #24
0
int main(int argc, char ** argv)
{
	char dst[PATH_MAX];

	if (strcmp(getenv("ZDTM_NEWNS"), "1"))
		goto test;

	if (unshare(CLONE_NEWNS)) {
		pr_perror("unshare");
		return 1;
	}

	sprintf(dst, "%s/%s", get_current_dir_name(), dirname);
	if (mkdir(dst, 755) < 0) {
		pr_perror("mkdir");
		return 1;
	}

	if (mount("/sys/kernel/debug", dst, NULL, MS_BIND | MS_REC, NULL)) {
		rmdir(dst);
		pr_perror("mount");
		return 1;
	}

	/* trigger the tracefs mount */
	strcat(dst, "/tracing/README");
	if (access(dst, F_OK) < 0) {
		umount(dst);
		rmdir(dst);
		pr_perror("access");
		return 1;
	}

test:
	test_init(argc, argv);

	test_daemon();
	test_waitsig();

	sprintf(dst, "%s/%s/tracing/README", get_current_dir_name(), dirname);

	/* EACCES is what we expect, since users can't actually /see/ this
	 * filesystem, but CRIU needs to know how to remount it, so the restore
	 * should succeed
	 */
	if (access(dst, F_OK) < 0 && errno != EACCES) {
		fail("couldn't access tracefs at %s", dst);
		return 1;
	}

	pass();
	return 0;
}
Example #25
0
int main(int argc, char *argv[])
{
	int i;

	test_init(argc, argv);

	fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
	if (fd<0){
		pr_perror("socket");
		goto out;
	}
	// setup local address & bind using
	// this address
	bzero(&la, sizeof(la));
	la.nl_family = AF_NETLINK;
	la.nl_pid = getpid();
	if (bind(fd, (struct sockaddr*) &la, sizeof(la))){
		pr_perror("bind failed");
		goto out;
	}
	//Preperation:
	form_request_del();
	send_request();
	recv_reply();

	test_daemon();

	while (test_go()){
		for (i=0; i < CMD_NUM; i++){
			cmd[i]();
			if (send_request() < 0){
				fail("send_request failed");
				goto out;
			};
			if (recv_reply() < 0){
				fail("RTNETLINK answers: %m");
				goto out;
			};

#ifdef DEBUG
			if (read_reply() < 0){
				fail("read_reply failed");
				goto out;
			}
#endif
		}
	}

	pass();

out:
	return 0;
}
Example #26
0
int main(int argc, char **argv)
{
	int fd, child_fd, pid;

	test_init(argc, argv);

	fd = child_fd = open(filename, O_CREAT | O_RDWR, 0600);
	if (fd < 0) {
		pr_perror("No file");
		return -1;
	}

	flock(fd, LOCK_EX);

	pid = fork();
	if (pid == 0) {
		test_waitsig();
		exit(0);
	}

	close(fd);

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		pr_perror("No file 2");
		kill(pid, SIGTERM);
		waitpid(pid, NULL, 0);
		return -1;
	}

	if (flock(fd, LOCK_EX | LOCK_NB) == 0) {
		pr_perror("Bogus locks");
		kill(pid, SIGTERM);
		waitpid(pid, NULL, 0);
		return -1;
	}

	test_daemon();
	test_waitsig();

	if (check_file_locks(pid, fd, child_fd) > 0)
		pass();
	else
		fail("Flock file locks check failed");

	kill(pid, SIGTERM);
	waitpid(pid, NULL, 0);
	close(fd);
	unlink(filename);

	return 0;
}
Example #27
0
int main(int argc, char **argv)
{
	char *start_addr, *grow_down;
	test_init(argc, argv);

	start_addr = mmap(NULL, PAGE_SIZE * 10, PROT_READ | PROT_WRITE,
					MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
	if (start_addr == MAP_FAILED) {
		pr_perror("Can't mal a new region");
		return 1;
	}
	munmap(start_addr, PAGE_SIZE * 10);

	grow_down = mmap(start_addr + PAGE_SIZE * 3, PAGE_SIZE * 3,
			 PROT_READ | PROT_WRITE,
			 MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED | MAP_GROWSDOWN, -1, 0);
	if (grow_down == MAP_FAILED) {
		pr_perror("Can't mal a new region");
		return 1;
	}

	grow_down[0 * PAGE_SIZE] = 'x';
	grow_down[1 * PAGE_SIZE] = 'y';
	grow_down[2 * PAGE_SIZE] = 'z';

	/*
	 * Split the grow-down vma on three parts.
	 * Only the irst one will have a guard page
	 */
	if (mprotect(grow_down + PAGE_SIZE, PAGE_SIZE, PROT_READ)) {
		pr_perror("Can't change set protection on a region of memory");
		return 1;
	}

	test_daemon();
	test_waitsig();

	test_msg("%c %c %c\n", grow_down[0 * PAGE_SIZE],
		 grow_down[1 * PAGE_SIZE], grow_down[2 * PAGE_SIZE]);

	if (grow_down[0 * PAGE_SIZE] != 'x')
		return 1;
	if (grow_down[1 * PAGE_SIZE] != 'y')
		return 1;
	if (grow_down[2 * PAGE_SIZE] != 'z')
		return 1;

	pass();

	return 0;
}
Example #28
0
int main(int argc, char ** argv)
{
	void *start;
	int fd, i;

	test_init(argc, argv);

	fd = open(filename, O_RDWR | O_CREAT, 0666);
	if (fd < 0)
		return 1;

	ftruncate(fd, 4096);

	start = mmap(0, 4096 * TEST_SIZE * 4, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
	if (start == MAP_FAILED)
		return 1;

	for (i = 0; i < TEST_SIZE; i++) {
		int *addr;
		addr = mmap(start + i * 3 * 4096, 4096,
				PROT_READ | PROT_WRITE,
				MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd, 0);
		if (addr == MAP_FAILED)
			return 1;
		addr[0] = i * 2;
		addr = mmap(start + (i * 3 + 1) * 4096, 4096,
				PROT_READ | PROT_WRITE,
				MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
		if (addr == MAP_FAILED)
			return 1;
		addr[0] = i;
	}

	test_daemon();

	test_waitsig();

	for (i = 0; i < TEST_SIZE; i++) {
		int *addr;
		addr = start + i * 3 * 4096;
		if (addr[0] != i * 2)
			fail();
		addr = start + (i * 3  + 1) * 4096;
		if (addr[0] != i)
			fail();
	}

	pass();

	return 0;
}
Example #29
0
int main(int argc, char **argv)
{
	int ret = -1;
	char path[PATH_MAX];

	test_init(argc, argv);

	if (mount_and_add(cgname, "test") < 0)
		return -1;

	sprintf(path, "%s/%s/test", dirname, cgname);
	if (chownmod(path, O_DIRECTORY) < 0)
		goto out_umount;

	sprintf(path, "%s/%s/test/notify_on_release", dirname, cgname);
	if (chownmod(path, O_RDWR) < 0)
		goto out_umount;


	sprintf(path, "%s/%s/test/cgroup.procs", dirname, cgname);
	if (chownmod(path, O_RDWR) < 0)
		goto out_umount;

	test_daemon();
	test_waitsig();

	sprintf(path, "%s/%s/test", dirname, cgname);
	if (checkperms(path) < 0)
		goto out_umount;

	sprintf(path, "%s/%s/test/notify_on_release", dirname, cgname);
	if (checkperms(path) < 0)
		goto out_umount;

	sprintf(path, "%s/%s/test/cgroup.procs", dirname, cgname);
	if (checkperms(path) < 0)
		goto out_umount;

	pass();
	ret = 0;

out_umount:
	sprintf(path, "%s/%s/test", dirname, cgname);
	rmdir(path);
	sprintf(path, "%s/%s", dirname, cgname);
	umount(path);
	rmdir(path);
	rmdir(dirname);
	return ret;
}
Example #30
0
int main(int argc, char **argv)
{
	test_init(argc, argv);

	setprofile();

	test_daemon();
	test_waitsig();

	if (checkprofile(0) == 0)
		pass();

	return 0;
}