Esempio n. 1
0
static
int
report_checkN(int rv, int error, int *right_errors, int right_num)
{
	int i, goterror;
	int result = 1;

	if (rv==-1) {
		goterror = error;
	}
	else {
		goterror = 0;
	}

	for (i=0; i<right_num; i++) {
		if (goterror == right_errors[i]) {
			report_result(rv, error);
			report_passed(&result);
			return result;
		}
	}

	if (goterror == ENOSYS) {
		report_saw_enosys();
		say("(unimplemented) ");
		report_skipped(&result);
	}
	else {
		report_result(rv, error);
		report_failure(&result);
	}
	return result;
}
Esempio n. 2
0
/*
 * Note: unlike everything else this calls skipped/aborted, because
 * otherwise it has to communicate to the caller which to call and
 * that's a pain.
 */
int
create_testdir(void)
{
	int rv;
	rv = mkdir(TESTDIR, 0775);
	if (rv<0) {
		if (errno == ENOSYS) {
			report_saw_enosys();
			report_warnx("mkdir unimplemented; cannot run test");
			report_skipped();
		}
		else {
			report_warn("mkdir %s failed", TESTDIR);
			report_aborted();
		}
		return -1;
	}
	return 0;
}
Esempio n. 3
0
static
int
lseek_file_stdin(void)
{
	int fd, fd2, rv, status;
	const char slogan[] = "There ain't no such thing as a free lunch";
	size_t len = strlen(slogan);
	pid_t pid;
	int result = 0;

	report_begin("lseek stdin when open on file");

	/* fork so we don't affect our own stdin */
	pid = fork();
	if (pid<0) {
		report_warn("fork failed");
		report_aborted(&result);
		return result;
	}
	else if (pid!=0) {
		/* parent */
		rv = waitpid(pid, &status, 0);
		if (rv<0) {
			report_warn("waitpid failed");
			report_aborted(&result);
		}
		if (WIFSIGNALED(status)) {
			report_warnx("subprocess exited with signal %d",
				     WTERMSIG(status));
			report_aborted(&result);
		}
		else if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
			report_warnx("subprocess exited with code %d",
				     WEXITSTATUS(status));
			report_aborted(&result);
		}
		return result;
	}

	/* child */

	fd = open_testfile(NULL);
	if (fd<0) {
		_exit(0);
	}

	/*
	 * Move file to stdin.
	 * Use stdin (rather than stdout or stderr) to maximize the
	 * chances of detecting any special-case handling of fds 0-2.
	 * (Writing to stdin is fine as long as it's open for write,
	 * and it will be.)
	 */
	fd2 = dup2(fd, STDIN_FILENO);
	if (fd2<0) {
		report_warn("dup2 to stdin failed");
		close(fd);
		remove(TESTFILE);
		_exit(1);
	}
	if (fd2 != STDIN_FILENO) {
		report_warn("dup2 returned wrong file handle");
		close(fd);
		remove(TESTFILE);
		_exit(1);
	}
	close(fd);

	rv = write(STDIN_FILENO, slogan, len);
	if (rv<0) {
		report_warn("write to %s (via stdin) failed", TESTFILE);
		remove(TESTFILE);
		_exit(1);
	}

	if ((unsigned)rv != len) {
		report_warnx("write to %s (via stdin) got short count",
			     TESTFILE);
		remove(TESTFILE);
		_exit(1);
	}

	/* blah */
	report_skipped(&result);

	rv = lseek(STDIN_FILENO, 0, SEEK_SET);
	report_begin("try 1: SEEK_SET");
	result = report_check(rv, errno, 0);

	rv = lseek(STDIN_FILENO, 0, SEEK_END);
	report_begin("try 2: SEEK_END");
	result = report_check(rv, errno, 0);

	remove(TESTFILE);
	_exit(0);
}