예제 #1
0
파일: read_all.c 프로젝트: kraj/ltp
static void setup(void)
{
	if (tst_parse_int(str_reads, &reads, 1, INT_MAX))
		tst_brk(TBROK,
			"Invalid reads (-r) argument: '%s'", str_reads);

	if (tst_parse_long(str_max_workers, &max_workers, 1, LONG_MAX)) {
		tst_brk(TBROK,
			"Invalid max workers (-w) argument: '%s'",
			str_max_workers);
	}

	if (tst_parse_long(str_worker_count, &worker_count, 1, LONG_MAX)) {
		tst_brk(TBROK,
			"Invalid worker count (-W) argument: '%s'",
			str_worker_count);
	}

	if (!root_dir)
		tst_brk(TBROK, "The directory argument (-d) is required");

	if (!worker_count)
		worker_count = MIN(MAX(tst_ncpus() - 1, 1), max_workers);
	workers = SAFE_MALLOC(worker_count * sizeof(*workers));
}
예제 #2
0
파일: mem.c 프로젝트: Havner/ltp
/*
 * oom - allocates memory according to specified testcase and checks
 *       desired outcome (e.g. child killed, operation failed with ENOMEM)
 * @testcase: selects how child allocates memory
 *            valid choices are: NORMAL, MLOCK and KSM
 * @lite: if non-zero, child makes only single TESTMEM+MB allocation
 *        if zero, child keeps allocating memory until it gets killed
 *        or some operation fails
 * @retcode: expected return code of child process
 *           if matches child ret code, this function reports PASS,
 *           otherwise it reports FAIL
 * @allow_sigkill: if zero and child is killed, this function reports FAIL
 *                 if non-zero, then if child is killed by SIGKILL
 *                 it is considered as PASS
 */
void oom(int testcase, int lite, int retcode, int allow_sigkill)
{
	pid_t pid;
	int status, threads;

	switch (pid = fork()) {
	case -1:
		if (errno == retcode) {
			tst_resm(TPASS | TERRNO, "fork");
			return;
		}
		tst_brkm(TBROK | TERRNO, cleanup, "fork");
	case 0:
		threads = MAX(1, tst_ncpus() - 1);
		child_alloc(testcase, lite, threads);
	default:
		break;
	}

	tst_resm(TINFO, "expected victim is %d.", pid);
	if (waitpid(-1, &status, 0) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");

	if (WIFSIGNALED(status)) {
		if (allow_sigkill && WTERMSIG(status) == SIGKILL) {
			tst_resm(TPASS, "victim signalled: (%d) %s",
				SIGKILL,
				tst_strsig(SIGKILL));
		} else {
			tst_resm(TFAIL, "victim signalled: (%d) %s",
				WTERMSIG(status),
				tst_strsig(WTERMSIG(status)));
		}
	} else if (WIFEXITED(status)) {
		if (WEXITSTATUS(status) == retcode) {
			tst_resm(TPASS, "victim retcode: (%d) %s",
				retcode, strerror(retcode));
		} else {
			tst_resm(TFAIL, "victim unexpectedly ended with "
				"retcode: %d, expected: %d",
				WEXITSTATUS(status), retcode);
		}
	} else {
		tst_resm(TFAIL, "victim unexpectedly ended");
	}
}
예제 #3
0
파일: getcwd04.c 프로젝트: 1587/ltp
static void setup(void)
{
	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	if (tst_ncpus() == 1)
		tst_brkm(TCONF, NULL, "This test needs two cpus at least");

	tst_tmpdir();

	if (signal(SIGALRM, sigproc) == SIG_ERR)
		tst_brkm(TBROK | TERRNO, cleanup, "signal(SIGALRM) failed");

	alarm(TIMEOUT);

	SAFE_GETCWD(cleanup, init_cwd, PATH_MAX);
}
예제 #4
0
파일: mem.c 프로젝트: sathnaga/ltp
/*
 * oom - allocates memory according to specified testcase and checks
 *       desired outcome (e.g. child killed, operation failed with ENOMEM)
 * @testcase: selects how child allocates memory
 *            valid choices are: NORMAL, MLOCK and KSM
 * @lite: if non-zero, child makes only single TESTMEM+MB allocation
 *        if zero, child keeps allocating memory until it gets killed
 *        or some operation fails
 * @retcode: expected return code of child process
 *           if matches child ret code, this function reports PASS,
 *           otherwise it reports FAIL
 * @allow_sigkill: if zero and child is killed, this function reports FAIL
 *                 if non-zero, then if child is killed by SIGKILL
 *                 it is considered as PASS
 */
void oom(int testcase, int lite, int retcode, int allow_sigkill)
{
	pid_t pid;
	int status, threads;

	switch (pid = SAFE_FORK()) {
	case 0:
		threads = MAX(1, tst_ncpus() - 1);
		child_alloc(testcase, lite, threads);
	default:
		break;
	}

	tst_res(TINFO, "expected victim is %d.", pid);
	SAFE_WAITPID(-1, &status, 0);

	if (WIFSIGNALED(status)) {
		if (allow_sigkill && WTERMSIG(status) == SIGKILL) {
			tst_res(TPASS, "victim signalled: (%d) %s",
				SIGKILL,
				tst_strsig(SIGKILL));
		} else {
			tst_res(TFAIL, "victim signalled: (%d) %s",
				WTERMSIG(status),
				tst_strsig(WTERMSIG(status)));
		}
	} else if (WIFEXITED(status)) {
		if (WEXITSTATUS(status) == retcode) {
			tst_res(TPASS, "victim retcode: (%d) %s",
				retcode, strerror(retcode));
		} else {
			tst_res(TFAIL, "victim unexpectedly ended with "
				"retcode: %d, expected: %d",
				WEXITSTATUS(status), retcode);
		}
	} else {
		tst_res(TFAIL, "victim unexpectedly ended");
	}
}
예제 #5
0
파일: ltpapicmd.c 프로젝트: Nan619/ltp-ddt
/*
 * Function:    main - entry point of this program
 *
 * Description: Parses the arguments to each command. Most commands have in
 *              common atlest 2 arguments, type of test result, which is one of
 *              TPASS, TFAIL, TBROK, TCONF, etc, and a message that describes
 *              the result. Other arguments are a file, the contents of which
 *              are printed after the type of test result and associated message
 *              is printed, also a cleanup function that will be executed.
 *              Currently this function name is ignored but MUST be provided
 *              for compatability reasons.
 *
 *              The different commands are actually a hard link to this program
 *              the program invokes the appropriate function based on the
 *              command name with which it was invoked.
 *
 *              Set the values for TCID to the name of the test case.
 *              set the value for TST_TOTAL for total number of tests this is
 *              required in case one test breaks and all following tests also
 *              should be reported as broken.
 *              Set Tst_count before every individual test.
 *
 * Exit:        0 on success
 *              -1 on failure
 */
int main(int argc, char *argv[])
{
	int trestype;		/* test result type TFAIL, TPASS, TINFO etc */
	char *arg_fmt;		/* message string printed along with test type */
	char *cmd_name;		/* name by which this program is invoked tst_brk etc */
	char *tst_total;	/* total number of tests in the file. */
	char *tst_count;	/* sets the value of Tst_count with this value */
	char *file_name;	/* contents of this file are printed; see tst_res() */

	arg_fmt = SAFE_MALLOC(NULL, 1024);
	cmd_name = SAFE_MALLOC(NULL, 1024);

	strcpy(cmd_name, SAFE_BASENAME(NULL, (argv++)[0]));

	TCID = getenv("TCID");
	tst_total = getenv("TST_TOTAL");
	tst_count = getenv("TST_COUNT");
	if (TCID == NULL || tst_total == NULL || tst_count == NULL) {
		if (strcmp(cmd_name, "tst_kvercmp") != 0) {
			fprintf(stderr,
				"\nSet variables TCID, TST_TOTAL, and TST_COUNT before each test:\n"
				"export TCID=<test name>\n"
				"export TST_TOTAL=<Total Number of Tests >\n"
				"export TST_COUNT=<Test case number>\n\n");
			/* Make sure the user knows there's an error. */
			abort();
		}
	} else {
		TST_TOTAL = atoi(tst_total);
		Tst_count = atoi(tst_count);
		if (Tst_count > 0)
			Tst_count--;

		if (strcmp(TCID, " ") == 0) {
			fprintf(stderr,
				"Variable TCID not set, use: TCID=<test name>\n");
			exit(1);
		}
		if (TST_TOTAL <= 0) {
			fprintf(stderr,
				"Variable TST_TOTAL is set to 0, must be "
				"greater than zero\n");
			exit(1);
		}
	}

	if (strcmp(cmd_name, "tst_brk") == 0) {
		if (argc < 5) {
			fprintf(stderr, "Usage: %s TTYPE FNAME FUNC STRING\n"
				"\tTTYPE  - Test Result Type; one of TFAIL, TBROK, TCONF, "
				"and TRETR.\n"
				"\tFNAME  - Print contents of this file after the message\n"
				"\tFUNC   - Cleanup function (ignored), but MUST be provided\n"
				"\tSTRING - Message explaining the test result\n",
				cmd_name);
			exit(1);
		}
		trestype = ident_ttype((argv++)[0]);
		file_name = (argv++)[0];
		argv++;
		strcpy(arg_fmt, *argv);
		tst_brk(trestype, file_name, NULL, arg_fmt);
	} else if (strcmp(cmd_name, "tst_res") == 0) {
		if (argc < 4) {
			fprintf(stderr, "Usage: %s TTYPE FNAME STRING\n"
				"\tTTYPE  - Test Result Type; one of TFAIL, TBROK, TCONF, "
				"and  TRETR.\n"
				"\tFNAME  - Print contents of this file after the message\n"
				"\tSTRING - Message explaining the test result\n",
				cmd_name);
			exit(1);
		}
		trestype = ident_ttype((argv++)[0]);
		file_name = (argv++)[0];
		strcpy(arg_fmt, *argv);
		tst_res(trestype, file_name, arg_fmt);
	} else if (strcmp(cmd_name, "tst_brkm") == 0) {
		if (argc < 4) {
			fprintf(stderr, "Usage: %s TTYPE FUNC STRING\n"
				"\tTTYPE  - Test Result Type; one of TFAIL, TBROK, TCONF, "
				"and TRETR.\n"
				"\tFUNC   - Cleanup function (ignored), but MUST be provided\n"
				"\tSTRING - Message explaining the test result\n",
				cmd_name);
			exit(1);
		}
		trestype = ident_ttype((argv++)[0]);
		argv++;
		strcpy(arg_fmt, *argv);
		tst_brkm(trestype, NULL, arg_fmt);
	} else if (strcmp(cmd_name, "tst_resm") == 0) {
		if (argc < 3) {
			fprintf(stderr, "Usage: %s TTYPE STRING\n"
				"\tTTYPE  - Test Result Type; one of TFAIL, TBROK, TCONF, "
				"and TRETR.\n"
				"\tSTRING - Message explaining the test result\n",
				cmd_name);
			exit(1);
		}
		trestype = ident_ttype((argv++)[0]);
		strcpy(arg_fmt, *argv);
		tst_resm(trestype, arg_fmt);
	} else if (strcmp(cmd_name, "tst_exit") == 0) {
		tst_exit();
	} else if (strcmp(cmd_name, "tst_flush") == 0) {
		tst_flush();
	} else if (strcmp(cmd_name, "tst_kvercmp") == 0) {
		int exit_value;

		if (argc < 4) {
			fprintf(stderr, "Usage: %s NUM NUM NUM\n"
				"Compares to the running kernel version.\n\n"
				"\tNUM - A positive integer.\n"
				"\tThe first NUM is the kernel VERSION\n"
				"\tThe second NUM is the kernel PATCHLEVEL\n"
				"\tThe third NUM is the kernel SUBLEVEL\n\n"
				"\tExit status is 0 if the running kernel is older than the\n"
				"\t\tkernel specified by NUM NUM NUM.\n"
				"\tExit status is 1 for kernels of the same age.\n"
				"\tExit status is 2 if the running kernel is newer.\n",
				cmd_name);
			exit(1);
		}
		exit_value = tst_kvercmp(atoi(argv[0]), atoi(argv[1]),
					 atoi(argv[2]));
		if (exit_value < 0)
			exit_value = 0;
		else if (exit_value == 0)
			exit_value = 1;
		else if (exit_value > 0)
			exit_value = 2;
		exit(exit_value);
	} else if (strcmp(cmd_name, "tst_ncpus") == 0) {
		printf("%li\n", tst_ncpus());
	} else if (strcmp(cmd_name, "tst_ncpus_max") == 0) {
		printf("%li\n", tst_ncpus_max());
	}

	exit(0);
}
예제 #6
0
파일: ltpapicmd.c 프로젝트: AbhiramiP/ltp
/*
 * Function:    main - entry point of this program
 *
 * Description: Parses the arguments to each command. Most commands have in
 *              common atlest 2 arguments, type of test result, which is one of
 *              TPASS, TFAIL, TBROK, TCONF, etc, and a message that describes
 *              the result. Other arguments are a file, the contents of which
 *              are printed after the type of test result and associated message
 *              is printed, also a cleanup function that will be executed.
 *              Currently this function name is ignored but MUST be provided
 *              for compatability reasons.
 *
 *              The different commands are actually a hard link to this program
 *              the program invokes the appropriate function based on the
 *              command name with which it was invoked.
 *
 *              Set the values for TCID to the name of the test case.
 *              set the value for TST_TOTAL for total number of tests this is
 *              required in case one test breaks and all following tests also
 *              should be reported as broken.
 *              Set tst_count before every individual test.
 *
 * Exit:        0 on success
 *              -1 on failure
 */
int main(int argc, char *argv[])
{
	strcpy(cmd_name, SAFE_BASENAME(NULL, (argv++)[0]));

	TCID = getenv("TCID");
	tst_total = getenv("TST_TOTAL");
	tst_cntstr = getenv("TST_COUNT");
	if (TCID == NULL || tst_total == NULL || tst_cntstr == NULL) {
		if (!strcmp(cmd_name, "tst_kvercmp") &&
		    !strcmp(cmd_name, "tst_kvercmp2") &&
		    !strcmp(cmd_name, "tst_fs_has_free") &&
		    !strcmp(cmd_name, "tst_get_unused_port")) {
			fprintf(stderr,
				"\nSet variables TCID, TST_TOTAL, and TST_COUNT before each test:\n"
				"export TCID=<test name>\n"
				"export TST_TOTAL=<Total Number of Tests >\n"
				"export TST_COUNT=<Test case number>\n\n");
			/* Make sure the user knows there's an error. */
			abort();
		}
	} else {
		TST_TOTAL = atoi(tst_total);
		tst_count = atoi(tst_cntstr);
		if (tst_count > 0)
			tst_count--;

		if (strcmp(TCID, " ") == 0) {
			fprintf(stderr,
				"Variable TCID not set, use: TCID=<test name>\n");
			exit(1);
		}
		if (TST_TOTAL <= 0) {
			fprintf(stderr,
				"Variable TST_TOTAL is set to 0, must be "
				"greater than zero\n");
			exit(1);
		}
	}

	if (strcmp(cmd_name, "tst_brk") == 0) {
		apicmd_brk(argc, argv);
	} else if (strcmp(cmd_name, "tst_res") == 0) {
		apicmd_res(argc, argv);
	} else if (strcmp(cmd_name, "tst_brkm") == 0) {
		apicmd_brkm(argc, argv);
	} else if (strcmp(cmd_name, "tst_resm") == 0) {
		apicmd_resm(argc, argv);
	} else if (strcmp(cmd_name, "tst_exit") == 0) {
		tst_exit();
	} else if (strcmp(cmd_name, "tst_flush") == 0) {
		tst_flush();
	} else if (strcmp(cmd_name, "tst_kvercmp") == 0) {
		apicmd_kvercmp(argc, argv);
	} else if (strcmp(cmd_name, "tst_kvercmp2") == 0) {
		apicmd_kvercmp2(argc, argv);
	} else if (strcmp(cmd_name, "tst_ncpus") == 0) {
		printf("%li\n", tst_ncpus());
	} else if (strcmp(cmd_name, "tst_ncpus_conf") == 0) {
		printf("%li\n", tst_ncpus_conf());
	} else if (strcmp(cmd_name, "tst_ncpus_max") == 0) {
		printf("%li\n", tst_ncpus_max());
	} else if (strcmp(cmd_name, "tst_get_unused_port") == 0) {
		printf("%u\n", apicmd_get_unused_port(argc, argv));
	} else if (strcmp(cmd_name, "tst_fs_has_free") == 0) {
		apicmd_fs_has_free(argc, argv);
	}

	exit(0);
}