@@ -44,34 +44,38 @@
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
lseek_fd_device(void)
|
||||
{
|
||||
int fd, rv;
|
||||
int result;
|
||||
|
||||
report_begin("lseek on device");
|
||||
|
||||
fd = open("null:", O_RDONLY);
|
||||
if (fd<0) {
|
||||
report_warn("opening null: failed");
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
rv = lseek(fd, 309, SEEK_SET);
|
||||
report_check(rv, errno, ESPIPE);
|
||||
result = report_check(rv, errno, ESPIPE);
|
||||
|
||||
close(fd);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
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");
|
||||
|
||||
@@ -79,27 +83,27 @@ lseek_file_stdin(void)
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
else if (pid!=0) {
|
||||
/* parent */
|
||||
rv = waitpid(pid, &status, 0);
|
||||
if (rv<0) {
|
||||
report_warn("waitpid failed");
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
}
|
||||
if (WIFSIGNALED(status)) {
|
||||
report_warnx("subprocess exited with signal %d",
|
||||
WTERMSIG(status));
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
}
|
||||
else if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
|
||||
report_warnx("subprocess exited with code %d",
|
||||
WEXITSTATUS(status));
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
}
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* child */
|
||||
@@ -146,133 +150,159 @@ lseek_file_stdin(void)
|
||||
}
|
||||
|
||||
/* blah */
|
||||
report_skipped();
|
||||
report_skipped(&result);
|
||||
|
||||
rv = lseek(STDIN_FILENO, 0, SEEK_SET);
|
||||
report_begin("try 1: SEEK_SET");
|
||||
report_check(rv, errno, 0);
|
||||
result = report_check(rv, errno, 0);
|
||||
|
||||
rv = lseek(STDIN_FILENO, 0, SEEK_END);
|
||||
report_begin("try 2: SEEK_END");
|
||||
report_check(rv, errno, 0);
|
||||
result = report_check(rv, errno, 0);
|
||||
|
||||
remove(TESTFILE);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
lseek_loc_negative(void)
|
||||
{
|
||||
int fd, rv;
|
||||
int result;
|
||||
|
||||
report_begin("lseek to negative offset");
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
rv = lseek(fd, -309, SEEK_SET);
|
||||
report_check(rv, errno, EINVAL);
|
||||
result = report_check(rv, errno, EINVAL);
|
||||
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
lseek_whence_inval(void)
|
||||
{
|
||||
int fd, rv;
|
||||
int result;
|
||||
|
||||
report_begin("lseek with invalid whence code");
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
rv = lseek(fd, 0, 3594);
|
||||
report_check(rv, errno, EINVAL);
|
||||
result = report_check(rv, errno, EINVAL);
|
||||
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
lseek_loc_pasteof(void)
|
||||
{
|
||||
const char *message = "blahblah";
|
||||
int fd;
|
||||
off_t pos;
|
||||
int result;
|
||||
|
||||
report_begin("seek past/to EOF");
|
||||
|
||||
fd = open_testfile(message);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
pos = lseek(fd, 5340, SEEK_SET);
|
||||
if (pos == -1) {
|
||||
report_warn("lseek past EOF failed");
|
||||
report_failure();
|
||||
report_failure(&result);
|
||||
goto out;
|
||||
}
|
||||
if (pos != 5340) {
|
||||
report_warnx("lseek to 5340 got offset %lld", (long long) pos);
|
||||
report_failure();
|
||||
report_failure(&result);
|
||||
goto out;
|
||||
}
|
||||
|
||||
pos = lseek(fd, -50, SEEK_CUR);
|
||||
if (pos == -1) {
|
||||
report_warn("small seek beyond EOF failed");
|
||||
report_failure();
|
||||
report_failure(&result);
|
||||
goto out;
|
||||
}
|
||||
if (pos != 5290) {
|
||||
report_warnx("SEEK_CUR to 5290 got offset %lld",
|
||||
(long long) pos);
|
||||
report_failure();
|
||||
report_failure(&result);
|
||||
goto out;
|
||||
}
|
||||
|
||||
pos = lseek(fd, 0, SEEK_END);
|
||||
if (pos == -1) {
|
||||
report_warn("seek to EOF failed");
|
||||
report_failure();
|
||||
report_failure(&result);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (pos != (off_t) strlen(message)) {
|
||||
report_warnx("seek to EOF got %lld (should be %zu)",
|
||||
(long long) pos, strlen(message));
|
||||
report_failure();
|
||||
report_failure(&result);
|
||||
goto out;
|
||||
}
|
||||
|
||||
report_passed();
|
||||
report_passed(&result);
|
||||
|
||||
out:
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
test_lseek(void)
|
||||
{
|
||||
test_lseek_fd();
|
||||
int ntests = 0, lost_points = 0;
|
||||
int result;
|
||||
|
||||
lseek_fd_device();
|
||||
lseek_file_stdin();
|
||||
lseek_loc_negative();
|
||||
lseek_loc_pasteof();
|
||||
lseek_whence_inval();
|
||||
test_lseek_fd(&ntests, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = lseek_fd_device();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = lseek_file_stdin();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = lseek_loc_negative();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = lseek_loc_pasteof();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = lseek_whence_inval();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
if(!lost_points)
|
||||
success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
|
||||
}
|
||||
|
Reference in New Issue
Block a user