コード例 #1
0
ファイル: tst_test.c プロジェクト: ShaolongHu/ltp
static void do_setup(int argc, char *argv[])
{
	if (!tst_test)
		tst_brk(TBROK, "No tests to run");

	if (!tst_test->test && !tst_test->test_all)
		tst_brk(TBROK, "No test function speficied");

	if (tst_test->test && tst_test->test_all)
		tst_brk(TBROK, "You can define either test() or test_all()");

	if (tst_test->test && !tst_test->tcnt)
		tst_brk(TBROK, "Number of tests (tcnt) must not be > 0");

	if (tst_test->test_all && tst_test->tcnt)
		tst_brk(TBROK, "You can't define tcnt for test_all()");

	if (tst_test->needs_root && geteuid() != 0)
		tst_brk(TCONF, "Test needs to be run as root");

	if (tst_test->min_kver)
		check_kver();

	parse_opts(argc, argv);

	setup_ipc();

	if (needs_tmpdir()) {
		tst_tmpdir();
		tmpdir_created = 1;
	}

	if (tst_test->needs_device) {
		tdev.dev = tst_acquire_device(NULL);
		tdev.fs_type = tst_dev_fs_type();

		if (!tdev.dev)
			tst_brk(TCONF, "Failed to acquire device");

		tst_device = &tdev;
	}

	if (tst_test->resource_files)
		copy_resources();

	main_pid = getpid();

	if (tst_test->setup)
		tst_test->setup();

	if (main_pid != getpid())
		tst_brk(TBROK, "Runaway child in setup()!");
}
コード例 #2
0
ファイル: tst_test.c プロジェクト: sathnaga/ltp
static void do_setup(int argc, char *argv[])
{
	if (!tst_test)
		tst_brk(TBROK, "No tests to run");

	if (tst_test->tconf_msg)
		tst_brk(TCONF, "%s", tst_test->tconf_msg);

	assert_test_fn();

	tid = get_tid(argv);

	if (tst_test->sample)
		tst_test = tst_timer_test_setup(tst_test);

	parse_opts(argc, argv);

	if (tst_test->needs_root && geteuid() != 0)
		tst_brk(TCONF, "Test needs to be run as root");

	if (tst_test->min_kver)
		check_kver();

	if (tst_test->format_device)
		tst_test->needs_device = 1;

	if (tst_test->mount_device) {
		tst_test->needs_device = 1;
		tst_test->format_device = 1;
	}

	if (tst_test->all_filesystems)
		tst_test->needs_device = 1;

	setup_ipc();

	if (needs_tmpdir() && !tst_tmpdir_created())
		tst_tmpdir();

	if (tst_test->mntpoint)
		SAFE_MKDIR(tst_test->mntpoint, 0777);

	if ((tst_test->needs_rofs || tst_test->mount_device ||
	     tst_test->all_filesystems) && !tst_test->mntpoint) {
		tst_brk(TBROK, "tst_test->mntpoint must be set!");
	}

	if (tst_test->needs_rofs) {
		/* If we failed to mount read-only tmpfs. Fallback to
		 * using a device with empty read-only filesystem.
		 */
		if (mount(NULL, tst_test->mntpoint, "tmpfs", MS_RDONLY, NULL)) {
			tst_res(TINFO | TERRNO, "Can't mount tmpfs read-only"
				" at %s, setting up a device instead\n",
				tst_test->mntpoint);
			tst_test->mount_device = 1;
			tst_test->needs_device = 1;
			tst_test->format_device = 1;
			tst_test->mnt_flags = MS_RDONLY;
		} else {
			mntpoint_mounted = 1;
		}
	}

	if (tst_test->needs_device && !mntpoint_mounted) {
		tdev.dev = tst_acquire_device_(NULL, tst_test->dev_min_size);

		if (!tdev.dev)
			tst_brk(TCONF, "Failed to acquire device");

		tst_device = &tdev;

		if (tst_test->dev_fs_type)
			tdev.fs_type = tst_test->dev_fs_type;
		else
			tdev.fs_type = tst_dev_fs_type();

		if (!tst_test->all_filesystems)
			prepare_device();
	}

	if (tst_test->resource_files)
		copy_resources();
}