示例#1
0
文件: tkill01.c 项目: dacongy/ltp
int main(int ac, char **av)
{
	int tid;
	int lc;
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			if (signal(SIGUSR1, &sig_action) == SIG_ERR)
				tst_brkm(TBROK | TERRNO, cleanup,
					 "signal(SIGUSR1, ..) failed");
			TEST(tid = ltp_syscall(__NR_gettid));
			if (TEST_RETURN == -1) {
				tst_resm(TFAIL | TTERRNO, "tkill failed");
			}
			TEST(ltp_syscall(__NR_tkill, tid, SIGUSR1));
			if (TEST_RETURN == 0) {
				tst_resm(TPASS, "tkill call succeeded");
			} else {
				tst_resm(TFAIL | TTERRNO, "tkill failed");
			}
		}
	}
	cleanup();
	tst_exit();
}
示例#2
0
static void test_clone_thread(int t)
{
	pid_t child;
	int i, status;

	fflush(stdout);
	child = FORK_OR_VFORK();
	switch (child) {
	case 0:
		tgid = ltp_syscall(__NR_getpid);
		tst_result = -1;
		clone_child(&test_cases[t], 0);

		for (i = 0; i < 5000; i++) {
			sched_yield();
			usleep(1000);
			if (tst_result != -1)
				break;
		}
		ltp_syscall(__NR_exit, tst_result);
	case -1:
		tst_brkm(TBROK | TERRNO, NULL, "test_clone_thread fork");
	default:
		status = wait4child(child);
		if (status == 0) {
			tst_resm(TPASS, "test %s", test_cases[t].name);
		} else {
			tst_resm(TFAIL, "test %s, status: %d",
				 test_cases[t].name, status);
		}
	};
}
示例#3
0
int main(int ac, char **av)
{
	int lc;
	const char *msg;
	kernel_timer_t timer_id;

	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/* Create a Posix timer */
		if (ltp_syscall(__NR_timer_create, CLOCK_REALTIME, NULL,
			&timer_id) < 0) {
			tst_count = TST_TOTAL;
			tst_brkm(TBROK | TERRNO, cleanup,
				 "timer_delete can't be tested because "
				 "timer_create failed");
		}
		TEST(ltp_syscall(__NR_timer_delete, timer_id));
		tst_resm((TEST_RETURN == 0 ? TPASS : TFAIL | TTERRNO),
			 "%s", (TEST_RETURN == 0 ? "passed" : "failed"));
	}

	cleanup();
	tst_exit();
}
示例#4
0
static void test_invalid_mem(void)
{
	unsigned long *p;

	tst_resm(TINFO, "test_invalid_mem -1");
	TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node, -1, -1));
	check_ret(-1);
	check_errno(EFAULT);

	tst_resm(TINFO, "test_invalid_mem invalid prot");
	p = mmap(NULL, getpagesize(), PROT_NONE,
		 MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
	if (p == MAP_FAILED)
		tst_brkm(TBROK | TERRNO, cleanup, "mmap");
	TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
	check_ret(-1);
	check_errno(EFAULT);

	if (munmap(p, getpagesize()) < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "munmap");
	tst_resm(TINFO, "test_invalid_mem unmmaped");
	TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
	check_ret(-1);
	check_errno(EFAULT);
}
static int
accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags)
{
#ifdef DEBUG
	tst_resm(TINFO, "Calling accept4(): flags = %x", flags);
	if (flags != 0) {
		tst_resm(TINFO, " (");
		if (flags & SOCK_CLOEXEC)
			tst_resm(TINFO, "SOCK_CLOEXEC");
		if ((flags & SOCK_CLOEXEC) && (flags & SOCK_NONBLOCK))
			tst_resm(TINFO, " ");
		if (flags & SOCK_NONBLOCK)
			tst_resm(TINFO, "SOCK_NONBLOCK");
		tst_resm(TINFO, ")");
	}
	tst_resm(TINFO, "\n");
#endif

#if USE_SOCKETCALL
	long args[6];

	args[0] = fd;
	args[1] = (long)sockaddr;
	args[2] = (long)addrlen;
	args[3] = flags;

	return ltp_syscall(__NR_socketcall, SYS_ACCEPT4, args);
#else
	return ltp_syscall(__NR_accept4, fd, sockaddr, addrlen, flags);
#endif
}
示例#6
0
文件: ssetmask01.c 项目: 1587/ltp
int main(int ac, char **av)
{
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			ltp_syscall(__NR_ssetmask, SIGALRM);
			TEST(ltp_syscall(__NR_sgetmask));
			if (TEST_RETURN != SIGALRM) {
				tst_brkm(TFAIL | TTERRNO, cleanup,
					 "sgetmask() failed");
			}
			TEST(ltp_syscall(__NR_ssetmask, SIGUSR1));
			if (TEST_RETURN != SIGALRM) {
				tst_brkm(TFAIL | TTERRNO, cleanup,
					 "ssetmask() failed");
			}
			tst_resm(TPASS, "Got SIGALRM--Test PASS ");
		}
	}
	cleanup();
	tst_exit();
}
示例#7
0
int main(int ac, char **av)
{
	int lc, i;
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		for (i = 0; i < TST_TOTAL; i++) {

			if (setup_test(i) < 0)
				continue;

			TEST(ltp_syscall(__NR_clock_settime, clocks[i], temp));

			/* Change the UID back to root */
			if (i == TST_TOTAL - 1) {
				if (seteuid(0) == -1) {
					tst_brkm(TBROK | TERRNO, cleanup,
						 "Failed to set the effective "
						 "uid to root");
				}
			}

			/* check return code */
			if (TEST_RETURN == -1 && TEST_ERRNO == testcases[i]) {
				tst_resm(TPASS | TTERRNO,
					 "clock_settime(2) got expected "
					 "failure.");
			} else {
				tst_resm(TFAIL | TTERRNO,
					 "clock_settime(2) failed to produce "
					 "expected error (return code = %ld)",
					 TEST_RETURN);
				/* Restore the clock to its previous state. */
				if (TEST_RETURN == 0) {
					if (ltp_syscall(__NR_clock_settime,
						    CLOCK_REALTIME,
						    &saved) < 0) {
						tst_resm(TWARN | TERRNO,
							 "FATAL: could not set "
							 "the clock!");
					}
				}
			}

		}

	}

	cleanup();
	tst_exit();
}
示例#8
0
int main(int ac, char **av)
{
	sigset_t set, set1, set2;
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); ++lc) {

		tst_count = 0;

		if (sigemptyset(&set) < 0)
			tst_brkm(TFAIL | TERRNO, cleanup, "sigemptyset failed");
		struct sigaction act, oact;
		memset(&act, 0, sizeof(act));
		memset(&oact, 0, sizeof(oact));
		act.sa_handler = sig_handler;

		TEST(ltp_rt_sigaction(SIGALRM, &act, &oact, SIGSETSIZE));
		if (TEST_RETURN == -1)
			tst_brkm(TFAIL | TTERRNO, cleanup,
				 "rt_sigaction failed");

		TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
			     &set1, SIGSETSIZE));
		if (TEST_RETURN == -1)
			tst_brkm(TFAIL | TTERRNO, cleanup,
				 "rt_sigprocmask failed");

		TEST(alarm(5));
		int result;
		TEST(result = ltp_syscall(__NR_rt_sigsuspend, &set,
			SIGSETSIZE));
		TEST(alarm(0));
		if (result == -1 && TEST_ERRNO != EINTR) {
			TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
				&set2, SIGSETSIZE));
			if (TEST_RETURN == -1) {
				tst_brkm(TFAIL | TTERRNO, cleanup,
					 "rt_sigprocmask failed");
			} else if (set1.__val[0] != set2.__val[0]) {
				tst_brkm(TFAIL | TTERRNO, cleanup,
					 "rt_sigsuspend failed to "
					 "preserve signal mask");
			} else {
				tst_resm(TPASS, "rt_sigsuspend PASSED");
			}
		} else {
			tst_resm(TFAIL | TTERRNO, "rt_sigsuspend failed");
		}

	}

	cleanup();

	tst_exit();
}
示例#9
0
文件: pipe2_01.c 项目: 1587/ltp
int main(int argc, char *argv[])
{
	int fd[2], i, coe;
	int lc;

	tst_parse_opts(argc, argv, NULL, NULL);
	if ((tst_kvercmp(2, 6, 27)) < 0) {
		tst_brkm(TCONF,
			 NULL,
			 "This test can only run on kernels that are 2.6.27 and higher");
	}
	setup();

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			if (ltp_syscall(__NR_pipe2, fd, 0) != 0) {
				tst_brkm(TFAIL, cleanup, "pipe2(0) failed");
			}
			for (i = 0; i < 2; ++i) {
				coe = fcntl(fd[i], F_GETFD);
				if (coe == -1) {
					tst_brkm(TBROK, cleanup,
						 "fcntl failed");
				}
				if (coe & FD_CLOEXEC) {
					tst_brkm(TFAIL,
						 cleanup, "pipe2(0) set close-on-exit for fd[%d]",
						 i);
				}
			}
			close(fd[0]);
			close(fd[1]);

			if (ltp_syscall(__NR_pipe2, fd, O_CLOEXEC) != 0) {
				tst_brkm(TFAIL, cleanup,
					 "pipe2(O_CLOEXEC) failed");
			}
			for (i = 0; i < 2; ++i) {
				coe = fcntl(fd[i], F_GETFD);
				if (coe == -1) {
					tst_brkm(TBROK, cleanup,
						 "fcntl failed");
				}
				if ((coe & FD_CLOEXEC) == 0) {
					tst_brkm(TFAIL,
						 cleanup, "pipe2(O_CLOEXEC) does not set close-on-exit for fd[%d]",
						 i);
				}
			}
			close(fd[0]);
			close(fd[1]);
			tst_resm(TPASS, "pipe2(O_CLOEXEC) PASSED");
			cleanup();
		}
	}
	tst_exit();
}
示例#10
0
文件: pidns30.c 项目: AiprNick/ltp
int main(int argc, char *argv[])
{
	int status;
	char buf[5];
	pid_t cpid;

	setup();

	if (pipe(child_to_father) == -1 || pipe(father_to_child) == -1) {
		tst_brkm(TBROK | TERRNO, cleanup, "pipe failed");
	}

	ltp_syscall(__NR_mq_unlink, mqname);

	/* container creation on PID namespace */
	cpid = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_fn, NULL);
	if (cpid == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");

	mqd =
	    ltp_syscall(__NR_mq_open, mqname, O_RDWR | O_CREAT | O_EXCL, 0777,
		    NULL);
	if (mqd == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "mq_open failed");
	else
		tst_resm(TINFO, "successfully created posix mqueue");

	if (write(father_to_child[1], buf, 1) != 1)
		tst_brkm(TBROK | TERRNO, cleanup, "write failed");

	/* Close the appropriate end of each pipe */
	close(child_to_father[1]);
	close(father_to_child[0]);

	/* Is container ready */
	read(child_to_father[0], buf, 5);
	if (strcmp(buf, "c:ok") != 0)
		tst_brkm(TBROK, cleanup,
			 "container did not respond as expected!");

	rc = mq_send(mqd, MSG, strlen(MSG), MSG_PRIO);
	if (rc == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "mq_send failed");
	else
		tst_resm(TINFO, "mq_send succeeded");

	/* Tell the child the message has been sent */
	if (write(father_to_child[1], "f:ok", 5) != 5)
		tst_brkm(TBROK | TERRNO, cleanup, "write failed");

	/* Wait for child to finish */
	if (wait(&status) == -1)
		tst_resm(TBROK | TERRNO, "wait failed");

	cleanup();

	tst_exit();
}
示例#11
0
static int child_clone_thread(void)
{
	if (tgid == ltp_syscall(__NR_getpid))
		tst_result = TPASS;
	else
		tst_result = TFAIL;
	ltp_syscall(__NR_exit, 0);
	return 0;
}
示例#12
0
文件: swapoff02.c 项目: MohdVara/ltp
int main(int ac, char **av)
{
	int lc, i;
	const char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		for (i = 0; i < TST_TOTAL; i++) {

			if (testcase[i].setup)
				testcase[i].setup();

			TEST(ltp_syscall(__NR_swapoff, testcase[i].path));

			if (testcase[i].cleanup)
				testcase[i].cleanup();

			if (TEST_RETURN == -1
			    && (TEST_ERRNO == testcase[i].exp_errno)) {
				tst_resm(TPASS,
					 "swapoff(2) expected failure;"
					 " Got errno - %s : %s",
					 testcase[i].exp_errval,
					 testcase[i].err_desc);

			} else {
				tst_resm(TFAIL, "swapoff(2) failed to produce"
					 " expected error; %d, errno"
					 ": %s and got %d",
					 testcase[i].exp_errno,
					 testcase[i].exp_errval, TEST_ERRNO);

				if ((TEST_RETURN == 0) && (i == 2)) {
					if (ltp_syscall
					    (__NR_swapon, "./swapfile01",
					     0) != 0) {
						tst_brkm(TBROK, cleanup,
							 " Failed to turn on"
							 " swap file");
					}
				}
			}

			TEST_ERROR_LOG(TEST_ERRNO);
		}
	}

	cleanup();
	tst_exit();
}
示例#13
0
int main(int argc, char *argv[])
{
	int fd, fl;
	int lc;
	char *msg;

	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	if ((tst_kvercmp(2, 6, 27)) < 0) {
		tst_brkm(TCONF, NULL,
			 "This test can only run on kernels that are 2.6.27 "
			 "and higher");
	}
	setup();

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			fd = ltp_syscall(__NR_inotify_init1, 0);
			if (fd == -1) {
				tst_brkm(TFAIL | TERRNO, cleanup,
					 "inotify_init1(0) failed");
			}
			fl = fcntl(fd, F_GETFL);
			if (fl == -1) {
				tst_brkm(TBROK | TERRNO, cleanup,
					 "fcntl failed");
			}
			if (fl & O_NONBLOCK) {
				tst_brkm(TFAIL, cleanup,
					 "inotify_init1(0) set non-blocking "
					 "mode");
			}
			close(fd);

			fd = ltp_syscall(__NR_inotify_init1, IN_NONBLOCK);
			if (fd == -1) {
				tst_brkm(TFAIL | TERRNO, cleanup,
					 "inotify_init1(IN_NONBLOCK) failed");
			}
			fl = fcntl(fd, F_GETFL);
			if (fl == -1) {
				tst_brkm(TBROK | TERRNO, cleanup,
					 "fcntl failed");
			}
			if ((fl & O_NONBLOCK) == 0) {
				tst_brkm(TFAIL, cleanup,
					 "inotify_init1(IN_NONBLOCK) set "
					 "non-blocking mode");
			}
			close(fd);
			tst_resm(TPASS, "inotify_init1(IN_NONBLOCK) PASSED");
		}
	}
	tst_exit();
}
示例#14
0
static int child_clone_parent_settid(void)
{
	if (ptid == ltp_syscall(__NR_getpid))
		ltp_syscall(__NR_exit, 0);
	printf("FAIL: ptid != getpid() (%d != %d)\n",
	       ptid, getpid());
	ltp_syscall(__NR_exit, 1);
	return 0;
}
示例#15
0
int main(int ac, char **av)
{
	int lc;
	const char *msg;

	struct sigevent ev;
	struct itimerspec spec;
	int timer;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	ev.sigev_value = (sigval_t) 0;
	ev.sigev_signo = SIGALRM;
	ev.sigev_notify = SIGEV_SIGNAL;
	TEST(ltp_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer));

	if (TEST_RETURN != 0)
		tst_brkm(TBROK | TERRNO, cleanup, "Failed to create timer");

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		tst_count = 0;

		TEST(ltp_syscall(__NR_timer_gettime, timer, &spec));
		if (TEST_RETURN == 0) {
			tst_resm(TPASS, "timer_gettime(CLOCK_REALTIME) Passed");
		} else {
			tst_resm(TFAIL | TERRNO,
			         "timer_gettime(CLOCK_REALTIME) Failed");
		}

		TEST(ltp_syscall(__NR_timer_gettime, -1, &spec));
		if (TEST_RETURN == -1 && TEST_ERRNO == EINVAL) {
			tst_resm(TPASS,	"timer_gettime(-1) Failed: EINVAL");
		} else {
			tst_resm(TFAIL | TERRNO,
			         "timer_gettime(-1) = %li", TEST_RETURN);
		}

		TEST(ltp_syscall(__NR_timer_gettime, timer, NULL));
		if (TEST_RETURN == -1 && TEST_ERRNO == EFAULT) {
			tst_resm(TPASS,	"timer_gettime(NULL) Failed: EFAULT");
		} else {
			tst_resm(TFAIL | TERRNO,
			         "timer_gettime(-1) = %li", TEST_RETURN);
		}
	}

	cleanup();
	tst_exit();
}
示例#16
0
文件: capset01.c 项目: gaowanlong/ltp
int main(int ac, char **av)
{

	int lc;
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		TEST(ltp_syscall(__NR_capset, &header, &data));

		if (TEST_RETURN == 0) {
			tst_resm(TPASS, "capset() returned %ld", TEST_RETURN);
		} else {
			tst_resm(TFAIL | TTERRNO,
				 "Test Failed, capset() returned %ld"
				 " Maybe you need to do `modprobe capability`?",
				 TEST_RETURN);
		}
	}

	cleanup();

	tst_exit();
}
示例#17
0
文件: linkat02.c 项目: qyxia/ltp
static void linkat_verify(const struct test_struct *desc)
{
	if (desc->setupfunc != NULL) {
		if (desc->setupfunc == setup_emlink &&
		    fs_type == TST_XFS_MAGIC) {
			tst_resm(TCONF, "Test skipped XFS filesystem.");
			return;
		} else {
			desc->setupfunc();
		}
	}

	TEST(ltp_syscall(__NR_linkat, AT_FDCWD, desc->oldfname,
			 AT_FDCWD, desc->newfname, desc->flags));

	if (desc->cleanfunc != NULL)
		desc->cleanfunc();

	if (TEST_RETURN != -1) {
		tst_resm(TFAIL,
			 "linkat(""AT_FDCWD"", %s, ""AT_FDCWD"", %s, %d)"
			 "succeeded unexpectedly", desc->oldfname,
			 desc->newfname, desc->flags);
		return;
	}

	if (TEST_ERRNO == desc->expected_errno) {
		tst_resm(TPASS | TTERRNO, "linkat failed as expected");
	} else {
		tst_resm(TFAIL | TTERRNO,
			 "linkat failed unexpectedly; expected: "
			 "%d - %s", desc->expected_errno,
			 strerror(desc->expected_errno));
	}
}
示例#18
0
int main(int ac, char **av)
{
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;
		TEST(ltp_syscall(__NR_sysfs, INVALID_OPTION));

		/* check return code */
		if ((TEST_RETURN == -1) && (TEST_ERRNO == EINVAL)) {
			tst_resm(TPASS, "sysfs(2) expected failure;"
				 " Got errno - EINVAL :" " Invalid option");
		} else {
			tst_resm(TFAIL, "sysfs(2) failed to produce"
				 " expected error; %d, errno"
				 " : EINVAL and got %d", EINVAL, TEST_ERRNO);
		}
	}

	/*Clean up and exit */
	cleanup();
	tst_exit();

}				/*End of main */
示例#19
0
文件: capget02.c 项目: 1587/ltp
int main(int ac, char **av)
{

	int lc, i;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {
			test_setup(i);
			TEST(ltp_syscall(__NR_capget, test_cases[i].headerp,
				     test_cases[i].datap));

			if (TEST_RETURN == -1 &&
			    TEST_ERRNO == test_cases[i].exp_errno) {
				tst_resm(TPASS | TTERRNO,
					 "capget failed as expected");
			} else {
				tst_resm(TFAIL | TTERRNO,
					 "capget failed unexpectedly (%ld)",
					 TEST_RETURN);
			}
		}
	}

	cleanup();

	tst_exit();

}
示例#20
0
int main(int ac, char **av)
{
	int newtid = -1;
	int lc;
	const char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}

	setup();

	for (lc = 0; TEST_LOOPING(lc); ++lc) {
		tst_count = 0;
		for (testno = 0; testno < TST_TOTAL; ++testno) {
			TEST(ltp_syscall(__NR_set_tid_address, &newtid));
			if (TEST_RETURN == getpid()) {
				tst_resm(TPASS,
					 "set_tid_address call succeeded:  as expected %ld",
					 TEST_RETURN);
			} else {
				tst_resm(TFAIL, "%s failed - errno = %d : %s",
					 TCID, TEST_ERRNO,
					 strerror(TEST_ERRNO));
				cleanup();
				tst_exit();
			}
		}
	}
	cleanup();
	tst_exit();
}
示例#21
0
文件: swapon03.c 项目: AbhiramiP/ltp
/*
 * Check if the file is at /proc/swaps and remove it giving swapoff
 */
static int check_and_swapoff(const char *filename)
{
	char cmd_buffer[256];
	int rc = -1;

	if (snprintf(cmd_buffer, sizeof(cmd_buffer),
		     "grep -q '%s.*file' /proc/swaps", filename) < 0) {
		tst_resm(TWARN,
			 "sprintf() failed to create the command string");
	} else {

		rc = 0;

		if (system(cmd_buffer) == 0) {

			/* now we need to swapoff the file */
			if (ltp_syscall(__NR_swapoff, filename) != 0) {

				tst_resm(TWARN, "Failed to turn off swap "
					 "file. system reboot after "
					 "execution of LTP test suite "
					 "is recommended");
				rc = -1;

			}

		}
	}

	return rc;
}
示例#22
0
int main(int ac, char **av)
{
    int lc, i;

    tst_parse_opts(ac, av, NULL, NULL);

    setup();

    for (lc = 0; TEST_LOOPING(lc); lc++) {

        tst_count = 0;

        for (i = 0; i < TST_TOTAL; i++) {

            /* Set up individual test */
            if (setup_test(i) == 0) {
                TEST(ltp_syscall(__NR_timer_settime, timer,
                                 flag, &new_set, old_temp));
                tst_resm((TEST_RETURN == 0 ?
                          TPASS :
                          TFAIL | TTERRNO),
                         "%s",
                         (TEST_RETURN ==
                          0 ? "passed" : "failed")
                        );
            }

        }
    }

    cleanup();
    tst_exit();
}
示例#23
0
static int migrate_to_node(pid_t pid, int node)
{
	unsigned long nodemask_size, max_node;
	unsigned long *old_nodes, *new_nodes;
	int i;

	tst_resm(TINFO, "pid(%d) migrate pid %d to node -> %d",
		 getpid(), pid, node);
	max_node = LTP_ALIGN(get_max_node(), sizeof(unsigned long)*8);
	nodemask_size = max_node / 8;
	old_nodes = SAFE_MALLOC(NULL, nodemask_size);
	new_nodes = SAFE_MALLOC(NULL, nodemask_size);

	memset(old_nodes, 0, nodemask_size);
	memset(new_nodes, 0, nodemask_size);
	for (i = 0; i < num_nodes; i++)
		set_bit(old_nodes, nodes[i], 1);
	set_bit(new_nodes, node, 1);

	TEST(ltp_syscall(__NR_migrate_pages, pid, max_node, old_nodes,
		new_nodes));
	if (TEST_RETURN != 0) {
		if (TEST_RETURN < 0)
			tst_resm(TFAIL | TERRNO, "migrate_pages failed "
				 "ret: %ld, ", TEST_RETURN);
		else
			tst_resm(TWARN, "migrate_pages could not migrate all "
				 "pages, not migrated: %ld", TEST_RETURN);
		print_mem_stats(pid, node);
	}
	free(old_nodes);
	free(new_nodes);
	return TEST_RETURN;
}
示例#24
0
int main(int ac, char **av)
{
	int status;
	pid_t cpid, w;

	setup();

	cpid = fork();		//call exit_group()
	if (cpid == -1) {
		tst_brkm(TFAIL | TERRNO, cleanup, "fork failed");
	} else if (cpid == 0) {
		sleep(5);
		TEST(ltp_syscall(__NR_exit_group, 4));
	} else {
		w = wait(&status);
		if (w == -1)
			tst_brkm(TBROK | TERRNO, cleanup, "wait failed");
		if (WIFEXITED(status) && (WEXITSTATUS(status) == 4))
			tst_resm(TPASS, "exit_group succeeded");
		else {
			tst_resm(TFAIL | TERRNO,
				 "exit_group failed (wait status = %d)", w);
		}
	}
	cleanup();
	tst_exit();
}
示例#25
0
int main(int argc, char **argv)
{
	int lc;
	char *msg;

	msg = parse_opts(argc, argv, NULL, NULL);
	if (msg != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		/* insert dummy_del_mod.ko */
		if (module_loaded == 0) {
			tst_module_load(NULL, MODULE_NAME_KO, NULL);
			module_loaded = 1;
		}

		TEST(ltp_syscall(__NR_delete_module, MODULE_NAME, 0));
		if (TEST_RETURN == -1) {
			tst_resm(TFAIL | TTERRNO, "delete_module() failed to "
				 "remove module entry for %s ", MODULE_NAME);
		} else {
			tst_resm(TPASS, "delete_module() successful");
			module_loaded = 0;
		}

	}

	cleanup();
	tst_exit();
}
示例#26
0
文件: pidns31.c 项目: AiprNick/ltp
/*
 * steps F_STEP_XX : called from main
 * steps C_STEP_XX : called from child_fn
 */
static void cleanup_resources(int step, mqd_t mqd)
{
	switch (step) {
	case C_STEP_1:
		close(father_to_child[0]);
		/* fall through */
	case C_STEP_0:
		mq_close(mqd);
		break;

	case F_STEP_3:
		remove_mqueue(mqd);
		close(father_to_child[1]);
		break;

	case F_STEP_2:
		ltp_syscall(__NR_mq_notify, mqd, NULL);
		/* fall through */
	case F_STEP_1:
		remove_mqueue(mqd);
		/* fall through */
	case F_STEP_0:
		remove_pipe(father_to_child);
		break;
	default:
		tst_resm(TWARN, "Unknown code - no resource removed.");
		break;
	}
}
示例#27
0
static int filter_nodemask_mem(nodemask_t * nodemask, unsigned long max_node)
{
#if MPOL_F_MEMS_ALLOWED
	unsigned long nodemask_size = max_node / 8 + 1;
	memset(nodemask, 0, nodemask_size);
	/*
	 * avoid numa_get_mems_allowed(), because of bug in getpol()
	 * utility function in older versions:
	 * http://www.spinics.net/lists/linux-numa/msg00849.html
	 */
	if (ltp_syscall(__NR_get_mempolicy, NULL, nodemask->n,
		    max_node, 0, MPOL_F_MEMS_ALLOWED) < 0)
		return -2;
#else
	int i;
	/*
	 * old libnuma/kernel don't have MPOL_F_MEMS_ALLOWED, so let's assume
	 * that we can use any node with memory > 0
	 */
	for (i = 0; i < max_node; i++) {
		if (!nodemask_isset(nodemask, i))
			continue;
		if (numa_node_size64(i, NULL) <= 0)
			nodemask_clr(nodemask, i);
	}
#endif /* MPOL_F_MEMS_ALLOWED */
	return 0;
}
示例#28
0
文件: capget01.c 项目: MohdVara/ltp
int main(int ac, char **av)
{

	int lc;
	const char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	/* header.version must be _LINUX_CAPABILITY_VERSION */
	header.version = _LINUX_CAPABILITY_VERSION;

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		TEST(ltp_syscall(__NR_capget, &header, &data));

		if (TEST_RETURN == 0) {
			tst_resm(TPASS, "capget() returned %ld", TEST_RETURN);
		} else {
			tst_resm(TFAIL | TTERRNO,
				 "Test Failed, capget() returned %ld",
				 TEST_RETURN);
		}
	}

	cleanup();

	tst_exit();
}
示例#29
0
文件: splice01.c 项目: exhoty/ltp
static inline long splice(int fd_in, loff_t * off_in,
			  int fd_out, loff_t * off_out,
			  size_t len, unsigned int flags)
{
	return ltp_syscall(__NR_splice, fd_in, off_in, fd_out, off_out,
		len, flags);
}
示例#30
0
static int my_rt_sigtimedwait(const sigset_t * set, siginfo_t * info,
			      struct timespec *timeout)
{

	/* The last argument is (number_of_signals)/(bits_per_byte), which are 64 and 8, resp. */
	return ltp_syscall(__NR_rt_sigtimedwait, set, info, timeout, 8);
}