コード例 #1
0
ファイル: tst_mkfs.c プロジェクト: nloopa/Linux-Test-Project
void tst_mkfs(void (cleanup_fn)(void), const char *dev,
              const char *fs_type, const char *fs_opts)
{
    tst_resm(TINFO, "Formatting %s with %s extra opts='%s'",
             dev, fs_type, fs_opts ? fs_opts : "");

    if (!fs_type)
        tst_brkm(TBROK, cleanup_fn, "No fs_type specified");

    const char *argv[] = {"mkfs", "-t", fs_type, NULL, NULL, NULL, NULL};
    int pos = 3;

    /*
     * The mkfs.xfs aborts if it finds a filesystem superblock
     * on the device, which is the case here as we reuse one
     * device for all tests.
     */
    if (!strcmp(fs_type, "xfs")) {
        tst_resm(TINFO, "Appending '-f' force flag to mkfs.xfs");
        argv[pos++] = "-f";
    }

    if (fs_opts)
        argv[pos++] = fs_opts;

    argv[pos] = dev;

    tst_run_cmd(cleanup_fn, argv, "/dev/null", NULL);
}
コード例 #2
0
ファイル: nfs05_make_tree.c プロジェクト: 1587/ltp
static void run_targets(const char *dirname, char *cfile, pid_t tid)
{
	int i, k, fd;
	char subdir[PATH_MAX] = {0};
	char *output_file;
	char buf[11];
	const char *const cmd_run[] = {cfile, NULL};

	SAFE_ASPRINTF(&output_file, "%s/cmd.out", dirname);

	/* run each binary */
	for (i = 0; i < dirs_num; ++i) {
		for (k = 0; k < file_num; ++k) {
			snprintf(cfile, PATH_MAX, "%s%s/%d.%d.%d",
				 dirname, subdir, tid, i, k);

			tst_run_cmd(cmd_run, output_file, NULL, 0);

			fd = SAFE_OPEN(output_file, O_RDONLY);
			SAFE_READ(1, fd, buf, 11);
			if (strncmp(buf, "hello world", 11))
				tst_brk(TFAIL, "command printed wrong message");
			SAFE_CLOSE(fd);
		}
		strcat(subdir, "/dir");
	}

	free(output_file);
}
コード例 #3
0
ファイル: tst_mkfs.c プロジェクト: gibertre/ltp
void tst_mkfs(void (cleanup_fn)(void), const char *dev,
	      const char *fs_type, const char *const fs_opts[])
{
	int i, pos = 3;
	const char *argv[OPTS_MAX] = {"mkfs", "-t", fs_type};
	char fs_opts_str[1024] = "";

	if (!fs_type)
		tst_brkm(TBROK, cleanup_fn, "No fs_type specified");

	/*
	 * mkfs.xfs and mkfs.btrfs aborts if it finds a filesystem
	 * superblock on the device, which is the case here as we
	 * reuse one device for all tests.
	 */
	if (!strcmp(fs_type, "xfs")) {
		tst_resm(TINFO, "Appending '-f' flag to mkfs.%s", fs_type);
		argv[pos++] = "-f";
	}

	if (!strcmp(fs_type, "btrfs")) {
		/*
		 * The -f option was added to btrfs-progs v3.12
		 */
		if (system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {
			tst_resm(TINFO, "Appending '-f' flag to mkfs.%s",
				fs_type);
			argv[pos++] = "-f";
		}
	}

	if (fs_opts) {
		for (i = 0; fs_opts[i]; i++) {
			argv[pos++] = fs_opts[i];

			if (pos + 2 > OPTS_MAX) {
				tst_brkm(TBROK, cleanup_fn,
				         "Too much mkfs options");
			}

			if (i)
				strcat(fs_opts_str, " ");
			strcat(fs_opts_str, fs_opts[i]);
		}
	}

	argv[pos++] = dev;
	argv[pos] = NULL;

	tst_resm(TINFO, "Formatting %s with %s extra opts='%s'",
		 dev, fs_type, fs_opts_str);
	tst_run_cmd(cleanup_fn, argv, "/dev/null", NULL);
}
コード例 #4
0
ファイル: tst_mkfs.c プロジェクト: ShaolongHu/ltp
void tst_mkfs(void (cleanup_fn)(void), const char *dev,
              const char *fs_type, const char *const fs_opts[],
              const char *extra_opt)
{
	int i, pos = 3;
	const char *argv[OPTS_MAX] = {"mkfs", "-t", fs_type};
	char fs_opts_str[1024] = "";

	if (!dev)
		tst_brkm(TBROK, cleanup_fn, "No device specified");

	if (!fs_type)
		tst_brkm(TBROK, cleanup_fn, "No fs_type specified");

	if (fs_opts) {
		for (i = 0; fs_opts[i]; i++) {
			argv[pos++] = fs_opts[i];

			if (pos + 2 > OPTS_MAX) {
				tst_brkm(TBROK, cleanup_fn,
				         "Too much mkfs options");
			}

			if (i)
				strcat(fs_opts_str, " ");
			strcat(fs_opts_str, fs_opts[i]);
		}
	}

	argv[pos++] = dev;

	if (extra_opt) {
		argv[pos++] = extra_opt;

		if (pos + 1 > OPTS_MAX) {
			tst_brkm(TBROK, cleanup_fn,
			         "Too much mkfs options");
		}
	}

	argv[pos] = NULL;

	tst_resm(TINFO, "Formatting %s with %s opts='%s' extra opts='%s'",
	         dev, fs_type, fs_opts_str, extra_opt ? extra_opt : "");
	tst_run_cmd(cleanup_fn, argv, "/dev/null", NULL, 0);
}
コード例 #5
0
ファイル: libswapon.c プロジェクト: 1587/ltp
/*
 * Make a swap file
 */
void make_swapfile(void (cleanup)(void), const char *swapfile)
{
	if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
	    TST_BYTES)) {
		tst_brkm(TBROK, cleanup,
			"Insufficient disk space to create swap file");
	}

	/* create file */
	if (tst_fill_file(swapfile, 0,
			sysconf(_SC_PAGESIZE), 10) != 0) {
		tst_brkm(TBROK, cleanup, "Failed to create swapfile");
	}

	/* make the file swapfile */
	const char *argv[2 + 1];
	argv[0] = "mkswap";
	argv[1] = swapfile;
	argv[2] = NULL;

	tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
}
コード例 #6
0
ファイル: nfs05_make_tree.c プロジェクト: 1587/ltp
static void *thread_fn(LTP_ATTRIBUTE_UNUSED void *args)
{
	const char prog_buf[] = "#include <stdio.h>\n"
				"int main(void)\n{\n"
				"\tprintf(\"hello world\");\n"
				"\treturn 0;\n}\n";

	const char make_buf_n[] = "CFLAGS := -O -w -g\n"
				  "SRCS=$(wildcard *.c)\n"
				  "TARGETS=$(SRCS:.c=)\n"
				  "all: $(TARGETS)\n"
				  "$(TARGETS): %: %.c\n"
				  "\t$(CC) -o $@ $<\n"
				  "clean:\n\trm -f $(TARGETS)\n"
				  ".PHONY: all clean\n";

	const char make_buf[] = "CFLAGS := -O -w -g\n"
				"SUBDIR = dir\n"
				"SRCS=$(wildcard *.c)\n"
				"TARGETS=$(SRCS:.c=)\n"
				"all: $(SUBDIR) $(TARGETS)\n"
				"$(TARGETS): %: %.c\n"
				"\t$(CC) -o $@ $<\n"
				"$(SUBDIR):\n\t$(MAKE) -C $@\n"
				"clean:\n"
				"\trm -f $(TARGETS)\n"
				"\t$(MAKE) -C $(SUBDIR) clean\n"
				".PHONY: all $(SUBDIR) clean\n";

	int i, k, fd, dirfd, ret;
	char *dirname;
	char cfile[PATH_MAX];
	char hostname[256];
	pid_t tid = gettid();

	SAFE_GETHOSTNAME(hostname, 256);
	SAFE_ASPRINTF(&dirname, "%s.%ld", hostname, tid);

	SAFE_MKDIR(dirname, 0755);
	dirfd = SAFE_OPEN(dirname, O_DIRECTORY);

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

		fd = openat(dirfd, "makefile", O_CREAT | O_RDWR,
			    S_IRWXU | S_IRWXG | S_IRWXO);
		if (fd < 0)
			tst_brk(TFAIL | TERRNO, "openat(makefile) failed");

		if (i == dirs_num - 1)
			SAFE_WRITE(1, fd, make_buf_n, sizeof(make_buf_n) - 1);
		else
			SAFE_WRITE(1, fd, make_buf, sizeof(make_buf) - 1);

		SAFE_CLOSE(fd);

		for (k = 0; k < file_num; ++k) {
			snprintf(cfile, PATH_MAX, "%d.%d.%d.c", tid, i, k);
			fd = openat(dirfd, cfile, O_CREAT | O_RDWR,
				    S_IRWXU | S_IRWXG | S_IRWXO);
			if (fd < 0) {
				tst_brk(TFAIL | TERRNO,
					"openat(%s) failed", cfile);
			}

			SAFE_WRITE(1, fd, prog_buf, sizeof(prog_buf) - 1);
			SAFE_CLOSE(fd);
		}

		if (i == dirs_num - 1)
			break;

		ret = mkdirat(dirfd, "dir", 0755);
		if (ret < 0)
			tst_brk(TFAIL | TERRNO, "mkdirat('dir') failed");
		dirfd = openat(dirfd, "dir", O_DIRECTORY);
		if (dirfd < 0)
			tst_brk(TFAIL | TERRNO, "openat('dir') failed");
	}

	const char *const cmd_make[] = {"make", "-s", "-C", dirname, NULL};
	const char *const cmd_make_clean[] = {
		"make", "-C", dirname, "-s", "clean", NULL};

	tst_run_cmd(cmd_make, NULL, NULL, 0);

	run_targets(dirname, cfile, tid);

	tst_run_cmd(cmd_make_clean, NULL, NULL, 0);

	free(dirname);

	return NULL;
}