Added userland/testbin

This commit is contained in:
Guru Prasad Srinivasa 2016-02-29 20:10:59 -05:00
parent a5963a0e31
commit d466eb7102
53 changed files with 1538 additions and 460 deletions

View File

@ -11,7 +11,8 @@ SUBDIRS=add argtest badcall bigexec bigfile bigfork bigseek bloat conman \
malloctest matmult multiexec palin parallelvm poisondisk psort \ malloctest matmult multiexec palin parallelvm poisondisk psort \
quinthuge quintmat quintsort randcall redirect rmdirtest rmtest \ quinthuge quintmat quintsort randcall redirect rmdirtest rmtest \
sbrktest schedpong shll sink sort sparsefile spinner sty tail tictac \ sbrktest schedpong shll sink sort sparsefile spinner sty tail tictac \
triplehuge triplemat triplesort usemtest waiter zero triplehuge triplemat triplesort usemtest waiter zero \
consoletest shelltest opentest readwritetest closetest
# But not: # But not:
# userthreads (no support in kernel API in base system) # userthreads (no support in kernel API in base system)

View File

@ -38,6 +38,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include <test161/test161.h>
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@ -52,6 +53,8 @@ main(int argc, char *argv[])
j = atoi(argv[2]); j = atoi(argv[2]);
tprintf("Answer: %d\n", i+j); tprintf("Answer: %d\n", i+j);
char buf[16];
snprintf(buf, 16, "%d", i+j);
secprintf(SECRET, buf, "/testbin/add");
return 0; return 0;
} }

View File

@ -36,6 +36,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <test161/test161.h>
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@ -44,6 +45,9 @@ main(int argc, char *argv[])
int i; int i;
tprintf("argc: %d\n", argc); tprintf("argc: %d\n", argc);
char buf[16];
snprintf(buf, 16, "argc: %d", argc);
secprintf(SECRET, buf, "/testbin/argtest");
for (i=0; i<=argc; i++) { for (i=0; i<=argc; i++) {
tmp = argv[i]; tmp = argv[i];
@ -51,6 +55,7 @@ main(int argc, char *argv[])
tmp = "[NULL]"; tmp = "[NULL]";
} }
tprintf("argv[%d]: %s\n", i, tmp); tprintf("argv[%d]: %s\n", i, tmp);
secprintf(SECRET, tmp, "/testbin/argtest");
} }
return 0; return 0;

View File

@ -38,7 +38,7 @@
#include "test.h" #include "test.h"
static static
void int
chdir_empty(void) chdir_empty(void)
{ {
int rv; int rv;
@ -49,13 +49,19 @@ chdir_empty(void)
report_begin("chdir to empty string"); report_begin("chdir to empty string");
rv = chdir(""); rv = chdir("");
report_check2(rv, errno, EINVAL, 0); return report_check2(rv, errno, EINVAL, 0);
} }
void void
test_chdir(void) test_chdir(void)
{ {
test_chdir_path(); int ntests = 0, result = 0, lost_points = 0;
chdir_empty(); test_chdir_path(&ntests, &lost_points);
ntests++;
result = chdir_empty();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-chdir", ntests - lost_points, ntests);
} }

View File

@ -36,5 +36,8 @@
void void
test_close(void) test_close(void)
{ {
test_close_fd(); int ntests = 0, lost_points = 0;
test_close_fd(&ntests, &lost_points);
partial_credit(SECRET, "/testbin/badcall-close", ntests- lost_points, ntests);
} }

View File

@ -45,27 +45,29 @@
#include "test.h" #include "test.h"
static static
void int
dup2_fd2(int fd, const char *desc) dup2_fd2(int fd, const char *desc)
{ {
int rv; int rv, failure;
report_begin("%s", desc); report_begin("%s", desc);
rv = dup2(STDIN_FILENO, fd); rv = dup2(STDIN_FILENO, fd);
report_check(rv, errno, EBADF); failure = report_check(rv, errno, EBADF);
if (rv != -1) { if (rv != -1) {
close(fd); /* just in case */ close(fd); /* just in case */
} }
return failure;
} }
static static
void int
dup2_self(void) dup2_self(void)
{ {
struct stat sb; struct stat sb;
int rv; int rv;
int testfd; int testfd;
int failure;
/* use fd that isn't in use */ /* use fd that isn't in use */
testfd = CLOSED_FD; testfd = CLOSED_FD;
@ -75,22 +77,23 @@ dup2_self(void)
rv = dup2(STDIN_FILENO, testfd); rv = dup2(STDIN_FILENO, testfd);
if (rv == -1) { if (rv == -1) {
report_result(rv, errno); report_result(rv, errno);
report_aborted(); report_aborted(&failure);
return; return failure;
} }
report_begin("dup2 to same fd"); report_begin("dup2 to same fd");
rv = dup2(testfd, testfd); rv = dup2(testfd, testfd);
if (rv == testfd) { if (rv == testfd) {
report_passed(); report_passed(&failure);
} }
else if (rv<0) { else if (rv<0) {
report_result(rv, errno); report_result(rv, errno);
report_failure(); report_failure(&failure);
} }
else { else {
report_warnx("returned %d instead", rv); report_warnx("returned %d instead", rv);
report_failure(); report_failure(&failure);
failure = FAILED;
} }
report_begin("fstat fd after dup2 to itself"); report_begin("fstat fd after dup2 to itself");
@ -100,43 +103,59 @@ dup2_self(void)
} }
report_result(rv, errno); report_result(rv, errno);
if (rv==0) { if (rv==0) {
report_passed(); report_passed(&failure);
} }
else if (errno != ENOSYS) { else if (errno != ENOSYS) {
report_failure(); report_failure(&failure);
} }
else { else {
report_skipped(); report_skipped(&failure);
/* no support for fstat; try lseek */ /* no support for fstat; try lseek */
report_begin("lseek fd after dup2 to itself"); report_begin("lseek fd after dup2 to itself");
rv = lseek(testfd, 0, SEEK_CUR); rv = lseek(testfd, 0, SEEK_CUR);
report_result(rv, errno); report_result(rv, errno);
if (rv==0 || (rv==-1 && errno==ESPIPE)) { if (rv==0 || (rv==-1 && errno==ESPIPE)) {
report_passed(); report_passed(&failure);
} }
else { else {
report_failure(); report_failure(&failure);
} }
} }
close(testfd); close(testfd);
return failure;
} }
void void
test_dup2(void) test_dup2(void)
{ {
int ntests = 0, failure, lost_points = 0;
/* This does the first fd. */ /* This does the first fd. */
test_dup2_fd(); test_dup2_fd(&ntests, &lost_points);
/* Any interesting cases added here should also go in common_fds.c */ /* Any interesting cases added here should also go in common_fds.c */
dup2_fd2(-1, "dup2 to -1"); ntests++;
dup2_fd2(-5, "dup2 to -5"); failure = dup2_fd2(-1, "dup2 to -1");
dup2_fd2(IMPOSSIBLE_FD, "dup2 to impossible fd"); handle_result(failure, &lost_points);
ntests++;
failure = dup2_fd2(-5, "dup2 to -5");
handle_result(failure, &lost_points);
ntests++;
failure = dup2_fd2(IMPOSSIBLE_FD, "dup2 to impossible fd");
handle_result(failure, &lost_points);
#ifdef OPEN_MAX #ifdef OPEN_MAX
dup2_fd2(OPEN_MAX, "dup2 to OPEN_MAX"); ntests++;
failure = dup2_fd2(OPEN_MAX, "dup2 to OPEN_MAX");
handle_result(failure, &lost_points);
#else #else
warnx("Warning: OPEN_MAX not defined - test skipped"); warnx("Warning: OPEN_MAX not defined - test skipped");
#endif #endif
dup2_self(); ntests++;
failure = dup2_self();
handle_result(failure, &lost_points);
partial_credit(SECRET, "/testbin/badcall-dup2", ntests - lost_points, ntests);
} }

View File

@ -42,7 +42,7 @@
static static
int int
exec_common_fork(void) exec_common_fork(int *result)
{ {
int pid, rv, status, err; int pid, rv, status, err;
@ -56,7 +56,7 @@ exec_common_fork(void)
err = errno; err = errno;
report_begin("forking for test"); report_begin("forking for test");
report_result(pid, err); report_result(pid, err);
report_aborted(); report_aborted(result);
return -1; return -1;
} }
@ -70,10 +70,11 @@ exec_common_fork(void)
err = errno; err = errno;
report_begin("waiting for test subprocess"); report_begin("waiting for test subprocess");
report_result(rv, err); report_result(rv, err);
report_failure(); report_failure(result);
return -1; return -1;
} }
if (WIFEXITED(status) && WEXITSTATUS(status) == MAGIC_STATUS) { if (WIFEXITED(status) && WEXITSTATUS(status) == MAGIC_STATUS) {
*result = SUCCESS;
return 1; return 1;
} }
/* Oops... */ /* Oops... */
@ -84,98 +85,137 @@ exec_common_fork(void)
else { else {
report_warnx("exit %d", WEXITSTATUS(status)); report_warnx("exit %d", WEXITSTATUS(status));
} }
report_failure(); report_failure(result);
return -1; return -1;
} }
static static
void int
exec_badprog(const void *prog, const char *desc) exec_badprog(const void *prog, const char *desc)
{ {
int rv; int rv;
int result;
char *args[2]; char *args[2];
args[0] = (char *)"foo"; args[0] = (char *)"foo";
args[1] = NULL; args[1] = NULL;
if (exec_common_fork() != 0) { if (exec_common_fork(&result) != 0) {
return; return result;
} }
report_begin(desc); report_begin(desc);
rv = execv(prog, args); rv = execv(prog, args);
report_check(rv, errno, EFAULT); result = report_check(rv, errno, EFAULT);
exit(MAGIC_STATUS); //XXX: Make sure this doesn't interfere with SIGNALLED/EXITED
int code = MAGIC_STATUS | result;
exit(code);
} }
static static
void int
exec_emptyprog(void) exec_emptyprog(void)
{ {
int rv; int rv;
int result;
char *args[2]; char *args[2];
args[0] = (char *)"foo"; args[0] = (char *)"foo";
args[1] = NULL; args[1] = NULL;
if (exec_common_fork() != 0) { if (exec_common_fork(&result) != 0) {
return; return result;
} }
report_begin("exec the empty string"); report_begin("exec the empty string");
rv = execv("", args); rv = execv("", args);
report_check2(rv, errno, EINVAL, EISDIR); result = report_check2(rv, errno, EINVAL, EISDIR);
exit(MAGIC_STATUS); //XXX: Make sure this doesn't interfere with SIGNALLED/EXITED
int code = MAGIC_STATUS | result;
exit(code);
} }
static static
void int
exec_badargs(void *args, const char *desc) exec_badargs(void *args, const char *desc)
{ {
int rv; int rv;
int result;
if (exec_common_fork() != 0) { if (exec_common_fork(&result) != 0) {
return; return result;
} }
report_begin(desc); report_begin(desc);
rv = execv("/bin/true", args); rv = execv("/bin/true", args);
report_check(rv, errno, EFAULT); result = report_check(rv, errno, EFAULT);
exit(MAGIC_STATUS); //XXX: Make sure this doesn't interfere with SIGNALLED/EXITED
int code = MAGIC_STATUS | result;
exit(code);
} }
static static
void int
exec_onearg(void *ptr, const char *desc) exec_onearg(void *ptr, const char *desc)
{ {
int rv; int rv;
int result;
char *args[3]; char *args[3];
args[0] = (char *)"foo"; args[0] = (char *)"foo";
args[1] = (char *)ptr; args[1] = (char *)ptr;
args[2] = NULL; args[2] = NULL;
if (exec_common_fork() != 0) { if (exec_common_fork(&result) != 0) {
return; return result;
} }
report_begin(desc); report_begin(desc);
rv = execv("/bin/true", args); rv = execv("/bin/true", args);
report_check(rv, errno, EFAULT); result = report_check(rv, errno, EFAULT);
exit(MAGIC_STATUS); //XXX: Make sure this doesn't interfere with SIGNALLED/EXITED
int code = MAGIC_STATUS | result;
exit(code);
} }
void void
test_execv(void) test_execv(void)
{ {
exec_badprog(NULL, "exec with NULL program"); int ntests = 0, result = 0, lost_points = 0;
exec_badprog(INVAL_PTR, "exec with invalid pointer program"); ntests++;
exec_badprog(KERN_PTR, "exec with kernel pointer program"); result = exec_badprog(NULL, "exec with NULL program");
handle_result(result, &lost_points);
exec_emptyprog(); ntests++;
result = exec_badprog(INVAL_PTR, "exec with invalid pointer program");
handle_result(result, &lost_points);
exec_badargs(NULL, "exec with NULL arglist"); ntests++;
exec_badargs(INVAL_PTR, "exec with invalid pointer arglist"); result = exec_badprog(KERN_PTR, "exec with kernel pointer program");
exec_badargs(KERN_PTR, "exec with kernel pointer arglist"); handle_result(result, &lost_points);
exec_onearg(INVAL_PTR, "exec with invalid pointer arg"); ntests++;
exec_onearg(KERN_PTR, "exec with kernel pointer arg"); result = exec_emptyprog();
handle_result(result, &lost_points);
ntests++;
result = exec_badargs(NULL, "exec with NULL arglist");
handle_result(result, &lost_points);
ntests++;
result = exec_badargs(INVAL_PTR, "exec with invalid pointer arglist");
handle_result(result, &lost_points);
ntests++;
result = exec_badargs(KERN_PTR, "exec with kernel pointer arglist");
handle_result(result, &lost_points);
ntests++;
result = exec_onearg(INVAL_PTR, "exec with invalid pointer arg");
handle_result(result, &lost_points);
ntests++;
result = exec_onearg(KERN_PTR, "exec with kernel pointer arg");
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-execv", ntests - lost_points, ntests);
} }

View File

@ -36,6 +36,10 @@
void void
test_fsync(void) test_fsync(void)
{ {
test_fsync_fd(); int ntests = 0, lost_points = 0;
test_fsync_fd(&ntests, &lost_points);
partial_credit(SECRET, "/testbin/badcall-fsync", ntests - lost_points, ntests);
} }

View File

@ -44,52 +44,66 @@
#include "test.h" #include "test.h"
static static
void int
ftruncate_fd_device(void) ftruncate_fd_device(void)
{ {
int rv, fd; int rv, fd;
int result;
report_begin("ftruncate on device"); report_begin("ftruncate on device");
fd = open("null:", O_RDWR); fd = open("null:", O_RDWR);
if (fd<0) { if (fd<0) {
report_warn("opening null: failed"); report_warn("opening null: failed");
report_aborted(); report_aborted(&result);
return; return result;
} }
rv = ftruncate(fd, 6); rv = ftruncate(fd, 6);
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
close(fd); close(fd);
return result;
} }
static static
void int
ftruncate_size_neg(void) ftruncate_size_neg(void)
{ {
int rv, fd; int rv, fd;
int result;
report_begin("ftruncate to negative size"); report_begin("ftruncate to negative size");
fd = open_testfile(NULL); fd = open_testfile(NULL);
if (fd<0) { if (fd<0) {
report_aborted(); report_aborted(&result);
return; return result;
} }
rv = ftruncate(fd, -60); rv = ftruncate(fd, -60);
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
close(fd); close(fd);
remove(TESTFILE); remove(TESTFILE);
return result;
} }
void void
test_ftruncate(void) test_ftruncate(void)
{ {
test_ftruncate_fd(); int ntests = 0, lost_points = 0;
int result;
ftruncate_fd_device(); test_ftruncate_fd(&ntests, &lost_points);
ftruncate_size_neg();
ntests++;
result = ftruncate_fd_device();
handle_result(result, &lost_points);
ntests++;
result = ftruncate_size_neg();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-ftruncate", ntests - lost_points, ntests);
} }

View File

@ -36,5 +36,8 @@
void void
test_getcwd(void) test_getcwd(void)
{ {
test_getcwd_buf(); int ntests = 0, lost_points = 0;
test_getcwd_buf(&ntests, &lost_points);
partial_credit(SECRET, "/testbin/badcall-getcwd", ntests - lost_points, ntests);
} }

View File

@ -36,6 +36,10 @@
void void
test_getdirentry(void) test_getdirentry(void)
{ {
test_getdirentry_fd(); int ntests = 0, lost_points = 0;
test_getdirentry_buf();
test_getdirentry_fd(&ntests, &lost_points);
test_getdirentry_buf(&ntests, &lost_points);
partial_credit(SECRET, "/testbin/badcall-getdirentry", ntests - lost_points, ntests);
} }

View File

@ -41,30 +41,34 @@
#include "test.h" #include "test.h"
static static
void int
one_ioctl_badbuf(int fd, int code, const char *codename, one_ioctl_badbuf(int fd, int code, const char *codename,
void *ptr, const char *ptrdesc) void *ptr, const char *ptrdesc)
{ {
int rv; int rv;
int result;
report_begin("ioctl %s with %s", codename, ptrdesc); report_begin("ioctl %s with %s", codename, ptrdesc);
rv = ioctl(fd, code, ptr); rv = ioctl(fd, code, ptr);
report_check(rv, errno, EFAULT); result = report_check(rv, errno, EFAULT);
return result;
} }
static static
void int
any_ioctl_badbuf(int fd, int code, const char *codename) any_ioctl_badbuf(int fd, int code, const char *codename)
{ {
one_ioctl_badbuf(fd, code, codename, NULL, "NULL pointer"); int result;
one_ioctl_badbuf(fd, code, codename, INVAL_PTR, "invalid pointer"); result = one_ioctl_badbuf(fd, code, codename, NULL, "NULL pointer");
one_ioctl_badbuf(fd, code, codename, KERN_PTR, "kernel pointer"); result |= one_ioctl_badbuf(fd, code, codename, INVAL_PTR, "invalid pointer");
result |= one_ioctl_badbuf(fd, code, codename, KERN_PTR, "kernel pointer");
return result;
} }
#define IOCTL(fd, sym) any_ioctl_badbuf(fd, sym, #sym) #define IOCTL(fd, sym) any_ioctl_badbuf(fd, sym, #sym)
static static
void int
ioctl_badbuf(void) ioctl_badbuf(void)
{ {
/* /*
@ -79,25 +83,38 @@ ioctl_badbuf(void)
/* suppress gcc warning */ /* suppress gcc warning */
(void)any_ioctl_badbuf; (void)any_ioctl_badbuf;
return 0;
} }
static static
void int
ioctl_badcode(void) ioctl_badcode(void)
{ {
int rv; int rv;
int result;
report_begin("invalid ioctl"); report_begin("invalid ioctl");
rv = ioctl(STDIN_FILENO, NONEXIST_IOCTL, NULL); rv = ioctl(STDIN_FILENO, NONEXIST_IOCTL, NULL);
report_check(rv, errno, EIOCTL); result = report_check(rv, errno, EIOCTL);
return result;
} }
void void
test_ioctl(void) test_ioctl(void)
{ {
test_ioctl_fd(); int ntests = 0, lost_points = 0;
int result;
test_ioctl_fd(&ntests, &lost_points);
/* Since we don't actually define any ioctls, this is not meaningful */ /* Since we don't actually define any ioctls, this is not meaningful */
ioctl_badcode(); ntests++;
ioctl_badbuf(); result = ioctl_badcode();
handle_result(result, &lost_points);
ntests++;
result = ioctl_badbuf();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-ioctl", ntests - lost_points, ntests);
} }

View File

@ -37,52 +37,69 @@
#include "test.h" #include "test.h"
static static
void int
link_dir(void) link_dir(void)
{ {
int rv; int rv;
int result;
report_begin("hard link of ."); report_begin("hard link of .");
rv = link(".", TESTDIR); rv = link(".", TESTDIR);
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
if (rv==0) { if (rv==0) {
/* this might help recover... maybe */ /* this might help recover... maybe */
remove(TESTDIR); remove(TESTDIR);
} }
return result;
} }
static static
void int
link_empty1(void) link_empty1(void)
{ {
int rv; int rv;
report_begin("hard link of empty string"); report_begin("hard link of empty string");
rv = link("", TESTDIR); rv = link("", TESTDIR);
report_check(rv, errno, EINVAL); return report_check(rv, errno, EINVAL);
} }
static static
void int
link_empty2(void) link_empty2(void)
{ {
int rv; int rv;
int result = FAILED;
report_begin("hard link to empty string"); report_begin("hard link to empty string");
if (create_testdir()<0) { if (create_testdir()<0) {
/*report_aborted();*/ /* XXX in create_testdir */ /*report_aborted();*/ /* XXX in create_testdir */
return; return result;
} }
rv = link(TESTDIR, ""); rv = link(TESTDIR, "");
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
rmdir(TESTDIR); rmdir(TESTDIR);
return result;
} }
void void
test_link(void) test_link(void)
{ {
test_link_paths(); int ntests = 0, lost_points = 0;
link_dir(); int result;
link_empty1();
link_empty2(); test_link_paths(&ntests, &lost_points);
ntests++;
result = link_dir();
handle_result(result, &lost_points);
ntests++;
result = link_empty1();
handle_result(result, &lost_points);
ntests++;
result = link_empty2();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-link", ntests - lost_points, ntests);
} }

View File

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

View File

@ -44,44 +44,57 @@
#include "test.h" #include "test.h"
static static
void int
mkdir_dot(void) mkdir_dot(void)
{ {
int rv; int rv;
report_begin("mkdir ."); report_begin("mkdir .");
rv = mkdir(".", 0775); rv = mkdir(".", 0775);
report_check(rv, errno, EEXIST); return report_check(rv, errno, EEXIST);
} }
static static
void int
mkdir_dotdot(void) mkdir_dotdot(void)
{ {
int rv; int rv;
report_begin("mkdir .."); report_begin("mkdir ..");
rv = mkdir("..", 0775); rv = mkdir("..", 0775);
report_check(rv, errno, EEXIST); return report_check(rv, errno, EEXIST);
} }
static static
void int
mkdir_empty(void) mkdir_empty(void)
{ {
int rv; int rv;
report_begin("mkdir of empty string"); report_begin("mkdir of empty string");
rv = mkdir("", 0775); rv = mkdir("", 0775);
report_check(rv, errno, EINVAL); return report_check(rv, errno, EINVAL);
} }
void void
test_mkdir(void) test_mkdir(void)
{ {
test_mkdir_path(); int ntests = 0, lost_points = 0;
int result;
mkdir_dot(); test_mkdir_path(&ntests, &lost_points);
ntests++;
result = mkdir_dot();
handle_result(result, &lost_points);
ntests++;
mkdir_dotdot(); mkdir_dotdot();
handle_result(result, &lost_points);
ntests++;
mkdir_empty(); mkdir_empty();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-mkdir", ntests - lost_points, ntests);
} }

View File

@ -44,35 +44,47 @@
#include "test.h" #include "test.h"
static static
void int
open_badflags(void) open_badflags(void)
{ {
int fd; int fd;
report_begin("open null: with bad flags"); report_begin("open null: with bad flags");
fd = open("null:", 309842); fd = open("null:", 309842);
report_check(fd, errno, EINVAL); return report_check(fd, errno, EINVAL);
} }
static static
void int
open_empty(void) open_empty(void)
{ {
int rv; int rv;
int result;
report_begin("open empty string"); report_begin("open empty string");
rv = open("", O_RDONLY); rv = open("", O_RDONLY);
report_check2(rv, errno, 0, EINVAL); result = report_check2(rv, errno, 0, EINVAL);
if (rv>=0) { if (rv>=0) {
close(rv); close(rv);
} }
return result;
} }
void void
test_open(void) test_open(void)
{ {
test_open_path(); int ntests = 0, lost_points = 0;
int result;
open_badflags(); test_open_path(&ntests, &lost_points);
open_empty();
ntests++;
result = open_badflags();
handle_result(result, &lost_points);
ntests++;
result = open_empty();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-open", ntests - lost_points, ntests);
} }

View File

@ -44,22 +44,23 @@
#include "test.h" #include "test.h"
static static
void int
pipe_badptr(void *ptr, const char *desc) pipe_badptr(void *ptr, const char *desc)
{ {
int rv; int rv;
report_begin("%s", desc); report_begin("%s", desc);
rv = pipe(ptr); rv = pipe(ptr);
report_check(rv, errno, EFAULT); return report_check(rv, errno, EFAULT);
} }
static static
void int
pipe_unaligned(void) pipe_unaligned(void)
{ {
int fds[3], rv; int fds[3], rv;
char *ptr; char *ptr;
int result;
report_begin("pipe with unaligned pointer"); report_begin("pipe with unaligned pointer");
@ -67,15 +68,31 @@ pipe_unaligned(void)
ptr++; ptr++;
rv = pipe((int *)ptr); rv = pipe((int *)ptr);
report_survival(rv, errno); report_survival(rv, errno, &result);
return result;
} }
void void
test_pipe(void) test_pipe(void)
{ {
pipe_badptr(NULL, "pipe with NULL pointer"); int ntests = 0, lost_points = 0;
pipe_badptr(INVAL_PTR, "pipe with invalid pointer"); int result;
pipe_badptr(KERN_PTR, "pipe with kernel pointer");
pipe_unaligned(); ntests++;
result = pipe_badptr(NULL, "pipe with NULL pointer");
handle_result(result, &lost_points);
ntests++;
result = pipe_badptr(INVAL_PTR, "pipe with invalid pointer");
handle_result(result, &lost_points);
ntests++;
result = pipe_badptr(KERN_PTR, "pipe with kernel pointer");
handle_result(result, &lost_points);
ntests++;
result = pipe_unaligned();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-pipe", ntests - lost_points, ntests);
} }

View File

@ -36,7 +36,12 @@
void void
test_read(void) test_read(void)
{ {
test_read_fd(); int ntests = 0, lost_points = 0;
test_read_buf();
test_read_fd(&ntests, &lost_points);
test_read_buf(&ntests, &lost_points);
partial_credit(SECRET, "/testbin/badcall-read", ntests - lost_points, ntests);
} }

View File

@ -37,26 +37,28 @@
#include "test.h" #include "test.h"
static static
void int
readlink_file(void) readlink_file(void)
{ {
char buf[128]; char buf[128];
int fd, rv; int fd, rv;
int result;
report_begin("readlink on file"); report_begin("readlink on file");
fd = open_testfile("the question contains an invalid assumption"); fd = open_testfile("the question contains an invalid assumption");
if (fd<0) { if (fd<0) {
report_aborted(); report_aborted(&result);
return; return result;
} }
close(fd); close(fd);
rv = readlink(TESTFILE, buf, sizeof(buf)); rv = readlink(TESTFILE, buf, sizeof(buf));
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
remove(TESTFILE); remove(TESTFILE);
return result;
} }
static static
void int
readlink_dir(void) readlink_dir(void)
{ {
char buf[128]; char buf[128];
@ -64,11 +66,11 @@ readlink_dir(void)
report_begin("readlink on ."); report_begin("readlink on .");
rv = readlink(".", buf, sizeof(buf)); rv = readlink(".", buf, sizeof(buf));
report_check(rv, errno, EISDIR); return report_check(rv, errno, EISDIR);
} }
static static
void int
readlink_empty(void) readlink_empty(void)
{ {
char buf[128]; char buf[128];
@ -76,17 +78,30 @@ readlink_empty(void)
report_begin("readlink on empty string"); report_begin("readlink on empty string");
rv = readlink("", buf, sizeof(buf)); rv = readlink("", buf, sizeof(buf));
report_check2(rv, errno, EISDIR, EINVAL); return report_check2(rv, errno, EISDIR, EINVAL);
} }
void void
test_readlink(void) test_readlink(void)
{ {
test_readlink_path(); int ntests = 0, lost_points = 0;
test_readlink_buf(); int result;
readlink_file(); test_readlink_path(&ntests, &lost_points);
readlink_dir(); test_readlink_buf(&ntests, &lost_points);
readlink_empty();
ntests++;
result = readlink_file();
handle_result(result, &lost_points);
ntests++;
result = readlink_dir();
handle_result(result, &lost_points);
ntests++;
result = readlink_empty();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-readlink", ntests - lost_points, ntests);
} }

View File

@ -44,7 +44,7 @@
#include "test.h" #include "test.h"
static static
void int
reboot_badflags(void) reboot_badflags(void)
{ {
int rv; int rv;
@ -52,11 +52,18 @@ reboot_badflags(void)
tprintf("(This should not kill the system...)\n"); tprintf("(This should not kill the system...)\n");
report_begin("reboot with invalid flags"); report_begin("reboot with invalid flags");
rv = reboot(15353); rv = reboot(15353);
report_check(rv, errno, EINVAL); return report_check(rv, errno, EINVAL);
} }
void void
test_reboot(void) test_reboot(void)
{ {
reboot_badflags(); int ntests = 0, lost_points = 0;
int result;
ntests++;
result = reboot_badflags();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-reboot", ntests - lost_points, ntests);
} }

View File

@ -44,63 +44,82 @@
#include "test.h" #include "test.h"
static static
void int
remove_dir(void) remove_dir(void)
{ {
int rv; int rv;
int result = FAILED;
report_begin("remove() on a directory"); report_begin("remove() on a directory");
if (create_testdir() < 0) { if (create_testdir() < 0) {
/*report_aborted();*/ /* XXX in create_testdir */ /*report_aborted();*/ /* XXX in create_testdir */
return; return result;
} }
rv = remove(TESTDIR); rv = remove(TESTDIR);
report_check(rv, errno, EISDIR); result = report_check(rv, errno, EISDIR);
rmdir(TESTDIR); rmdir(TESTDIR);
return result;
} }
static static
void int
remove_dot(void) remove_dot(void)
{ {
int rv; int rv;
report_begin("remove() on ."); report_begin("remove() on .");
rv = remove("."); rv = remove(".");
report_check2(rv, errno, EISDIR, EINVAL); return report_check2(rv, errno, EISDIR, EINVAL);
} }
static static
void int
remove_dotdot(void) remove_dotdot(void)
{ {
int rv; int rv;
report_begin("remove() on .."); report_begin("remove() on ..");
rv = remove(".."); rv = remove("..");
report_check2(rv, errno, EISDIR, EINVAL); return report_check2(rv, errno, EISDIR, EINVAL);
} }
static static
void int
remove_empty(void) remove_empty(void)
{ {
int rv; int rv;
report_begin("remove() on empty string"); report_begin("remove() on empty string");
rv = remove(""); rv = remove("");
report_check2(rv, errno, EISDIR, EINVAL); return report_check2(rv, errno, EISDIR, EINVAL);
} }
void void
test_remove(void) test_remove(void)
{ {
test_remove_path(); int ntests = 0, lost_points = 0;
int result;
remove_dir(); test_remove_path(&ntests, &lost_points);
remove_dot();
remove_dotdot(); ntests++;
remove_empty(); result = remove_dir();
handle_result(result, &lost_points);
ntests++;
result = remove_dot();
handle_result(result, &lost_points);
ntests++;
result = remove_dotdot();
handle_result(result, &lost_points);
ntests++;
result = remove_empty();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-remove", ntests - lost_points, ntests);
} }

View File

@ -37,75 +37,99 @@
#include "test.h" #include "test.h"
static static
void int
rename_dot(void) rename_dot(void)
{ {
int rv; int rv;
int result;
report_begin("rename ."); report_begin("rename .");
rv = rename(".", TESTDIR); rv = rename(".", TESTDIR);
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
if (rv==0) { if (rv==0) {
/* oops... put it back */ /* oops... put it back */
rename(TESTDIR, "."); rename(TESTDIR, ".");
} }
return result;
} }
static static
void int
rename_dotdot(void) rename_dotdot(void)
{ {
int rv; int rv;
int result;
report_begin("rename .."); report_begin("rename ..");
rv = rename("..", TESTDIR); rv = rename("..", TESTDIR);
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
if (rv==0) { if (rv==0) {
/* oops... put it back */ /* oops... put it back */
rename(TESTDIR, ".."); rename(TESTDIR, "..");
} }
return result;
} }
static static
void int
rename_empty1(void) rename_empty1(void)
{ {
int rv; int rv;
int result;
report_begin("rename empty string"); report_begin("rename empty string");
rv = rename("", TESTDIR); rv = rename("", TESTDIR);
report_check2(rv, errno, EISDIR, EINVAL); result = report_check2(rv, errno, EISDIR, EINVAL);
if (rv==0) { if (rv==0) {
/* don't try to remove it */ /* don't try to remove it */
rename(TESTDIR, TESTDIR "-foo"); rename(TESTDIR, TESTDIR "-foo");
} }
return result;
} }
static static
void int
rename_empty2(void) rename_empty2(void)
{ {
int rv; int rv;
int result = FAILED;
report_begin("rename to empty string"); report_begin("rename to empty string");
if (create_testdir()<0) { if (create_testdir()<0) {
/*report_aborted();*/ /* XXX in create_testdir */ /*report_aborted();*/ /* XXX in create_testdir */
return; return result;
} }
rv = rename(TESTDIR, ""); rv = rename(TESTDIR, "");
report_check2(rv, errno, EISDIR, EINVAL); result = report_check2(rv, errno, EISDIR, EINVAL);
rmdir(TESTDIR); rmdir(TESTDIR);
return result;
} }
void void
test_rename(void) test_rename(void)
{ {
test_rename_paths(); int ntests = 0, lost_points = 0;
int result;
rename_dot(); test_rename_paths(&ntests, &lost_points);
rename_dotdot();
rename_empty1(); ntests++;
rename_empty2(); result = rename_dot();
handle_result(result, &lost_points);
ntests++;
result = rename_dotdot();
handle_result(result, &lost_points);
ntests++;
result = rename_empty1();
handle_result(result, &lost_points);
ntests++;
result = rename_empty2();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-rename", ntests - lost_points, ntests);
} }

View File

@ -44,61 +44,82 @@
#include "test.h" #include "test.h"
static static
void int
rmdir_file(void) rmdir_file(void)
{ {
int rv; int rv;
int result;
report_begin("rmdir a file"); report_begin("rmdir a file");
if (create_testfile()<0) { if (create_testfile()<0) {
report_aborted(); report_aborted(&result);
return; return result;
} }
rv = rmdir(TESTFILE); rv = rmdir(TESTFILE);
report_check(rv, errno, ENOTDIR); result = report_check(rv, errno, ENOTDIR);
remove(TESTFILE); remove(TESTFILE);
return result;
} }
static static
void int
rmdir_dot(void) rmdir_dot(void)
{ {
int rv; int rv;
int result;
report_begin("rmdir ."); report_begin("rmdir .");
rv = rmdir("."); rv = rmdir(".");
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
return result;
} }
static static
void int
rmdir_dotdot(void) rmdir_dotdot(void)
{ {
int rv; int rv;
report_begin("rmdir .."); report_begin("rmdir ..");
rv = rmdir(".."); rv = rmdir("..");
report_check2(rv, errno, EINVAL, ENOTEMPTY); return report_check2(rv, errno, EINVAL, ENOTEMPTY);
} }
static static
void int
rmdir_empty(void) rmdir_empty(void)
{ {
int rv; int rv;
report_begin("rmdir empty string"); report_begin("rmdir empty string");
rv = rmdir(""); rv = rmdir("");
report_check(rv, errno, EINVAL); return report_check(rv, errno, EINVAL);
} }
void void
test_rmdir(void) test_rmdir(void)
{ {
test_rmdir_path(); int ntests = 0, lost_points = 0;
int result;
rmdir_file(); test_rmdir_path(&ntests, &lost_points);
rmdir_dot();
rmdir_dotdot(); ntests++;
rmdir_empty(); result = rmdir_file();
handle_result(result, &lost_points);
ntests++;
result = rmdir_dot();
handle_result(result, &lost_points);
ntests++;
result = rmdir_dotdot();
handle_result(result, &lost_points);
ntests++;
result = rmdir_empty();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-rmdir", ntests - lost_points, ntests);
} }

View File

@ -59,7 +59,7 @@ try_sbrk(long val)
} }
static static
void int
enforce_sbrk(long val, const char *desc, int err) enforce_sbrk(long val, const char *desc, int err)
{ {
int result; int result;
@ -67,59 +67,78 @@ enforce_sbrk(long val, const char *desc, int err)
report_begin("sbrk %s", desc); report_begin("sbrk %s", desc);
result = try_sbrk(val); result = try_sbrk(val);
report_check(result, errno, err); return report_check(result, errno, err);
} }
static static
void int
sbrk_bigpos(void) sbrk_bigpos(void)
{ {
enforce_sbrk(4096*1024*256, "huge positive", ENOMEM); return enforce_sbrk(4096*1024*256, "huge positive", ENOMEM);
} }
static static
void int
sbrk_bigneg(void) sbrk_bigneg(void)
{ {
enforce_sbrk(-4096*1024*256, "huge negative", EINVAL); return enforce_sbrk(-4096*1024*256, "huge negative", EINVAL);
} }
static static
void int
sbrk_neg(void) sbrk_neg(void)
{ {
enforce_sbrk(-8192, "too-large negative", EINVAL); return enforce_sbrk(-8192, "too-large negative", EINVAL);
} }
static static
void int
sbrk_unalignedpos(void) sbrk_unalignedpos(void)
{ {
int result; int result;
report_begin("sbrk unaligned positive"); report_begin("sbrk unaligned positive");
result = try_sbrk(17); result = try_sbrk(17);
report_check2(result, errno, 0, EINVAL); return report_check2(result, errno, 0, EINVAL);
} }
static static
void int
sbrk_unalignedneg(void) sbrk_unalignedneg(void)
{ {
int result; int result;
report_begin("sbrk unaligned negative"); report_begin("sbrk unaligned negative");
result = try_sbrk(-17); result = try_sbrk(-17);
report_check2(result, errno, 0, EINVAL); return report_check2(result, errno, 0, EINVAL);
} }
void void
test_sbrk(void) test_sbrk(void)
{ {
sbrk_neg(); int ntests = 0, lost_points = 0;
sbrk_bigpos(); int result;
sbrk_bigneg();
sbrk_unalignedpos(); ntests++;
sbrk_unalignedneg(); result = sbrk_neg();
handle_result(result, &lost_points);
ntests++;
result = sbrk_bigpos();
handle_result(result, &lost_points);
ntests++;
result = sbrk_bigneg();
handle_result(result, &lost_points);
ntests++;
result = sbrk_unalignedpos();
handle_result(result, &lost_points);
ntests++;
result = sbrk_unalignedneg();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-sbrk", ntests - lost_points, ntests);
} }

View File

@ -67,7 +67,7 @@ badbuf_stat(struct stat *sb)
} }
static static
void int
common_badbuf(int (*statfunc)(struct stat *), void *ptr, common_badbuf(int (*statfunc)(struct stat *), void *ptr,
const char *call, const char *ptrdesc) const char *call, const char *ptrdesc)
{ {
@ -75,22 +75,24 @@ common_badbuf(int (*statfunc)(struct stat *), void *ptr,
report_begin("%s with %s buf", call, ptrdesc); report_begin("%s with %s buf", call, ptrdesc);
rv = statfunc(ptr); rv = statfunc(ptr);
report_check(rv, errno, EFAULT); return report_check(rv, errno, EFAULT);
} }
static static
void int
any_badbuf(int (*statfunc)(struct stat *), const char *call) any_badbuf(int (*statfunc)(struct stat *), const char *call)
{ {
common_badbuf(statfunc, NULL, call, "NULL"); int result;
common_badbuf(statfunc, INVAL_PTR, call, "invalid pointer"); result = common_badbuf(statfunc, NULL, call, "NULL");
common_badbuf(statfunc, KERN_PTR, call, "kernel pointer"); result |= common_badbuf(statfunc, INVAL_PTR, call, "invalid pointer");
result |= common_badbuf(statfunc, KERN_PTR, call, "kernel pointer");
return result;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static static
void int
any_empty(int (*statfunc)(const char *, struct stat *), const char *call) any_empty(int (*statfunc)(const char *, struct stat *), const char *call)
{ {
struct stat sb; struct stat sb;
@ -98,7 +100,7 @@ any_empty(int (*statfunc)(const char *, struct stat *), const char *call)
report_begin("%s on empty string", call); report_begin("%s on empty string", call);
rv = statfunc("", &sb); rv = statfunc("", &sb);
report_check2(rv, errno, 0, EINVAL); return report_check2(rv, errno, 0, EINVAL);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -106,23 +108,53 @@ any_empty(int (*statfunc)(const char *, struct stat *), const char *call)
void void
test_fstat(void) test_fstat(void)
{ {
test_fstat_fd(); int ntests = 0, lost_points = 0;
any_badbuf(badbuf_fstat, "fstat"); int result;
test_fstat_fd(&ntests, &lost_points);
ntests++;
result = any_badbuf(badbuf_fstat, "fstat");
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-fstat", ntests - lost_points, ntests);
} }
void void
test_lstat(void) test_lstat(void)
{ {
test_lstat_path(); int ntests = 0, lost_points = 0;
any_empty(lstat, "lstat"); int result;
any_badbuf(badbuf_lstat, "lstat");
test_lstat_path(&ntests, &lost_points);
ntests++;
result = any_empty(lstat, "lstat");
handle_result(result, &lost_points);
ntests++;
result = any_badbuf(badbuf_lstat, "lstat");
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-lstat", ntests - lost_points, ntests);
} }
void void
test_stat(void) test_stat(void)
{ {
test_stat_path(); int ntests = 0, lost_points = 0;
any_empty(stat, "stat"); int result;
any_badbuf(badbuf_stat, "stat");
test_stat_path(&ntests, &lost_points);
ntests++;
result = any_empty(stat, "stat");
handle_result(result, &lost_points);
ntests++;
result = any_badbuf(badbuf_stat, "stat");
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-stat", ntests - lost_points, ntests);
} }

View File

@ -37,32 +37,46 @@
#include "test.h" #include "test.h"
static static
void int
symlink_empty1(void) symlink_empty1(void)
{ {
int rv; int rv;
int result;
report_begin("symlink -> empty string"); report_begin("symlink -> empty string");
rv = symlink("", TESTLINK); rv = symlink("", TESTLINK);
report_check2(rv, errno, 0, EINVAL); result = report_check2(rv, errno, 0, EINVAL);
remove(TESTLINK); remove(TESTLINK);
return result;
} }
static static
void int
symlink_empty2(void) symlink_empty2(void)
{ {
int rv; int rv;
report_begin("symlink named empty string"); report_begin("symlink named empty string");
rv = symlink("foo", ""); rv = symlink("foo", "");
report_check(rv, errno, EINVAL); return report_check(rv, errno, EINVAL);
} }
void void
test_symlink(void) test_symlink(void)
{ {
test_symlink_paths(); int ntests = 0, lost_points = 0;
symlink_empty1(); int result;
symlink_empty2();
test_symlink_paths(&ntests, &lost_points);
ntests++;
result = symlink_empty1();
handle_result(result, &lost_points);
ntests++;
result = symlink_empty2();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-symlink", ntests - lost_points, ntests);
} }

View File

@ -44,33 +44,48 @@
#include "test.h" #include "test.h"
static static
void int
time_badsecs(void *ptr, const char *desc) time_badsecs(void *ptr, const char *desc)
{ {
int rv; int rv;
report_begin("%s", desc); report_begin("%s", desc);
rv = __time(ptr, NULL); rv = __time(ptr, NULL);
report_check(rv, errno, EFAULT); return report_check(rv, errno, EFAULT);
} }
static static
void int
time_badnsecs(void *ptr, const char *desc) time_badnsecs(void *ptr, const char *desc)
{ {
int rv; int rv;
report_begin("%s", desc); report_begin("%s", desc);
rv = __time(NULL, ptr); rv = __time(NULL, ptr);
report_check(rv, errno, EFAULT); return report_check(rv, errno, EFAULT);
} }
void void
test_time(void) test_time(void)
{ {
time_badsecs(INVAL_PTR, "__time with invalid seconds pointer"); int ntests = 0, lost_points = 0;
time_badsecs(KERN_PTR, "__time with kernel seconds pointer"); int result;
time_badnsecs(INVAL_PTR, "__time with invalid nsecs pointer"); ntests++;
time_badnsecs(KERN_PTR, "__time with kernel nsecs pointer"); result = time_badsecs(INVAL_PTR, "__time with invalid seconds pointer");
handle_result(result, &lost_points);
ntests++;
result = time_badsecs(KERN_PTR, "__time with kernel seconds pointer");
handle_result(result, &lost_points);
ntests++;
result = time_badnsecs(INVAL_PTR, "__time with invalid nsecs pointer");
handle_result(result, &lost_points);
ntests++;
result = time_badnsecs(KERN_PTR, "__time with kernel nsecs pointer");
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-time", ntests - lost_points, ntests);
} }

View File

@ -42,7 +42,7 @@
#include "test.h" #include "test.h"
static static
void int
wait_badpid(pid_t pid, const char *desc) wait_badpid(pid_t pid, const char *desc)
{ {
pid_t rv; pid_t rv;
@ -59,23 +59,24 @@ wait_badpid(pid_t pid, const char *desc)
else if (err == ENOSYS) { else if (err == ENOSYS) {
report_saw_enosys(); report_saw_enosys();
} }
report_check2(rv, err, ESRCH, ECHILD); return report_check2(rv, err, ESRCH, ECHILD);
} }
static static
void int
wait_nullstatus(void) wait_nullstatus(void)
{ {
pid_t pid, rv; pid_t pid, rv;
int x; int x;
int result;
report_begin("wait with NULL status"); report_begin("wait with NULL status");
pid = fork(); pid = fork();
if (pid<0) { if (pid<0) {
report_warn("fork failed"); report_warn("fork failed");
report_aborted(); report_aborted(&result);
return; return result;
} }
if (pid==0) { if (pid==0) {
exit(0); exit(0);
@ -83,50 +84,54 @@ wait_nullstatus(void)
/* POSIX explicitly says passing NULL for status is allowed */ /* POSIX explicitly says passing NULL for status is allowed */
rv = waitpid(pid, NULL, 0); rv = waitpid(pid, NULL, 0);
report_check(rv, errno, 0); result = report_check(rv, errno, 0);
waitpid(pid, &x, 0); waitpid(pid, &x, 0);
return result;
} }
static static
void int
wait_badstatus(void *ptr, const char *desc) wait_badstatus(void *ptr, const char *desc)
{ {
pid_t pid, rv; pid_t pid, rv;
int x; int x;
int result;
report_begin(desc); report_begin(desc);
pid = fork(); pid = fork();
if (pid<0) { if (pid<0) {
report_warn("fork failed"); report_warn("fork failed");
report_aborted(); report_aborted(&result);
return; return result;
} }
if (pid==0) { if (pid==0) {
exit(0); exit(0);
} }
rv = waitpid(pid, ptr, 0); rv = waitpid(pid, ptr, 0);
report_check(rv, errno, EFAULT); result = report_check(rv, errno, EFAULT);
waitpid(pid, &x, 0); waitpid(pid, &x, 0);
return result;
} }
static static
void int
wait_unaligned(void) wait_unaligned(void)
{ {
pid_t pid, rv; pid_t pid, rv;
int x; int x;
int status[2]; /* will have integer alignment */ int status[2]; /* will have integer alignment */
char *ptr; char *ptr;
int result;
report_begin("wait with unaligned status"); report_begin("wait with unaligned status");
pid = fork(); pid = fork();
if (pid<0) { if (pid<0) {
report_warn("fork failed"); report_warn("fork failed");
report_aborted(); report_aborted(&result);
return; return result;
} }
if (pid==0) { if (pid==0) {
exit(0); exit(0);
@ -139,55 +144,61 @@ wait_unaligned(void)
ptr++; ptr++;
rv = waitpid(pid, (int *)ptr, 0); rv = waitpid(pid, (int *)ptr, 0);
report_survival(rv, errno); report_survival(rv, errno, &result);
if (rv<0) { if (rv<0) {
waitpid(pid, &x, 0); waitpid(pid, &x, 0);
} }
return result;
} }
static static
void int
wait_badflags(void) wait_badflags(void)
{ {
pid_t pid, rv; pid_t pid, rv;
int x; int x;
int result;
report_begin("wait with bad flags"); report_begin("wait with bad flags");
pid = fork(); pid = fork();
if (pid<0) { if (pid<0) {
report_warn("fork failed"); report_warn("fork failed");
report_aborted(); report_aborted(&result);
return; return result;
} }
if (pid==0) { if (pid==0) {
exit(0); exit(0);
} }
rv = waitpid(pid, &x, 309429); rv = waitpid(pid, &x, 309429);
report_check(rv, errno, EINVAL); result = report_check(rv, errno, EINVAL);
waitpid(pid, &x, 0); waitpid(pid, &x, 0);
return result;
} }
static static
void int
wait_self(void) wait_self(void)
{ {
pid_t rv; pid_t rv;
int x; int x;
int result;
report_begin("wait for self"); report_begin("wait for self");
rv = waitpid(getpid(), &x, 0); rv = waitpid(getpid(), &x, 0);
report_survival(rv, errno); report_survival(rv, errno, &result);
return result;
} }
static static
void int
wait_parent(void) wait_parent(void)
{ {
pid_t mypid, childpid, rv; pid_t mypid, childpid, rv;
int x; int x;
int result;
report_begin("wait for parent"); report_begin("wait for parent");
report_hassubs(); report_hassubs();
@ -196,30 +207,32 @@ wait_parent(void)
childpid = fork(); childpid = fork();
if (childpid<0) { if (childpid<0) {
report_warn("can't fork"); report_warn("can't fork");
report_aborted(); report_aborted(&result);
return; return result;
} }
if (childpid==0) { if (childpid==0) {
/* Child. Wait for parent. */ /* Child. Wait for parent. */
rv = waitpid(mypid, &x, 0); rv = waitpid(mypid, &x, 0);
report_beginsub("from child:"); report_beginsub("from child:");
report_survival(rv, errno); report_survival(rv, errno, &result);
_exit(0); _exit(0);
} }
rv = waitpid(childpid, &x, 0); rv = waitpid(childpid, &x, 0);
report_beginsub("from parent:"); report_beginsub("from parent:");
report_survival(rv, errno); report_survival(rv, errno, &result);
return result;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static static
void int
wait_siblings_child(const char *semname) wait_siblings_child(const char *semname)
{ {
pid_t pids[2], mypid, otherpid; pid_t pids[2], mypid, otherpid;
int rv, fd, semfd, x; int rv, fd, semfd, x;
char c; char c;
int result;
mypid = getpid(); mypid = getpid();
@ -244,7 +257,7 @@ wait_siblings_child(const char *semname)
if (fd<0) { if (fd<0) {
report_warn("child process (pid %d) can't open %s", report_warn("child process (pid %d) can't open %s",
mypid, TESTFILE); mypid, TESTFILE);
return; return FAILED;
} }
/* /*
@ -257,13 +270,13 @@ wait_siblings_child(const char *semname)
if (rv<0) { if (rv<0) {
report_warn("child process (pid %d) lseek error", report_warn("child process (pid %d) lseek error",
mypid); mypid);
return; return FAILED;
} }
rv = read(fd, pids, sizeof(pids)); rv = read(fd, pids, sizeof(pids));
if (rv<0) { if (rv<0) {
report_warn("child process (pid %d) read error", report_warn("child process (pid %d) read error",
mypid); mypid);
return; return FAILED;
} }
} while (rv < (int)sizeof(pids)); } while (rv < (int)sizeof(pids));
@ -276,23 +289,25 @@ wait_siblings_child(const char *semname)
else { else {
report_warn("child process (pid %d) got garbage in comm file", report_warn("child process (pid %d) got garbage in comm file",
mypid); mypid);
return; return FAILED;
} }
close(fd); close(fd);
rv = waitpid(otherpid, &x, 0); rv = waitpid(otherpid, &x, 0);
report_beginsub("sibling (pid %d)", mypid); report_beginsub("sibling (pid %d)", mypid);
report_survival(rv, errno); report_survival(rv, errno, &result);
return result;
} }
static static
void int
wait_siblings(void) wait_siblings(void)
{ {
pid_t pids[2]; pid_t pids[2];
int rv, fd, semfd, x; int rv, fd, semfd, x;
int bad = 0; int bad = 0;
char semname[32]; char semname[32];
int result;
/* This test may also blow up if FS synchronization is substandard */ /* This test may also blow up if FS synchronization is substandard */
@ -303,26 +318,26 @@ wait_siblings(void)
semfd = open(semname, O_WRONLY|O_CREAT|O_TRUNC, 0664); semfd = open(semname, O_WRONLY|O_CREAT|O_TRUNC, 0664);
if (semfd < 0) { if (semfd < 0) {
report_warn("can't make semaphore"); report_warn("can't make semaphore");
report_aborted(); report_aborted(&result);
return; return result;
} }
fd = open_testfile(NULL); fd = open_testfile(NULL);
if (fd<0) { if (fd<0) {
report_aborted(); report_aborted(&result);
close(semfd); close(semfd);
remove(semname); remove(semname);
return; return result;
} }
pids[0] = fork(); pids[0] = fork();
if (pids[0]<0) { if (pids[0]<0) {
report_warn("can't fork"); report_warn("can't fork");
report_aborted(); report_aborted(&result);
close(fd); close(fd);
close(semfd); close(semfd);
remove(semname); remove(semname);
return; return result;
} }
if (pids[0]==0) { if (pids[0]==0) {
close(fd); close(fd);
@ -334,12 +349,12 @@ wait_siblings(void)
pids[1] = fork(); pids[1] = fork();
if (pids[1]<0) { if (pids[1]<0) {
report_warn("can't fork"); report_warn("can't fork");
report_aborted(); report_aborted(&result);
/* abandon the other child process :( */ /* abandon the other child process :( */
close(fd); close(fd);
close(semfd); close(semfd);
remove(semname); remove(semname);
return; return result;
} }
if (pids[1]==0) { if (pids[1]==0) {
close(fd); close(fd);
@ -351,21 +366,21 @@ wait_siblings(void)
rv = write(fd, pids, sizeof(pids)); rv = write(fd, pids, sizeof(pids));
if (rv < 0) { if (rv < 0) {
report_warn("write error on %s", TESTFILE); report_warn("write error on %s", TESTFILE);
report_aborted(); report_aborted(&result);
/* abandon child procs :( */ /* abandon child procs :( */
close(fd); close(fd);
close(semfd); close(semfd);
remove(semname); remove(semname);
return; return result;
} }
if (rv != (int)sizeof(pids)) { if (rv != (int)sizeof(pids)) {
report_warnx("write error on %s: short count", TESTFILE); report_warnx("write error on %s: short count", TESTFILE);
report_aborted(); report_aborted(&result);
/* abandon child procs :( */ /* abandon child procs :( */
close(fd); close(fd);
close(semfd); close(semfd);
remove(semname); remove(semname);
return; return result;
} }
/* gate the child procs */ /* gate the child procs */
@ -388,15 +403,17 @@ wait_siblings(void)
} }
if (bad) { if (bad) {
/* XXX: aborted, or failure, or what? */ /* XXX: aborted, or failure, or what? */
report_aborted(); report_aborted(&result);
} }
else { else {
report_passed(); report_passed(&result);
} }
close(fd); close(fd);
close(semfd); close(semfd);
remove(semname); remove(semname);
remove(TESTFILE); remove(TESTFILE);
return result;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -404,20 +421,60 @@ wait_siblings(void)
void void
test_waitpid(void) test_waitpid(void)
{ {
wait_badpid(-8, "wait for pid -8"); int ntests = 0, lost_points = 0;
wait_badpid(-1, "wait for pid -1"); int result;
wait_badpid(0, "pid zero");
wait_badpid(NONEXIST_PID, "nonexistent pid");
wait_nullstatus(); ntests++;
wait_badstatus(INVAL_PTR, "wait with invalid pointer status"); result = wait_badpid(-8, "wait for pid -8");
wait_badstatus(KERN_PTR, "wait with kernel pointer status"); handle_result(result, &lost_points);
wait_unaligned(); ntests++;
result = wait_badpid(-1, "wait for pid -1");
handle_result(result, &lost_points);
wait_badflags(); ntests++;
result = wait_badpid(0, "pid zero");
handle_result(result, &lost_points);
wait_self(); ntests++;
wait_parent(); result = wait_badpid(NONEXIST_PID, "nonexistent pid");
wait_siblings(); handle_result(result, &lost_points);
ntests++;
result = wait_nullstatus();
handle_result(result, &lost_points);
ntests++;
result = wait_badstatus(INVAL_PTR, "wait with invalid pointer status");
handle_result(result, &lost_points);
ntests++;
result = wait_badstatus(KERN_PTR, "wait with kernel pointer status");
handle_result(result, &lost_points);
ntests++;
result = wait_unaligned();
handle_result(result, &lost_points);
ntests++;
result = wait_badflags();
handle_result(result, &lost_points);
ntests++;
result = wait_self();
handle_result(result, &lost_points);
ntests++;
result = wait_parent();
handle_result(result, &lost_points);
ntests++;
result = wait_siblings();
handle_result(result, &lost_points);
partial_credit(SECRET, "/testbin/badcall-waitpid", ntests - lost_points, ntests);
} }

View File

@ -36,6 +36,10 @@
void void
test_write(void) test_write(void)
{ {
test_write_fd(); int ntests = 0, lost_points = 0;
test_write_buf();
test_write_fd(&ntests, &lost_points);
test_write_buf(&ntests, &lost_points);
partial_credit(SECRET, "/testbin/badcall-write", ntests - lost_points, ntests);
} }

View File

@ -175,33 +175,46 @@ getcwd_badbuf(void *buf)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static static
void int
common_badbuf(struct buftest *info, void *buf, const char *bufdesc) common_badbuf(struct buftest *info, void *buf, const char *bufdesc)
{ {
int rv; int rv;
int result;
report_begin("%s with %s buffer", info->name, bufdesc); report_begin("%s with %s buffer", info->name, bufdesc);
info->setup(); info->setup();
rv = info->op(buf); rv = info->op(buf);
report_check(rv, errno, EFAULT); result = report_check(rv, errno, EFAULT);
info->cleanup(); info->cleanup();
return result;
} }
static static
void int
any_badbuf(struct buftest *info) any_badbuf(struct buftest *info, int *ntests, int *lost_points)
{ {
common_badbuf(info, NULL, "NULL"); int result;
common_badbuf(info, INVAL_PTR, "invalid");
common_badbuf(info, KERN_PTR, "kernel-space"); *ntests += 1;
result = common_badbuf(info, NULL, "NULL");
handle_result(result, lost_points);
*ntests += 1;
result = common_badbuf(info, INVAL_PTR, "invalid");
handle_result(result, lost_points);
*ntests += 1;
result = common_badbuf(info, KERN_PTR, "kernel-space");
handle_result(result, lost_points);
return result;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#define T(call) \ #define T(call) \
void \ void \
test_##call##_buf(void) \ test_##call##_buf(int *ntests, int *lost_points) \
{ \ { \
static struct buftest info = { \ static struct buftest info = { \
call##_setup, \ call##_setup, \
@ -209,7 +222,7 @@ any_badbuf(struct buftest *info)
call##_cleanup, \ call##_cleanup, \
#call, \ #call, \
}; \ }; \
any_badbuf(&info); \ any_badbuf(&info, ntests, lost_points); \
} }
T(read); T(read);

View File

@ -138,46 +138,58 @@ dup2_cleanup(void)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static static
void int
any_badfd(int (*func)(int fd), void (*cleanup)(void), const char *callname, any_badfd(int (*func)(int fd), void (*cleanup)(void), const char *callname,
int fd, const char *fddesc) int fd, const char *fddesc)
{ {
int rv; int rv;
int result;
report_begin("%s using %s", callname, fddesc); report_begin("%s using %s", callname, fddesc);
rv = func(fd); rv = func(fd);
report_check(rv, errno, EBADF); result = report_check(rv, errno, EBADF);
if (cleanup) { if (cleanup) {
cleanup(); cleanup();
} }
return result;
} }
static static
void void
runtest(int (*func)(int fd), void (*cleanup)(void), const char *callname, runtest(int (*func)(int fd), void (*cleanup)(void), const char *callname,
enum rwtestmodes rw) enum rwtestmodes rw, int *ntests, int *lost_points)
{ {
int fd; int fd;
int result;
/* /*
* If adding cases, also see bad_dup2.c * If adding cases, also see bad_dup2.c
*/ */
/* basic invalid case: fd -1 */ /* basic invalid case: fd -1 */
any_badfd(func, cleanup, callname, -1, "fd -1"); *ntests += 1;
result = any_badfd(func, cleanup, callname, -1, "fd -1");
handle_result(result, lost_points);
/* also try -5 in case -1 is special somehow */ /* also try -5 in case -1 is special somehow */
any_badfd(func, cleanup, callname, -5, "fd -5"); *ntests += 1;
result = any_badfd(func, cleanup, callname, -5, "fd -5");
handle_result(result, lost_points);
/* try a fd we know is closed */ /* try a fd we know is closed */
any_badfd(func, cleanup, callname, CLOSED_FD, "closed fd"); *ntests += 1;
result = any_badfd(func, cleanup, callname, CLOSED_FD, "closed fd");
handle_result(result, lost_points);
/* try a positive fd we know is out of range */ /* try a positive fd we know is out of range */
any_badfd(func, cleanup, callname, IMPOSSIBLE_FD, "impossible fd"); *ntests += 1;
result = any_badfd(func, cleanup, callname, IMPOSSIBLE_FD, "impossible fd");
handle_result(result, lost_points);
/* test for off-by-one errors */ /* test for off-by-one errors */
#ifdef OPEN_MAX #ifdef OPEN_MAX
any_badfd(func, cleanup, callname, OPEN_MAX, "fd OPEN_MAX"); *ntests += 1;
result = any_badfd(func, cleanup, callname, OPEN_MAX, "fd OPEN_MAX");
handle_result(result, lost_points);
#else #else
warnx("Warning: OPEN_MAX not defined, test skipped"); warnx("Warning: OPEN_MAX not defined, test skipped");
#endif #endif
@ -188,8 +200,10 @@ runtest(int (*func)(int fd), void (*cleanup)(void), const char *callname,
/* already printed a message */ /* already printed a message */
} }
else { else {
any_badfd(func, cleanup, callname, fd, *ntests += 1;
result = any_badfd(func, cleanup, callname, fd,
"fd opened read-only"); "fd opened read-only");
handle_result(result, lost_points);
} }
close(fd); close(fd);
} }
@ -199,8 +213,10 @@ runtest(int (*func)(int fd), void (*cleanup)(void), const char *callname,
/* already printed a message */ /* already printed a message */
} }
else { else {
any_badfd(func, cleanup, callname, fd, *ntests += 1;
result = any_badfd(func, cleanup, callname, fd,
"fd opened write-only"); "fd opened write-only");
handle_result(result, lost_points);
} }
close(fd); close(fd);
} }
@ -208,18 +224,18 @@ runtest(int (*func)(int fd), void (*cleanup)(void), const char *callname,
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#define T(call, rw) \ #define T(call, rw) \
void \ void \
test_##call##_fd(void) \ test_##call##_fd(int *ntests, int *lost_points) \
{ \ { \
runtest(call##_badfd, NULL, #call, rw); \ runtest(call##_badfd, NULL, #call, rw, ntests, lost_points); \
} }
#define TC(call, rw) \ #define TC(call, rw) \
void \ void \
test_##call##_fd(void) \ test_##call##_fd(int *ntests, int *lost_points) \
{ \ { \
runtest(call##_badfd, call##_cleanup, #call, rw);\ runtest(call##_badfd, call##_cleanup, #call, rw, ntests, lost_points); \
} }
T(read, RW_TEST_WRONLY); T(read, RW_TEST_WRONLY);

View File

@ -148,46 +148,58 @@ stat_badpath(const char *name)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static static
void int
common_badpath(int (*func)(const char *path), int mk, int rm, const char *path, common_badpath(int (*func)(const char *path), int mk, int rm, const char *path,
const char *call, const char *pathdesc) const char *call, const char *pathdesc)
{ {
int rv; int rv;
int result;
report_begin("%s with %s path", call, pathdesc); report_begin("%s with %s path", call, pathdesc);
if (mk) { if (mk) {
if (create_testfile()<0) { if (create_testfile()<0) {
report_aborted(); report_aborted(&result);
return; return result;
} }
} }
rv = func(path); rv = func(path);
report_check(rv, errno, EFAULT); result = report_check(rv, errno, EFAULT);
if (mk || rm) { if (mk || rm) {
remove(TESTFILE); remove(TESTFILE);
} }
return result;
} }
static static
void void
any_badpath(int (*func)(const char *path), const char *call, int mk, int rm) any_badpath(int (*func)(const char *path), const char *call, int mk, int rm,
int *ntests, int *lost_points)
{ {
common_badpath(func, mk, rm, NULL, call, "NULL"); int result;
common_badpath(func, mk, rm, INVAL_PTR, call, "invalid-pointer"); // We have a total of 3 tests
common_badpath(func, mk, rm, KERN_PTR, call, "kernel-pointer"); *ntests = *ntests + 3;
result = common_badpath(func, mk, rm, NULL, call, "NULL");
handle_result(result, lost_points);
result = common_badpath(func, mk, rm, INVAL_PTR, call, "invalid-pointer");
handle_result(result, lost_points);
result = common_badpath(func, mk, rm, KERN_PTR, call, "kernel-pointer");
handle_result(result, lost_points);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/* functions with one pathname */ /* functions with one pathname */
#define T(call) \ #define T(call) \
void \ void \
test_##call##_path(void) \ test_##call##_path(int *ntests, int *lost_points) \
{ \ { \
any_badpath(call##_badpath, #call, 0, 0); \ any_badpath(call##_badpath, #call, 0, 0, ntests, lost_points); \
} }
T(open); T(open);
@ -200,12 +212,12 @@ T(stat);
T(lstat); T(lstat);
/* functions with two pathnames */ /* functions with two pathnames */
#define T2(call) \ #define T2(call) \
void \ void \
test_##call##_paths(void) \ test_##call##_paths(int *ntests, int *lost_points) \
{ \ { \
any_badpath(call##_badpath1, #call "(arg1)", 0, 1); \ any_badpath(call##_badpath1, #call "(arg1)", 0, 1, ntests, lost_points); \
any_badpath(call##_badpath2, #call "(arg2)", 1, 1); \ any_badpath(call##_badpath2, #call "(arg2)", 1, 1, ntests, lost_points); \
} }
T2(rename); T2(rename);

View File

@ -121,16 +121,18 @@ int
create_testdir(void) create_testdir(void)
{ {
int rv; int rv;
int result;
rv = mkdir(TESTDIR, 0775); rv = mkdir(TESTDIR, 0775);
if (rv<0) { if (rv<0) {
if (errno == ENOSYS) { if (errno == ENOSYS) {
report_saw_enosys(); report_saw_enosys();
report_warnx("mkdir unimplemented; cannot run test"); report_warnx("mkdir unimplemented; cannot run test");
report_skipped(); report_skipped(&result);
} }
else { else {
report_warn("mkdir %s failed", TESTDIR); report_warn("mkdir %s failed", TESTDIR);
report_aborted(); report_aborted(&result);
} }
return -1; return -1;
} }

View File

@ -251,27 +251,31 @@ report_end(const char *msg)
} }
void void
report_passed(void) report_passed(int *status)
{ {
report_end("passed"); report_end("passed");
*status = SUCCESS;
} }
void void
report_failure(void) report_failure(int *status)
{ {
report_end("FAILURE"); report_end("FAILURE");
*status = FAILED;
} }
void void
report_skipped(void) report_skipped(int *status)
{ {
report_end("------"); report_end("------");
*status = SKIPPED;
} }
void void
report_aborted(void) report_aborted(int *status)
{ {
report_end("ABORTED"); report_end("ABORTED");
*status = ABORTED;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -283,18 +287,19 @@ report_aborted(void)
*/ */
void void
report_survival(int rv, int error) report_survival(int rv, int error, int *result)
{ {
/* allow any error as long as we survive */ /* allow any error as long as we survive */
report_result(rv, error); report_result(rv, error);
report_passed(); report_passed(result);
} }
static static
void int
report_checkN(int rv, int error, int *right_errors, int right_num) report_checkN(int rv, int error, int *right_errors, int right_num)
{ {
int i, goterror; int i, goterror;
int result = 1;
if (rv==-1) { if (rv==-1) {
goterror = error; goterror = error;
@ -306,39 +311,40 @@ report_checkN(int rv, int error, int *right_errors, int right_num)
for (i=0; i<right_num; i++) { for (i=0; i<right_num; i++) {
if (goterror == right_errors[i]) { if (goterror == right_errors[i]) {
report_result(rv, error); report_result(rv, error);
report_passed(); report_passed(&result);
return; return result;
} }
} }
if (goterror == ENOSYS) { if (goterror == ENOSYS) {
report_saw_enosys(); report_saw_enosys();
say("(unimplemented) "); say("(unimplemented) ");
report_skipped(); report_skipped(&result);
} }
else { else {
report_result(rv, error); report_result(rv, error);
report_failure(); report_failure(&result);
} }
return result;
} }
void int
report_check(int rv, int error, int right_error) report_check(int rv, int error, int right_error)
{ {
report_checkN(rv, error, &right_error, 1); return report_checkN(rv, error, &right_error, 1);
} }
void int
report_check2(int rv, int error, int okerr1, int okerr2) report_check2(int rv, int error, int okerr1, int okerr2)
{ {
int ok[2]; int ok[2];
ok[0] = okerr1; ok[0] = okerr1;
ok[1] = okerr2; ok[1] = okerr2;
report_checkN(rv, error, ok, 2); return report_checkN(rv, error, ok, 2);
} }
void int
report_check3(int rv, int error, int okerr1, int okerr2, int okerr3) report_check3(int rv, int error, int okerr1, int okerr2, int okerr3)
{ {
int ok[3]; int ok[3];
@ -346,5 +352,13 @@ report_check3(int rv, int error, int okerr1, int okerr2, int okerr3)
ok[0] = okerr1; ok[0] = okerr1;
ok[1] = okerr2; ok[1] = okerr2;
ok[2] = okerr3; ok[2] = okerr3;
report_checkN(rv, error, ok, 3); return report_checkN(rv, error, ok, 3);
} }
void
handle_result(int result, int *lost_points)
{
if(result)
*lost_points = *lost_points + 1;
}

View File

@ -27,6 +27,8 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <test161/test161.h>
#define TESTFILE "badcallfile" #define TESTFILE "badcallfile"
#define TESTDIR "badcalldir" #define TESTDIR "badcalldir"
#define TESTLINK "badcalllink" #define TESTLINK "badcalllink"
@ -37,6 +39,11 @@
#define PF(a, b) #define PF(a, b)
#endif #endif
#define SUCCESS 0
#define SKIPPED 1
#define FAILED 2
#define ABORTED 3
/* driver.c */ /* driver.c */
int open_testfile(const char *str); int open_testfile(const char *str);
int reopen_testfile(int openflags); int reopen_testfile(int openflags);
@ -52,46 +59,46 @@ PF(1, 2) void report_warn(const char *fmt, ...);
PF(1, 2) void report_warnx(const char *fmt, ...); PF(1, 2) void report_warnx(const char *fmt, ...);
void report_result(int rv, int error); void report_result(int rv, int error);
void report_saw_enosys(void); void report_saw_enosys(void);
void report_passed(void); void report_passed(int *result);
void report_failure(void); void report_failure(int *result);
void report_skipped(void); void report_skipped(int *result);
void report_aborted(void); void report_aborted(int *result);
void report_survival(int rv, int error); void report_survival(int rv, int error, int *result);
void report_check(int rv, int error, int right_error); int report_check(int rv, int error, int right_error);
void report_check2(int rv, int error, int okerr1, int okerr2); int report_check2(int rv, int error, int okerr1, int okerr2);
void report_check3(int rv, int error, int okerr1, int okerr2, int okerr3); int report_check3(int rv, int error, int okerr1, int okerr2, int okerr3);
/* common_buf.c */ /* common_buf.c */
void test_read_buf(void); void test_read_buf(int *ntests, int *lost_points);
void test_write_buf(void); void test_write_buf(int *ntests, int *lost_points);
void test_getdirentry_buf(void); void test_getdirentry_buf(int *ntests, int *lost_points);
void test_getcwd_buf(void); void test_getcwd_buf(int *ntests, int *lost_points);
void test_readlink_buf(void); void test_readlink_buf(int *ntests, int *lost_points);
/* common_fds.c */ /* common_fds.c */
void test_read_fd(void); void test_read_fd(int *ntests, int *lost_points);
void test_write_fd(void); void test_write_fd(int *ntests, int *lost_points);
void test_close_fd(void); void test_close_fd(int *ntests, int *lost_points);
void test_ioctl_fd(void); void test_ioctl_fd(int *ntests, int *lost_points);
void test_lseek_fd(void); void test_lseek_fd(int *ntests, int *lost_points);
void test_fsync_fd(void); void test_fsync_fd(int *ntests, int *lost_points);
void test_ftruncate_fd(void); void test_ftruncate_fd(int *ntests, int *lost_points);
void test_fstat_fd(void); void test_fstat_fd(int *ntests, int *lost_points);
void test_getdirentry_fd(void); void test_getdirentry_fd(int *ntests, int *lost_points);
void test_dup2_fd(void); void test_dup2_fd(int *ntests, int *lost_points);
/* common_path.c */ /* common_path.c */
void test_open_path(void); void test_open_path(int *ntests, int *lost_points);
void test_remove_path(void); void test_remove_path(int *ntests, int *lost_points);
void test_rename_paths(void); void test_rename_paths(int *ntests, int *lost_points);
void test_link_paths(void); void test_link_paths(int *ntests, int *lost_points);
void test_mkdir_path(void); void test_mkdir_path(int *ntests, int *lost_points);
void test_rmdir_path(void); void test_rmdir_path(int *ntests, int *lost_points);
void test_chdir_path(void); void test_chdir_path(int *ntests, int *lost_points);
void test_symlink_paths(void); void test_symlink_paths(int *ntests, int *lost_points);
void test_readlink_path(void); void test_readlink_path(int *ntests, int *lost_points);
void test_stat_path(void); void test_stat_path(int *ntests, int *lost_points);
void test_lstat_path(void); void test_lstat_path(int *ntests, int *lost_points);
/* bad_*.c */ /* bad_*.c */
void test_execv(void); void test_execv(void);
@ -122,3 +129,6 @@ void test_time(void);
void test_getcwd(void); void test_getcwd(void);
void test_stat(void); void test_stat(void);
void test_lstat(void); /* in bad_stat.c */ void test_lstat(void); /* in bad_stat.c */
void handle_result(int result, int *lost_points);

View File

@ -41,6 +41,7 @@
#include <limits.h> #include <limits.h>
#include <assert.h> #include <assert.h>
#include <err.h> #include <err.h>
#include <test161/test161.h>
#define _PATH_MYSELF "/testbin/bigexec" #define _PATH_MYSELF "/testbin/bigexec"
@ -377,6 +378,7 @@ main(int argc, char *argv[])
else if (checkmany(argc, argv, 1000, word8)) { else if (checkmany(argc, argv, 1000, word8)) {
#endif #endif
warnx("Complete."); warnx("Complete.");
success(TEST161_SUCCESS, SECRET, "/testbin/bigexec");
return 0; return 0;
} }
else { else {
@ -384,4 +386,5 @@ main(int argc, char *argv[])
dumpargs(argc, argv); dumpargs(argc, argv);
return 1; return 1;
} }
success(TEST161_SUCCESS, SECRET, "/testbin/bigexec");
} }

View File

@ -0,0 +1,11 @@
# Makefile for closetest
TOP=../../..
.include "$(TOP)/mk/os161.config.mk"
PROG=closetest
SRCS=closetest.c
BINDIR=/testbin
.include "$(TOP)/mk/os161.prog.mk"

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* closetest.c
*
* Tests the close syscall
*
* This should run correctly when open and close are implemented correctly.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include <test161/test161.h>
int
main(int argc, char **argv)
{
// Assume argument passing is *not* supported.
(void) argc;
(void) argv;
int ret, fd = -1;
// Try to open a file and then close it
fd = open("sys161.conf", O_RDONLY);
if(fd < 0) {
err(-1, "Open syscall failed");
}
else if(fd < 3) {
warnx("Open syscall returned number(%d) used by standard file descriptors (0,1,2)", fd);
}
ret = close(fd);
if(ret) {
err(1, "Failed to close file\n");
}
// Can we close 0?
ret = close(0);
if(ret) {
err(1, "Failed to close STDIN\n");
}
success(TEST161_SUCCESS, SECRET, "/testbin/closetest");
// Exit may not be implemented. So crash.
crash_prog();
return 0;
}

View File

@ -0,0 +1,11 @@
# Makefile for consoletest
TOP=../../..
.include "$(TOP)/mk/os161.config.mk"
PROG=consoletest
SRCS=consoletest.c
BINDIR=/testbin
.include "$(TOP)/mk/os161.prog.mk"

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* consoletest.c
*
* Tests whether console can be written to.
*
* This should run correctly when open and write syscalls are correctly implemented
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include <test161/test161.h>
// 23 Mar 2012 : GWA : BUFFER_COUNT must be even.
int
main(int argc, char **argv)
{
// 23 Mar 2012 : GWA : Assume argument passing is *not* supported.
(void) argc;
(void) argv;
secprintf(SECRET, "Able was i ere i saw elbA\n", "/testbin/consoletest");
// Guru: Since exit() may not yet be implemented, just trigger a
// failure that the grading scripts expect to see.
tprintf("Accessing invalid memory location to trigger failure\n");
tprintf("%d", *((int *) 0xd34db33f));
return 0;
}

View File

@ -46,6 +46,8 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <err.h> #include <err.h>
#include <test161/test161.h>
#if defined(__mips__) #if defined(__mips__)
#define KERNEL_ADDR 0x80000000 #define KERNEL_ADDR 0x80000000
@ -384,5 +386,7 @@ main(int argc, char **argv)
} }
} }
} }
printf("Should print success\n");
success(TEST161_SUCCESS, SECRET, "/testbin/crash");
return 0; return 0;
} }

View File

@ -32,6 +32,7 @@
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <err.h> #include <err.h>
#include <test161/test161.h>
#define _PATH_SELF "/testbin/factorial" #define _PATH_SELF "/testbin/factorial"
@ -246,6 +247,7 @@ main(int argc, char *argv[])
else if (argc == 3) { else if (argc == 3) {
if (!strcmp(argv[1], "1") || !strcmp(argv[1], "0")) { if (!strcmp(argv[1], "1") || !strcmp(argv[1], "0")) {
tprintf("%s\n", argv[2]); tprintf("%s\n", argv[2]);
secprintf(SECRET, argv[2], "/testbin/factorial");
} }
else { else {
number_init(&n1, argv[1]); number_init(&n1, argv[1]);

View File

@ -41,6 +41,9 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <err.h> #include <err.h>
#include <errno.h>
#include <test161/test161.h>
// 23 Mar 2012 : GWA : BUFFER_COUNT must be even. // 23 Mar 2012 : GWA : BUFFER_COUNT must be even.
@ -158,10 +161,8 @@ main(int argc, char **argv)
err(1, "seek after close succeeded"); err(1, "seek after close succeeded");
} }
// 23 Mar 2012 : GWA : FIXME : Spin until exit() works. success(TEST161_SUCCESS, SECRET, "/testbin/fileonlytest");
// Exit may not be implemented. So crash.
tprintf("Spinning in case exit() doesn't work.\n"); crash_prog();
while (1) {};
return 0; return 0;
} }

View File

@ -37,10 +37,16 @@
*/ */
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <test161/test161.h>
#define FORKTEST_FILENAME_BASE "forktest"
static char filename[32];
/* /*
* This is used by all processes, to try to help make sure all * This is used by all processes, to try to help make sure all
@ -48,6 +54,18 @@
*/ */
static volatile int mypid; static volatile int mypid;
/*
* Helper function to do pow()
*/
static
int pow_int(int x, int y) {
int i;
int result = 1;
for(i = 0; i < y; i++)
result *= x;
return result;
}
/* /*
* Helper function for fork that prints a warning on error. * Helper function for fork that prints a warning on error.
*/ */
@ -141,17 +159,38 @@ test(int nowait)
* to prevent wait/exit problems if fork corrupts memory. * to prevent wait/exit problems if fork corrupts memory.
*/ */
/*
* Guru: We have a problem here.
* We need to write the output to a file since test161 is
* supposed to be as simple as possible. This requires the
* test to tell test161 whether it passed or succeeded.
* We cannot lseek and read stdout, to check the output,
* so we need to write the output to a file and then check it later.
*
* So far so good. However, if in the future, forktest is
* going to be combined with triple/quint/etc, then the filename
* cannot be the same across multiple copies. So we need a
* unique filename per instance of forktest.
* So...
*/
snprintf(filename, 32, "%s-%d.bin", FORKTEST_FILENAME_BASE, getpid());
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if(fd < 3) {
// 0, 1, 2 are stdin, stdout, stderr
err(1, "Failed to open file to write data into\n");
}
pid0 = dofork(); pid0 = dofork();
putchar('A'); write(fd, "A", 1);
check(); check();
pid1 = dofork(); pid1 = dofork();
putchar('B'); write(fd, "B", 1);
check(); check();
pid2 = dofork(); pid2 = dofork();
putchar('C'); write(fd, "C", 1);
check(); check();
pid3 = dofork(); pid3 = dofork();
putchar('D'); write(fd, "D", 1);
check(); check();
/* /*
@ -163,7 +202,44 @@ test(int nowait)
dowait(nowait, pid1); dowait(nowait, pid1);
dowait(nowait, pid0); dowait(nowait, pid0);
putchar('\n'); // Check if file contents are correct
// lseek may not be implemented..so close and reopen
close(fd);
fd = open(filename, O_RDONLY);
if(fd < 3) {
err(1, "Failed to open file for verification\n");
}
char buffer[30];
int len;
int char_idx, i;
int observed, expected;
char character = 'A';
memset(buffer, 0, 30);
len = read(fd, buffer, 30);
printf("%s\n", buffer);
if(len != 30) {
err(1, "Did not get expected number of characters\n");
}
// Check if number of instances of each character is correct
// 2As; 4Bs; 8Cs; 16Ds
for(char_idx = 0; char_idx < 4; char_idx++) {
observed = 0;
expected = pow_int(2, char_idx + 1);
for(i = 0; i < 30; i++) {
// In C, char can be directly converted to an ASCII index
// So, A is 65, B is 66, ...
if(buffer[i] == character + char_idx) {
observed++;
}
}
if(observed != expected) {
// Failed
err(1, "Failed! Expected %d%cs..observed: %d\n", expected, character + char_idx, observed);
}
}
success(TEST161_SUCCESS, SECRET, "/testbin/forktest");
close(fd);
} }
int int

View File

@ -0,0 +1,11 @@
# Makefile for opentest
TOP=../../..
.include "$(TOP)/mk/os161.config.mk"
PROG=opentest
SRCS=opentest.c
BINDIR=/testbin
.include "$(TOP)/mk/os161.prog.mk"

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* consoletest.c
*
* Tests whether console can be written to.
*
* This should run correctly when open and write syscalls are correctly implemented
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include <test161/test161.h>
int
main(int argc, char **argv)
{
// Assume argument passing is *not* supported.
(void) argc;
(void) argv;
int fd, fd1;
// Attempt to open a file that we 'know' exists
fd = open("bin/true", O_RDONLY);
if(fd < 0) {
err(-1, "Open syscall failed");
}
else if(fd < 3) {
warnx("Open syscall returned number used by standard file descriptors (0,1,2)");
}
// Attempt to open the same file again. We should get a different fd
fd1 = open("bin/true", O_RDONLY);
if(fd1 < 0) {
err(-1, "Open syscall failed");
}
else if(fd1 < 3) {
warnx("Open syscall returned number used by standard file descriptors (0,1,2)");
}
else if(fd1 == fd) {
err(-1, "Open syscall returned same file descriptor for second open() call\n");
}
success(TEST161_SUCCESS, SECRET, "/testbin/opentest");
// Exit may not be implemented. So crash.
crash_prog();
return 0;
}

View File

@ -30,6 +30,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <test161/test161.h>
#include "extern.h" #include "extern.h"
@ -162,5 +163,6 @@ main(int argc, char *argv[])
srandom(seed); srandom(seed);
trycalls(an, dofork, count); trycalls(an, dofork, count);
success(TEST161_SUCCESS, SECRET, "/testbin/randcall");
return 0; return 0;
} }

View File

@ -0,0 +1,11 @@
# Makefile for readwritetest
TOP=../../..
.include "$(TOP)/mk/os161.config.mk"
PROG=readwritetest
SRCS=readwritetest.c
BINDIR=/testbin
.include "$(TOP)/mk/os161.prog.mk"

View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* readwritetest.c
*
* Tests whether read and write syscalls works
* This should run correctly when open, write and read are
* implemented correctly.
*
* NOTE: While checking, this test only checks the first 31 characters.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include <test161/test161.h>
#define FILENAME "readwritetest.dat"
static const char *MAGIC = "h4xa0rRq0Vgbc96tiYJ^!#nXzZSAKPO";
int
main(int argc, char **argv)
{
// 23 Mar 2012 : GWA : Assume argument passing is *not* supported.
(void) argc;
(void) argv;
int fd, len;
int expected_len = strlen(MAGIC);
fd = open(FILENAME, O_WRONLY | O_CREAT | O_TRUNC);
if(fd < 0) {
err(1, "Failed to open file.\n");
}
len = write(fd, MAGIC, expected_len);
if(len != expected_len) {
err(1, "writetest expected to write %d bytes to readwritetest.dat."
" Syscall reports that it wrote %d bytes.\n"
"Is your write syscall returning the right value?\n",
expected_len, len);
}
// Now, we test
// close() may not be implemented.
// So just try to open the file again.
fd = open(FILENAME, O_RDONLY);
if(fd < 0) {
err(1, "Failed to open file.\n");
}
char buf[32];
len = read(fd, buf, expected_len);
if(len != 31) {
err(1, "readtest expected to read %d bytes from readtest.dat."
" Only read %d bytes.\n",
expected_len, len);
}
if(strcmp(MAGIC, buf) != 0) {
err(1, "Did not match MAGIC string.\n"
"MAGIC: %s\n"
"GOT : %s\n", MAGIC, buf);
}
secprintf(SECRET, MAGIC, "/testbin/readwritetest");
// Exit may not be implemented. So crash.
crash_prog();
return 0;
}

View File

@ -43,6 +43,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <err.h> #include <err.h>
#include <test161/test161.h>
#define PATH_CAT "/bin/cat" #define PATH_CAT "/bin/cat"
#define INFILE "redirect.in" #define INFILE "redirect.in"
@ -59,6 +60,7 @@ doopen(const char *path, int openflags)
fd = open(path, openflags, 0664); fd = open(path, openflags, 0664);
if (fd < 0) { if (fd < 0) {
err(1, "%s", path); err(1, "%s", path);
crash_prog();
} }
return fd; return fd;
} }
@ -75,6 +77,7 @@ dodup2(int ofd, int nfd, const char *file)
} }
if (r != nfd) { if (r != nfd) {
errx(1, "%s: dup2: Expected %d, got %d", nfd, r); errx(1, "%s: dup2: Expected %d, got %d", nfd, r);
crash_prog();
} }
} }
@ -99,10 +102,12 @@ mkfile(void)
r = write(fd, slogan, strlen(slogan)); r = write(fd, slogan, strlen(slogan));
if (r < 0) { if (r < 0) {
err(1, "%s: write", INFILE); err(1, "%s: write", INFILE);
crash_prog();
} }
if ((size_t)r != strlen(slogan)) { if ((size_t)r != strlen(slogan)) {
errx(1, "%s: write: Short count (got %zd, expected %zu)", errx(1, "%s: write: Short count (got %zd, expected %zu)",
INFILE, r, strlen(slogan)); INFILE, r, strlen(slogan));
crash_prog();
} }
doclose(fd, INFILE); doclose(fd, INFILE);
@ -121,13 +126,16 @@ chkfile(void)
r = read(fd, buf, sizeof(buf)); r = read(fd, buf, sizeof(buf));
if (r < 0) { if (r < 0) {
err(1, "%s: read", OUTFILE); err(1, "%s: read", OUTFILE);
crash_prog();
} }
if (r == 0) { if (r == 0) {
errx(1, "%s: read: Unexpected EOF", OUTFILE); errx(1, "%s: read: Unexpected EOF", OUTFILE);
crash_prog();
} }
if ((size_t)r != strlen(slogan)) { if ((size_t)r != strlen(slogan)) {
errx(1, "%s: read: Short count (got %zd, expected %zu)", errx(1, "%s: read: Short count (got %zd, expected %zu)",
OUTFILE, r, strlen(slogan)); OUTFILE, r, strlen(slogan));
crash_prog();
} }
doclose(fd, OUTFILE); doclose(fd, OUTFILE);
@ -147,6 +155,7 @@ cat(void)
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
err(1, "fork"); err(1, "fork");
crash_prog();
} }
if (pid == 0) { if (pid == 0) {
@ -169,12 +178,15 @@ cat(void)
result = waitpid(pid, &status, 0); result = waitpid(pid, &status, 0);
if (result == -1) { if (result == -1) {
err(1, "waitpid"); err(1, "waitpid");
crash_prog();
} }
if (WIFSIGNALED(status)) { if (WIFSIGNALED(status)) {
errx(1, "pid %d: Signal %d", (int)pid, WTERMSIG(status)); errx(1, "pid %d: Signal %d", (int)pid, WTERMSIG(status));
crash_prog();
} }
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
errx(1, "pid %d: Exit %d", (int)pid, WEXITSTATUS(status)); errx(1, "pid %d: Exit %d", (int)pid, WEXITSTATUS(status));
crash_prog();
} }
} }
@ -191,6 +203,7 @@ main(void)
chkfile(); chkfile();
tprintf("Passed.\n"); tprintf("Passed.\n");
success(TEST161_SUCCESS, SECRET, "/testbin/redirect");
(void)remove(INFILE); (void)remove(INFILE);
(void)remove(OUTFILE); (void)remove(OUTFILE);
return 0; return 0;

View File

@ -0,0 +1,11 @@
# Makefile for shelltest
TOP=../../..
.include "$(TOP)/mk/os161.config.mk"
PROG=shelltest
SRCS=shelltest.c
BINDIR=/testbin
.include "$(TOP)/mk/os161.prog.mk"

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* shelltest.c
*
* Tests whether console can be written to.
*
* This should run correctly when open and write syscalls are correctly implemented
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include <test161/test161.h>
// 23 Mar 2012 : GWA : BUFFER_COUNT must be even.
int
main(int argc, char **argv)
{
// 23 Mar 2012 : GWA : Assume argument passing is *not* supported.
(void) argc;
(void) argv;
int i;
char buf[64];
for(i = 0; i < 3; i++) {
memset(buf, 0, sizeof(buf));
snprintf(buf, 64, "line-%d: Able was i ere i saw elbA", i + 1);
secprintf(SECRET, buf, "/testbin/shelltest");
}
// Expects exit() to work
return 0;
}

View File

@ -41,6 +41,8 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <err.h> #include <err.h>
#include <string.h>
#include <test161/test161.h>
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@ -57,7 +59,7 @@ main(int argc, char *argv[])
filename = argv[1]; filename = argv[1];
size = atoi(argv[2]); size = atoi(argv[2]);
byte = '\n'; byte = '@';
if (size == 0) { if (size == 0) {
err(1, "Sparse files of length zero are not meaningful"); err(1, "Sparse files of length zero are not meaningful");
@ -65,7 +67,7 @@ main(int argc, char *argv[])
tprintf("Creating a sparse file of size %d\n", size); tprintf("Creating a sparse file of size %d\n", size);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC); fd = open(filename, O_RDWR|O_CREAT|O_TRUNC);
if (fd < 0) { if (fd < 0) {
err(1, "%s: create", filename); err(1, "%s: create", filename);
} }
@ -81,7 +83,26 @@ main(int argc, char *argv[])
errx(1, "%s: write: Unexpected result count %d", filename, r); errx(1, "%s: write: Unexpected result count %d", filename, r);
} }
// Now check this byte.
// First seek to the beginning and then seek back to where the byte
// should be.
if(lseek(fd, 0, SEEK_SET) == -1) {
err(1, "lseek failed to seek to beginning of file\n");
}
// Now seek back to where the byte should be
// While at it, also test SEEK_CUR
if(lseek(fd, size-1, SEEK_CUR) == -1) {
err(1, "lseek failed to seek to %d of file\n", size-1);
}
char test;
r = read(fd, &test, 1);
if(test != byte) {
err(1, "Byte test failed. Expected (%c) != Observed (%c)\n", byte, test);
}
close(fd); close(fd);
success(TEST161_SUCCESS, SECRET, "/testbin/sparsefile");
// Exit may not be implemented. So crash.
crash_prog();
return 0; return 0;
} }