Initial Spring 2016 commit.
This commit is contained in:
19
userland/testbin/Makefile
Normal file
19
userland/testbin/Makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Makefile for src/testbin (sources for programs installed in /testbin)
|
||||
#
|
||||
|
||||
TOP=../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
SUBDIRS=add argtest badcall bigexec bigfile bigfork bigseek bloat conman \
|
||||
crash ctest dirconc dirseek dirtest f_test factorial farm faulter \
|
||||
filetest forkbomb forktest frack guzzle hash hog huge kitchen \
|
||||
malloctest matmult multiexec palin parallelvm poisondisk psort \
|
||||
quinthuge quintmat quintsort randcall redirect rmdirtest rmtest \
|
||||
sbrktest schedpong sink sort sparsefile sty tail tictac triplehuge \
|
||||
triplemat triplesort usemtest zero
|
||||
|
||||
# But not:
|
||||
# userthreads (no support in kernel API in base system)
|
||||
|
||||
.include "$(TOP)/mk/os161.subdir.mk"
|
11
userland/testbin/add/Makefile
Normal file
11
userland/testbin/add/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for add
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=add
|
||||
SRCS=add.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
57
userland/testbin/add/add.c
Normal file
57
userland/testbin/add/add.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Simple program to add two numbers (given in as arguments). Used to
|
||||
* test argument passing to child processes.
|
||||
*
|
||||
* Intended for the basic system calls assignment; this should work
|
||||
* once execv() argument handling is implemented.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, j;
|
||||
|
||||
if (argc != 3) {
|
||||
errx(1, "Usage: add num1 num2");
|
||||
}
|
||||
|
||||
i = atoi(argv[1]);
|
||||
j = atoi(argv[2]);
|
||||
|
||||
printf("Answer: %d\n", i+j);
|
||||
|
||||
return 0;
|
||||
}
|
11
userland/testbin/argtest/Makefile
Normal file
11
userland/testbin/argtest/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for argtest
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=argtest
|
||||
SRCS=argtest.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
57
userland/testbin/argtest/argtest.c
Normal file
57
userland/testbin/argtest/argtest.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Program to test argument passing: it displays the argc and all
|
||||
* of argv, and then exits.
|
||||
*
|
||||
* Intended for the basic system calls assignment. This may help
|
||||
* debugging the argument handling of execv().
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *tmp;
|
||||
int i;
|
||||
|
||||
printf("argc: %d\n", argc);
|
||||
|
||||
for (i=0; i<=argc; i++) {
|
||||
tmp = argv[i];
|
||||
if (tmp==NULL) {
|
||||
tmp = "[NULL]";
|
||||
}
|
||||
printf("argv[%d]: %s\n", i, tmp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
43
userland/testbin/badcall/Makefile
Normal file
43
userland/testbin/badcall/Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
# Makefile for badcall
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
SRCS=\
|
||||
bad_execv.c \
|
||||
bad_waitpid.c \
|
||||
bad_open.c \
|
||||
bad_read.c \
|
||||
bad_write.c \
|
||||
bad_close.c \
|
||||
bad_reboot.c \
|
||||
bad_sbrk.c \
|
||||
bad_ioctl.c \
|
||||
bad_lseek.c \
|
||||
bad_fsync.c \
|
||||
bad_ftruncate.c \
|
||||
bad_stat.c \
|
||||
bad_remove.c \
|
||||
bad_rename.c \
|
||||
bad_link.c \
|
||||
bad_mkdir.c \
|
||||
bad_rmdir.c \
|
||||
bad_chdir.c \
|
||||
bad_getdirentry.c \
|
||||
bad_symlink.c \
|
||||
bad_readlink.c \
|
||||
bad_dup2.c \
|
||||
bad_pipe.c \
|
||||
bad_time.c \
|
||||
bad_getcwd.c \
|
||||
common_buf.c \
|
||||
common_fds.c \
|
||||
common_path.c \
|
||||
report.c \
|
||||
driver.c
|
||||
|
||||
PROG=badcall
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
61
userland/testbin/badcall/bad_chdir.c
Normal file
61
userland/testbin/badcall/bad_chdir.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Invalid calls to chdir()
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
chdir_empty(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
/*
|
||||
* This is actually valid by some interpretations.
|
||||
*/
|
||||
|
||||
report_begin("chdir to empty string");
|
||||
rv = chdir("");
|
||||
report_check2(rv, errno, EINVAL, 0);
|
||||
}
|
||||
|
||||
void
|
||||
test_chdir(void)
|
||||
{
|
||||
test_chdir_path();
|
||||
chdir_empty();
|
||||
}
|
||||
|
40
userland/testbin/badcall/bad_close.c
Normal file
40
userland/testbin/badcall/bad_close.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Invalid calls to close()
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
void
|
||||
test_close(void)
|
||||
{
|
||||
test_close_fd();
|
||||
}
|
142
userland/testbin/badcall/bad_dup2.c
Normal file
142
userland/testbin/badcall/bad_dup2.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Invalid calls to dup2
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
dup2_fd2(int fd, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("%s", desc);
|
||||
rv = dup2(STDIN_FILENO, fd);
|
||||
report_check(rv, errno, EBADF);
|
||||
|
||||
if (rv != -1) {
|
||||
close(fd); /* just in case */
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dup2_self(void)
|
||||
{
|
||||
struct stat sb;
|
||||
int rv;
|
||||
int testfd;
|
||||
|
||||
/* use fd that isn't in use */
|
||||
testfd = CLOSED_FD;
|
||||
|
||||
report_begin("copying stdin to test with");
|
||||
|
||||
rv = dup2(STDIN_FILENO, testfd);
|
||||
if (rv == -1) {
|
||||
report_result(rv, errno);
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
|
||||
report_begin("dup2 to same fd");
|
||||
rv = dup2(testfd, testfd);
|
||||
if (rv == testfd) {
|
||||
report_passed();
|
||||
}
|
||||
else if (rv<0) {
|
||||
report_result(rv, errno);
|
||||
report_failure();
|
||||
}
|
||||
else {
|
||||
report_warnx("returned %d instead", rv);
|
||||
report_failure();
|
||||
}
|
||||
|
||||
report_begin("fstat fd after dup2 to itself");
|
||||
rv = fstat(testfd, &sb);
|
||||
if (errno == ENOSYS) {
|
||||
report_saw_enosys();
|
||||
}
|
||||
report_result(rv, errno);
|
||||
if (rv==0) {
|
||||
report_passed();
|
||||
}
|
||||
else if (errno != ENOSYS) {
|
||||
report_failure();
|
||||
}
|
||||
else {
|
||||
report_skipped();
|
||||
/* no support for fstat; try lseek */
|
||||
report_begin("lseek fd after dup2 to itself");
|
||||
rv = lseek(testfd, 0, SEEK_CUR);
|
||||
report_result(rv, errno);
|
||||
if (rv==0 || (rv==-1 && errno==ESPIPE)) {
|
||||
report_passed();
|
||||
}
|
||||
else {
|
||||
report_failure();
|
||||
}
|
||||
}
|
||||
|
||||
close(testfd);
|
||||
}
|
||||
|
||||
void
|
||||
test_dup2(void)
|
||||
{
|
||||
/* This does the first fd. */
|
||||
test_dup2_fd();
|
||||
|
||||
/* Any interesting cases added here should also go in common_fds.c */
|
||||
dup2_fd2(-1, "dup2 to -1");
|
||||
dup2_fd2(-5, "dup2 to -5");
|
||||
dup2_fd2(IMPOSSIBLE_FD, "dup2 to impossible fd");
|
||||
#ifdef OPEN_MAX
|
||||
dup2_fd2(OPEN_MAX, "dup2 to OPEN_MAX");
|
||||
#else
|
||||
warnx("Warning: OPEN_MAX not defined - test skipped");
|
||||
#endif
|
||||
|
||||
dup2_self();
|
||||
}
|
181
userland/testbin/badcall/bad_execv.c
Normal file
181
userland/testbin/badcall/bad_execv.c
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* bad calls to execv()
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
int
|
||||
exec_common_fork(void)
|
||||
{
|
||||
int pid, rv, status, err;
|
||||
|
||||
/*
|
||||
* This does not happen in a test context (from the point of
|
||||
* view of report.c) so we have to fiddle a bit.
|
||||
*/
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
err = errno;
|
||||
report_begin("forking for test");
|
||||
report_result(pid, err);
|
||||
report_aborted();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pid==0) {
|
||||
/* child */
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = waitpid(pid, &status, 0);
|
||||
if (rv == -1) {
|
||||
err = errno;
|
||||
report_begin("waiting for test subprocess");
|
||||
report_result(rv, err);
|
||||
report_failure();
|
||||
return -1;
|
||||
}
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == MAGIC_STATUS) {
|
||||
return 1;
|
||||
}
|
||||
/* Oops... */
|
||||
report_begin("exit code of subprocess; should be %d", MAGIC_STATUS);
|
||||
if (WIFSIGNALED(status)) {
|
||||
report_warnx("signal %d", WTERMSIG(status));
|
||||
}
|
||||
else {
|
||||
report_warnx("exit %d", WEXITSTATUS(status));
|
||||
}
|
||||
report_failure();
|
||||
return -1;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
exec_badprog(const void *prog, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
char *args[2];
|
||||
args[0] = (char *)"foo";
|
||||
args[1] = NULL;
|
||||
|
||||
if (exec_common_fork() != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
report_begin(desc);
|
||||
rv = execv(prog, args);
|
||||
report_check(rv, errno, EFAULT);
|
||||
exit(MAGIC_STATUS);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
exec_emptyprog(void)
|
||||
{
|
||||
int rv;
|
||||
char *args[2];
|
||||
args[0] = (char *)"foo";
|
||||
args[1] = NULL;
|
||||
|
||||
if (exec_common_fork() != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
report_begin("exec the empty string");
|
||||
rv = execv("", args);
|
||||
report_check2(rv, errno, EINVAL, EISDIR);
|
||||
exit(MAGIC_STATUS);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
exec_badargs(void *args, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (exec_common_fork() != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
report_begin(desc);
|
||||
rv = execv("/bin/true", args);
|
||||
report_check(rv, errno, EFAULT);
|
||||
exit(MAGIC_STATUS);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
exec_onearg(void *ptr, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
char *args[3];
|
||||
args[0] = (char *)"foo";
|
||||
args[1] = (char *)ptr;
|
||||
args[2] = NULL;
|
||||
|
||||
if (exec_common_fork() != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
report_begin(desc);
|
||||
rv = execv("/bin/true", args);
|
||||
report_check(rv, errno, EFAULT);
|
||||
exit(MAGIC_STATUS);
|
||||
}
|
||||
|
||||
void
|
||||
test_execv(void)
|
||||
{
|
||||
exec_badprog(NULL, "exec with NULL program");
|
||||
exec_badprog(INVAL_PTR, "exec with invalid pointer program");
|
||||
exec_badprog(KERN_PTR, "exec with kernel pointer program");
|
||||
|
||||
exec_emptyprog();
|
||||
|
||||
exec_badargs(NULL, "exec with NULL arglist");
|
||||
exec_badargs(INVAL_PTR, "exec with invalid pointer arglist");
|
||||
exec_badargs(KERN_PTR, "exec with kernel pointer arglist");
|
||||
|
||||
exec_onearg(INVAL_PTR, "exec with invalid pointer arg");
|
||||
exec_onearg(KERN_PTR, "exec with kernel pointer arg");
|
||||
}
|
41
userland/testbin/badcall/bad_fsync.c
Normal file
41
userland/testbin/badcall/bad_fsync.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* fsync
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
void
|
||||
test_fsync(void)
|
||||
{
|
||||
test_fsync_fd();
|
||||
}
|
||||
|
95
userland/testbin/badcall/bad_ftruncate.c
Normal file
95
userland/testbin/badcall/bad_ftruncate.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ftruncate
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
ftruncate_fd_device(void)
|
||||
{
|
||||
int rv, fd;
|
||||
|
||||
report_begin("ftruncate on device");
|
||||
|
||||
fd = open("null:", O_RDWR);
|
||||
if (fd<0) {
|
||||
report_warn("opening null: failed");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
|
||||
rv = ftruncate(fd, 6);
|
||||
report_check(rv, errno, EINVAL);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
ftruncate_size_neg(void)
|
||||
{
|
||||
int rv, fd;
|
||||
|
||||
report_begin("ftruncate to negative size");
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
|
||||
rv = ftruncate(fd, -60);
|
||||
report_check(rv, errno, EINVAL);
|
||||
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
}
|
||||
|
||||
void
|
||||
test_ftruncate(void)
|
||||
{
|
||||
test_ftruncate_fd();
|
||||
|
||||
ftruncate_fd_device();
|
||||
ftruncate_size_neg();
|
||||
}
|
40
userland/testbin/badcall/bad_getcwd.c
Normal file
40
userland/testbin/badcall/bad_getcwd.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* __getcwd
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
void
|
||||
test_getcwd(void)
|
||||
{
|
||||
test_getcwd_buf();
|
||||
}
|
41
userland/testbin/badcall/bad_getdirentry.c
Normal file
41
userland/testbin/badcall/bad_getdirentry.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* getdirentry
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
void
|
||||
test_getdirentry(void)
|
||||
{
|
||||
test_getdirentry_fd();
|
||||
test_getdirentry_buf();
|
||||
}
|
103
userland/testbin/badcall/bad_ioctl.c
Normal file
103
userland/testbin/badcall/bad_ioctl.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ioctl
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
one_ioctl_badbuf(int fd, int code, const char *codename,
|
||||
void *ptr, const char *ptrdesc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("ioctl %s with %s", codename, ptrdesc);
|
||||
rv = ioctl(fd, code, ptr);
|
||||
report_check(rv, errno, EFAULT);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
any_ioctl_badbuf(int fd, int code, const char *codename)
|
||||
{
|
||||
one_ioctl_badbuf(fd, code, codename, NULL, "NULL pointer");
|
||||
one_ioctl_badbuf(fd, code, codename, INVAL_PTR, "invalid pointer");
|
||||
one_ioctl_badbuf(fd, code, codename, KERN_PTR, "kernel pointer");
|
||||
}
|
||||
|
||||
#define IOCTL(fd, sym) any_ioctl_badbuf(fd, sym, #sym)
|
||||
|
||||
static
|
||||
void
|
||||
ioctl_badbuf(void)
|
||||
{
|
||||
/*
|
||||
* Since we don't actually define any ioctls, this code won't
|
||||
* actually run. But if you do define ioctls, turn these tests
|
||||
* on for those that actually use the data buffer argument for
|
||||
* anything.
|
||||
*/
|
||||
|
||||
/* IOCTL(STDIN_FILENO, TIOCGETA); */
|
||||
|
||||
|
||||
/* suppress gcc warning */
|
||||
(void)any_ioctl_badbuf;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
ioctl_badcode(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("invalid ioctl");
|
||||
rv = ioctl(STDIN_FILENO, NONEXIST_IOCTL, NULL);
|
||||
report_check(rv, errno, EIOCTL);
|
||||
}
|
||||
|
||||
void
|
||||
test_ioctl(void)
|
||||
{
|
||||
test_ioctl_fd();
|
||||
|
||||
/* Since we don't actually define any ioctls, this is not meaningful */
|
||||
ioctl_badcode();
|
||||
ioctl_badbuf();
|
||||
}
|
88
userland/testbin/badcall/bad_link.c
Normal file
88
userland/testbin/badcall/bad_link.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* link
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
link_dir(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("hard link of .");
|
||||
rv = link(".", TESTDIR);
|
||||
report_check(rv, errno, EINVAL);
|
||||
if (rv==0) {
|
||||
/* this might help recover... maybe */
|
||||
remove(TESTDIR);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
link_empty1(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("hard link of empty string");
|
||||
rv = link("", TESTDIR);
|
||||
report_check(rv, errno, EINVAL);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
link_empty2(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("hard link to empty string");
|
||||
if (create_testdir()<0) {
|
||||
/*report_aborted();*/ /* XXX in create_testdir */
|
||||
return;
|
||||
}
|
||||
rv = link(TESTDIR, "");
|
||||
report_check(rv, errno, EINVAL);
|
||||
rmdir(TESTDIR);
|
||||
}
|
||||
|
||||
void
|
||||
test_link(void)
|
||||
{
|
||||
test_link_paths();
|
||||
link_dir();
|
||||
link_empty1();
|
||||
link_empty2();
|
||||
}
|
278
userland/testbin/badcall/bad_lseek.c
Normal file
278
userland/testbin/badcall/bad_lseek.c
Normal file
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* lseek
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
lseek_fd_device(void)
|
||||
{
|
||||
int fd, rv;
|
||||
|
||||
report_begin("lseek on device");
|
||||
|
||||
fd = open("null:", O_RDONLY);
|
||||
if (fd<0) {
|
||||
report_warn("opening null: failed");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
|
||||
rv = lseek(fd, 309, SEEK_SET);
|
||||
report_check(rv, errno, ESPIPE);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
lseek_file_stdin(void)
|
||||
{
|
||||
int fd, fd2, rv, status;
|
||||
const char slogan[] = "There ain't no such thing as a free lunch";
|
||||
size_t len = strlen(slogan);
|
||||
pid_t pid;
|
||||
|
||||
report_begin("lseek stdin when open on file");
|
||||
|
||||
/* fork so we don't affect our own stdin */
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
else if (pid!=0) {
|
||||
/* parent */
|
||||
rv = waitpid(pid, &status, 0);
|
||||
if (rv<0) {
|
||||
report_warn("waitpid failed");
|
||||
report_aborted();
|
||||
}
|
||||
if (WIFSIGNALED(status)) {
|
||||
report_warnx("subprocess exited with signal %d",
|
||||
WTERMSIG(status));
|
||||
report_aborted();
|
||||
}
|
||||
else if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
|
||||
report_warnx("subprocess exited with code %d",
|
||||
WEXITSTATUS(status));
|
||||
report_aborted();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* child */
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Move file to stdin.
|
||||
* Use stdin (rather than stdout or stderr) to maximize the
|
||||
* chances of detecting any special-case handling of fds 0-2.
|
||||
* (Writing to stdin is fine as long as it's open for write,
|
||||
* and it will be.)
|
||||
*/
|
||||
fd2 = dup2(fd, STDIN_FILENO);
|
||||
if (fd2<0) {
|
||||
report_warn("dup2 to stdin failed");
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
_exit(1);
|
||||
}
|
||||
if (fd2 != STDIN_FILENO) {
|
||||
report_warn("dup2 returned wrong file handle");
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
_exit(1);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
rv = write(STDIN_FILENO, slogan, len);
|
||||
if (rv<0) {
|
||||
report_warn("write to %s (via stdin) failed", TESTFILE);
|
||||
remove(TESTFILE);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
if ((unsigned)rv != len) {
|
||||
report_warnx("write to %s (via stdin) got short count",
|
||||
TESTFILE);
|
||||
remove(TESTFILE);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
/* blah */
|
||||
report_skipped();
|
||||
|
||||
rv = lseek(STDIN_FILENO, 0, SEEK_SET);
|
||||
report_begin("try 1: SEEK_SET");
|
||||
report_check(rv, errno, 0);
|
||||
|
||||
rv = lseek(STDIN_FILENO, 0, SEEK_END);
|
||||
report_begin("try 2: SEEK_END");
|
||||
report_check(rv, errno, 0);
|
||||
|
||||
remove(TESTFILE);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
lseek_loc_negative(void)
|
||||
{
|
||||
int fd, rv;
|
||||
|
||||
report_begin("lseek to negative offset");
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
|
||||
rv = lseek(fd, -309, SEEK_SET);
|
||||
report_check(rv, errno, EINVAL);
|
||||
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
lseek_whence_inval(void)
|
||||
{
|
||||
int fd, rv;
|
||||
|
||||
report_begin("lseek with invalid whence code");
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
|
||||
rv = lseek(fd, 0, 3594);
|
||||
report_check(rv, errno, EINVAL);
|
||||
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
lseek_loc_pasteof(void)
|
||||
{
|
||||
const char *message = "blahblah";
|
||||
int fd;
|
||||
off_t pos;
|
||||
|
||||
report_begin("seek past/to EOF");
|
||||
|
||||
fd = open_testfile(message);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
|
||||
pos = lseek(fd, 5340, SEEK_SET);
|
||||
if (pos == -1) {
|
||||
report_warn("lseek past EOF failed");
|
||||
report_failure();
|
||||
goto out;
|
||||
}
|
||||
if (pos != 5340) {
|
||||
report_warnx("lseek to 5340 got offset %lld", (long long) pos);
|
||||
report_failure();
|
||||
goto out;
|
||||
}
|
||||
|
||||
pos = lseek(fd, -50, SEEK_CUR);
|
||||
if (pos == -1) {
|
||||
report_warn("small seek beyond EOF failed");
|
||||
report_failure();
|
||||
goto out;
|
||||
}
|
||||
if (pos != 5290) {
|
||||
report_warnx("SEEK_CUR to 5290 got offset %lld",
|
||||
(long long) pos);
|
||||
report_failure();
|
||||
goto out;
|
||||
}
|
||||
|
||||
pos = lseek(fd, 0, SEEK_END);
|
||||
if (pos == -1) {
|
||||
report_warn("seek to EOF failed");
|
||||
report_failure();
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (pos != (off_t) strlen(message)) {
|
||||
report_warnx("seek to EOF got %lld (should be %zu)",
|
||||
(long long) pos, strlen(message));
|
||||
report_failure();
|
||||
goto out;
|
||||
}
|
||||
|
||||
report_passed();
|
||||
|
||||
out:
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
test_lseek(void)
|
||||
{
|
||||
test_lseek_fd();
|
||||
|
||||
lseek_fd_device();
|
||||
lseek_file_stdin();
|
||||
lseek_loc_negative();
|
||||
lseek_loc_pasteof();
|
||||
lseek_whence_inval();
|
||||
}
|
87
userland/testbin/badcall/bad_mkdir.c
Normal file
87
userland/testbin/badcall/bad_mkdir.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* mkdir
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
mkdir_dot(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("mkdir .");
|
||||
rv = mkdir(".", 0775);
|
||||
report_check(rv, errno, EEXIST);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mkdir_dotdot(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("mkdir ..");
|
||||
rv = mkdir("..", 0775);
|
||||
report_check(rv, errno, EEXIST);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mkdir_empty(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("mkdir of empty string");
|
||||
rv = mkdir("", 0775);
|
||||
report_check(rv, errno, EINVAL);
|
||||
}
|
||||
|
||||
void
|
||||
test_mkdir(void)
|
||||
{
|
||||
test_mkdir_path();
|
||||
|
||||
mkdir_dot();
|
||||
mkdir_dotdot();
|
||||
mkdir_empty();
|
||||
}
|
78
userland/testbin/badcall/bad_open.c
Normal file
78
userland/testbin/badcall/bad_open.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* invalid calls to open()
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
open_badflags(void)
|
||||
{
|
||||
int fd;
|
||||
|
||||
report_begin("open null: with bad flags");
|
||||
fd = open("null:", 309842);
|
||||
report_check(fd, errno, EINVAL);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
open_empty(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("open empty string");
|
||||
rv = open("", O_RDONLY);
|
||||
report_check2(rv, errno, 0, EINVAL);
|
||||
if (rv>=0) {
|
||||
close(rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_open(void)
|
||||
{
|
||||
test_open_path();
|
||||
|
||||
open_badflags();
|
||||
open_empty();
|
||||
}
|
81
userland/testbin/badcall/bad_pipe.c
Normal file
81
userland/testbin/badcall/bad_pipe.c
Normal 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* pipe
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
pipe_badptr(void *ptr, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("%s", desc);
|
||||
rv = pipe(ptr);
|
||||
report_check(rv, errno, EFAULT);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
pipe_unaligned(void)
|
||||
{
|
||||
int fds[3], rv;
|
||||
char *ptr;
|
||||
|
||||
report_begin("pipe with unaligned pointer");
|
||||
|
||||
ptr = (char *)&fds[0];
|
||||
ptr++;
|
||||
|
||||
rv = pipe((int *)ptr);
|
||||
report_survival(rv, errno);
|
||||
}
|
||||
|
||||
void
|
||||
test_pipe(void)
|
||||
{
|
||||
pipe_badptr(NULL, "pipe with NULL pointer");
|
||||
pipe_badptr(INVAL_PTR, "pipe with invalid pointer");
|
||||
pipe_badptr(KERN_PTR, "pipe with kernel pointer");
|
||||
|
||||
pipe_unaligned();
|
||||
}
|
42
userland/testbin/badcall/bad_read.c
Normal file
42
userland/testbin/badcall/bad_read.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Invalid calls to read()
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
void
|
||||
test_read(void)
|
||||
{
|
||||
test_read_fd();
|
||||
test_read_buf();
|
||||
}
|
||||
|
92
userland/testbin/badcall/bad_readlink.c
Normal file
92
userland/testbin/badcall/bad_readlink.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* readlink
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
readlink_file(void)
|
||||
{
|
||||
char buf[128];
|
||||
int fd, rv;
|
||||
|
||||
report_begin("readlink on file");
|
||||
fd = open_testfile("the question contains an invalid assumption");
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
rv = readlink(TESTFILE, buf, sizeof(buf));
|
||||
report_check(rv, errno, EINVAL);
|
||||
remove(TESTFILE);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
readlink_dir(void)
|
||||
{
|
||||
char buf[128];
|
||||
int rv;
|
||||
|
||||
report_begin("readlink on .");
|
||||
rv = readlink(".", buf, sizeof(buf));
|
||||
report_check(rv, errno, EISDIR);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
readlink_empty(void)
|
||||
{
|
||||
char buf[128];
|
||||
int rv;
|
||||
|
||||
report_begin("readlink on empty string");
|
||||
rv = readlink("", buf, sizeof(buf));
|
||||
report_check2(rv, errno, EISDIR, EINVAL);
|
||||
}
|
||||
|
||||
void
|
||||
test_readlink(void)
|
||||
{
|
||||
test_readlink_path();
|
||||
test_readlink_buf();
|
||||
|
||||
readlink_file();
|
||||
readlink_dir();
|
||||
readlink_empty();
|
||||
}
|
||||
|
62
userland/testbin/badcall/bad_reboot.c
Normal file
62
userland/testbin/badcall/bad_reboot.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Invalid calls to reboot()
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
reboot_badflags(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
printf("(This should not kill the system...)\n");
|
||||
report_begin("reboot with invalid flags");
|
||||
rv = reboot(15353);
|
||||
report_check(rv, errno, EINVAL);
|
||||
}
|
||||
|
||||
void
|
||||
test_reboot(void)
|
||||
{
|
||||
reboot_badflags();
|
||||
}
|
106
userland/testbin/badcall/bad_remove.c
Normal file
106
userland/testbin/badcall/bad_remove.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* remove
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
remove_dir(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("remove() on a directory");
|
||||
|
||||
if (create_testdir() < 0) {
|
||||
/*report_aborted();*/ /* XXX in create_testdir */
|
||||
return;
|
||||
}
|
||||
|
||||
rv = remove(TESTDIR);
|
||||
report_check(rv, errno, EISDIR);
|
||||
rmdir(TESTDIR);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
remove_dot(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("remove() on .");
|
||||
rv = remove(".");
|
||||
report_check2(rv, errno, EISDIR, EINVAL);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
remove_dotdot(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("remove() on ..");
|
||||
rv = remove("..");
|
||||
report_check2(rv, errno, EISDIR, EINVAL);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
remove_empty(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("remove() on empty string");
|
||||
rv = remove("");
|
||||
report_check2(rv, errno, EISDIR, EINVAL);
|
||||
}
|
||||
|
||||
void
|
||||
test_remove(void)
|
||||
{
|
||||
test_remove_path();
|
||||
|
||||
remove_dir();
|
||||
remove_dot();
|
||||
remove_dotdot();
|
||||
remove_empty();
|
||||
}
|
111
userland/testbin/badcall/bad_rename.c
Normal file
111
userland/testbin/badcall/bad_rename.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* rename
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
rename_dot(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("rename .");
|
||||
|
||||
rv = rename(".", TESTDIR);
|
||||
report_check(rv, errno, EINVAL);
|
||||
if (rv==0) {
|
||||
/* oops... put it back */
|
||||
rename(TESTDIR, ".");
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
rename_dotdot(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("rename ..");
|
||||
rv = rename("..", TESTDIR);
|
||||
report_check(rv, errno, EINVAL);
|
||||
if (rv==0) {
|
||||
/* oops... put it back */
|
||||
rename(TESTDIR, "..");
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
rename_empty1(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("rename empty string");
|
||||
rv = rename("", TESTDIR);
|
||||
report_check2(rv, errno, EISDIR, EINVAL);
|
||||
if (rv==0) {
|
||||
/* don't try to remove it */
|
||||
rename(TESTDIR, TESTDIR "-foo");
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
rename_empty2(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("rename to empty string");
|
||||
if (create_testdir()<0) {
|
||||
/*report_aborted();*/ /* XXX in create_testdir */
|
||||
return;
|
||||
}
|
||||
rv = rename(TESTDIR, "");
|
||||
report_check2(rv, errno, EISDIR, EINVAL);
|
||||
rmdir(TESTDIR);
|
||||
}
|
||||
|
||||
void
|
||||
test_rename(void)
|
||||
{
|
||||
test_rename_paths();
|
||||
|
||||
rename_dot();
|
||||
rename_dotdot();
|
||||
rename_empty1();
|
||||
rename_empty2();
|
||||
}
|
||||
|
104
userland/testbin/badcall/bad_rmdir.c
Normal file
104
userland/testbin/badcall/bad_rmdir.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* rmdir
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
rmdir_file(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("rmdir a file");
|
||||
if (create_testfile()<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
rv = rmdir(TESTFILE);
|
||||
report_check(rv, errno, ENOTDIR);
|
||||
remove(TESTFILE);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
rmdir_dot(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("rmdir .");
|
||||
rv = rmdir(".");
|
||||
report_check(rv, errno, EINVAL);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
rmdir_dotdot(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("rmdir ..");
|
||||
rv = rmdir("..");
|
||||
report_check2(rv, errno, EINVAL, ENOTEMPTY);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
rmdir_empty(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("rmdir empty string");
|
||||
rv = rmdir("");
|
||||
report_check(rv, errno, EINVAL);
|
||||
}
|
||||
|
||||
void
|
||||
test_rmdir(void)
|
||||
{
|
||||
test_rmdir_path();
|
||||
|
||||
rmdir_file();
|
||||
rmdir_dot();
|
||||
rmdir_dotdot();
|
||||
rmdir_empty();
|
||||
}
|
125
userland/testbin/badcall/bad_sbrk.c
Normal file
125
userland/testbin/badcall/bad_sbrk.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* sbrk
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
/*
|
||||
* typing wrapper around sbrk
|
||||
*/
|
||||
static
|
||||
int
|
||||
try_sbrk(long val)
|
||||
{
|
||||
void *rv;
|
||||
rv = sbrk(val);
|
||||
if (rv==(void *)-1) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
enforce_sbrk(long val, const char *desc, int err)
|
||||
{
|
||||
int result;
|
||||
|
||||
report_begin("sbrk %s", desc);
|
||||
|
||||
result = try_sbrk(val);
|
||||
report_check(result, errno, err);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
sbrk_bigpos(void)
|
||||
{
|
||||
enforce_sbrk(4096*1024*256, "huge positive", ENOMEM);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
sbrk_bigneg(void)
|
||||
{
|
||||
enforce_sbrk(-4096*1024*256, "huge negative", EINVAL);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
sbrk_neg(void)
|
||||
{
|
||||
enforce_sbrk(-8192, "too-large negative", EINVAL);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
sbrk_unalignedpos(void)
|
||||
{
|
||||
int result;
|
||||
|
||||
report_begin("sbrk unaligned positive");
|
||||
result = try_sbrk(17);
|
||||
report_check2(result, errno, 0, EINVAL);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
sbrk_unalignedneg(void)
|
||||
{
|
||||
int result;
|
||||
|
||||
report_begin("sbrk unaligned negative");
|
||||
result = try_sbrk(-17);
|
||||
report_check2(result, errno, 0, EINVAL);
|
||||
}
|
||||
|
||||
void
|
||||
test_sbrk(void)
|
||||
{
|
||||
sbrk_neg();
|
||||
sbrk_bigpos();
|
||||
sbrk_bigneg();
|
||||
sbrk_unalignedpos();
|
||||
sbrk_unalignedneg();
|
||||
}
|
||||
|
128
userland/testbin/badcall/bad_stat.c
Normal file
128
userland/testbin/badcall/bad_stat.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bad calls to fstat, lstat, and stat
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
int
|
||||
badbuf_fstat(struct stat *sb)
|
||||
{
|
||||
return fstat(STDIN_FILENO, sb);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
badbuf_lstat(struct stat *sb)
|
||||
{
|
||||
return lstat("null:", sb);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
badbuf_stat(struct stat *sb)
|
||||
{
|
||||
return stat("null:", sb);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
common_badbuf(int (*statfunc)(struct stat *), void *ptr,
|
||||
const char *call, const char *ptrdesc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("%s with %s buf", call, ptrdesc);
|
||||
rv = statfunc(ptr);
|
||||
report_check(rv, errno, EFAULT);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
any_badbuf(int (*statfunc)(struct stat *), const char *call)
|
||||
{
|
||||
common_badbuf(statfunc, NULL, call, "NULL");
|
||||
common_badbuf(statfunc, INVAL_PTR, call, "invalid pointer");
|
||||
common_badbuf(statfunc, KERN_PTR, call, "kernel pointer");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
any_empty(int (*statfunc)(const char *, struct stat *), const char *call)
|
||||
{
|
||||
struct stat sb;
|
||||
int rv;
|
||||
|
||||
report_begin("%s on empty string", call);
|
||||
rv = statfunc("", &sb);
|
||||
report_check2(rv, errno, 0, EINVAL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
test_fstat(void)
|
||||
{
|
||||
test_fstat_fd();
|
||||
any_badbuf(badbuf_fstat, "fstat");
|
||||
}
|
||||
|
||||
void
|
||||
test_lstat(void)
|
||||
{
|
||||
test_lstat_path();
|
||||
any_empty(lstat, "lstat");
|
||||
any_badbuf(badbuf_lstat, "lstat");
|
||||
}
|
||||
|
||||
void
|
||||
test_stat(void)
|
||||
{
|
||||
test_stat_path();
|
||||
any_empty(stat, "stat");
|
||||
any_badbuf(badbuf_stat, "stat");
|
||||
}
|
||||
|
68
userland/testbin/badcall/bad_symlink.c
Normal file
68
userland/testbin/badcall/bad_symlink.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* symlink
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
symlink_empty1(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("symlink -> empty string");
|
||||
rv = symlink("", TESTLINK);
|
||||
report_check2(rv, errno, 0, EINVAL);
|
||||
remove(TESTLINK);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
symlink_empty2(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("symlink named empty string");
|
||||
rv = symlink("foo", "");
|
||||
report_check(rv, errno, EINVAL);
|
||||
}
|
||||
|
||||
void
|
||||
test_symlink(void)
|
||||
{
|
||||
test_symlink_paths();
|
||||
symlink_empty1();
|
||||
symlink_empty2();
|
||||
}
|
76
userland/testbin/badcall/bad_time.c
Normal file
76
userland/testbin/badcall/bad_time.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* __time
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
time_badsecs(void *ptr, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("%s", desc);
|
||||
rv = __time(ptr, NULL);
|
||||
report_check(rv, errno, EFAULT);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
time_badnsecs(void *ptr, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("%s", desc);
|
||||
rv = __time(NULL, ptr);
|
||||
report_check(rv, errno, EFAULT);
|
||||
}
|
||||
|
||||
void
|
||||
test_time(void)
|
||||
{
|
||||
time_badsecs(INVAL_PTR, "__time with invalid seconds pointer");
|
||||
time_badsecs(KERN_PTR, "__time with kernel seconds pointer");
|
||||
|
||||
time_badnsecs(INVAL_PTR, "__time with invalid nsecs pointer");
|
||||
time_badnsecs(KERN_PTR, "__time with kernel nsecs pointer");
|
||||
}
|
423
userland/testbin/badcall/bad_waitpid.c
Normal file
423
userland/testbin/badcall/bad_waitpid.c
Normal file
@@ -0,0 +1,423 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* bad calls to waitpid()
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
wait_badpid(pid_t pid, const char *desc)
|
||||
{
|
||||
pid_t rv;
|
||||
int x;
|
||||
int err;
|
||||
|
||||
report_begin(desc);
|
||||
rv = waitpid(pid, &x, 0);
|
||||
err = errno;
|
||||
/* Allow ENOSYS for 0 or negative values of pid only */
|
||||
if (pid <= 0 && rv == -1 && err == ENOSYS) {
|
||||
err = ESRCH;
|
||||
}
|
||||
else if (err == ENOSYS) {
|
||||
report_saw_enosys();
|
||||
}
|
||||
report_check2(rv, err, ESRCH, ECHILD);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
wait_nullstatus(void)
|
||||
{
|
||||
pid_t pid, rv;
|
||||
int x;
|
||||
|
||||
report_begin("wait with NULL status");
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
if (pid==0) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* POSIX explicitly says passing NULL for status is allowed */
|
||||
rv = waitpid(pid, NULL, 0);
|
||||
report_check(rv, errno, 0);
|
||||
waitpid(pid, &x, 0);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
wait_badstatus(void *ptr, const char *desc)
|
||||
{
|
||||
pid_t pid, rv;
|
||||
int x;
|
||||
|
||||
report_begin(desc);
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
if (pid==0) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
rv = waitpid(pid, ptr, 0);
|
||||
report_check(rv, errno, EFAULT);
|
||||
waitpid(pid, &x, 0);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
wait_unaligned(void)
|
||||
{
|
||||
pid_t pid, rv;
|
||||
int x;
|
||||
int status[2]; /* will have integer alignment */
|
||||
char *ptr;
|
||||
|
||||
report_begin("wait with unaligned status");
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
if (pid==0) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* start with proper integer alignment */
|
||||
ptr = (char *)(&status[0]);
|
||||
|
||||
/* generate improper alignment on platforms with restrictions */
|
||||
ptr++;
|
||||
|
||||
rv = waitpid(pid, (int *)ptr, 0);
|
||||
report_survival(rv, errno);
|
||||
if (rv<0) {
|
||||
waitpid(pid, &x, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
wait_badflags(void)
|
||||
{
|
||||
pid_t pid, rv;
|
||||
int x;
|
||||
|
||||
report_begin("wait with bad flags");
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
if (pid==0) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
rv = waitpid(pid, &x, 309429);
|
||||
report_check(rv, errno, EINVAL);
|
||||
waitpid(pid, &x, 0);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
wait_self(void)
|
||||
{
|
||||
pid_t rv;
|
||||
int x;
|
||||
|
||||
report_begin("wait for self");
|
||||
|
||||
rv = waitpid(getpid(), &x, 0);
|
||||
report_survival(rv, errno);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
wait_parent(void)
|
||||
{
|
||||
pid_t mypid, childpid, rv;
|
||||
int x;
|
||||
|
||||
report_begin("wait for parent");
|
||||
report_hassubs();
|
||||
|
||||
mypid = getpid();
|
||||
childpid = fork();
|
||||
if (childpid<0) {
|
||||
report_warn("can't fork");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
if (childpid==0) {
|
||||
/* Child. Wait for parent. */
|
||||
rv = waitpid(mypid, &x, 0);
|
||||
report_beginsub("from child:");
|
||||
report_survival(rv, errno);
|
||||
_exit(0);
|
||||
}
|
||||
rv = waitpid(childpid, &x, 0);
|
||||
report_beginsub("from parent:");
|
||||
report_survival(rv, errno);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
wait_siblings_child(const char *semname)
|
||||
{
|
||||
pid_t pids[2], mypid, otherpid;
|
||||
int rv, fd, semfd, x;
|
||||
char c;
|
||||
|
||||
mypid = getpid();
|
||||
|
||||
/*
|
||||
* Get our own handle for the semaphore, in case naive
|
||||
* file-level synchronization causes concurrent use to
|
||||
* deadlock.
|
||||
*/
|
||||
semfd = open(semname, O_RDONLY);
|
||||
if (semfd < 0) {
|
||||
report_warn("child process (pid %d) can't open %s",
|
||||
mypid, semname);
|
||||
}
|
||||
else {
|
||||
if (read(semfd, &c, 1) < 0) {
|
||||
report_warn("in pid %d: %s: read", mypid, semname);
|
||||
}
|
||||
close(semfd);
|
||||
}
|
||||
|
||||
fd = open(TESTFILE, O_RDONLY);
|
||||
if (fd<0) {
|
||||
report_warn("child process (pid %d) can't open %s",
|
||||
mypid, TESTFILE);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* In case the semaphore above didn't work, as a backup
|
||||
* busy-wait until the parent writes the pids into the
|
||||
* file. If the semaphore did work, this shouldn't loop.
|
||||
*/
|
||||
do {
|
||||
rv = lseek(fd, 0, SEEK_SET);
|
||||
if (rv<0) {
|
||||
report_warn("child process (pid %d) lseek error",
|
||||
mypid);
|
||||
return;
|
||||
}
|
||||
rv = read(fd, pids, sizeof(pids));
|
||||
if (rv<0) {
|
||||
report_warn("child process (pid %d) read error",
|
||||
mypid);
|
||||
return;
|
||||
}
|
||||
} while (rv < (int)sizeof(pids));
|
||||
|
||||
if (mypid==pids[0]) {
|
||||
otherpid = pids[1];
|
||||
}
|
||||
else if (mypid==pids[1]) {
|
||||
otherpid = pids[0];
|
||||
}
|
||||
else {
|
||||
report_warn("child process (pid %d) got garbage in comm file",
|
||||
mypid);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
rv = waitpid(otherpid, &x, 0);
|
||||
report_beginsub("sibling (pid %d)", mypid);
|
||||
report_survival(rv, errno);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
wait_siblings(void)
|
||||
{
|
||||
pid_t pids[2];
|
||||
int rv, fd, semfd, x;
|
||||
int bad = 0;
|
||||
char semname[32];
|
||||
|
||||
/* This test may also blow up if FS synchronization is substandard */
|
||||
|
||||
report_begin("siblings wait for each other");
|
||||
report_hassubs();
|
||||
|
||||
snprintf(semname, sizeof(semname), "sem:badcall.%d", (int)getpid());
|
||||
semfd = open(semname, O_WRONLY|O_CREAT|O_TRUNC, 0664);
|
||||
if (semfd < 0) {
|
||||
report_warn("can't make semaphore");
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
}
|
||||
|
||||
pids[0] = fork();
|
||||
if (pids[0]<0) {
|
||||
report_warn("can't fork");
|
||||
report_aborted();
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
}
|
||||
if (pids[0]==0) {
|
||||
close(fd);
|
||||
close(semfd);
|
||||
wait_siblings_child(semname);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
pids[1] = fork();
|
||||
if (pids[1]<0) {
|
||||
report_warn("can't fork");
|
||||
report_aborted();
|
||||
/* abandon the other child process :( */
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
}
|
||||
if (pids[1]==0) {
|
||||
close(fd);
|
||||
close(semfd);
|
||||
wait_siblings_child(semname);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
rv = write(fd, pids, sizeof(pids));
|
||||
if (rv < 0) {
|
||||
report_warn("write error on %s", TESTFILE);
|
||||
report_aborted();
|
||||
/* abandon child procs :( */
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
}
|
||||
if (rv != (int)sizeof(pids)) {
|
||||
report_warnx("write error on %s: short count", TESTFILE);
|
||||
report_aborted();
|
||||
/* abandon child procs :( */
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
}
|
||||
|
||||
/* gate the child procs */
|
||||
rv = write(semfd, " ", 2);
|
||||
if (rv < 0) {
|
||||
report_warn("%s: write", semname);
|
||||
bad = 1;
|
||||
}
|
||||
|
||||
report_beginsub("overall");
|
||||
rv = waitpid(pids[0], &x, 0);
|
||||
if (rv<0) {
|
||||
report_warn("error waiting for child 0 (pid %d)", pids[0]);
|
||||
bad = 1;
|
||||
}
|
||||
rv = waitpid(pids[1], &x, 0);
|
||||
if (rv<0) {
|
||||
report_warn("error waiting for child 1 (pid %d)", pids[1]);
|
||||
bad = 1;
|
||||
}
|
||||
if (bad) {
|
||||
/* XXX: aborted, or failure, or what? */
|
||||
report_aborted();
|
||||
}
|
||||
else {
|
||||
report_passed();
|
||||
}
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
remove(TESTFILE);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
test_waitpid(void)
|
||||
{
|
||||
wait_badpid(-8, "wait for pid -8");
|
||||
wait_badpid(-1, "wait for pid -1");
|
||||
wait_badpid(0, "pid zero");
|
||||
wait_badpid(NONEXIST_PID, "nonexistent pid");
|
||||
|
||||
wait_nullstatus();
|
||||
wait_badstatus(INVAL_PTR, "wait with invalid pointer status");
|
||||
wait_badstatus(KERN_PTR, "wait with kernel pointer status");
|
||||
|
||||
wait_unaligned();
|
||||
|
||||
wait_badflags();
|
||||
|
||||
wait_self();
|
||||
wait_parent();
|
||||
wait_siblings();
|
||||
}
|
41
userland/testbin/badcall/bad_write.c
Normal file
41
userland/testbin/badcall/bad_write.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Invalid calls to write()
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
void
|
||||
test_write(void)
|
||||
{
|
||||
test_write_fd();
|
||||
test_write_buf();
|
||||
}
|
219
userland/testbin/badcall/common_buf.c
Normal file
219
userland/testbin/badcall/common_buf.c
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Calls with invalid transfer buffers
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static int buf_fd;
|
||||
|
||||
struct buftest {
|
||||
int (*setup)(void);
|
||||
int (*op)(void *);
|
||||
void (*cleanup)(void);
|
||||
const char *name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
int
|
||||
read_setup(void)
|
||||
{
|
||||
buf_fd = open_testfile("i do not like green eggs and ham");
|
||||
if (buf_fd<0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
read_badbuf(void *buf)
|
||||
{
|
||||
return read(buf_fd, buf, 128);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
read_cleanup(void)
|
||||
{
|
||||
close(buf_fd);
|
||||
remove(TESTFILE);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
static
|
||||
int
|
||||
write_setup(void)
|
||||
{
|
||||
buf_fd = open_testfile(NULL);
|
||||
if (buf_fd<0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
write_badbuf(void *ptr)
|
||||
{
|
||||
return write(buf_fd, ptr, 128);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
write_cleanup(void)
|
||||
{
|
||||
close(buf_fd);
|
||||
remove(TESTFILE);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
static
|
||||
int
|
||||
getdirentry_setup(void)
|
||||
{
|
||||
buf_fd = open(".", O_RDONLY);
|
||||
if (buf_fd < 0) {
|
||||
warn("UH-OH: couldn't open .");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
getdirentry_badbuf(void *ptr)
|
||||
{
|
||||
return getdirentry(buf_fd, ptr, 1024);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
getdirentry_cleanup(void)
|
||||
{
|
||||
close(buf_fd);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
static
|
||||
int
|
||||
readlink_setup(void)
|
||||
{
|
||||
return create_testlink();
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
readlink_badbuf(void *buf)
|
||||
{
|
||||
return readlink(TESTLINK, buf, 168);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
readlink_cleanup(void)
|
||||
{
|
||||
remove(TESTLINK);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
static int getcwd_setup(void) { return 0; }
|
||||
static void getcwd_cleanup(void) {}
|
||||
|
||||
static
|
||||
int
|
||||
getcwd_badbuf(void *buf)
|
||||
{
|
||||
return __getcwd(buf, 408);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
common_badbuf(struct buftest *info, void *buf, const char *bufdesc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
|
||||
report_begin("%s with %s buffer", info->name, bufdesc);
|
||||
info->setup();
|
||||
rv = info->op(buf);
|
||||
report_check(rv, errno, EFAULT);
|
||||
info->cleanup();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
any_badbuf(struct buftest *info)
|
||||
{
|
||||
common_badbuf(info, NULL, "NULL");
|
||||
common_badbuf(info, INVAL_PTR, "invalid");
|
||||
common_badbuf(info, KERN_PTR, "kernel-space");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#define T(call) \
|
||||
void \
|
||||
test_##call##_buf(void) \
|
||||
{ \
|
||||
static struct buftest info = { \
|
||||
call##_setup, \
|
||||
call##_badbuf, \
|
||||
call##_cleanup, \
|
||||
#call, \
|
||||
}; \
|
||||
any_badbuf(&info); \
|
||||
}
|
||||
|
||||
T(read);
|
||||
T(write);
|
||||
T(getdirentry);
|
||||
T(readlink);
|
||||
T(getcwd);
|
234
userland/testbin/badcall/common_fds.c
Normal file
234
userland/testbin/badcall/common_fds.c
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Calls with invalid fds
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
|
||||
enum rwtestmodes {
|
||||
RW_TEST_NONE,
|
||||
RW_TEST_RDONLY,
|
||||
RW_TEST_WRONLY,
|
||||
};
|
||||
|
||||
static
|
||||
int
|
||||
read_badfd(int fd)
|
||||
{
|
||||
char buf[128];
|
||||
return read(fd, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
write_badfd(int fd)
|
||||
{
|
||||
char buf[128];
|
||||
memset(buf, 'a', sizeof(buf));
|
||||
return write(fd, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
int
|
||||
close_badfd(int fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
ioctl_badfd(int fd)
|
||||
{
|
||||
return ioctl(fd, 0, NULL);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
lseek_badfd(int fd)
|
||||
{
|
||||
return lseek(fd, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
fsync_badfd(int fd)
|
||||
{
|
||||
return fsync(fd);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
ftruncate_badfd(int fd)
|
||||
{
|
||||
return ftruncate(fd, 60);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
fstat_badfd(int fd)
|
||||
{
|
||||
struct stat sb;
|
||||
return fstat(fd, &sb);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
getdirentry_badfd(int fd)
|
||||
{
|
||||
char buf[32];
|
||||
return getdirentry(fd, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
dup2_badfd(int fd)
|
||||
{
|
||||
/* use the +1 to avoid doing dup2(CLOSED_FD, CLOSED_FD) */
|
||||
return dup2(fd, CLOSED_FD+1);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dup2_cleanup(void)
|
||||
{
|
||||
close(CLOSED_FD+1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
any_badfd(int (*func)(int fd), void (*cleanup)(void), const char *callname,
|
||||
int fd, const char *fddesc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("%s using %s", callname, fddesc);
|
||||
rv = func(fd);
|
||||
report_check(rv, errno, EBADF);
|
||||
if (cleanup) {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
runtest(int (*func)(int fd), void (*cleanup)(void), const char *callname,
|
||||
enum rwtestmodes rw)
|
||||
{
|
||||
int fd;
|
||||
|
||||
/*
|
||||
* If adding cases, also see bad_dup2.c
|
||||
*/
|
||||
|
||||
/* basic invalid case: fd -1 */
|
||||
any_badfd(func, cleanup, callname, -1, "fd -1");
|
||||
|
||||
/* also try -5 in case -1 is special somehow */
|
||||
any_badfd(func, cleanup, callname, -5, "fd -5");
|
||||
|
||||
/* try a fd we know is closed */
|
||||
any_badfd(func, cleanup, callname, CLOSED_FD, "closed fd");
|
||||
|
||||
/* try a positive fd we know is out of range */
|
||||
any_badfd(func, cleanup, callname, IMPOSSIBLE_FD, "impossible fd");
|
||||
|
||||
/* test for off-by-one errors */
|
||||
#ifdef OPEN_MAX
|
||||
any_badfd(func, cleanup, callname, OPEN_MAX, "fd OPEN_MAX");
|
||||
#else
|
||||
warnx("Warning: OPEN_MAX not defined, test skipped");
|
||||
#endif
|
||||
|
||||
if (rw == RW_TEST_RDONLY) {
|
||||
fd = reopen_testfile(O_RDONLY|O_CREAT);
|
||||
if (fd < 0) {
|
||||
/* already printed a message */
|
||||
}
|
||||
else {
|
||||
any_badfd(func, cleanup, callname, fd,
|
||||
"fd opened read-only");
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
if (rw == RW_TEST_WRONLY) {
|
||||
fd = reopen_testfile(O_WRONLY|O_CREAT);
|
||||
if (fd < 0) {
|
||||
/* already printed a message */
|
||||
}
|
||||
else {
|
||||
any_badfd(func, cleanup, callname, fd,
|
||||
"fd opened write-only");
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#define T(call, rw) \
|
||||
void \
|
||||
test_##call##_fd(void) \
|
||||
{ \
|
||||
runtest(call##_badfd, NULL, #call, rw); \
|
||||
}
|
||||
|
||||
#define TC(call, rw) \
|
||||
void \
|
||||
test_##call##_fd(void) \
|
||||
{ \
|
||||
runtest(call##_badfd, call##_cleanup, #call, rw);\
|
||||
}
|
||||
|
||||
T(read, RW_TEST_WRONLY);
|
||||
T(write, RW_TEST_RDONLY);
|
||||
T(close, RW_TEST_NONE);
|
||||
T(ioctl, RW_TEST_NONE);
|
||||
T(lseek, RW_TEST_NONE);
|
||||
T(fsync, RW_TEST_NONE);
|
||||
T(ftruncate, RW_TEST_RDONLY);
|
||||
T(fstat, RW_TEST_NONE);
|
||||
T(getdirentry, RW_TEST_WRONLY);
|
||||
TC(dup2, RW_TEST_NONE);
|
213
userland/testbin/badcall/common_path.c
Normal file
213
userland/testbin/badcall/common_path.c
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Calls with invalid pathnames
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
int
|
||||
open_badpath(const char *path)
|
||||
{
|
||||
return open(path, O_RDONLY);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
remove_badpath(const char *path)
|
||||
{
|
||||
return remove(path);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
rename_badpath1(const char *path)
|
||||
{
|
||||
return rename(path, TESTFILE);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
rename_badpath2(const char *path)
|
||||
{
|
||||
return rename(TESTFILE, path);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
link_badpath1(const char *path)
|
||||
{
|
||||
return link(path, TESTFILE);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
link_badpath2(const char *path)
|
||||
{
|
||||
return link(TESTFILE, path);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
mkdir_badpath(const char *path)
|
||||
{
|
||||
return mkdir(path, 0775);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
rmdir_badpath(const char *path)
|
||||
{
|
||||
return rmdir(path);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
chdir_badpath(const char *path)
|
||||
{
|
||||
return chdir(path);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
symlink_badpath1(const char *path)
|
||||
{
|
||||
return symlink(path, TESTFILE);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
symlink_badpath2(const char *path)
|
||||
{
|
||||
return symlink(TESTFILE, path);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
readlink_badpath(const char *path)
|
||||
{
|
||||
char buf[128];
|
||||
return readlink(path, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
lstat_badpath(const char *name)
|
||||
{
|
||||
struct stat sb;
|
||||
return lstat(name, &sb);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
stat_badpath(const char *name)
|
||||
{
|
||||
struct stat sb;
|
||||
return stat(name, &sb);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
common_badpath(int (*func)(const char *path), int mk, int rm, const char *path,
|
||||
const char *call, const char *pathdesc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
report_begin("%s with %s path", call, pathdesc);
|
||||
|
||||
if (mk) {
|
||||
if (create_testfile()<0) {
|
||||
report_aborted();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rv = func(path);
|
||||
report_check(rv, errno, EFAULT);
|
||||
|
||||
if (mk || rm) {
|
||||
remove(TESTFILE);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
any_badpath(int (*func)(const char *path), const char *call, int mk, int rm)
|
||||
{
|
||||
common_badpath(func, mk, rm, NULL, call, "NULL");
|
||||
common_badpath(func, mk, rm, INVAL_PTR, call, "invalid-pointer");
|
||||
common_badpath(func, mk, rm, KERN_PTR, call, "kernel-pointer");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
/* functions with one pathname */
|
||||
#define T(call) \
|
||||
void \
|
||||
test_##call##_path(void) \
|
||||
{ \
|
||||
any_badpath(call##_badpath, #call, 0, 0); \
|
||||
}
|
||||
|
||||
T(open);
|
||||
T(remove);
|
||||
T(mkdir);
|
||||
T(rmdir);
|
||||
T(chdir);
|
||||
T(readlink);
|
||||
T(stat);
|
||||
T(lstat);
|
||||
|
||||
/* functions with two pathnames */
|
||||
#define T2(call) \
|
||||
void \
|
||||
test_##call##_paths(void) \
|
||||
{ \
|
||||
any_badpath(call##_badpath1, #call "(arg1)", 0, 1); \
|
||||
any_badpath(call##_badpath2, #call "(arg2)", 1, 1); \
|
||||
}
|
||||
|
||||
T2(rename);
|
||||
T2(link);
|
||||
T2(symlink);
|
60
userland/testbin/badcall/config.h
Normal file
60
userland/testbin/badcall/config.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Note: if the assumptions in the constants below are violated by
|
||||
* your system design, please change the values as necessary. Don't
|
||||
* change stuff in the .c files, or disable tests, without consulting
|
||||
* the course staff first.
|
||||
*/
|
||||
|
||||
#if defined(__mips__)
|
||||
#define KERN_PTR ((void *)0x80000000) /* addr within kernel */
|
||||
#define INVAL_PTR ((void *)0x40000000) /* addr not part of program */
|
||||
#else
|
||||
#error "Please fix this"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We assume CLOSED_FD is a legal fd that won't be open when we're running.
|
||||
* CLOSED_FD+1 should also be legal and not open.
|
||||
*/
|
||||
#define CLOSED_FD 10
|
||||
|
||||
/* We assume IMPOSSIBLE_FD is a fd that is completely not allowed. */
|
||||
#define IMPOSSIBLE_FD 1234567890
|
||||
|
||||
/* We assume this pid won't exist while we're running. Change as needed. */
|
||||
#define NONEXIST_PID 34000
|
||||
|
||||
/* An arbitrary process exit code that hopefully won't occur by accident */
|
||||
#define MAGIC_STATUS 107
|
||||
|
||||
/* An ioctl that doesn't exist */
|
||||
#define NONEXIST_IOCTL 12345
|
289
userland/testbin/badcall/driver.c
Normal file
289
userland/testbin/badcall/driver.c
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
open_testfile(const char *string)
|
||||
{
|
||||
int fd, rv;
|
||||
size_t len;
|
||||
|
||||
fd = open(TESTFILE, O_RDWR|O_CREAT|O_TRUNC, 0664);
|
||||
if (fd<0) {
|
||||
report_warn("creating %s: failed", TESTFILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (string) {
|
||||
len = strlen(string);
|
||||
rv = write(fd, string, len);
|
||||
if (rv<0) {
|
||||
report_warn("write to %s failed", TESTFILE);
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
return -1;
|
||||
}
|
||||
if ((unsigned)rv != len) {
|
||||
report_warn("write to %s got short count", TESTFILE);
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
return -1;
|
||||
}
|
||||
rv = lseek(fd, 0, SEEK_SET);
|
||||
if (rv<0) {
|
||||
report_warn("rewind of %s failed", TESTFILE);
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
create_testfile(void)
|
||||
{
|
||||
int fd, rv;
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = close(fd);
|
||||
if (rv<0) {
|
||||
report_warn("closing %s failed", TESTFILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
reopen_testfile(int openflags)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(TESTFILE, openflags, 0664);
|
||||
if (fd < 0) {
|
||||
report_warn("reopening %s: failed", TESTFILE);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note: unlike everything else this calls skipped/aborted, because
|
||||
* otherwise it has to communicate to the caller which to call and
|
||||
* that's a pain.
|
||||
*/
|
||||
int
|
||||
create_testdir(void)
|
||||
{
|
||||
int rv;
|
||||
rv = mkdir(TESTDIR, 0775);
|
||||
if (rv<0) {
|
||||
if (errno == ENOSYS) {
|
||||
report_saw_enosys();
|
||||
report_warnx("mkdir unimplemented; cannot run test");
|
||||
report_skipped();
|
||||
}
|
||||
else {
|
||||
report_warn("mkdir %s failed", TESTDIR);
|
||||
report_aborted();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
create_testlink(void)
|
||||
{
|
||||
int rv;
|
||||
rv = symlink("blahblah", TESTLINK);
|
||||
if (rv<0) {
|
||||
report_warn("making symlink %s failed", TESTLINK);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
struct {
|
||||
int ch;
|
||||
int asst;
|
||||
const char *name;
|
||||
void (*f)(void);
|
||||
} ops[] = {
|
||||
{ 'a', 2, "execv", test_execv },
|
||||
{ 'b', 2, "waitpid", test_waitpid },
|
||||
{ 'c', 2, "open", test_open },
|
||||
{ 'd', 2, "read", test_read },
|
||||
{ 'e', 2, "write", test_write },
|
||||
{ 'f', 2, "close", test_close },
|
||||
{ 'g', 0, "reboot", test_reboot },
|
||||
{ 'h', 3, "sbrk", test_sbrk },
|
||||
{ 'i', 5, "ioctl", test_ioctl },
|
||||
{ 'j', 2, "lseek", test_lseek },
|
||||
{ 'k', 4, "fsync", test_fsync },
|
||||
{ 'l', 4, "ftruncate", test_ftruncate },
|
||||
{ 'm', 4, "fstat", test_fstat },
|
||||
{ 'n', 4, "remove", test_remove },
|
||||
{ 'o', 4, "rename", test_rename },
|
||||
{ 'p', 5, "link", test_link },
|
||||
{ 'q', 4, "mkdir", test_mkdir },
|
||||
{ 'r', 4, "rmdir", test_rmdir },
|
||||
{ 's', 2, "chdir", test_chdir },
|
||||
{ 't', 4, "getdirentry", test_getdirentry },
|
||||
{ 'u', 5, "symlink", test_symlink },
|
||||
{ 'v', 5, "readlink", test_readlink },
|
||||
{ 'w', 2, "dup2", test_dup2 },
|
||||
{ 'x', 5, "pipe", test_pipe },
|
||||
{ 'y', 5, "__time", test_time },
|
||||
{ 'z', 2, "__getcwd", test_getcwd },
|
||||
{ '{', 5, "stat", test_stat },
|
||||
{ '|', 5, "lstat", test_lstat },
|
||||
{ 0, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
#define LOWEST 'a'
|
||||
#define HIGHEST '|'
|
||||
|
||||
static
|
||||
void
|
||||
menu(void)
|
||||
{
|
||||
int i;
|
||||
for (i=0; ops[i].name; i++) {
|
||||
printf("[%c] %-24s", ops[i].ch, ops[i].name);
|
||||
if (i%2==1) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
if (i%2==1) {
|
||||
printf("\n");
|
||||
}
|
||||
printf("[1] %-24s", "asst1");
|
||||
printf("[2] %-24s\n", "asst2");
|
||||
printf("[3] %-24s", "asst3");
|
||||
printf("[4] %-24s\n", "asst4");
|
||||
printf("[*] %-24s", "all");
|
||||
printf("[!] %-24s\n", "quit");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
runit(int op)
|
||||
{
|
||||
int i, k;
|
||||
|
||||
if (op=='!') {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (op=='?') {
|
||||
menu();
|
||||
return;
|
||||
}
|
||||
|
||||
if (op=='*') {
|
||||
for (i=0; ops[i].name; i++) {
|
||||
printf("[%s]\n", ops[i].name);
|
||||
ops[i].f();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (op>='1' && op <= '4') {
|
||||
k = op-'0';
|
||||
for (i=0; ops[i].name; i++) {
|
||||
if (ops[i].asst <= k) {
|
||||
printf("[%s]\n", ops[i].name);
|
||||
ops[i].f();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (op < LOWEST || op > HIGHEST) {
|
||||
printf("Invalid request %c\n", op);
|
||||
return;
|
||||
}
|
||||
|
||||
ops[op-'a'].f();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int op, i, j;
|
||||
|
||||
printf("[%c-%c, 1-4, *, ?=menu, !=quit]\n", LOWEST, HIGHEST);
|
||||
|
||||
if (argc > 1) {
|
||||
for (i=1; i<argc; i++) {
|
||||
for (j=0; argv[i][j]; j++) {
|
||||
printf("Choose: %c\n",
|
||||
argv[i][j]);
|
||||
runit(argv[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
menu();
|
||||
while (1) {
|
||||
printf("Choose: ");
|
||||
op = getchar();
|
||||
if (op==EOF) {
|
||||
break;
|
||||
}
|
||||
printf("%c\n", op);
|
||||
runit(op);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
350
userland/testbin/badcall/report.c
Normal file
350
userland/testbin/badcall/report.c
Normal file
@@ -0,0 +1,350 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2015
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "test.h"
|
||||
|
||||
#define RESULT_COLUMN 72
|
||||
|
||||
/* current screen column (0-based) */
|
||||
static size_t horizpos;
|
||||
|
||||
/* saved screen column for subreports */
|
||||
static size_t subpos;
|
||||
|
||||
/* pending output buffer */
|
||||
static char outbuf[256];
|
||||
static size_t outbufpos;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Print things.
|
||||
*/
|
||||
static
|
||||
void
|
||||
vsay(const char *fmt, va_list ap)
|
||||
{
|
||||
size_t begin, i;
|
||||
|
||||
assert(outbufpos < sizeof(outbuf));
|
||||
|
||||
begin = outbufpos;
|
||||
vsnprintf(outbuf + outbufpos, sizeof(outbuf) - outbufpos, fmt, ap);
|
||||
outbufpos = strlen(outbuf);
|
||||
|
||||
for (i=begin; i<outbufpos; i++) {
|
||||
if (outbuf[i] == '\n') {
|
||||
horizpos = 0;
|
||||
}
|
||||
else {
|
||||
horizpos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
say(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsay(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
* Indent to a given horizontal position.
|
||||
*/
|
||||
static
|
||||
void
|
||||
indent_to(size_t pos)
|
||||
{
|
||||
while (horizpos < pos) {
|
||||
assert(outbufpos < sizeof(outbuf) - 1);
|
||||
outbuf[outbufpos++] = ' ';
|
||||
outbuf[outbufpos] = 0;
|
||||
horizpos++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush the output.
|
||||
*/
|
||||
static
|
||||
void
|
||||
flush(void)
|
||||
{
|
||||
write(STDOUT_FILENO, outbuf, outbufpos);
|
||||
outbufpos = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Begin a test. This flushes the description so it can be seen before
|
||||
* the test happens, in case the test explodes or deadlocks the system.
|
||||
*/
|
||||
void
|
||||
report_begin(const char *descfmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
say("badcall: ");
|
||||
va_start(ap, descfmt);
|
||||
vsay(descfmt, ap);
|
||||
va_end(ap);
|
||||
say("... ");
|
||||
flush();
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare to be able to print subreports.
|
||||
*/
|
||||
void
|
||||
report_hassubs(void)
|
||||
{
|
||||
subpos = horizpos;
|
||||
say("\n");
|
||||
flush();
|
||||
}
|
||||
|
||||
/*
|
||||
* Begin a subreport. This does *not* flush because sometimes the
|
||||
* subreports are in subprocesses and we want each one to print a
|
||||
* whole line at once to avoid output interleaving.
|
||||
*/
|
||||
void
|
||||
report_beginsub(const char *descfmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
assert(horizpos == 0);
|
||||
say(" ");
|
||||
va_start(ap, descfmt);
|
||||
vsay(descfmt, ap);
|
||||
va_end(ap);
|
||||
indent_to(subpos);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print a warning message (when within a test). This generates an
|
||||
* extra line for the warning. The warnx form is the same but doesn't
|
||||
* add errno.
|
||||
*/
|
||||
void
|
||||
report_warn(const char *fmt, ...)
|
||||
{
|
||||
size_t pos;
|
||||
const char *errmsg;
|
||||
va_list ap;
|
||||
|
||||
pos = horizpos;
|
||||
errmsg = strerror(errno);
|
||||
say("\n OOPS: ");
|
||||
va_start(ap, fmt);
|
||||
vsay(fmt, ap);
|
||||
va_end(ap);
|
||||
say(": %s\n", errmsg);
|
||||
indent_to(pos);
|
||||
flush();
|
||||
}
|
||||
|
||||
void
|
||||
report_warnx(const char *fmt, ...)
|
||||
{
|
||||
size_t pos;
|
||||
va_list ap;
|
||||
|
||||
pos = horizpos;
|
||||
say("\n oops: ");
|
||||
va_start(ap, fmt);
|
||||
vsay(fmt, ap);
|
||||
va_end(ap);
|
||||
say("\n");
|
||||
indent_to(pos);
|
||||
flush();
|
||||
}
|
||||
|
||||
/*
|
||||
* Report a system call result.
|
||||
*/
|
||||
void
|
||||
report_result(int rv, int error)
|
||||
{
|
||||
if (rv == -1) {
|
||||
say("%s ", strerror(error));
|
||||
}
|
||||
else {
|
||||
say("Success ");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Deal with ENOSYS. The kernel prints "Unknown syscall NN\n" if you
|
||||
* call a system call that the system call dispatcher doesn't know
|
||||
* about. This is not the only way to get ENOSYS, but it's the most
|
||||
* common. So, if we see ENOSYS assume that the kernel's injected a
|
||||
* newline.
|
||||
*
|
||||
* XXX this is pretty gross.
|
||||
*/
|
||||
void
|
||||
report_saw_enosys(void)
|
||||
{
|
||||
size_t pos = horizpos;
|
||||
|
||||
horizpos = 0;
|
||||
indent_to(pos);
|
||||
}
|
||||
|
||||
/*
|
||||
* End a test. These print "passed", "FAILURE", "------", or "ABORTED"
|
||||
* in the result column, and add the final newline.
|
||||
*/
|
||||
|
||||
static
|
||||
void
|
||||
report_end(const char *msg)
|
||||
{
|
||||
indent_to(RESULT_COLUMN);
|
||||
say("%s\n", msg);
|
||||
flush();
|
||||
}
|
||||
|
||||
void
|
||||
report_passed(void)
|
||||
{
|
||||
report_end("passed");
|
||||
}
|
||||
|
||||
void
|
||||
report_failure(void)
|
||||
{
|
||||
report_end("FAILURE");
|
||||
}
|
||||
|
||||
void
|
||||
report_skipped(void)
|
||||
{
|
||||
report_end("------");
|
||||
}
|
||||
|
||||
void
|
||||
report_aborted(void)
|
||||
{
|
||||
report_end("ABORTED");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Combination functions that call report_result and also
|
||||
* end the test, judging success based on whether the result
|
||||
* matches one or more expected results.
|
||||
*/
|
||||
|
||||
void
|
||||
report_survival(int rv, int error)
|
||||
{
|
||||
/* allow any error as long as we survive */
|
||||
report_result(rv, error);
|
||||
report_passed();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
report_checkN(int rv, int error, int *right_errors, int right_num)
|
||||
{
|
||||
int i, goterror;
|
||||
|
||||
if (rv==-1) {
|
||||
goterror = error;
|
||||
}
|
||||
else {
|
||||
goterror = 0;
|
||||
}
|
||||
|
||||
for (i=0; i<right_num; i++) {
|
||||
if (goterror == right_errors[i]) {
|
||||
report_result(rv, error);
|
||||
report_passed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (goterror == ENOSYS) {
|
||||
report_saw_enosys();
|
||||
say("(unimplemented) ");
|
||||
report_skipped();
|
||||
}
|
||||
else {
|
||||
report_result(rv, error);
|
||||
report_failure();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
report_check(int rv, int error, int right_error)
|
||||
{
|
||||
report_checkN(rv, error, &right_error, 1);
|
||||
}
|
||||
|
||||
void
|
||||
report_check2(int rv, int error, int okerr1, int okerr2)
|
||||
{
|
||||
int ok[2];
|
||||
|
||||
ok[0] = okerr1;
|
||||
ok[1] = okerr2;
|
||||
report_checkN(rv, error, ok, 2);
|
||||
}
|
||||
|
||||
void
|
||||
report_check3(int rv, int error, int okerr1, int okerr2, int okerr3)
|
||||
{
|
||||
int ok[3];
|
||||
|
||||
ok[0] = okerr1;
|
||||
ok[1] = okerr2;
|
||||
ok[2] = okerr3;
|
||||
report_checkN(rv, error, ok, 3);
|
||||
}
|
124
userland/testbin/badcall/test.h
Normal file
124
userland/testbin/badcall/test.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define TESTFILE "badcallfile"
|
||||
#define TESTDIR "badcalldir"
|
||||
#define TESTLINK "badcalllink"
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
#define PF(a, b) __attribute__((__format__(__printf__, a, b)))
|
||||
#else
|
||||
#define PF(a, b)
|
||||
#endif
|
||||
|
||||
/* driver.c */
|
||||
int open_testfile(const char *str);
|
||||
int reopen_testfile(int openflags);
|
||||
int create_testfile(void);
|
||||
int create_testdir(void);
|
||||
int create_testlink(void);
|
||||
|
||||
/* report.c */
|
||||
PF(1, 2) void report_begin(const char *descfmt, ...);
|
||||
void report_hassubs(void);
|
||||
PF(1, 2) void report_beginsub(const char *descfmt, ...);
|
||||
PF(1, 2) void report_warn(const char *fmt, ...);
|
||||
PF(1, 2) void report_warnx(const char *fmt, ...);
|
||||
void report_result(int rv, int error);
|
||||
void report_saw_enosys(void);
|
||||
void report_passed(void);
|
||||
void report_failure(void);
|
||||
void report_skipped(void);
|
||||
void report_aborted(void);
|
||||
void report_survival(int rv, int error);
|
||||
void report_check(int rv, int error, int right_error);
|
||||
void report_check2(int rv, int error, int okerr1, int okerr2);
|
||||
void report_check3(int rv, int error, int okerr1, int okerr2, int okerr3);
|
||||
|
||||
/* common_buf.c */
|
||||
void test_read_buf(void);
|
||||
void test_write_buf(void);
|
||||
void test_getdirentry_buf(void);
|
||||
void test_getcwd_buf(void);
|
||||
void test_readlink_buf(void);
|
||||
|
||||
/* common_fds.c */
|
||||
void test_read_fd(void);
|
||||
void test_write_fd(void);
|
||||
void test_close_fd(void);
|
||||
void test_ioctl_fd(void);
|
||||
void test_lseek_fd(void);
|
||||
void test_fsync_fd(void);
|
||||
void test_ftruncate_fd(void);
|
||||
void test_fstat_fd(void);
|
||||
void test_getdirentry_fd(void);
|
||||
void test_dup2_fd(void);
|
||||
|
||||
/* common_path.c */
|
||||
void test_open_path(void);
|
||||
void test_remove_path(void);
|
||||
void test_rename_paths(void);
|
||||
void test_link_paths(void);
|
||||
void test_mkdir_path(void);
|
||||
void test_rmdir_path(void);
|
||||
void test_chdir_path(void);
|
||||
void test_symlink_paths(void);
|
||||
void test_readlink_path(void);
|
||||
void test_stat_path(void);
|
||||
void test_lstat_path(void);
|
||||
|
||||
/* bad_*.c */
|
||||
void test_execv(void);
|
||||
void test_waitpid(void);
|
||||
void test_open(void);
|
||||
void test_read(void);
|
||||
void test_write(void);
|
||||
void test_close(void);
|
||||
void test_reboot(void);
|
||||
void test_sbrk(void);
|
||||
void test_ioctl(void);
|
||||
void test_lseek(void);
|
||||
void test_fsync(void);
|
||||
void test_ftruncate(void);
|
||||
void test_fstat(void); /* in bad_stat.c */
|
||||
void test_remove(void);
|
||||
void test_rename(void);
|
||||
void test_link(void);
|
||||
void test_mkdir(void);
|
||||
void test_rmdir(void);
|
||||
void test_chdir(void);
|
||||
void test_getdirentry(void);
|
||||
void test_symlink(void);
|
||||
void test_readlink(void);
|
||||
void test_dup2(void);
|
||||
void test_pipe(void);
|
||||
void test_time(void);
|
||||
void test_getcwd(void);
|
||||
void test_stat(void);
|
||||
void test_lstat(void); /* in bad_stat.c */
|
11
userland/testbin/bigexec/Makefile
Normal file
11
userland/testbin/bigexec/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for bigexec
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=bigexec
|
||||
SRCS=bigexec.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
387
userland/testbin/bigexec/bigexec.c
Normal file
387
userland/testbin/bigexec/bigexec.c
Normal file
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* Copyright (c) 2011
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* bigexec.c
|
||||
*
|
||||
* Checks that argv passing works and is not restricted to an
|
||||
* unreasonably small size.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
|
||||
#define _PATH_MYSELF "/testbin/bigexec"
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// words
|
||||
|
||||
static const char word8[] = "Dalemark";
|
||||
static char word4050[4051];
|
||||
static char word16320[16321];
|
||||
static char word65500[65501];
|
||||
|
||||
static
|
||||
void
|
||||
fill(char *buf, size_t buflen)
|
||||
{
|
||||
static const char *const names[22] = {
|
||||
"Alhammitt", "Biffa", "Cennoreth", "Dastgandlen", "Enblith",
|
||||
"Fenna", "Gull", "Hern", "Hildrida", "Kankredin", "Kialan",
|
||||
"Lenina", "Manaliabrid", "Mayelbridwen", "Noreth", "Osfameron",
|
||||
"Robin", "Tanamil", "Tanamoril", "Tanaqui", "Ynen", "Ynynen"
|
||||
};
|
||||
|
||||
const char *name;
|
||||
size_t len;
|
||||
|
||||
while (buflen > 4) {
|
||||
name = names[random()%22];
|
||||
len = strlen(name);
|
||||
if (len < buflen) {
|
||||
strcpy(buf, name);
|
||||
buf += len;
|
||||
buflen -= len;
|
||||
if (buflen > 1) {
|
||||
*buf = ' ';
|
||||
buf++;
|
||||
buflen--;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (buflen > 1) {
|
||||
*buf = '.';
|
||||
buf++;
|
||||
buflen--;
|
||||
}
|
||||
*buf = 0;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
prepwords(void)
|
||||
{
|
||||
srandom(16581);
|
||||
fill(word4050, sizeof(word4050));
|
||||
fill(word16320, sizeof(word16320));
|
||||
fill(word65500, sizeof(word65500));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// execing/checking
|
||||
|
||||
static
|
||||
void
|
||||
try(const char *first, ...)
|
||||
{
|
||||
const char *args[20];
|
||||
const char *s;
|
||||
va_list ap;
|
||||
int num;
|
||||
|
||||
assert(first != NULL);
|
||||
args[0] = _PATH_MYSELF;
|
||||
args[1] = first;
|
||||
num = 2;
|
||||
|
||||
va_start(ap, first);
|
||||
while (1) {
|
||||
s = va_arg(ap, const char *);
|
||||
if (s == NULL) {
|
||||
break;
|
||||
}
|
||||
assert(num < 20);
|
||||
args[num++] = s;
|
||||
}
|
||||
assert(num < 20);
|
||||
args[num] = NULL;
|
||||
execv(_PATH_MYSELF, (char **)args);
|
||||
err(1, "execv");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
trymany(int num, const char *word)
|
||||
{
|
||||
const char *args[num+2];
|
||||
int i;
|
||||
|
||||
args[0] = _PATH_MYSELF;
|
||||
for (i=0; i<num; i++) {
|
||||
args[i+1] = word;
|
||||
}
|
||||
args[num+1] = NULL;
|
||||
execv(_PATH_MYSELF, (char **)args);
|
||||
err(1, "execv");
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
check(int argc, char *argv[], const char *first, ...)
|
||||
{
|
||||
const char *s;
|
||||
va_list ap;
|
||||
int pos;
|
||||
|
||||
pos = 1;
|
||||
va_start(ap, first);
|
||||
s = first;
|
||||
while (s != NULL) {
|
||||
if (pos == argc) {
|
||||
/* not enough args */
|
||||
return 0;
|
||||
}
|
||||
assert(pos < argc);
|
||||
if (argv[pos] == NULL) {
|
||||
/* woops */
|
||||
warnx("argv[%d] is null but argc is %d", pos, argc);
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(argv[pos], s) != 0) {
|
||||
/* does not match */
|
||||
return 0;
|
||||
}
|
||||
s = va_arg(ap, const char *);
|
||||
pos++;
|
||||
}
|
||||
if (pos != argc) {
|
||||
/* too many args */
|
||||
return 0;
|
||||
}
|
||||
if (argv[pos] != NULL) {
|
||||
warnx("argv[argc] is not null");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
checkmany(int argc, char *argv[], int num, const char *word)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (argc != num + 1) {
|
||||
/* wrong number of args */
|
||||
return 0;
|
||||
}
|
||||
for (i=1; i<argc; i++) {
|
||||
if (strcmp(argv[i], word) != 0) {
|
||||
/* doesn't match */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// test driver
|
||||
|
||||
static
|
||||
void
|
||||
dumpargs(int argc, char *argv[])
|
||||
{
|
||||
const char *s;
|
||||
int i;
|
||||
|
||||
warnx("%d args", argc);
|
||||
warnx("argv[0]: %s", argv[0]);
|
||||
for (i=1; i<=argc; i++) {
|
||||
s = argv[i];
|
||||
if (s == NULL) {
|
||||
warnx("argv[%d]: is null", i);
|
||||
}
|
||||
else if (!strcmp(s, word8)) {
|
||||
warnx("argv[%d] is word8", i);
|
||||
}
|
||||
else if (!strcmp(s, word4050)) {
|
||||
warnx("argv[%d] is word4050", i);
|
||||
}
|
||||
else if (!strcmp(s, word16320)) {
|
||||
warnx("argv[%d] is word16320", i);
|
||||
}
|
||||
else if (!strcmp(s, word65500)) {
|
||||
warnx("argv[%d] is word65500", i);
|
||||
}
|
||||
else if (strlen(s) < 72) {
|
||||
warnx("argv[%d]: %s", i, s);
|
||||
}
|
||||
else {
|
||||
warnx("argv[%d] is %zu bytes, begins %.64s",
|
||||
i, strlen(s), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 0) {
|
||||
err(1, "argc is negative!?");
|
||||
}
|
||||
|
||||
prepwords();
|
||||
assert(strlen(word8) == 8);
|
||||
assert(strlen(word4050) == 4050);
|
||||
assert(strlen(word16320) == 16320);
|
||||
assert(strlen(word65500) == 65500);
|
||||
|
||||
assert(ARG_MAX >= 65536);
|
||||
|
||||
if (argv == NULL || argc == 0 || argc == 1) {
|
||||
/* no args -- start the test */
|
||||
warnx("Starting.");
|
||||
|
||||
/*
|
||||
* 1. Should always fit no matter what.
|
||||
*/
|
||||
warnx("1. Execing with one 8-letter word.");
|
||||
try(word8, NULL);
|
||||
}
|
||||
else if (check(argc, argv, word8, NULL)) {
|
||||
/*
|
||||
* 2. Fits in one page.
|
||||
*/
|
||||
warnx("2. Execing with one 4050-letter word.");
|
||||
try(word4050, NULL);
|
||||
}
|
||||
else if (check(argc, argv, word4050, NULL)) {
|
||||
/*
|
||||
* 3. Requires two pages but each word fits on a page.
|
||||
*/
|
||||
warnx("3. Execing with two 4050-letter words.");
|
||||
try(word4050, word4050, NULL);
|
||||
}
|
||||
else if (check(argc, argv, word4050, word4050, NULL)) {
|
||||
/*
|
||||
* 4. Requires the full 64K argv buffer, in large
|
||||
* chunks, with a little space for slop. Each word
|
||||
* fits on a page though. With null terminators and
|
||||
* 4-byte pointers the size is 4085*16 = 65360, and
|
||||
* with 8-byte pointers it would become 65424.
|
||||
*
|
||||
* Don't forget that argv[0] will be another 21 or 25
|
||||
* bytes and some implementations may reasonably need
|
||||
* to stash an ending NULL in the buffer too.
|
||||
*/
|
||||
warnx("4. Execing with 16 4050-letter words.");
|
||||
try(word4050, word4050, word4050, word4050,
|
||||
word4050, word4050, word4050, word4050,
|
||||
word4050, word4050, word4050, word4050,
|
||||
word4050, word4050, word4050, word4050,
|
||||
NULL);
|
||||
}
|
||||
else if (check(argc, argv,
|
||||
word4050, word4050, word4050, word4050,
|
||||
word4050, word4050, word4050, word4050,
|
||||
word4050, word4050, word4050, word4050,
|
||||
word4050, word4050, word4050, word4050,
|
||||
NULL)) {
|
||||
/*
|
||||
* 5. Requires more than one page for a single word.
|
||||
*/
|
||||
warnx("5. Execing with one 16320-letter word.");
|
||||
try(word16320, NULL);
|
||||
}
|
||||
else if (check(argc, argv, word16320, NULL)) {
|
||||
/*
|
||||
* 6. Ditto but makes sure it works with two of them.
|
||||
*/
|
||||
warnx("6. Execing with two 16320-letter words.");
|
||||
try(word16320, word16320, NULL);
|
||||
}
|
||||
else if (check(argc, argv, word16320, word16320, NULL)) {
|
||||
/*
|
||||
* 7. Requires the full 64K argv buffer.
|
||||
*/
|
||||
warnx("7. Execing with four 16320-letter words.");
|
||||
try(word16320, word16320, word16320, word16320,
|
||||
NULL);
|
||||
}
|
||||
else if (check(argc, argv, word16320, word16320,
|
||||
word16320, word16320, NULL)) {
|
||||
/*
|
||||
* 8. Also requires the full 64K argv buffer, but with
|
||||
* only one huge word.
|
||||
*/
|
||||
warnx("8. Execing with one 65500-letter word.");
|
||||
try(word65500, NULL);
|
||||
}
|
||||
else if (check(argc, argv, word65500, NULL)) {
|
||||
/*
|
||||
* 9. This fits on one page. Given 4-byte pointers,
|
||||
* (8+1+4)*300 = 3900. With 8-byte pointers, it
|
||||
* doesn't, but we aren't doing that. (Update this if
|
||||
* we ever move to a 64-bit platform.)
|
||||
*/
|
||||
assert((8+1+sizeof(char *))*300 < 4096);
|
||||
warnx("9. Execing with 300 8-letter words.");
|
||||
trymany(300, word8);
|
||||
}
|
||||
else if (checkmany(argc, argv, 300, word8)) {
|
||||
#if 1 /* enforce the full size */
|
||||
/*
|
||||
* 10. This requires the full 64K argv buffer.
|
||||
* With 4-byte pointers, (8+1+4)*5020 = 65260.
|
||||
* It also doesn't fit with 8-byte pointers.
|
||||
*
|
||||
* XXX for the time being, we'll allow less efficient
|
||||
* implementations that use two pointers per word.
|
||||
* Hence, (8+1+4+4)*3850 = 65450.
|
||||
*/
|
||||
assert((8+1+sizeof(char *))*5020 < 65536);
|
||||
assert((8+1+2*sizeof(char *))*3850 < 65536);
|
||||
warnx("10. Execing with 3850 8-letter words.");
|
||||
trymany(3850, word8);
|
||||
}
|
||||
else if (checkmany(argc, argv, 3850, word8)) {
|
||||
#else
|
||||
/*
|
||||
* 10a. This requires more than one page using small
|
||||
* words. With 4-byte pointers, (8+1+4)*1000 = 13000.
|
||||
*/
|
||||
warnx("10. Execing with 1000 8-letter words.");
|
||||
trymany(1000, word8);
|
||||
}
|
||||
else if (checkmany(argc, argv, 1000, word8)) {
|
||||
#endif
|
||||
warnx("Complete.");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
warnx("Received unknown/unexpected args:");
|
||||
dumpargs(argc, argv);
|
||||
return 1;
|
||||
}
|
||||
}
|
11
userland/testbin/bigfile/Makefile
Normal file
11
userland/testbin/bigfile/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for bigfile
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=bigfile
|
||||
SRCS=bigfile.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
107
userland/testbin/bigfile/bigfile.c
Normal file
107
userland/testbin/bigfile/bigfile.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create a large file in small increments.
|
||||
*
|
||||
* Should work on emufs (emu0:) once the basic system calls are done,
|
||||
* and should work on SFS when the file system assignment is
|
||||
* done. Sufficiently small files should work on SFS even before that
|
||||
* assignment.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
static char buffer[8192 + 1];
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *filename;
|
||||
char *s;
|
||||
size_t i, size, chunksize, offset;
|
||||
ssize_t len;
|
||||
int fd;
|
||||
|
||||
if (argc != 3) {
|
||||
warnx("Usage: bigfile <filename> <size>");
|
||||
errx(1, " or: bigfile <filename> <size>/<chunksize>");
|
||||
}
|
||||
|
||||
filename = argv[1];
|
||||
s = strchr(argv[2], '/');
|
||||
if (s != NULL) {
|
||||
*s++ = 0;
|
||||
chunksize = atoi(s);
|
||||
if (chunksize >= sizeof(buffer)) {
|
||||
chunksize = sizeof(buffer) - 1;
|
||||
}
|
||||
if (chunksize == 0) {
|
||||
errx(1, "Really?");
|
||||
}
|
||||
}
|
||||
else {
|
||||
chunksize = 10;
|
||||
}
|
||||
size = atoi(argv[2]);
|
||||
|
||||
/* round size up */
|
||||
size = ((size + chunksize - 1) / chunksize) * chunksize;
|
||||
|
||||
printf("Creating a file of size %d in %d-byte chunks\n",
|
||||
size, chunksize);
|
||||
|
||||
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC);
|
||||
if (fd < 0) {
|
||||
err(1, "%s: create", filename);
|
||||
}
|
||||
|
||||
i=0;
|
||||
while (i<size) {
|
||||
snprintf(buffer, sizeof(buffer), "%d\n", i);
|
||||
if (strlen(buffer) < chunksize) {
|
||||
offset = chunksize - strlen(buffer);
|
||||
memmove(buffer + offset, buffer, strlen(buffer)+1);
|
||||
memset(buffer, ' ', offset);
|
||||
}
|
||||
len = write(fd, buffer, strlen(buffer));
|
||||
if (len<0) {
|
||||
err(1, "%s: write", filename);
|
||||
}
|
||||
i += len;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
11
userland/testbin/bigfork/Makefile
Normal file
11
userland/testbin/bigfork/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for bigfork
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=bigfork
|
||||
SRCS=bigfork.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
239
userland/testbin/bigfork/bigfork.c
Normal file
239
userland/testbin/bigfork/bigfork.c
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (c) 2015
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* bigfork - concurrent VM test that behaves somewhat better than
|
||||
* parallelvm.
|
||||
*
|
||||
* This test is a mixture of forktest and parallelvm: it does nested
|
||||
* forks like forktest, and aimless matrix operations like parallelvm;
|
||||
* the goal is to serve as a performance benchmark more than as a
|
||||
* stress test (though it can be that too) and in particular to
|
||||
* exhibit less timing variance than parallelvm does. The variance is
|
||||
* still fairly high, but the variance of parallelvm is horrific.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
#define BRANCHES 6
|
||||
|
||||
/*
|
||||
* 6 branches gives 64 procs at the final stage, and we want this to
|
||||
* use about 4M. So each proc's memory load should be about 1/16M or
|
||||
* 64K. Which is 16384 ints, or four 64x64 matrixes.
|
||||
*/
|
||||
#define DIM 64
|
||||
|
||||
static int m1[DIM*DIM], m2[DIM*DIM], m3[DIM*DIM], m4[DIM*DIM];
|
||||
static const int right[BRANCHES] = {
|
||||
536763422,
|
||||
478946723,
|
||||
375722852,
|
||||
369910585,
|
||||
328220902,
|
||||
62977821,
|
||||
};
|
||||
static unsigned failures;
|
||||
|
||||
static
|
||||
void
|
||||
init(void)
|
||||
{
|
||||
unsigned i, j;
|
||||
|
||||
srandom(73771);
|
||||
for (i=0; i<DIM; i++) {
|
||||
for (j=0; j<DIM; j++) {
|
||||
m1[i*DIM+j] = random() % 11 - 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
add(int *x, const int *a, const int *b)
|
||||
{
|
||||
unsigned i, j;
|
||||
|
||||
for (i=0; i<DIM; i++) {
|
||||
for (j=0; j<DIM; j++) {
|
||||
x[i*DIM+j] = a[i*DIM+j] + b[i*DIM+j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mul(int *x, const int *a, const int *b)
|
||||
{
|
||||
unsigned i, j, k;
|
||||
|
||||
for (i=0; i<DIM; i++) {
|
||||
for (j=0; j<DIM; j++) {
|
||||
x[i*DIM+j] = 0;
|
||||
for (k=0; k<DIM; k++) {
|
||||
x[i*DIM+j] += a[i*DIM+k] * b[k*DIM+j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
scale(int *x, const int *a, int b)
|
||||
{
|
||||
unsigned i, j;
|
||||
|
||||
for (i=0; i<DIM; i++) {
|
||||
for (j=0; j<DIM; j++) {
|
||||
x[i*DIM+j] = a[i*DIM+j] / b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
grind(void)
|
||||
{
|
||||
/*
|
||||
* compute: m2 = m1*m1, m3 = m2+m1, m4 = m3*m3, m1 = m4 / 2
|
||||
*/
|
||||
mul(m2, m1, m1);
|
||||
add(m3, m2, m1);
|
||||
mul(m4, m3, m3);
|
||||
scale(m1, m4, 2);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
trace(void)
|
||||
{
|
||||
unsigned i;
|
||||
int val = 0;
|
||||
|
||||
for (i=0; i<DIM; i++) {
|
||||
val += m1[i*DIM+i];
|
||||
}
|
||||
while (val < 0) {
|
||||
val += 0x20000000;
|
||||
}
|
||||
return val % 0x20000000;
|
||||
}
|
||||
|
||||
static
|
||||
pid_t
|
||||
dofork(void)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
warn("fork");
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dowait(pid_t pid)
|
||||
{
|
||||
int status;
|
||||
|
||||
if (pid == -1) {
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
if (pid == 0) {
|
||||
exit(failures);
|
||||
}
|
||||
else {
|
||||
if (waitpid(pid, &status, 0) < 0) {
|
||||
warn("waitpid(%d)", pid);
|
||||
}
|
||||
else if (WIFSIGNALED(status)) {
|
||||
warnx("pid %d: signal %d", pid, WTERMSIG(status));
|
||||
}
|
||||
else if (WEXITSTATUS(status) > 0) {
|
||||
failures += WEXITSTATUS(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dotest(void)
|
||||
{
|
||||
unsigned i, me;
|
||||
pid_t pids[BRANCHES];
|
||||
int t;
|
||||
char msg[128];
|
||||
|
||||
me = 0;
|
||||
for (i=0; i<BRANCHES; i++) {
|
||||
pids[i] = dofork();
|
||||
if (pids[i] == 0) {
|
||||
me += 1U<<i;
|
||||
}
|
||||
grind();
|
||||
t = trace();
|
||||
if (t == right[i]) {
|
||||
snprintf(msg, sizeof(msg),
|
||||
"Stage %u #%u done: %d\n", i, me, trace());
|
||||
}
|
||||
else {
|
||||
snprintf(msg, sizeof(msg),
|
||||
"Stage %u #%u FAILED: got %d, expected %d\n",
|
||||
i, me, t, right[i]);
|
||||
failures++;
|
||||
}
|
||||
(void)write(STDOUT_FILENO, msg, strlen(msg));
|
||||
}
|
||||
|
||||
for (i=BRANCHES; i-- > 0; ) {
|
||||
dowait(pids[i]);
|
||||
}
|
||||
if (failures > 0) {
|
||||
printf("%u failures.\n", failures);
|
||||
}
|
||||
else {
|
||||
printf("Done.\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
init();
|
||||
dotest();
|
||||
return 0;
|
||||
}
|
11
userland/testbin/bigseek/Makefile
Normal file
11
userland/testbin/bigseek/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for bigseek
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=bigseek
|
||||
SRCS=bigseek.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
270
userland/testbin/bigseek/bigseek.c
Normal file
270
userland/testbin/bigseek/bigseek.c
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Copyright (c) 2014
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
* Test for seek positions > 2^32.
|
||||
*
|
||||
* This test is a bit hamstrung because neither emufs nor sfs supports
|
||||
* files larger than 2^32. (In fact, because sfs has 512-byte blocks,
|
||||
* to support a file of size 2^32 you'd need a quadruple-indirect
|
||||
* block, not just triple. But even with that it won't work because
|
||||
* the file size is a uint32_t.)
|
||||
*
|
||||
* We do, however, want to check if lseek is manipulating its 64-bit
|
||||
* argument correctly. The fs-independent code you're supposed to
|
||||
* write should be using off_t, which is 64 bits wide, to hold the
|
||||
* seek position. So seeking to positions past 2^32 should work, and
|
||||
* it should be possible to read back the seek position we set even if
|
||||
* it's past 2^32.
|
||||
*
|
||||
* Actually reading past 2^32 should behave the same as reading beyond
|
||||
* EOF anywhere else (produces EOF) and writing past 2^32 should yield
|
||||
* EFBIG.
|
||||
*
|
||||
* We also test between 2^31 and 2^32 in case values in that range are
|
||||
* getting truncated to a signed 32-bit value and then rejected for
|
||||
* being negative.
|
||||
*/
|
||||
|
||||
#define TESTFILE "bigseekfile"
|
||||
|
||||
static const char *slogans[] = {
|
||||
"QUO USQUE TANDEM ABUTERE CATILINA PATENTIA NOSTRA",
|
||||
"QUEM IN FINEM SESE EFFRENATA IACTABIT AUDACIA"
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
write_slogan(int fd, unsigned which, bool failok)
|
||||
{
|
||||
size_t len;
|
||||
ssize_t r;
|
||||
|
||||
len = strlen(slogans[which]);
|
||||
r = write(fd, slogans[which], len);
|
||||
if (r < 0) {
|
||||
if (failok && errno == EFBIG) {
|
||||
return;
|
||||
}
|
||||
err(1, "write");
|
||||
}
|
||||
if (failok) {
|
||||
errx(1, "write: expected failure but wrote %zd bytes", r);
|
||||
}
|
||||
if ((size_t)r != len) {
|
||||
errx(1, "write: result %zd bytes, expected %zu", r, len);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
check_slogan(int fd, unsigned which)
|
||||
{
|
||||
char buf[256];
|
||||
size_t len;
|
||||
ssize_t r;
|
||||
unsigned i, wrongcount;
|
||||
|
||||
r = read(fd, buf, sizeof(buf));
|
||||
if (r < 0) {
|
||||
err(1, "read");
|
||||
}
|
||||
if (r == 0) {
|
||||
errx(1, "read: Unexpected EOF");
|
||||
}
|
||||
|
||||
/* we should get either a full buffer or the length of the slogan */
|
||||
len = strlen(slogans[which]);
|
||||
if ((size_t)r != sizeof(buf) && (size_t)r != len) {
|
||||
errx(1, "read: result %zd bytes, expected %zu or %zu",
|
||||
r, sizeof(buf), len);
|
||||
}
|
||||
|
||||
/* slogan should match */
|
||||
if (memcmp(buf, slogans[which], len) != 0) {
|
||||
warnx("read: got wrong data");
|
||||
warnx("expected: %s", slogans[which]);
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
errx(1, "found: %s", buf);
|
||||
}
|
||||
|
||||
/* bytes past the slogan (if any) should be 0 */
|
||||
wrongcount = 0;
|
||||
for (i=len; i<(size_t)r; i++) {
|
||||
if (buf[i] != 0) {
|
||||
warnx("read: buf[%zu] was 0x%x, expected 0", i,
|
||||
(unsigned char)buf[i]);
|
||||
wrongcount++;
|
||||
}
|
||||
}
|
||||
if (wrongcount > 0) {
|
||||
errx(1, "%u bytes of trash in file", wrongcount);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
try_reading(int fd)
|
||||
{
|
||||
char buf[16];
|
||||
ssize_t r;
|
||||
|
||||
r = read(fd, buf, sizeof(buf));
|
||||
if (r == 0) {
|
||||
/* expected EOF */
|
||||
return;
|
||||
}
|
||||
if (r < 0) {
|
||||
err(1, "read");
|
||||
}
|
||||
errx(1, "read: Expected EOF but got %zd bytes", r);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
try_writing(int fd)
|
||||
{
|
||||
write_slogan(fd, 1, true);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dolseek(int fd, off_t pos, int whence, const char *whencestr, off_t expected)
|
||||
{
|
||||
off_t result;
|
||||
|
||||
result = lseek(fd, pos, whence);
|
||||
if (result == -1) {
|
||||
err(1, "lseek(fd, 0x%llx, %s)", pos, whencestr);
|
||||
}
|
||||
if (result != expected) {
|
||||
errx(1, "lseek(fd, 0x%llx, %s): Wrong return value"
|
||||
" (got 0x%llx, expected 0x%llx)", pos, whencestr,
|
||||
result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
try_seeking(int fd, off_t pos, off_t cursize)
|
||||
{
|
||||
printf("Seeking to (and near) 0x%llx\n", pos);
|
||||
|
||||
/* Go to the place. */
|
||||
dolseek(fd, pos, SEEK_SET, "SEEK_SET", pos);
|
||||
|
||||
/* Go to where we already are. */
|
||||
dolseek(fd, 0, SEEK_CUR, "SEEK_CUR", pos);
|
||||
|
||||
if (pos >= 10) {
|
||||
/* Back up a little. */
|
||||
dolseek(fd, -10, SEEK_CUR, "SEEK_CUR", pos - 10);
|
||||
|
||||
/* Forward a little. */
|
||||
dolseek(fd, 20, SEEK_CUR, "SEEK_CUR", pos + 10);
|
||||
}
|
||||
else {
|
||||
/* Just forward a little. */
|
||||
dolseek(fd, 10, SEEK_CUR, "SEEK_CUR", pos + 10);
|
||||
}
|
||||
|
||||
/* Via SEEK_END. */
|
||||
dolseek(fd, pos, SEEK_END, "SEEK_END", pos + cursize);
|
||||
|
||||
/* Go back to the exact place. */
|
||||
dolseek(fd, pos, SEEK_SET, "SEEK_SET", pos);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
off_t cursize;
|
||||
int fd;
|
||||
|
||||
printf("Creating file...\n");
|
||||
fd = open(TESTFILE, O_RDWR|O_CREAT|O_TRUNC, 0664);
|
||||
if (fd < 0) {
|
||||
err(1, "%s", TESTFILE);
|
||||
}
|
||||
|
||||
printf("Writing something at offset 0\n");
|
||||
write_slogan(fd, 0, false);
|
||||
cursize = strlen(slogans[0]);
|
||||
|
||||
try_seeking(fd, (off_t)0x1000LL, cursize);
|
||||
|
||||
printf("Writing something else\n");
|
||||
write_slogan(fd, 1, false);
|
||||
cursize = (off_t)0x1000LL + strlen(slogans[1]);
|
||||
|
||||
try_seeking(fd, (off_t)0, cursize);
|
||||
|
||||
/* If seek is totally bust, this will fail. */
|
||||
printf("Checking what we wrote\n");
|
||||
check_slogan(fd, 0);
|
||||
|
||||
try_seeking(fd, (off_t)0x1000LL, cursize);
|
||||
printf("Checking the other thing we wrote\n");
|
||||
check_slogan(fd, 1);
|
||||
|
||||
try_seeking(fd, (off_t)0x20LL, cursize);
|
||||
try_seeking(fd, (off_t)0x7fffffffLL, cursize);
|
||||
try_seeking(fd, (off_t)0x80000000LL, cursize);
|
||||
try_seeking(fd, (off_t)0x80000020LL, cursize);
|
||||
try_seeking(fd, (off_t)0x100000000LL, cursize);
|
||||
try_seeking(fd, (off_t)0x100000020LL, cursize);
|
||||
try_seeking(fd, (off_t)0x180000000LL, cursize);
|
||||
try_seeking(fd, (off_t)0x180000020LL, cursize);
|
||||
|
||||
printf("Now trying to read (should get EOF)\n");
|
||||
try_reading(fd);
|
||||
|
||||
printf("Now trying to write (should get EFBIG)\n");
|
||||
try_writing(fd);
|
||||
|
||||
try_seeking(fd, (off_t)0x100000000LL, cursize);
|
||||
|
||||
/* If seek truncates to 32 bits, this might read the slogan instead */
|
||||
printf("Trying to read again (should get EOF)\n");
|
||||
try_reading(fd);
|
||||
|
||||
printf("Passed.\n");
|
||||
|
||||
close(fd);
|
||||
remove(TESTFILE);
|
||||
return 0;
|
||||
}
|
11
userland/testbin/bloat/Makefile
Normal file
11
userland/testbin/bloat/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for bloat
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=bloat
|
||||
SRCS=bloat.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
204
userland/testbin/bloat/bloat.c
Normal file
204
userland/testbin/bloat/bloat.c
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* bloat - waste memory.
|
||||
*
|
||||
* This test allocates memory a page at a time and keeps going until
|
||||
* it runs out. It gets the memory directly with sbrk to avoid malloc-
|
||||
* related overheads, which as long as OS/161 has a dumb userlevel
|
||||
* malloc is important for performance.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
|
||||
/* OS/161 doesn't currently have a way to get this from the kernel. */
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
/* the memory we've gotten */
|
||||
static void *firstpage;
|
||||
static void *lastpage;
|
||||
|
||||
/* number of page allocations per cycle */
|
||||
static unsigned allocs;
|
||||
|
||||
/* number of pages to touch every cycle */
|
||||
static unsigned touchpages;
|
||||
|
||||
/* when touching pages, the extent to which we favor the middle of the range */
|
||||
static unsigned bias;
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
moremem(void)
|
||||
{
|
||||
static unsigned totalpages;
|
||||
|
||||
void *ptr;
|
||||
unsigned i;
|
||||
|
||||
for (i=0; i<allocs; i++) {
|
||||
ptr = sbrk(PAGE_SIZE);
|
||||
if (ptr == (void *)-1) {
|
||||
err(1, "After %u pages: sbrk", totalpages);
|
||||
}
|
||||
totalpages++;
|
||||
lastpage = ptr;
|
||||
if (firstpage == NULL) {
|
||||
firstpage = ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
touchpage(unsigned pagenum)
|
||||
{
|
||||
int *ptr;
|
||||
|
||||
ptr = (void *)((uintptr_t)firstpage + PAGE_SIZE * pagenum);
|
||||
*ptr = pagenum;
|
||||
}
|
||||
|
||||
static
|
||||
unsigned
|
||||
pickpage(unsigned numpages)
|
||||
{
|
||||
unsigned mnum, moffset;
|
||||
unsigned span, val, i;
|
||||
|
||||
/* take 1 in 1000 pages uniformly from the entire space */
|
||||
if (random() % 1000 == 0) {
|
||||
return random() % numpages;
|
||||
}
|
||||
|
||||
/* the rest is taken from the middle 1% */
|
||||
|
||||
mnum = numpages / 100;
|
||||
if (mnum < touchpages * 2) {
|
||||
mnum = touchpages * 2;
|
||||
}
|
||||
if (mnum >= numpages) {
|
||||
mnum = numpages;
|
||||
}
|
||||
moffset = numpages / 2 - mnum / 2;
|
||||
|
||||
assert(bias >= 1);
|
||||
span = (mnum + bias - 1) / bias;
|
||||
|
||||
do {
|
||||
val = 0;
|
||||
for (i=0; i<bias; i++) {
|
||||
val += random() % span;
|
||||
}
|
||||
} while (val >= mnum);
|
||||
return moffset + val;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
touchmem(void)
|
||||
{
|
||||
unsigned i, num;
|
||||
|
||||
num = (((uintptr_t)lastpage - (uintptr_t)firstpage) / PAGE_SIZE) + 1;
|
||||
|
||||
if (num % 256 == 0) {
|
||||
warnx("%u pages", num);
|
||||
}
|
||||
|
||||
for (i=0; i<touchpages; i++) {
|
||||
touchpage(pickpage(num));
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
run(void)
|
||||
{
|
||||
while (1) {
|
||||
moremem();
|
||||
touchmem();
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
printsettings(void)
|
||||
{
|
||||
printf("Page size: %u\n", PAGE_SIZE);
|
||||
printf("Allocating %u pages and touching %u pages on each cycle.\n",
|
||||
allocs, touchpages);
|
||||
printf("Page selection bias: %u\n", bias);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
warnx("bloat [-a allocs] [-b bias] [-p pages]");
|
||||
warnx(" allocs: number of pages allocated per cycle (default 4)");
|
||||
warnx(" bias: number of dice rolled to touch pages (default 8)");
|
||||
warnx(" pages: pages touched per cycle (default 8)");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* default mode */
|
||||
allocs = 4;
|
||||
touchpages = 8;
|
||||
bias = 8;
|
||||
|
||||
srandom(1234);
|
||||
|
||||
for (i=1; i<argc; i++) {
|
||||
if (!strcmp(argv[i], "-a")) {
|
||||
i++;
|
||||
if (i == argc) {
|
||||
errx(1, "-a: option requires argument");
|
||||
}
|
||||
allocs = atoi(argv[i]);
|
||||
if (allocs == 0) {
|
||||
errx(1, "-a: must not be zero");
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argv[i], "-b")) {
|
||||
i++;
|
||||
if (i == argc) {
|
||||
errx(1, "-b: option requires argument");
|
||||
}
|
||||
bias = atoi(argv[i]);
|
||||
if (bias == 0) {
|
||||
errx(1, "-b: must not be zero");
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argv[i], "-h")) {
|
||||
usage();
|
||||
}
|
||||
else if (!strcmp(argv[i], "-p")) {
|
||||
i++;
|
||||
if (i == argc) {
|
||||
errx(1, "-p: option requires argument");
|
||||
}
|
||||
touchpages = atoi(argv[i]);
|
||||
}
|
||||
else {
|
||||
errx(1, "Argument %s not recognized", argv[i]);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
printsettings();
|
||||
run();
|
||||
return 0;
|
||||
}
|
11
userland/testbin/conman/Makefile
Normal file
11
userland/testbin/conman/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for conman
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=conman
|
||||
SRCS=conman.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
58
userland/testbin/conman/conman.c
Normal file
58
userland/testbin/conman/conman.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* conman.c
|
||||
*
|
||||
* Echoes characters until a 'q' is read.
|
||||
* This should work once the basic system calls are implemented.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char ch=0;
|
||||
int len;
|
||||
|
||||
while (ch!='q') {
|
||||
len = read(STDIN_FILENO, &ch, 1);
|
||||
if (len < 0) {
|
||||
err(1, "stdin: read");
|
||||
}
|
||||
if (len==0) {
|
||||
/* EOF */
|
||||
break;
|
||||
}
|
||||
write(STDOUT_FILENO, &ch, 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
11
userland/testbin/crash/Makefile
Normal file
11
userland/testbin/crash/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for crash
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=crash
|
||||
SRCS=crash.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
388
userland/testbin/crash/crash.c
Normal file
388
userland/testbin/crash/crash.c
Normal file
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* crash.c
|
||||
*
|
||||
* Commit a variety of exceptions, primarily address faults.
|
||||
*
|
||||
* Once the basic system calls assignment is complete, none of these
|
||||
* should crash the kernel.
|
||||
*
|
||||
* They should all, however, terminate this program, except for the
|
||||
* one that writes to the code segment. (That one won't cause program
|
||||
* termination until/unless you implement read-only segments in your
|
||||
* VM system.)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <err.h>
|
||||
|
||||
#if defined(__mips__)
|
||||
#define KERNEL_ADDR 0x80000000
|
||||
#define INVAL_ADDR 0x40000000
|
||||
#define INSN_TYPE uint32_t
|
||||
#define INVAL_INSN 0x0000003f
|
||||
#else
|
||||
#error "Please fix this"
|
||||
#endif
|
||||
|
||||
#define MAGIC 123456
|
||||
|
||||
typedef void (*func)(void);
|
||||
|
||||
static int forking = 1;
|
||||
|
||||
static
|
||||
void
|
||||
read_from_null(void)
|
||||
{
|
||||
int *null = NULL;
|
||||
volatile int x;
|
||||
|
||||
x = *null;
|
||||
|
||||
// gcc 4.8 improperly demands this
|
||||
(void)x;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
read_from_inval(void)
|
||||
{
|
||||
int *ptr = (int *) INVAL_ADDR;
|
||||
volatile int x;
|
||||
|
||||
x = *ptr;
|
||||
|
||||
// gcc 4.8 improperly demands this
|
||||
(void)x;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
read_from_kernel(void)
|
||||
{
|
||||
int *ptr = (int *) KERNEL_ADDR;
|
||||
volatile int x;
|
||||
|
||||
x = *ptr;
|
||||
|
||||
// gcc 4.8 improperly demands this
|
||||
(void)x;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
write_to_null(void)
|
||||
{
|
||||
int *null = NULL;
|
||||
*null = 6;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
write_to_inval(void)
|
||||
{
|
||||
int *ptr = (int *) INVAL_ADDR;
|
||||
*ptr = 8;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
write_to_code(void)
|
||||
{
|
||||
INSN_TYPE *x = (INSN_TYPE *)write_to_code;
|
||||
*x = INVAL_INSN;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
write_to_kernel(void)
|
||||
{
|
||||
int *ptr = (int *) KERNEL_ADDR;
|
||||
*ptr = 8;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
jump_to_null(void)
|
||||
{
|
||||
func f = NULL;
|
||||
f();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
jump_to_inval(void)
|
||||
{
|
||||
func f = (func) INVAL_ADDR;
|
||||
f();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
jump_to_kernel(void)
|
||||
{
|
||||
func f = (func) KERNEL_ADDR;
|
||||
f();
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
illegal_instruction(void)
|
||||
{
|
||||
#if defined(__mips__)
|
||||
asm(".long 0x0000003f");
|
||||
#else
|
||||
#error "Please fix this"
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
alignment_error(void)
|
||||
{
|
||||
int x;
|
||||
int *ptr, *badptr;
|
||||
volatile uintptr_t ptrval;
|
||||
volatile int j;
|
||||
|
||||
x = 0;
|
||||
ptr = &x;
|
||||
/*
|
||||
* Try to hide what's going on from gcc; gcc 4.8 seems to
|
||||
* detect the unaligned access and issue unaligned read
|
||||
* instructions for it, so then it doesn't fault. Feh.
|
||||
*/
|
||||
ptrval = (uintptr_t)ptr;
|
||||
ptrval++;
|
||||
badptr = (int *)ptrval;
|
||||
|
||||
j = *badptr;
|
||||
|
||||
// gcc 4.8 improperly demands this
|
||||
(void)j;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
divide_by_zero(void)
|
||||
{
|
||||
volatile int x = 6;
|
||||
volatile int z = 0;
|
||||
volatile int a;
|
||||
|
||||
a = x/z;
|
||||
|
||||
// gcc 4.8 improperly demands this
|
||||
(void)a;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mod_by_zero(void)
|
||||
{
|
||||
volatile int x = 6;
|
||||
volatile int z = 0;
|
||||
volatile int a;
|
||||
|
||||
a = x%z;
|
||||
|
||||
// gcc 4.8 improperly demands this
|
||||
(void)a;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
recurse_inf(void)
|
||||
{
|
||||
volatile char buf[16];
|
||||
|
||||
buf[0] = 0;
|
||||
recurse_inf();
|
||||
buf[0] = 1;
|
||||
|
||||
// gcc 4.8 improperly demands this
|
||||
(void)buf;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
struct {
|
||||
int ch;
|
||||
const char *name;
|
||||
func f;
|
||||
int sig;
|
||||
} ops[] = {
|
||||
{ 'a', "read from NULL", read_from_null, SIGSEGV },
|
||||
{ 'b', "read from invalid address", read_from_inval, SIGSEGV },
|
||||
{ 'c', "read from kernel address", read_from_kernel, SIGBUS },
|
||||
{ 'd', "write to NULL", write_to_null, SIGSEGV },
|
||||
{ 'e', "write to invalid address", write_to_inval, SIGSEGV },
|
||||
{ 'f', "write to code segment", write_to_code, SIGSEGV },
|
||||
{ 'g', "write to kernel address", write_to_kernel, SIGBUS },
|
||||
{ 'h', "jump to NULL", jump_to_null, SIGSEGV },
|
||||
{ 'i', "jump to invalid address", jump_to_inval, SIGSEGV },
|
||||
{ 'j', "jump to kernel address", jump_to_kernel, SIGBUS },
|
||||
{ 'k', "alignment error", alignment_error, SIGBUS },
|
||||
{ 'l', "illegal instruction", illegal_instruction, SIGILL },
|
||||
{ 'm', "divide by zero", divide_by_zero, SIGTRAP },
|
||||
{ 'n', "mod by zero", mod_by_zero, SIGTRAP },
|
||||
{ 'o', "Recurse infinitely", recurse_inf, SIGSEGV },
|
||||
{ 0, NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
runop(int op)
|
||||
{
|
||||
int opindex;
|
||||
pid_t pid;
|
||||
int status;
|
||||
int ok;
|
||||
|
||||
if (op=='*') {
|
||||
for (unsigned i=0; ops[i].name; i++) {
|
||||
runop(ops[i].ch);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (op == '-') {
|
||||
forking = 0;
|
||||
warnx("Forking disabled - next try will be the last");
|
||||
return;
|
||||
}
|
||||
else if (op == '+') {
|
||||
forking = 1;
|
||||
warnx("Forking enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
/* intentionally don't check if op is in bounds :) */
|
||||
opindex = op-'a';
|
||||
|
||||
printf("Running: [%c] %s\n", ops[opindex].ch, ops[opindex].name);
|
||||
|
||||
if (forking) {
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
/* error */
|
||||
err(1, "fork");
|
||||
}
|
||||
else if (pid > 0) {
|
||||
/* parent */
|
||||
if (waitpid(pid, &status, 0) < 0) {
|
||||
err(1, "waitpid");
|
||||
}
|
||||
ok = 0;
|
||||
if (WIFSIGNALED(status)) {
|
||||
printf("Signal %d\n", WTERMSIG(status));
|
||||
if (WTERMSIG(status) == ops[opindex].sig) {
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Exit %d\n", WEXITSTATUS(status));
|
||||
if (WEXITSTATUS(status) == MAGIC) {
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
printf("Ok.\n");
|
||||
}
|
||||
else {
|
||||
printf("FAILED: expected signal %d\n",
|
||||
ops[opindex].sig);
|
||||
}
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* child, or not forking */
|
||||
|
||||
ops[opindex].f();
|
||||
|
||||
if (op == 'f') {
|
||||
warnx(".... I guess you don't support read-only segments");
|
||||
/* use this magic signaling value so parent doesn't say FAIL */
|
||||
_exit(MAGIC);
|
||||
}
|
||||
errx(1, "I wasn't killed!");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
ask(void)
|
||||
{
|
||||
unsigned i;
|
||||
int op;
|
||||
|
||||
while (1) {
|
||||
|
||||
for (i=0; ops[i].name; i++) {
|
||||
printf("[%c] %s\n", ops[i].ch, ops[i].name);
|
||||
}
|
||||
printf("[-] Disable forking\n");
|
||||
printf("[+] Enable forking (default)\n");
|
||||
printf("[*] Run everything\n");
|
||||
printf("[!] Quit\n");
|
||||
|
||||
printf("Choose: ");
|
||||
op = getchar();
|
||||
|
||||
if (op == '!') {
|
||||
break;
|
||||
}
|
||||
|
||||
runop(op);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 0 || argc == 1) {
|
||||
/* no arguments */
|
||||
ask();
|
||||
}
|
||||
else {
|
||||
/* run the selected ops */
|
||||
for (int i=1; i<argc; i++) {
|
||||
for (size_t j=0; argv[i][j]; j++) {
|
||||
runop(argv[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
11
userland/testbin/ctest/Makefile
Normal file
11
userland/testbin/ctest/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for ctest
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=ctest
|
||||
SRCS=ctest.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
101
userland/testbin/ctest/ctest.c
Normal file
101
userland/testbin/ctest/ctest.c
Normal 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Performance test from former 161 prof. Brad Chen
|
||||
* Stresses VM.
|
||||
*
|
||||
* Intended for the VM assignment. This should run successfully on a
|
||||
* variety of strides when the VM system is complete. Strides that are
|
||||
* not a multiple of 2 work better; see below.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* SIZE is the amount of memory used.
|
||||
* DEFAULT is the default stride.
|
||||
* Note that SIZE and DEFAULT should be relatively prime.
|
||||
*/
|
||||
#define SIZE (1024*1024/sizeof(struct entry))
|
||||
#define DEFAULT 477
|
||||
|
||||
struct entry {
|
||||
struct entry *e;
|
||||
};
|
||||
|
||||
struct entry array[SIZE];
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
volatile struct entry *e;
|
||||
unsigned i, stride;
|
||||
|
||||
stride = DEFAULT;
|
||||
if (argc == 2) {
|
||||
stride = atoi(argv[1]);
|
||||
}
|
||||
if (stride <= 0 || argc > 2) {
|
||||
printf("Usage: ctest [stridesize]\n");
|
||||
printf(" stridesize should not be a multiple of 2.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Starting ctest: stride %d\n", stride);
|
||||
|
||||
/*
|
||||
* Generate a huge linked list, with each entry pointing to
|
||||
* the slot STRIDE entries above it. As long as STRIDE and SIZE
|
||||
* are relatively prime, this will put all the entries on one
|
||||
* list. Otherwise you will get multiple disjoint lists. (All
|
||||
* these lists will be circular.)
|
||||
*/
|
||||
for (i=0; i<SIZE; i++) {
|
||||
array[i].e = &array[(i+stride) % SIZE];
|
||||
}
|
||||
|
||||
/*
|
||||
* Traverse the list. We stop after hitting each element once.
|
||||
*
|
||||
* (If STRIDE was even, this will hit some elements more than
|
||||
* once and others not at all.)
|
||||
*/
|
||||
e = &array[0];
|
||||
for (i=0; i<SIZE; i++) {
|
||||
if (i % stride == 0) {
|
||||
putchar('.');
|
||||
}
|
||||
e = e->e;
|
||||
}
|
||||
|
||||
printf("\nDone!\n");
|
||||
return 0;
|
||||
}
|
11
userland/testbin/dirconc/Makefile
Normal file
11
userland/testbin/dirconc/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for dirconc
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=dirconc
|
||||
SRCS=dirconc.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
362
userland/testbin/dirconc/dirconc.c
Normal file
362
userland/testbin/dirconc/dirconc.c
Normal file
@@ -0,0 +1,362 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Concurrent directory operations test.
|
||||
*
|
||||
* Your system should survive this (without leaving a corrupted file
|
||||
* system behind) once the file system assignment is complete.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NTRIES 100 /* loop count */
|
||||
#define NPROCS 5 /* actually totals 4x this +1 processes */
|
||||
|
||||
#define TESTDIR "dirconc"
|
||||
#define NNAMES 4
|
||||
#define NAMESIZE 32
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static const char *const names[NNAMES] = {
|
||||
"aaaa",
|
||||
"bbbb",
|
||||
"cccc",
|
||||
"dddd",
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
choose_name(char *buf, size_t len)
|
||||
{
|
||||
const char *a, *b, *c;
|
||||
|
||||
a = names[random()%NNAMES];
|
||||
if (random()%2==0) {
|
||||
snprintf(buf, len, "%s", a);
|
||||
return;
|
||||
}
|
||||
b = names[random()%NNAMES];
|
||||
if (random()%2==0) {
|
||||
snprintf(buf, len, "%s/%s", a, b);
|
||||
return;
|
||||
}
|
||||
c = names[random()%NNAMES];
|
||||
snprintf(buf, len, "%s/%s/%s", a, b, c);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* The purpose of this is to be atomic. In our world, straight
|
||||
* printf tends not to be.
|
||||
*/
|
||||
static
|
||||
void
|
||||
#ifdef __GNUC__
|
||||
__attribute__((__format__(__printf__, 1, 2)))
|
||||
#endif
|
||||
say(const char *fmt, ...)
|
||||
{
|
||||
char buf[512];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
write(STDOUT_FILENO, buf, strlen(buf));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
dorename(const char *name1, const char *name2)
|
||||
{
|
||||
if (rename(name1, name2) < 0) {
|
||||
switch (errno) {
|
||||
case ENOENT:
|
||||
case ENOTEMPTY:
|
||||
case EINVAL:
|
||||
break;
|
||||
default:
|
||||
say("pid %d: rename %s -> %s: %s\n",
|
||||
getpid(), name1, name2, strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
domkdir(const char *name)
|
||||
{
|
||||
if (mkdir(name, 0775)<0) {
|
||||
switch (errno) {
|
||||
case ENOENT:
|
||||
case EEXIST:
|
||||
break;
|
||||
default:
|
||||
say("pid %d: mkdir %s: %s\n",
|
||||
getpid(), name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dormdir(const char *name)
|
||||
{
|
||||
if (rmdir(name)<0) {
|
||||
switch (errno) {
|
||||
case ENOENT:
|
||||
case ENOTEMPTY:
|
||||
break;
|
||||
default:
|
||||
say("pid %d: rmdir %s: %s\n",
|
||||
getpid(), name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
cleanup_rmdir(const char *name)
|
||||
{
|
||||
if (rmdir(name)<0) {
|
||||
switch (errno) {
|
||||
case ENOENT:
|
||||
break;
|
||||
default:
|
||||
say("cleanup (pid %d): rmdir %s: %s\n",
|
||||
getpid(), name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
rename_proc(void)
|
||||
{
|
||||
char name1[NAMESIZE], name2[NAMESIZE];
|
||||
int ct;
|
||||
|
||||
for (ct=0; ct<NTRIES; ct++) {
|
||||
choose_name(name1, sizeof(name1));
|
||||
choose_name(name2, sizeof(name2));
|
||||
say("pid %2d: rename %s -> %s\n", (int)getpid(), name1, name2);
|
||||
dorename(name1, name2);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mkdir_proc(void)
|
||||
{
|
||||
char name[NAMESIZE];
|
||||
int ct;
|
||||
|
||||
for (ct=0; ct<NTRIES; ct++) {
|
||||
choose_name(name, sizeof(name));
|
||||
say("pid %2d: mkdir %s\n", (int)getpid(), name);
|
||||
domkdir(name);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
rmdir_proc(void)
|
||||
{
|
||||
char name[NAMESIZE];
|
||||
int ct;
|
||||
|
||||
for (ct=0; ct<NTRIES; ct++) {
|
||||
choose_name(name, sizeof(name));
|
||||
say("pid %2d: rmdir %s\n", (int)getpid(), name);
|
||||
dormdir(name);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
pid_t
|
||||
dofork(void (*func)(void))
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
say("fork: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (pid == 0) {
|
||||
/* child */
|
||||
func();
|
||||
exit(0);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
run(void)
|
||||
{
|
||||
pid_t pids[NPROCS*4], wp;
|
||||
int i, status;
|
||||
|
||||
for (i=0; i<NPROCS; i++) {
|
||||
pids[i*4] = dofork(mkdir_proc);
|
||||
pids[i*4+1] = dofork(mkdir_proc);
|
||||
pids[i*4+2] = dofork(rename_proc);
|
||||
pids[i*4+3] = dofork(rmdir_proc);
|
||||
}
|
||||
|
||||
for (i=0; i<NPROCS*4; i++) {
|
||||
if (pids[i]>=0) {
|
||||
wp = waitpid(pids[i], &status, 0);
|
||||
if (wp<0) {
|
||||
say("waitpid %d: %s\n", (int) pids[i],
|
||||
strerror(errno));
|
||||
}
|
||||
else if (WIFSIGNALED(status)) {
|
||||
say("pid %d: signal %d\n", (int) pids[i],
|
||||
WTERMSIG(status));
|
||||
}
|
||||
else if (WIFEXITED(status) && WEXITSTATUS(status)!=0) {
|
||||
say("pid %d: exit %d\n", (int) pids[i],
|
||||
WEXITSTATUS(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
setup(const char *fs)
|
||||
{
|
||||
if (chdir(fs)<0) {
|
||||
say("chdir: %s: %s\n", fs, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (mkdir(TESTDIR, 0775)<0) {
|
||||
say("mkdir: %s: %s\n", TESTDIR, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (chdir(TESTDIR)<0) {
|
||||
say("chdir: %s: %s\n", TESTDIR, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
recursive_cleanup(const char *sofar, int depth)
|
||||
{
|
||||
char buf[NAMESIZE*32];
|
||||
int i;
|
||||
|
||||
for (i=0; i<NNAMES; i++) {
|
||||
snprintf(buf, sizeof(buf), "%s/%s", sofar, names[i]);
|
||||
if (rmdir(buf)<0) {
|
||||
if (errno==ENOTEMPTY) {
|
||||
recursive_cleanup(buf, depth+1);
|
||||
cleanup_rmdir(buf);
|
||||
}
|
||||
else if (errno!=ENOENT) {
|
||||
say("cleanup (pid %d): rmdir %s: %s\n",
|
||||
getpid(), buf, strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
recursive_cleanup(".", 0);
|
||||
|
||||
chdir("..");
|
||||
cleanup_rmdir(TESTDIR);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *fs;
|
||||
long seed = 0;
|
||||
|
||||
say("Concurrent directory ops test\n");
|
||||
|
||||
if (argc==0 || argv==NULL) {
|
||||
say("Warning: argc is 0 - assuming you mean to run on lhd1: "
|
||||
"with seed 0\n");
|
||||
fs = "lhd1:";
|
||||
}
|
||||
else if (argc==2) {
|
||||
fs = argv[1];
|
||||
}
|
||||
else if (argc==3) {
|
||||
fs = argv[1];
|
||||
seed = atoi(argv[2]);
|
||||
}
|
||||
else {
|
||||
say("Usage: dirconc filesystem [random-seed]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
srandom(seed);
|
||||
setup(fs);
|
||||
say("Starting in %s/%s\n", fs, TESTDIR);
|
||||
|
||||
run();
|
||||
|
||||
say("Cleaning up\n");
|
||||
cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
11
userland/testbin/dirseek/Makefile
Normal file
11
userland/testbin/dirseek/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for dirseek
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=dirseek
|
||||
SRCS=dirseek.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
555
userland/testbin/dirseek/dirseek.c
Normal file
555
userland/testbin/dirseek/dirseek.c
Normal file
@@ -0,0 +1,555 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* dirseek.c
|
||||
*
|
||||
* Tests seeking on directories (both legally and illegally).
|
||||
*
|
||||
* Makes a test subdirectory in the current directory.
|
||||
*
|
||||
* Intended for the file system assignment. Should run (on SFS)
|
||||
* when that assignment is complete.
|
||||
*
|
||||
* Note: checks a few things that are not _strictly_ guaranteed
|
||||
* by the official semantics of getdirentry() but that are more
|
||||
* or less necessary in a sane implementation, like that the
|
||||
* current seek position returned after seeking is the same
|
||||
* position that was requested. If you believe your
|
||||
* implementation is legal and the the test is rejecting it
|
||||
* gratuitously, please contact the course staff.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
|
||||
#define TESTDIR "seektestdir"
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
int make_it;
|
||||
off_t pos;
|
||||
} testfiles[] = {
|
||||
{ ".", 0, -1 },
|
||||
{ "..", 0, -1 },
|
||||
{ "ridcully", 1, -1 },
|
||||
{ "weatherwax", 1, -1 },
|
||||
{ "ogg", 1, -1 },
|
||||
{ "vorbis", 1, -1 },
|
||||
{ "verence", 1, -1 },
|
||||
{ "magrat", 1, -1 },
|
||||
{ "agnes", 1, -1 },
|
||||
{ "rincewind", 1, -1 },
|
||||
{ "angua", 1, -1 },
|
||||
{ "cherry", 1, -1 },
|
||||
{ "dorfl", 1, -1 },
|
||||
{ "nobby", 1, -1 },
|
||||
{ "carrot", 1, -1 },
|
||||
{ "vimes", 1, -1 },
|
||||
{ "detritus", 1, -1 },
|
||||
{ "twoflower", 1, -1 },
|
||||
{ "teatime", 1, -1 },
|
||||
{ "qu", 1, -1 },
|
||||
{ NULL, 0, 0 }
|
||||
};
|
||||
|
||||
/************************************************************/
|
||||
/* Test code */
|
||||
/************************************************************/
|
||||
|
||||
static int dirfd;
|
||||
|
||||
static
|
||||
int
|
||||
findentry(const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; testfiles[i].name; i++) {
|
||||
if (!strcmp(testfiles[i].name, name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
openit(void)
|
||||
{
|
||||
dirfd = open(".", O_RDONLY);
|
||||
if (dirfd < 0) {
|
||||
err(1, ".: open");
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
closeit(void)
|
||||
{
|
||||
if (close(dirfd)<0) {
|
||||
err(1, ".: close");
|
||||
}
|
||||
dirfd = -1;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
readit(void)
|
||||
{
|
||||
char buf[4096];
|
||||
off_t pos;
|
||||
int len;
|
||||
int n, i, ix;
|
||||
|
||||
for (i=0; testfiles[i].name; i++) {
|
||||
testfiles[i].pos = -1;
|
||||
}
|
||||
|
||||
pos = lseek(dirfd, 0, SEEK_CUR);
|
||||
if (pos < 0) {
|
||||
err(1, ".: lseek(0, SEEK_CUR)");
|
||||
}
|
||||
n = 0;
|
||||
|
||||
while ((len = getdirentry(dirfd, buf, sizeof(buf)-1)) > 0) {
|
||||
|
||||
if ((unsigned)len >= sizeof(buf)-1) {
|
||||
errx(1, ".: entry %d: getdirentry returned "
|
||||
"invalid length %d", n, len);
|
||||
}
|
||||
buf[len] = 0;
|
||||
ix = findentry(buf);
|
||||
if (ix < 0) {
|
||||
errx(1, ".: entry %d: getdirentry returned "
|
||||
"unexpected name %s", n, buf);
|
||||
}
|
||||
|
||||
if (testfiles[ix].pos >= 0) {
|
||||
errx(1, ".: entry %d: getdirentry returned "
|
||||
"%s a second time", n, buf);
|
||||
}
|
||||
|
||||
testfiles[ix].pos = pos;
|
||||
|
||||
pos = lseek(dirfd, 0, SEEK_CUR);
|
||||
if (pos < 0) {
|
||||
err(1, ".: lseek(0, SEEK_CUR)");
|
||||
}
|
||||
n++;
|
||||
}
|
||||
if (len<0) {
|
||||
err(1, ".: entry %d: getdirentry", n);
|
||||
}
|
||||
|
||||
for (i=0; testfiles[i].name; i++) {
|
||||
if (testfiles[i].pos < 0) {
|
||||
errx(1, ".: getdirentry failed to return %s",
|
||||
testfiles[i].name);
|
||||
}
|
||||
}
|
||||
if (i!=n) {
|
||||
/*
|
||||
* If all of the other checks have passed, this should not
|
||||
* be able to fail. But... just in case I forgot something
|
||||
* or there's a bug...
|
||||
*/
|
||||
|
||||
errx(1, ".: getdirentry returned %d names, not %d (huh...?)",
|
||||
n, i);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
firstread(void)
|
||||
{
|
||||
off_t pos;
|
||||
|
||||
pos = lseek(dirfd, 0, SEEK_CUR);
|
||||
if (pos < 0) {
|
||||
err(1, ".: lseek(0, SEEK_CUR)");
|
||||
}
|
||||
if (pos != 0) {
|
||||
errx(1, ".: File position after open not 0");
|
||||
}
|
||||
|
||||
printf("Scanning directory...\n");
|
||||
|
||||
readit();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
doreadat0(void)
|
||||
{
|
||||
off_t pos;
|
||||
|
||||
printf("Rewinding directory and reading it again...\n");
|
||||
|
||||
pos = lseek(dirfd, 0, SEEK_SET);
|
||||
if (pos < 0) {
|
||||
err(1, ".: lseek(0, SEEK_SET)");
|
||||
}
|
||||
if (pos != 0) {
|
||||
errx(1, ".: lseek(0, SEEK_SET) returned %ld", (long) pos);
|
||||
}
|
||||
|
||||
readit();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
readone(const char *shouldbe)
|
||||
{
|
||||
char buf[4096];
|
||||
int len;
|
||||
|
||||
len = getdirentry(dirfd, buf, sizeof(buf)-1);
|
||||
if (len < 0) {
|
||||
err(1, ".: getdirentry");
|
||||
}
|
||||
if ((unsigned)len >= sizeof(buf)-1) {
|
||||
errx(1, ".: getdirentry returned invalid length %d", len);
|
||||
}
|
||||
buf[len] = 0;
|
||||
|
||||
if (strcmp(buf, shouldbe)) {
|
||||
errx(1, ".: getdirentry returned %s (expected %s)",
|
||||
buf, shouldbe);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
doreadone(int which)
|
||||
{
|
||||
off_t pos;
|
||||
pos = lseek(dirfd, testfiles[which].pos, SEEK_SET);
|
||||
if (pos<0) {
|
||||
err(1, ".: lseek(%ld, SEEK_SET)", (long) testfiles[which].pos);
|
||||
}
|
||||
if (pos != testfiles[which].pos) {
|
||||
errx(1, ".: lseek(%ld, SEEK_SET) returned %ld",
|
||||
(long) testfiles[which].pos, (long) pos);
|
||||
}
|
||||
|
||||
readone(testfiles[which].name);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
readallonebyone(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("Trying to read each entry again...\n");
|
||||
for (i=0; testfiles[i].name; i++) {
|
||||
doreadone(i);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
readallrandomly(void)
|
||||
{
|
||||
int n, i, x;
|
||||
|
||||
printf("Trying to read a bunch of entries randomly...\n");
|
||||
|
||||
for (i=0; testfiles[i].name; i++);
|
||||
n = i;
|
||||
|
||||
srandom(39584);
|
||||
for (i=0; i<512; i++) {
|
||||
x = (int)(random()%n);
|
||||
doreadone(x);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
readateof(void)
|
||||
{
|
||||
char buf[4096];
|
||||
int len;
|
||||
|
||||
len = getdirentry(dirfd, buf, sizeof(buf)-1);
|
||||
if (len < 0) {
|
||||
err(1, ".: at EOF: getdirentry");
|
||||
}
|
||||
if (len==0) {
|
||||
return;
|
||||
}
|
||||
if ((unsigned)len >= sizeof(buf)-1) {
|
||||
errx(1, ".: at EOF: getdirentry returned "
|
||||
"invalid length %d", len);
|
||||
}
|
||||
buf[len] = 0;
|
||||
errx(1, ".: at EOF: got unexpected name %s", buf);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
doreadateof(void)
|
||||
{
|
||||
off_t pos;
|
||||
int i;
|
||||
|
||||
printf("Trying to read after going to EOF...\n");
|
||||
|
||||
pos = lseek(dirfd, 0, SEEK_END);
|
||||
if (pos<0) {
|
||||
err(1, ".: lseek(0, SEEK_END)");
|
||||
}
|
||||
|
||||
for (i=0; testfiles[i].name; i++) {
|
||||
if (pos <= testfiles[i].pos) {
|
||||
errx(1, ".: EOF position %ld below position %ld of %s",
|
||||
pos, testfiles[i].pos, testfiles[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
readateof();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
inval_read(void)
|
||||
{
|
||||
char buf[4096];
|
||||
int len;
|
||||
|
||||
len = getdirentry(dirfd, buf, sizeof(buf)-1);
|
||||
|
||||
/* Any result is ok, as long as the system doesn't crash */
|
||||
(void)len;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dobadreads(void)
|
||||
{
|
||||
off_t pos, pos2, eof;
|
||||
int valid, i, k=0;
|
||||
|
||||
printf("Trying some possibly invalid reads...\n");
|
||||
|
||||
eof = lseek(dirfd, 0, SEEK_END);
|
||||
if (eof < 0) {
|
||||
err(1, ".: lseek(0, SEEK_END)");
|
||||
}
|
||||
|
||||
for (pos=0; pos < eof; pos++) {
|
||||
valid = 0;
|
||||
for (i=0; testfiles[i].name; i++) {
|
||||
if (pos==testfiles[i].pos) {
|
||||
valid = 1;
|
||||
}
|
||||
}
|
||||
if (valid) {
|
||||
/* don't try offsets that are known to be valid */
|
||||
continue;
|
||||
}
|
||||
|
||||
pos2 = lseek(dirfd, pos, SEEK_SET);
|
||||
if (pos2 < 0) {
|
||||
/* this is ok */
|
||||
}
|
||||
else {
|
||||
inval_read();
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
if (k>0) {
|
||||
printf("Survived %d invalid reads...\n", k);
|
||||
}
|
||||
else {
|
||||
printf("Couldn't find any invalid offsets to try...\n");
|
||||
}
|
||||
|
||||
printf("Trying to read beyond EOF...\n");
|
||||
pos2 = lseek(dirfd, eof + 1000, SEEK_SET);
|
||||
if (pos2 < 0) {
|
||||
/* this is ok */
|
||||
}
|
||||
else {
|
||||
inval_read();
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dotest(void)
|
||||
{
|
||||
printf("Opening directory...\n");
|
||||
openit();
|
||||
|
||||
printf("Running tests...\n");
|
||||
|
||||
/* read the whole directory */
|
||||
firstread();
|
||||
|
||||
/* make sure eof behaves right */
|
||||
readateof();
|
||||
|
||||
/* read all the filenames again by seeking */
|
||||
readallonebyone();
|
||||
|
||||
/* try reading at eof */
|
||||
doreadateof();
|
||||
|
||||
/* read a bunch of the filenames over and over again */
|
||||
readallrandomly();
|
||||
|
||||
/* rewind and read the whole thing again, to make sure that works */
|
||||
doreadat0();
|
||||
|
||||
/* do invalid reads */
|
||||
dobadreads();
|
||||
|
||||
/* rewind again to make sure the invalid attempts didn't break it */
|
||||
doreadat0();
|
||||
|
||||
printf("Closing directory...\n");
|
||||
closeit();
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
/* Setup code */
|
||||
/************************************************************/
|
||||
|
||||
static
|
||||
void
|
||||
mkfile(const char *name)
|
||||
{
|
||||
int fd, i, r;
|
||||
static const char message[] = "The turtle moves!\n";
|
||||
char buf[32*sizeof(message)+1];
|
||||
|
||||
buf[0]=0;
|
||||
for (i=0; i<32; i++) {
|
||||
strcat(buf, message);
|
||||
}
|
||||
|
||||
/* Use O_EXCL, because we know the file shouldn't already be there */
|
||||
fd = open(name, O_WRONLY|O_CREAT|O_EXCL, 0664);
|
||||
if (fd<0) {
|
||||
err(1, "%s: create", name);
|
||||
}
|
||||
|
||||
r = write(fd, buf, strlen(buf));
|
||||
if (r<0) {
|
||||
err(1, "%s: write", name);
|
||||
}
|
||||
if ((unsigned)r != strlen(buf)) {
|
||||
errx(1, "%s: short write (%d bytes)", name, r);
|
||||
}
|
||||
|
||||
if (close(fd)<0) {
|
||||
err(1, "%s: close", name);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("Making directory %s...\n", TESTDIR);
|
||||
|
||||
/* Create a directory */
|
||||
if (mkdir(TESTDIR, 0775)<0) {
|
||||
err(1, "%s: mkdir", TESTDIR);
|
||||
}
|
||||
|
||||
/* Switch to it */
|
||||
if (chdir(TESTDIR)<0) {
|
||||
err(1, "%s: chdir", TESTDIR);
|
||||
}
|
||||
|
||||
printf("Making some files...\n");
|
||||
|
||||
/* Populate it */
|
||||
for (i=0; testfiles[i].name; i++) {
|
||||
if (testfiles[i].make_it) {
|
||||
mkfile(testfiles[i].name);
|
||||
}
|
||||
testfiles[i].pos = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("Cleaning up...\n");
|
||||
|
||||
/* Remove the files */
|
||||
for (i=0; testfiles[i].name; i++) {
|
||||
if (testfiles[i].make_it) {
|
||||
if (remove(testfiles[i].name)<0) {
|
||||
err(1, "%s: remove", testfiles[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Leave the dir */
|
||||
if (chdir("..")<0) {
|
||||
err(1, "..: chdir");
|
||||
}
|
||||
|
||||
/* Remove the dir */
|
||||
if (rmdir(TESTDIR)<0) {
|
||||
err(1, "%s: rmdir", TESTDIR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
setup();
|
||||
|
||||
/* Do the whole thing twice */
|
||||
dotest();
|
||||
dotest();
|
||||
|
||||
cleanup();
|
||||
return 0;
|
||||
}
|
11
userland/testbin/dirtest/Makefile
Normal file
11
userland/testbin/dirtest/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for dirtest
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=dirtest
|
||||
SRCS=dirtest.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
86
userland/testbin/dirtest/dirtest.c
Normal file
86
userland/testbin/dirtest/dirtest.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* dirtest.c
|
||||
*
|
||||
* Tests your hierarchical directory implementation by creating
|
||||
* and deleting directories.
|
||||
*
|
||||
* Works in the current directory.
|
||||
*
|
||||
* Intended for the file system assignment. Should run (on SFS)
|
||||
* when that assignment is complete.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
|
||||
#define MAXLEVELS 5
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
const char *onename = "testdir";
|
||||
char dirname[512];
|
||||
|
||||
strcpy(dirname, onename);
|
||||
|
||||
for (i=0; i<MAXLEVELS; i++) {
|
||||
printf("Creating directory: %s\n", dirname);
|
||||
|
||||
if (mkdir(dirname, 0755)) {
|
||||
err(1, "%s: mkdir", dirname);
|
||||
}
|
||||
|
||||
strcat(dirname, "/");
|
||||
strcat(dirname, onename);
|
||||
}
|
||||
|
||||
printf("Passed directory creation test.\n");
|
||||
|
||||
for (i=0; i<MAXLEVELS; i++) {
|
||||
dirname[strlen(dirname) - strlen(onename) - 1] = 0;
|
||||
|
||||
printf("Removing directory: %s\n", dirname);
|
||||
|
||||
if (rmdir(dirname)) {
|
||||
err(1, "%s: rmdir", dirname);
|
||||
}
|
||||
}
|
||||
printf("Passed directory removal test.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
11
userland/testbin/f_test/Makefile
Normal file
11
userland/testbin/f_test/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for f_test
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=f_test
|
||||
SRCS=f_test.c f_read.c f_write.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
31
userland/testbin/f_test/f_hdr.h
Normal file
31
userland/testbin/f_test/f_hdr.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void subproc_read(void);
|
||||
void subproc_write(void);
|
106
userland/testbin/f_test/f_read.c
Normal file
106
userland/testbin/f_test/f_read.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* f_read.c
|
||||
*
|
||||
* This used to be a separate binary, because it came from Nachos
|
||||
* and nachos didn't support fork(). However, in OS/161 there's
|
||||
* no reason to make it a separate binary; doing so just makes
|
||||
* the test flaky.
|
||||
*
|
||||
*
|
||||
* it will start reading from a given file, concurrently
|
||||
* with other instances of f_read and f_write.
|
||||
*
|
||||
*/
|
||||
|
||||
#define SectorSize 512
|
||||
|
||||
#define TMULT 50
|
||||
#define FSIZE ((SectorSize + 1) * TMULT)
|
||||
|
||||
#define FNAME "f-testfile"
|
||||
#define READCHAR 'r'
|
||||
#define WRITECHAR 'w'
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include "f_hdr.h"
|
||||
|
||||
static char buffer[SectorSize + 1];
|
||||
|
||||
static
|
||||
void
|
||||
check_buffer(void)
|
||||
{
|
||||
int i;
|
||||
char ch = buffer[0];
|
||||
|
||||
for (i = 1; i < SectorSize + 1; i++) {
|
||||
if (buffer[i] != ch) {
|
||||
errx(1, "Read error: %s", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
putchar(ch);
|
||||
}
|
||||
|
||||
void
|
||||
subproc_read(void)
|
||||
{
|
||||
int fd;
|
||||
int i, res;
|
||||
|
||||
printf("File Reader starting ...\n\n");
|
||||
|
||||
fd = open(FNAME, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
err(1, "%s: open", FNAME);
|
||||
}
|
||||
|
||||
for (i=0; i<TMULT; i++) {
|
||||
res = read(fd, buffer, SectorSize + 1);
|
||||
if (res < 0) {
|
||||
err(1, "%s: read", FNAME);
|
||||
}
|
||||
|
||||
// yield();
|
||||
|
||||
if (res != SectorSize + 1) {
|
||||
errx(1, "%s: read: short count", FNAME);
|
||||
}
|
||||
check_buffer();
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
printf("File Read exited successfully!\n");
|
||||
}
|
348
userland/testbin/f_test/f_test.c
Normal file
348
userland/testbin/f_test/f_test.c
Normal file
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Razvan Surdulescu
|
||||
* abhi shelat
|
||||
* April 28 1997
|
||||
*
|
||||
* Test suite for Nachos HW4--The Filesystem
|
||||
*
|
||||
* Modified by dholland 1/31/2001 for OS/161
|
||||
*
|
||||
* This should run successfully (on SFS) when the file system
|
||||
* assignment is complete.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include "f_hdr.h"
|
||||
|
||||
#define SECTOR_SIZE 512
|
||||
|
||||
|
||||
#define BUFFER_SIZE (2 * SECTOR_SIZE + 1)
|
||||
#define BIGFILE_SIZE (270 * BUFFER_SIZE)
|
||||
#define BIGFILE_NAME "large-f"
|
||||
|
||||
#define LETTER(x) ('a' + (x % 31))
|
||||
|
||||
char fbuffer[BUFFER_SIZE];
|
||||
char ibuffer[32];
|
||||
|
||||
|
||||
#define DIR_DEPTH 8
|
||||
#define DIR_NAME "/t"
|
||||
#define DIRFILE_NAME "a"
|
||||
|
||||
|
||||
#define FNAME "f-testfile"
|
||||
#define TMULT 50
|
||||
#define FSIZE ((SECTOR_SIZE + 1) * TMULT)
|
||||
|
||||
#define READCHAR 'r'
|
||||
#define WRITECHAR 'w'
|
||||
|
||||
char cbuffer[SECTOR_SIZE + 1];
|
||||
|
||||
|
||||
/* ===================================================
|
||||
|
||||
*/
|
||||
|
||||
static
|
||||
pid_t
|
||||
forkoff(void (*func)(void))
|
||||
{
|
||||
pid_t pid = fork();
|
||||
switch (pid) {
|
||||
case -1:
|
||||
warn("fork");
|
||||
return -1;
|
||||
case 0:
|
||||
func();
|
||||
_exit(0);
|
||||
default: break;
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dowait(int pid)
|
||||
{
|
||||
int status;
|
||||
|
||||
if (waitpid(pid, &status, 0)<0) {
|
||||
warn("waitpid for %d", pid);
|
||||
}
|
||||
else if (WIFSIGNALED(status)) {
|
||||
warnx("pid %d: signal %d", pid, WTERMSIG(status));
|
||||
}
|
||||
else if (WEXITSTATUS(status) != 0) {
|
||||
warnx("pid %d: exit %d", pid, WEXITSTATUS(status));
|
||||
}
|
||||
}
|
||||
|
||||
/* ===================================================
|
||||
|
||||
*/
|
||||
|
||||
static
|
||||
void
|
||||
big_file(int size)
|
||||
{
|
||||
int i, j, fileid;
|
||||
|
||||
printf("[BIGFILE] test starting :\n");
|
||||
printf("\tCreating a file of size: %d\n", size);
|
||||
|
||||
fileid = open(BIGFILE_NAME, O_WRONLY|O_CREAT|O_TRUNC, 0664);
|
||||
if (fileid < 0) {
|
||||
err(1, "[BIGFILE]: %s: open for write", BIGFILE_NAME);
|
||||
}
|
||||
|
||||
for(i = 0; i < BUFFER_SIZE; i++) {
|
||||
fbuffer[i] = LETTER(i);
|
||||
}
|
||||
|
||||
printf("\tWriting to file.\n");
|
||||
for (i = 0; i < size; i += BUFFER_SIZE) {
|
||||
write(fileid, fbuffer, BUFFER_SIZE);
|
||||
|
||||
if (!(i % (10 * BUFFER_SIZE))) {
|
||||
printf("\rBW : %d", i);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n\tReading from file.\n");
|
||||
close(fileid);
|
||||
|
||||
fileid = open(BIGFILE_NAME, O_RDONLY);
|
||||
if (fileid < 0) {
|
||||
err(1, "[BIGFILE]: %s: open for read", BIGFILE_NAME);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i += BUFFER_SIZE) {
|
||||
j = read(fileid, fbuffer, BUFFER_SIZE);
|
||||
if (j<0) {
|
||||
err(1, "[BIGFILE]: read");
|
||||
}
|
||||
if (j != BUFFER_SIZE) {
|
||||
errx(1, "[BIGFILE]: read: only %d bytes", j);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(i % (10 * BUFFER_SIZE))) {
|
||||
printf("\rBR : %d", i);
|
||||
}
|
||||
|
||||
/* Check to see that the data is consistent : */
|
||||
for (j = 0; j < BUFFER_SIZE; j++) {
|
||||
if (fbuffer[j] != LETTER(j)) {
|
||||
errx(1, "[BIGFILE] : Failed read check : "
|
||||
"inconsistent data read: %d", i+j);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
close(fileid);
|
||||
if (remove(BIGFILE_NAME)) {
|
||||
err(1, "[BIGFILE]: %s: remove", BIGFILE_NAME);
|
||||
}
|
||||
|
||||
printf("\n[BIGFILE] : Success!\n");
|
||||
}
|
||||
|
||||
/* ===================================================
|
||||
|
||||
*/
|
||||
|
||||
static
|
||||
void
|
||||
concur(void)
|
||||
{
|
||||
int i, fd;
|
||||
int r1, r2, w1;
|
||||
|
||||
printf("Spawning 2 readers, 1 writer.\n");
|
||||
|
||||
|
||||
fd = open(FNAME, O_WRONLY|O_CREAT|O_TRUNC, 0664);
|
||||
if (fd < 0) {
|
||||
err(1, "[CONCUR]: %s: open", FNAME);
|
||||
}
|
||||
|
||||
printf("Initializing test file: ");
|
||||
|
||||
for (i = 0; i < SECTOR_SIZE + 1; i++) {
|
||||
cbuffer[i] = READCHAR;
|
||||
}
|
||||
|
||||
for (i = 0; i < TMULT; i++) {
|
||||
write(fd, cbuffer, SECTOR_SIZE + 1);
|
||||
}
|
||||
|
||||
|
||||
close(fd);
|
||||
|
||||
printf("Done initializing. Starting processes...\n");
|
||||
|
||||
r1 = forkoff(subproc_read);
|
||||
w1 = forkoff(subproc_write);
|
||||
r2 = forkoff(subproc_read);
|
||||
|
||||
printf("Waiting for processes.\n");
|
||||
|
||||
dowait(r1);
|
||||
dowait(r2);
|
||||
dowait(w1);
|
||||
|
||||
if (remove(FNAME)) {
|
||||
err(1, "[CONCUR]: %s: remove", FNAME);
|
||||
}
|
||||
|
||||
printf("[CONCUR] Done!\n");
|
||||
}
|
||||
|
||||
/* ===================================================
|
||||
|
||||
*/
|
||||
|
||||
static
|
||||
void
|
||||
dir_test(int depth)
|
||||
{
|
||||
int i, fd;
|
||||
char tmp[] = DIR_NAME;
|
||||
char fmp[] = DIRFILE_NAME;
|
||||
char dirname[64];
|
||||
|
||||
strcpy(dirname, ".");
|
||||
|
||||
for (i = 0; i < depth; i++) {
|
||||
strcat(dirname, tmp);
|
||||
|
||||
printf("\tCreating dir : %s\n", dirname);
|
||||
|
||||
if (mkdir(dirname, 0775) < 0) {
|
||||
err(1, "[DIRTEST]: %s: mkdir", dirname);
|
||||
}
|
||||
|
||||
strcat(dirname, fmp);
|
||||
printf("\tCreating file: %s\n", dirname);
|
||||
|
||||
fd = open(dirname, O_WRONLY|O_CREAT|O_TRUNC, 0664);
|
||||
if (fd<0) {
|
||||
err(1, "[DIRTEST]: %s: open", dirname);
|
||||
}
|
||||
|
||||
dirname[strlen(dirname) - strlen(fmp)] = '\0';
|
||||
}
|
||||
|
||||
printf("[DIRTEST] : Passed directory creation test.\n");
|
||||
|
||||
for (i = 0; i < depth; i++) {
|
||||
strcat(dirname, fmp);
|
||||
|
||||
printf("\tDeleting file: %s\n", dirname);
|
||||
|
||||
if (remove(dirname)) {
|
||||
err(1, "[DIRTEST]: %s: remove", dirname);
|
||||
}
|
||||
|
||||
dirname[strlen(dirname) - strlen(fmp)] = '\0';
|
||||
printf("\tRemoving dir : %s\n", dirname);
|
||||
|
||||
if (rmdir(dirname)) {
|
||||
err(1, "[DIRTEST]: %s: rmdir", dirname);
|
||||
}
|
||||
|
||||
dirname[strlen(dirname) - strlen(tmp)] = '\0';
|
||||
}
|
||||
|
||||
printf("[DIRTEST] : Passed directory removal test.\n");
|
||||
printf("[DIRTEST] : Success!\n");
|
||||
}
|
||||
|
||||
/* ===================================================
|
||||
|
||||
*/
|
||||
|
||||
#define RUNBIGFILE 0x1
|
||||
#define RUNDIRTEST 0x2
|
||||
#define RUNCONCUR 0x4
|
||||
#define RUNTHEMALL (RUNBIGFILE | RUNDIRTEST | RUNCONCUR)
|
||||
|
||||
int
|
||||
main(int argc, char * argv[])
|
||||
{
|
||||
int tv = 0;
|
||||
|
||||
if (argc > 1) {
|
||||
if (*argv[1]=='1') {
|
||||
tv = RUNBIGFILE;
|
||||
}
|
||||
else if (*argv[1]=='2') {
|
||||
tv = RUNDIRTEST;
|
||||
}
|
||||
else if (*argv[1]=='3') {
|
||||
tv = RUNCONCUR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tv = RUNTHEMALL;
|
||||
}
|
||||
|
||||
if (tv & RUNBIGFILE) {
|
||||
printf("[BIGFILE] : Run #1\n");
|
||||
big_file(BIGFILE_SIZE);
|
||||
printf("[BIGFILE] : Run #2\n");
|
||||
big_file(BIGFILE_SIZE);
|
||||
}
|
||||
|
||||
if (tv & RUNDIRTEST) {
|
||||
printf("[DIRTEST] : Run #1\n");
|
||||
dir_test(DIR_DEPTH);
|
||||
printf("[DIRTEST] : Run #2\n");
|
||||
dir_test(DIR_DEPTH);
|
||||
}
|
||||
|
||||
if (tv & RUNCONCUR) {
|
||||
printf("[CONCUR]\n");
|
||||
concur();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
85
userland/testbin/f_test/f_write.c
Normal file
85
userland/testbin/f_test/f_write.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* f_write.c
|
||||
*
|
||||
* This used to be a separate binary, because it came from Nachos
|
||||
* and nachos didn't support fork(). However, in OS/161 there's
|
||||
* no reason to make it a separate binary; doing so just makes
|
||||
* the test flaky.
|
||||
*
|
||||
*
|
||||
* It will start writing into a file, concurrently with
|
||||
* one or more instances of f_read.
|
||||
*
|
||||
*/
|
||||
|
||||
#define SectorSize 512
|
||||
|
||||
#define TMULT 50
|
||||
#define FSIZE ((SectorSize + 1) * TMULT)
|
||||
|
||||
#define FNAME "f-testfile"
|
||||
#define READCHAR 'r'
|
||||
#define WRITECHAR 'w'
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <err.h>
|
||||
#include "f_hdr.h"
|
||||
|
||||
static char buffer[SectorSize + 1];
|
||||
|
||||
void
|
||||
subproc_write(void)
|
||||
{
|
||||
int fd;
|
||||
int i;
|
||||
|
||||
for (i=0; i < SectorSize + 1; i++) {
|
||||
buffer[i] = WRITECHAR;
|
||||
}
|
||||
|
||||
printf("File Writer starting ...\n");
|
||||
|
||||
fd = open(FNAME, O_WRONLY);
|
||||
if (fd < 0) {
|
||||
err(1, "%s: open", FNAME);
|
||||
}
|
||||
|
||||
for (i=0; i<TMULT; i++) {
|
||||
// yield();
|
||||
write(fd, buffer, SectorSize + 1);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
printf("File Write exited successfully!\n");
|
||||
}
|
11
userland/testbin/factorial/Makefile
Normal file
11
userland/testbin/factorial/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for factorial
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=factorial
|
||||
SRCS=factorial.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
263
userland/testbin/factorial/factorial.c
Normal file
263
userland/testbin/factorial/factorial.c
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
* Copyright (c) 2014
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
|
||||
#define _PATH_SELF "/testbin/factorial"
|
||||
|
||||
/*
|
||||
* factorial - compute factorials by recursive exec
|
||||
*
|
||||
* External usage: factorial N
|
||||
* (compute N!)
|
||||
*
|
||||
* Internal usage: factoral N M
|
||||
* (compute N! * M)
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// arithmetic
|
||||
|
||||
/*
|
||||
* We compute using binary-coded decimal integers where
|
||||
* each byte contains the digit characters '0' through '9'.
|
||||
* This is not exactly optimum for computation but it's
|
||||
* perfect for sending numbers through execv.
|
||||
*/
|
||||
|
||||
#define NUMSIZE 8191
|
||||
struct number {
|
||||
char buf[NUMSIZE+1]; /* includes space for a null-terminator */
|
||||
size_t first; /* first valid digit */
|
||||
};
|
||||
|
||||
static struct number scratch;
|
||||
|
||||
static
|
||||
void
|
||||
number_init(struct number *n, const char *txt)
|
||||
{
|
||||
size_t len, i;
|
||||
|
||||
len = strlen(txt);
|
||||
if (len > NUMSIZE) {
|
||||
warnx("%s", txt);
|
||||
errx(1, "Number too large");
|
||||
}
|
||||
n->first = NUMSIZE - len;
|
||||
strcpy(n->buf + n->first, txt);
|
||||
#if 0
|
||||
for (i=0; i<n->first; i++) {
|
||||
n->buf[i] = '0';
|
||||
}
|
||||
#endif
|
||||
for (i=n->first; i<NUMSIZE; i++) {
|
||||
if (n->buf[i] < '0' || n->buf[i] > '9') {
|
||||
warnx("%s", txt);
|
||||
errx(1, "Number contained non-digit characters");
|
||||
}
|
||||
}
|
||||
assert(n->buf[NUMSIZE] == 0);
|
||||
while (n->first < NUMSIZE && n->buf[n->first] == '0') {
|
||||
n->first++;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
char *
|
||||
number_get(struct number *n)
|
||||
{
|
||||
size_t pos;
|
||||
|
||||
pos = n->first;
|
||||
while (pos < NUMSIZE && n->buf[pos] == '0') {
|
||||
pos++;
|
||||
}
|
||||
if (pos == NUMSIZE) {
|
||||
pos--;
|
||||
n->buf[pos] = '0';
|
||||
}
|
||||
return &n->buf[pos];
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
finishcarry(struct number *r, const struct number *b, size_t pos,
|
||||
unsigned carry)
|
||||
{
|
||||
if (carry > 0 && b->first == 0) {
|
||||
/* if b->first is 0, pos may now be 2^32-1 */
|
||||
errx(1, "Overflow");
|
||||
}
|
||||
while (carry > 0) {
|
||||
if (pos == 0) {
|
||||
errx(1, "Overflow");
|
||||
}
|
||||
r->buf[pos--] = carry % 10 + '0';
|
||||
carry = carry / 10;
|
||||
}
|
||||
r->first = pos + 1;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
pluseq(struct number *r, const struct number *b)
|
||||
{
|
||||
size_t pos;
|
||||
unsigned an, bn, rn, carry;
|
||||
|
||||
carry = 0;
|
||||
for (pos = NUMSIZE; pos-- > b->first; ) {
|
||||
an = pos < r->first ? 0 : r->buf[pos] - '0';
|
||||
bn = b->buf[pos] - '0';
|
||||
rn = an + bn + carry;
|
||||
r->buf[pos] = rn % 10 + '0';
|
||||
carry = rn / 10;
|
||||
}
|
||||
finishcarry(r, b, pos, carry);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
dec(struct number *r)
|
||||
{
|
||||
size_t pos;
|
||||
|
||||
for (pos = NUMSIZE; pos-- > r->first; ) {
|
||||
if (r->buf[pos] == '0') {
|
||||
r->buf[pos] = '9';
|
||||
}
|
||||
else {
|
||||
r->buf[pos]--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* This should really not happen. */
|
||||
errx(1, "Underflow");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
multc(struct number *r, const struct number *a, unsigned bn, size_t offset)
|
||||
{
|
||||
size_t pos;
|
||||
unsigned an, rn, carry;
|
||||
|
||||
for (pos = NUMSIZE; pos-- > NUMSIZE - offset; ) {
|
||||
r->buf[pos] = '0';
|
||||
}
|
||||
carry = 0;
|
||||
for (pos = NUMSIZE; pos-- > a->first; ) {
|
||||
an = a->buf[pos] - '0';
|
||||
rn = an * bn + carry;
|
||||
if (pos < offset) {
|
||||
errx(1, "Overflow");
|
||||
}
|
||||
r->buf[pos - offset] = rn % 10 + '0';
|
||||
carry = rn / 10;
|
||||
}
|
||||
if (carry > 0 && pos < offset) {
|
||||
errx(1, "Overflow");
|
||||
}
|
||||
finishcarry(r, a, pos - offset, carry);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
mult(struct number *r, const struct number *a, const struct number *b)
|
||||
{
|
||||
unsigned offset;
|
||||
size_t apos;
|
||||
|
||||
/* B should normally be the larger number */
|
||||
if (a->first < b->first) {
|
||||
mult(r, b, a);
|
||||
return;
|
||||
}
|
||||
|
||||
number_init(&scratch, "0");
|
||||
offset = 0;
|
||||
for (apos = NUMSIZE; apos-- > a->first; ) {
|
||||
multc(&scratch, b, a->buf[apos] - '0', offset);
|
||||
pluseq(r, &scratch);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// argv logic
|
||||
|
||||
static
|
||||
void
|
||||
self(const char *arg1, const char *arg2)
|
||||
{
|
||||
const char *args[4];
|
||||
|
||||
args[0] = _PATH_SELF;
|
||||
args[1] = arg1;
|
||||
args[2] = arg2;
|
||||
args[3] = NULL;
|
||||
execv(_PATH_SELF, (char **)args);
|
||||
err(1, "execv");
|
||||
}
|
||||
|
||||
static struct number n1, n2, multbuf;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc == 0) {
|
||||
/* Assume we've just been run from the menu. */
|
||||
self("404", "1");
|
||||
}
|
||||
else if (argc == 2) {
|
||||
self(argv[1], "1");
|
||||
}
|
||||
else if (argc == 3) {
|
||||
if (!strcmp(argv[1], "1") || !strcmp(argv[1], "0")) {
|
||||
printf("%s\n", argv[2]);
|
||||
}
|
||||
else {
|
||||
number_init(&n1, argv[1]);
|
||||
number_init(&n2, argv[2]);
|
||||
number_init(&multbuf, "0");
|
||||
mult(&multbuf, &n1, &n2);
|
||||
dec(&n1);
|
||||
self(number_get(&n1), number_get(&multbuf));
|
||||
}
|
||||
}
|
||||
else {
|
||||
warnx("Usage: factorial N");
|
||||
}
|
||||
return 0;
|
||||
}
|
11
userland/testbin/farm/Makefile
Normal file
11
userland/testbin/farm/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for farm
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=farm
|
||||
SRCS=farm.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
111
userland/testbin/farm/farm.c
Normal file
111
userland/testbin/farm/farm.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* farm.c
|
||||
*
|
||||
* Run a bunch of cpu pigs and one cat.
|
||||
* The file it cats is "catfile". This should be created in advance.
|
||||
*
|
||||
* This test should itself run correctly when the basic system calls
|
||||
* are complete. It may be helpful for scheduler performance analysis.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
static char *hargv[2] = { (char *)"hog", NULL };
|
||||
static char *cargv[3] = { (char *)"cat", (char *)"catfile", NULL };
|
||||
|
||||
#define MAXPROCS 6
|
||||
static int pids[MAXPROCS], npids;
|
||||
|
||||
static
|
||||
void
|
||||
spawnv(const char *prog, char **argv)
|
||||
{
|
||||
int pid = fork();
|
||||
switch (pid) {
|
||||
case -1:
|
||||
err(1, "fork");
|
||||
case 0:
|
||||
/* child */
|
||||
execv(prog, argv);
|
||||
err(1, "%s", prog);
|
||||
default:
|
||||
/* parent */
|
||||
pids[npids++] = pid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
waitall(void)
|
||||
{
|
||||
int i, status;
|
||||
for (i=0; i<npids; i++) {
|
||||
if (waitpid(pids[i], &status, 0)<0) {
|
||||
warn("waitpid for %d", pids[i]);
|
||||
}
|
||||
else if (WIFSIGNALED(status)) {
|
||||
warnx("pid %d: signal %d", pids[i], WTERMSIG(status));
|
||||
}
|
||||
else if (WEXITSTATUS(status) != 0) {
|
||||
warnx("pid %d: exit %d", pids[i], WEXITSTATUS(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
hog(void)
|
||||
{
|
||||
spawnv("/testbin/hog", hargv);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
cat(void)
|
||||
{
|
||||
spawnv("/bin/cat", cargv);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
hog();
|
||||
hog();
|
||||
hog();
|
||||
cat();
|
||||
|
||||
waitall();
|
||||
|
||||
return 0;
|
||||
}
|
11
userland/testbin/faulter/Makefile
Normal file
11
userland/testbin/faulter/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for faulter
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=faulter
|
||||
SRCS=faulter.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
56
userland/testbin/faulter/faulter.c
Normal file
56
userland/testbin/faulter/faulter.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* faulter.c
|
||||
*
|
||||
* Tries to access an illegal address.
|
||||
*
|
||||
* When the system calls assignment is complete, this should run and
|
||||
* get killed without causing the kernel to panic.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define REALLY_BIG_ADDRESS 0x40000000
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
volatile int i;
|
||||
|
||||
printf("\nEntering the faulter program - I should die immediately\n");
|
||||
i = *(int *)REALLY_BIG_ADDRESS;
|
||||
|
||||
// gcc 4.8 improperly demands this
|
||||
(void)i;
|
||||
|
||||
printf("I didn't get killed! Program has a bug\n");
|
||||
return 0;
|
||||
}
|
11
userland/testbin/filetest/Makefile
Normal file
11
userland/testbin/filetest/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for filetest
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=filetest
|
||||
SRCS=filetest.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
108
userland/testbin/filetest/filetest.c
Normal file
108
userland/testbin/filetest/filetest.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* filetest.c
|
||||
*
|
||||
* Tests the filesystem by opening, writing to and reading from a
|
||||
* user specified file.
|
||||
*
|
||||
* This should run (on SFS) even before the file system assignment is started.
|
||||
* It should also continue to work once said assignment is complete.
|
||||
* It will not run fully on emufs, because emufs does not support remove().
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
static char writebuf[40] = "Twiddle dee dee, Twiddle dum dum.......\n";
|
||||
static char readbuf[41];
|
||||
|
||||
const char *file;
|
||||
int fd, rv;
|
||||
|
||||
if (argc == 0) {
|
||||
warnx("No arguments - running on \"testfile\"");
|
||||
file = "testfile";
|
||||
}
|
||||
else if (argc == 2) {
|
||||
file = argv[1];
|
||||
}
|
||||
else {
|
||||
errx(1, "Usage: filetest <filename>");
|
||||
}
|
||||
|
||||
fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0664);
|
||||
if (fd<0) {
|
||||
err(1, "%s: open for write", file);
|
||||
}
|
||||
|
||||
|
||||
rv = write(fd, writebuf, 40);
|
||||
if (rv<0) {
|
||||
err(1, "%s: write", file);
|
||||
}
|
||||
|
||||
rv = close(fd);
|
||||
if (rv<0) {
|
||||
err(1, "%s: close (1st time)", file);
|
||||
}
|
||||
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd<0) {
|
||||
err(1, "%s: open for read", file);
|
||||
}
|
||||
|
||||
rv = read(fd, readbuf, 40);
|
||||
if (rv<0) {
|
||||
err(1, "%s: read", file);
|
||||
}
|
||||
rv = close(fd);
|
||||
if (rv<0) {
|
||||
err(1, "%s: close (2nd time)", file);
|
||||
}
|
||||
/* ensure null termination */
|
||||
readbuf[40] = 0;
|
||||
|
||||
if (strcmp(readbuf, writebuf)) {
|
||||
errx(1, "Buffer data mismatch!");
|
||||
}
|
||||
|
||||
rv = remove(file);
|
||||
if (rv<0) {
|
||||
err(1, "%s: remove", file);
|
||||
}
|
||||
printf("Passed filetest.\n");
|
||||
return 0;
|
||||
}
|
11
userland/testbin/forkbomb/Makefile
Normal file
11
userland/testbin/forkbomb/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for forkbomb
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=forkbomb
|
||||
SRCS=forkbomb.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
76
userland/testbin/forkbomb/forkbomb.c
Normal file
76
userland/testbin/forkbomb/forkbomb.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* forkbomb - apply malthus to an operating system ;-)
|
||||
*
|
||||
* DO NOT RUN THIS ON A REAL SYSTEM - IT WILL GRIND TO A HALT AND
|
||||
* PEOPLE WILL COME AFTER YOU WIELDING BASEBALL BATS OR THE AD
|
||||
* BOARD(*). WE WARNED YOU.
|
||||
*
|
||||
* We don't expect your system to withstand this without grinding to
|
||||
* a halt, but once your basic system calls are complete it shouldn't
|
||||
* crash. Likewise for after your virtual memory system is complete.
|
||||
*
|
||||
* (...at least in an ideal world. However, it can be difficult to
|
||||
* handle all the loose ends involved. Heroic measures are not
|
||||
* expected. If in doubt, talk to the course staff.)
|
||||
*
|
||||
*
|
||||
* (*) The Administrative Board of Harvard College handles formal
|
||||
* disciplinary action.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
static volatile int pid;
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
while (1) {
|
||||
fork();
|
||||
|
||||
pid = getpid();
|
||||
|
||||
/* Make sure each fork has its own address space. */
|
||||
for (i=0; i<300; i++) {
|
||||
volatile int seenpid;
|
||||
seenpid = pid;
|
||||
if (seenpid != getpid()) {
|
||||
errx(1, "pid mismatch (%d, should be %d) "
|
||||
"- your vm is broken!",
|
||||
seenpid, getpid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
userland/testbin/forktest/Makefile
Normal file
11
userland/testbin/forktest/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for forktest
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=forktest
|
||||
SRCS=forktest.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
190
userland/testbin/forktest/forktest.c
Normal file
190
userland/testbin/forktest/forktest.c
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* forktest - test fork().
|
||||
*
|
||||
* This should work correctly when fork is implemented.
|
||||
*
|
||||
* It should also continue to work after subsequent assignments, most
|
||||
* notably after implementing the virtual memory system.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <err.h>
|
||||
|
||||
/*
|
||||
* This is used by all processes, to try to help make sure all
|
||||
* processes have a distinct address space.
|
||||
*/
|
||||
static volatile int mypid;
|
||||
|
||||
/*
|
||||
* Helper function for fork that prints a warning on error.
|
||||
*/
|
||||
static
|
||||
int
|
||||
dofork(void)
|
||||
{
|
||||
int pid;
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
warn("fork");
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to make sure each process has its own address space. Write
|
||||
* the pid into the data segment and read it back repeatedly, making
|
||||
* sure it's correct every time.
|
||||
*/
|
||||
static
|
||||
void
|
||||
check(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
mypid = getpid();
|
||||
|
||||
/* Make sure each fork has its own address space. */
|
||||
for (i=0; i<800; i++) {
|
||||
volatile int seenpid;
|
||||
seenpid = mypid;
|
||||
if (seenpid != getpid()) {
|
||||
errx(1, "pid mismatch (%d, should be %d) "
|
||||
"- your vm is broken!",
|
||||
seenpid, getpid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for a child process.
|
||||
*
|
||||
* This assumes dowait is called the same number of times as dofork
|
||||
* and passed its results in reverse order. Any forks that fail send
|
||||
* us -1 and are ignored. The first 0 we see indicates the fork that
|
||||
* generated the current process; that means it's time to exit. Only
|
||||
* the parent of all the processes returns from the chain of dowaits.
|
||||
*/
|
||||
static
|
||||
void
|
||||
dowait(int nowait, int pid)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (pid<0) {
|
||||
/* fork in question failed; just return */
|
||||
return;
|
||||
}
|
||||
if (pid==0) {
|
||||
/* in the fork in question we were the child; exit */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!nowait) {
|
||||
if (waitpid(pid, &x, 0)<0) {
|
||||
warn("waitpid");
|
||||
}
|
||||
else if (WIFSIGNALED(x)) {
|
||||
warnx("pid %d: signal %d", pid, WTERMSIG(x));
|
||||
}
|
||||
else if (WEXITSTATUS(x) != 0) {
|
||||
warnx("pid %d: exit %d", pid, WEXITSTATUS(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Actually run the test.
|
||||
*/
|
||||
static
|
||||
void
|
||||
test(int nowait)
|
||||
{
|
||||
int pid0, pid1, pid2, pid3;
|
||||
|
||||
/*
|
||||
* Caution: This generates processes geometrically.
|
||||
*
|
||||
* It is unrolled to encourage gcc to registerize the pids,
|
||||
* to prevent wait/exit problems if fork corrupts memory.
|
||||
*/
|
||||
|
||||
pid0 = dofork();
|
||||
putchar('A');
|
||||
check();
|
||||
pid1 = dofork();
|
||||
putchar('B');
|
||||
check();
|
||||
pid2 = dofork();
|
||||
putchar('C');
|
||||
check();
|
||||
pid3 = dofork();
|
||||
putchar('D');
|
||||
check();
|
||||
|
||||
/*
|
||||
* These must be called in reverse order to avoid waiting
|
||||
* improperly.
|
||||
*/
|
||||
dowait(nowait, pid3);
|
||||
dowait(nowait, pid2);
|
||||
dowait(nowait, pid1);
|
||||
dowait(nowait, pid0);
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
static const char expected[] =
|
||||
"|----------------------------|\n";
|
||||
int nowait=0;
|
||||
|
||||
if (argc==2 && !strcmp(argv[1], "-w")) {
|
||||
nowait=1;
|
||||
}
|
||||
else if (argc!=1 && argc!=0) {
|
||||
warnx("usage: forktest [-w]");
|
||||
return 1;
|
||||
}
|
||||
warnx("Starting. Expect this many:");
|
||||
write(STDERR_FILENO, expected, strlen(expected));
|
||||
|
||||
test(nowait);
|
||||
|
||||
warnx("Complete.");
|
||||
return 0;
|
||||
}
|
11
userland/testbin/frack/Makefile
Normal file
11
userland/testbin/frack/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for frack
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=frack
|
||||
SRCS=main.c workloads.c ops.c do.c check.c pool.c data.c name.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
2911
userland/testbin/frack/check.c
Normal file
2911
userland/testbin/frack/check.c
Normal file
File diff suppressed because it is too large
Load Diff
51
userland/testbin/frack/check.h
Normal file
51
userland/testbin/frack/check.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
int check_createfile(unsigned name);
|
||||
int check_openfile(unsigned name);
|
||||
void check_closefile(int handle, unsigned name);
|
||||
void check_write(int handle, unsigned name, unsigned code, unsigned seq,
|
||||
off_t pos, off_t len);
|
||||
void check_truncate(int handle, unsigned name, off_t len);
|
||||
void check_mkdir(unsigned name);
|
||||
void check_rmdir(unsigned name);
|
||||
void check_unlink(unsigned name);
|
||||
void check_link(unsigned from, unsigned to);
|
||||
void check_rename(unsigned from, unsigned to);
|
||||
void check_renamexd(unsigned fromdir, unsigned from,
|
||||
unsigned todir, unsigned to);
|
||||
void check_chdir(unsigned name);
|
||||
void check_chdirup(void);
|
||||
void check_sync(void);
|
||||
|
||||
|
||||
void check_setup(void);
|
||||
void checkfs(void);
|
227
userland/testbin/frack/data.c
Normal file
227
userland/testbin/frack/data.c
Normal file
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "data.h"
|
||||
|
||||
/*
|
||||
* XXX for now hardwire things we know about SFS
|
||||
*/
|
||||
#define BLOCKSIZE /*SFS_BLOCKSIZE*/ 512
|
||||
|
||||
static char databuf[DATA_MAXSIZE];
|
||||
static char readbuf[DATA_MAXSIZE];
|
||||
|
||||
static
|
||||
void
|
||||
prepdata(unsigned code, unsigned seq, char *buf, off_t len)
|
||||
{
|
||||
char smallbuf[32];
|
||||
char letter;
|
||||
size_t slen;
|
||||
|
||||
snprintf(smallbuf, sizeof(smallbuf), "%u@%u\n", seq, code);
|
||||
slen = strlen(smallbuf);
|
||||
|
||||
while (len >= slen) {
|
||||
memcpy(buf, smallbuf, slen);
|
||||
buf += slen;
|
||||
len -= slen;
|
||||
}
|
||||
if (len > 1) {
|
||||
letter = 'A' + (code + seq) % 26;
|
||||
memset(buf, letter, len - 1);
|
||||
buf += len - 1;
|
||||
}
|
||||
if (len > 0) {
|
||||
*buf = '\n';
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
matches_at(size_t start, size_t len)
|
||||
{
|
||||
if (!memcmp(databuf + start, readbuf + start, len)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
byte_at(size_t start, size_t len, unsigned char val)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
if ((unsigned char)readbuf[start + i] != val) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
zero_at(size_t start, size_t len)
|
||||
{
|
||||
return byte_at(start, len, 0);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
poison_at(size_t start, size_t len)
|
||||
{
|
||||
return byte_at(start, len, POISON_VAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the data found in the read buffer matches what should be
|
||||
* there.
|
||||
* NAMESTR is the name of the file, for error reporting.
|
||||
* REGIONOFFSET is where the write region began.
|
||||
* CODE and SEQ are the keys for generating the expected data.
|
||||
* ZEROSTART is the first offset into the write region at which the
|
||||
* data "can" be zeros instead.
|
||||
* LEN is the length of the write.
|
||||
* CHECKSTART is the offset into the write region where we begin checking.
|
||||
* CHECKLEN is the length of the region we check.
|
||||
*/
|
||||
int
|
||||
data_matches(const char *namestr, off_t regionoffset,
|
||||
unsigned code, unsigned seq, off_t zerostart, off_t len,
|
||||
off_t checkstart, off_t checklen)
|
||||
{
|
||||
int ret;
|
||||
off_t where;
|
||||
size_t howmuch;
|
||||
off_t absend, slop;
|
||||
|
||||
assert(len <= DATA_MAXSIZE);
|
||||
assert(checklen > 0);
|
||||
assert(checklen <= len);
|
||||
assert(checkstart >= 0 && checkstart < len);
|
||||
assert(checkstart + checklen <= len);
|
||||
assert(zerostart >= 0);
|
||||
assert(zerostart <= len);
|
||||
|
||||
prepdata(code, seq, databuf, len);
|
||||
|
||||
ret = 1;
|
||||
while (checklen > 0) {
|
||||
/* check one block at a time */
|
||||
where = checkstart;
|
||||
howmuch = BLOCKSIZE;
|
||||
/* no more than is left to do */
|
||||
if (howmuch > checklen) {
|
||||
howmuch = checklen;
|
||||
}
|
||||
/* if we stick over a block boundary, stop there */
|
||||
absend = regionoffset + where + howmuch;
|
||||
slop = absend % BLOCKSIZE;
|
||||
if (slop != 0 && slop < howmuch) {
|
||||
howmuch -= slop;
|
||||
}
|
||||
/* if we go past the zerostart point, stop there */
|
||||
if (where < zerostart && where + howmuch > zerostart) {
|
||||
howmuch = zerostart - where;
|
||||
}
|
||||
assert(howmuch > 0);
|
||||
|
||||
if (matches_at(where, howmuch)) {
|
||||
/* nothing */
|
||||
}
|
||||
else if (zero_at(where, howmuch)) {
|
||||
if (where >= zerostart) {
|
||||
printf("WARNING: file %s range %lld-%lld is "
|
||||
"zeroed\n",
|
||||
namestr, regionoffset + where,
|
||||
regionoffset + where + howmuch);
|
||||
}
|
||||
else {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
else if (poison_at(where, howmuch)) {
|
||||
if (where >= zerostart) {
|
||||
printf("ERROR: file %s range %lld-%lld is "
|
||||
"poisoned\n",
|
||||
namestr, regionoffset + where,
|
||||
regionoffset + where + howmuch);
|
||||
}
|
||||
else {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
checkstart += howmuch;
|
||||
checklen -= howmuch;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
data_check(const char *namestr, off_t regionoffset,
|
||||
unsigned code, unsigned seq, off_t zerostart, off_t len,
|
||||
off_t checkstart, off_t checklen)
|
||||
{
|
||||
assert(zerostart >= 0);
|
||||
assert(zerostart <= len);
|
||||
|
||||
if (!data_matches(namestr, regionoffset,
|
||||
code, seq, zerostart, len, checkstart, checklen)) {
|
||||
printf("ERROR: file %s range %lld-%lld contains garbage\n",
|
||||
namestr, regionoffset + checkstart,
|
||||
regionoffset + checkstart + checklen);
|
||||
}
|
||||
}
|
||||
|
||||
void *
|
||||
data_map(unsigned code, unsigned seq, off_t len)
|
||||
{
|
||||
assert(len <= DATA_MAXSIZE);
|
||||
prepdata(code, seq, databuf, len);
|
||||
return databuf;
|
||||
}
|
||||
|
||||
void *
|
||||
data_mapreadbuf(off_t len)
|
||||
{
|
||||
assert(len <= DATA_MAXSIZE);
|
||||
return readbuf;
|
||||
}
|
41
userland/testbin/frack/data.h
Normal file
41
userland/testbin/frack/data.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void *data_map(unsigned code, unsigned seq, off_t len);
|
||||
void *data_mapreadbuf(off_t len);
|
||||
int data_matches(const char *namestr, off_t regionoffset,
|
||||
unsigned code, unsigned seq, off_t zerostart, off_t len,
|
||||
off_t checkstart, off_t checklen);
|
||||
void data_check(const char *namestr, off_t regionoffset,
|
||||
unsigned code, unsigned seq, off_t zerostart, off_t len,
|
||||
off_t checkstart, off_t checklen);
|
||||
|
||||
#define DATA_MAXSIZE 65536
|
||||
#define POISON_VAL 0xa9
|
251
userland/testbin/frack/do.c
Normal file
251
userland/testbin/frack/do.c
Normal file
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "data.h"
|
||||
#include "name.h"
|
||||
#include "do.h"
|
||||
|
||||
int
|
||||
do_opendir(unsigned name)
|
||||
{
|
||||
const char *namestr;
|
||||
int fd;
|
||||
|
||||
namestr = name_get(name);
|
||||
fd = open(namestr, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
err(1, "%s: opendir", namestr);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
void
|
||||
do_closedir(int fd, unsigned name)
|
||||
{
|
||||
if (close(fd)) {
|
||||
warn("%s: closedir", name_get(name));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
do_createfile(unsigned name)
|
||||
{
|
||||
const char *namestr;
|
||||
int fd;
|
||||
|
||||
namestr = name_get(name);
|
||||
fd = open(namestr, O_WRONLY|O_CREAT|O_EXCL, 0664);
|
||||
if (fd < 0) {
|
||||
err(1, "%s: create", namestr);
|
||||
}
|
||||
printf("create %s\n", namestr);
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
do_openfile(unsigned name, int dotrunc)
|
||||
{
|
||||
const char *namestr;
|
||||
int fd;
|
||||
|
||||
namestr = name_get(name);
|
||||
fd = open(namestr, O_WRONLY | (dotrunc ? O_TRUNC : 0), 0664);
|
||||
if (fd < 0) {
|
||||
err(1, "%s: open", namestr);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
void
|
||||
do_closefile(int fd, unsigned name)
|
||||
{
|
||||
if (close(fd)) {
|
||||
warn("%s: close", name_get(name));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
do_write(int fd, unsigned name, unsigned code, unsigned seq,
|
||||
off_t pos, off_t len)
|
||||
{
|
||||
off_t done = 0;
|
||||
ssize_t ret;
|
||||
char *buf;
|
||||
const char *namestr;
|
||||
|
||||
namestr = name_get(name);
|
||||
buf = data_map(code, seq, len);
|
||||
if (lseek(fd, pos, SEEK_SET) == -1) {
|
||||
err(1, "%s: lseek to %lld", name_get(name), pos);
|
||||
}
|
||||
|
||||
while (done < len) {
|
||||
ret = write(fd, buf + done, len - done);
|
||||
if (ret == -1) {
|
||||
err(1, "%s: write %lld at %lld", name_get(name),
|
||||
len, pos);
|
||||
}
|
||||
done += ret;
|
||||
}
|
||||
|
||||
printf("write %s: %lld at %lld\n", namestr, len, pos);
|
||||
}
|
||||
|
||||
void
|
||||
do_truncate(int fd, unsigned name, off_t len)
|
||||
{
|
||||
const char *namestr;
|
||||
|
||||
namestr = name_get(name);
|
||||
if (ftruncate(fd, len) == -1) {
|
||||
err(1, "%s: truncate to %lld", namestr, len);
|
||||
}
|
||||
printf("truncate %s: to %lld\n", namestr, len);
|
||||
}
|
||||
|
||||
void
|
||||
do_mkdir(unsigned name)
|
||||
{
|
||||
const char *namestr;
|
||||
|
||||
namestr = name_get(name);
|
||||
if (mkdir(namestr, 0775) == -1) {
|
||||
err(1, "%s: mkdir", namestr);
|
||||
}
|
||||
printf("mkdir %s\n", namestr);
|
||||
}
|
||||
|
||||
void
|
||||
do_rmdir(unsigned name)
|
||||
{
|
||||
const char *namestr;
|
||||
|
||||
namestr = name_get(name);
|
||||
if (rmdir(namestr) == -1) {
|
||||
err(1, "%s: rmdir", namestr);
|
||||
}
|
||||
printf("rmdir %s\n", namestr);
|
||||
}
|
||||
|
||||
void
|
||||
do_unlink(unsigned name)
|
||||
{
|
||||
const char *namestr;
|
||||
|
||||
namestr = name_get(name);
|
||||
if (remove(namestr) == -1) {
|
||||
err(1, "%s: remove", namestr);
|
||||
}
|
||||
printf("remove %s\n", namestr);
|
||||
}
|
||||
|
||||
void
|
||||
do_link(unsigned from, unsigned to)
|
||||
{
|
||||
const char *fromstr, *tostr;
|
||||
|
||||
fromstr = name_get(from);
|
||||
tostr = name_get(to);
|
||||
if (link(fromstr, tostr) == -1) {
|
||||
err(1, "link %s to %s", fromstr, tostr);
|
||||
}
|
||||
printf("link %s %s\n", fromstr, tostr);
|
||||
}
|
||||
|
||||
void
|
||||
do_rename(unsigned from, unsigned to)
|
||||
{
|
||||
const char *fromstr, *tostr;
|
||||
|
||||
fromstr = name_get(from);
|
||||
tostr = name_get(to);
|
||||
if (rename(fromstr, tostr) == -1) {
|
||||
err(1, "rename %s to %s", fromstr, tostr);
|
||||
}
|
||||
printf("rename %s %s\n", fromstr, tostr);
|
||||
}
|
||||
|
||||
void
|
||||
do_renamexd(unsigned fromdir, unsigned from, unsigned todir, unsigned to)
|
||||
{
|
||||
char frombuf[64];
|
||||
char tobuf[64];
|
||||
|
||||
strcpy(frombuf, name_get(fromdir));
|
||||
strcat(frombuf, "/");
|
||||
strcat(frombuf, name_get(from));
|
||||
|
||||
strcpy(tobuf, name_get(todir));
|
||||
strcat(tobuf, "/");
|
||||
strcat(tobuf, name_get(to));
|
||||
|
||||
if (rename(frombuf, tobuf) == -1) {
|
||||
err(1, "rename %s to %s", frombuf, tobuf);
|
||||
}
|
||||
printf("rename %s %s\n", frombuf, tobuf);
|
||||
}
|
||||
|
||||
void
|
||||
do_chdir(unsigned name)
|
||||
{
|
||||
const char *namestr;
|
||||
|
||||
namestr = name_get(name);
|
||||
if (chdir(namestr) == -1) {
|
||||
err(1, "chdir: %s", namestr);
|
||||
}
|
||||
printf("chdir %s\n", namestr);
|
||||
}
|
||||
|
||||
void
|
||||
do_chdirup(void)
|
||||
{
|
||||
if (chdir("..") == -1) {
|
||||
err(1, "chdir: ..");
|
||||
}
|
||||
printf("chdir ..\n");
|
||||
}
|
||||
|
||||
void
|
||||
do_sync(void)
|
||||
{
|
||||
if (sync()) {
|
||||
warn("sync");
|
||||
}
|
||||
printf("sync\n");
|
||||
printf("----------------------------------------\n");
|
||||
}
|
48
userland/testbin/frack/do.h
Normal file
48
userland/testbin/frack/do.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
int do_opendir(unsigned name);
|
||||
void do_closedir(int handle, unsigned name);
|
||||
int do_createfile(unsigned name);
|
||||
int do_openfile(unsigned name, int dotrunc);
|
||||
void do_closefile(int handle, unsigned name);
|
||||
void do_write(int handle, unsigned name, unsigned code, unsigned seq,
|
||||
off_t pos, off_t len);
|
||||
void do_truncate(int handle, unsigned name, off_t len);
|
||||
void do_mkdir(unsigned name);
|
||||
void do_rmdir(unsigned name);
|
||||
void do_unlink(unsigned name);
|
||||
void do_link(unsigned from, unsigned to);
|
||||
void do_rename(unsigned from, unsigned to);
|
||||
void do_renamexd(unsigned fromdir, unsigned from, unsigned todir, unsigned to);
|
||||
void do_chdir(unsigned name);
|
||||
void do_chdirup(void);
|
||||
void do_sync(void);
|
196
userland/testbin/frack/main.c
Normal file
196
userland/testbin/frack/main.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "workloads.h"
|
||||
#include "main.h"
|
||||
|
||||
struct workload {
|
||||
const char *name;
|
||||
const char *argname;
|
||||
union {
|
||||
void (*witharg)(const char *);
|
||||
void (*noarg)(void);
|
||||
} run;
|
||||
};
|
||||
|
||||
#define WL(n) { .name = #n, .argname = NULL, .run.noarg = wl_##n }
|
||||
#define WLA(n,a) { .name = #n, .argname = #a, .run.witharg = wl_##n }
|
||||
|
||||
static const struct workload workloads[] = {
|
||||
WLA(createwrite, size),
|
||||
WLA(rewrite, size),
|
||||
WLA(randupdate, size),
|
||||
WLA(truncwrite, size),
|
||||
WLA(makehole, size),
|
||||
WLA(fillhole, size),
|
||||
WLA(truncfill, size),
|
||||
WLA(append, size),
|
||||
WLA(trunczero, size),
|
||||
WLA(trunconeblock, size),
|
||||
WLA(truncsmallersize, size),
|
||||
WLA(trunclargersize, size),
|
||||
WLA(appendandtrunczero, size),
|
||||
WLA(appendandtruncpartly, size),
|
||||
WL(mkfile),
|
||||
WL(mkdir),
|
||||
WL(mkmanyfile),
|
||||
WL(mkmanydir),
|
||||
WL(mktree),
|
||||
WLA(mkrandtree, seed),
|
||||
WL(rmfile),
|
||||
WL(rmdir),
|
||||
WL(rmfiledelayed),
|
||||
WL(rmfiledelayedappend),
|
||||
WL(rmdirdelayed),
|
||||
WL(rmmanyfile),
|
||||
WL(rmmanyfiledelayed),
|
||||
WL(rmmanyfiledelayedandappend),
|
||||
WL(rmmanydir),
|
||||
WL(rmmanydirdelayed),
|
||||
WL(rmtree),
|
||||
WLA(rmrandtree, seed),
|
||||
WL(linkfile),
|
||||
WL(linkmanyfile),
|
||||
WL(unlinkfile),
|
||||
WL(unlinkmanyfile),
|
||||
WL(linkunlinkfile),
|
||||
WL(renamefile),
|
||||
WL(renamedir),
|
||||
WL(renamesubtree),
|
||||
WL(renamexdfile),
|
||||
WL(renamexddir),
|
||||
WL(renamexdsubtree),
|
||||
WL(renamemanyfile),
|
||||
WL(renamemanydir),
|
||||
WL(renamemanysubtree),
|
||||
WL(copyandrename),
|
||||
WL(untar),
|
||||
WL(compile),
|
||||
WL(cvsupdate),
|
||||
WLA(writefileseq, seed),
|
||||
WLA(writetruncseq, seed),
|
||||
WLA(mkrmseq, seed),
|
||||
WLA(linkunlinkseq, seed),
|
||||
WLA(renameseq, seed),
|
||||
WLA(diropseq, seed),
|
||||
WLA(genseq, seed),
|
||||
};
|
||||
static const unsigned numworkloads = sizeof(workloads) / sizeof(workloads[0]);
|
||||
|
||||
#undef WL
|
||||
#undef WLA
|
||||
|
||||
static
|
||||
const struct workload *
|
||||
findworkload(const char *name)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i=0; i<numworkloads; i++) {
|
||||
if (!strcmp(workloads[i].name, name)) {
|
||||
return &workloads[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
printworkloads(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
printf("Supported workloads:\n");
|
||||
for (i=0; i<numworkloads; i++) {
|
||||
printf(" %s", workloads[i].name);
|
||||
if (workloads[i].argname) {
|
||||
printf(" %s", workloads[i].argname);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *workloadname;
|
||||
const struct workload *workload;
|
||||
int checkmode = 0;
|
||||
|
||||
if (argc == 2 && !strcmp(argv[1], "list")) {
|
||||
printworkloads();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
warnx("Usage: %s do|check workload [arg]", argv[0]);
|
||||
warnx("Use \"list\" for a list of workloads");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "do")) {
|
||||
checkmode = 0;
|
||||
}
|
||||
else if (!strcmp(argv[1], "check")) {
|
||||
checkmode = 1;
|
||||
}
|
||||
else {
|
||||
errx(1, "Action must be \"do\" or \"check\"");
|
||||
}
|
||||
|
||||
workloadname = argv[2];
|
||||
workload = findworkload(workloadname);
|
||||
if (workload == NULL) {
|
||||
errx(1, "Unknown workload %s\n", workloadname);
|
||||
printworkloads();
|
||||
exit(1);
|
||||
}
|
||||
setcheckmode(checkmode);
|
||||
if (workload->argname) {
|
||||
if (argc != 4) {
|
||||
errx(1, "%s requires argument %s\n",
|
||||
workloadname, workload->argname);
|
||||
}
|
||||
workload->run.witharg(argv[3]);
|
||||
}
|
||||
else {
|
||||
if (argc != 3) {
|
||||
errx(1, "Stray argument for workload %s",workloadname);
|
||||
}
|
||||
workload->run.noarg();
|
||||
}
|
||||
complete();
|
||||
return 0;
|
||||
}
|
32
userland/testbin/frack/main.h
Normal file
32
userland/testbin/frack/main.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void setcheckmode(int checkmode);
|
||||
void complete(void);
|
93
userland/testbin/frack/name.c
Normal file
93
userland/testbin/frack/name.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "name.h"
|
||||
|
||||
#define MAXNAMES 32
|
||||
|
||||
static const char *const names[MAXNAMES] = {
|
||||
"allspice",
|
||||
"anise",
|
||||
"basil",
|
||||
"cardamom",
|
||||
"cayenne",
|
||||
"cilantro",
|
||||
"cinnamon",
|
||||
"cloves",
|
||||
"coriander",
|
||||
"cumin",
|
||||
"dill",
|
||||
"fennel",
|
||||
"fenugreek",
|
||||
"galangal",
|
||||
"ginger",
|
||||
"horseradish",
|
||||
"lemongrass",
|
||||
"licorice",
|
||||
"mace",
|
||||
"marjoram",
|
||||
"mustard",
|
||||
"nutmeg",
|
||||
"oregano",
|
||||
"parsley",
|
||||
"paprika",
|
||||
"pepper",
|
||||
"saffron",
|
||||
"sage",
|
||||
"rosemary",
|
||||
"thyme",
|
||||
"turmeric",
|
||||
"wasabi",
|
||||
};
|
||||
|
||||
const char *
|
||||
name_get(unsigned name)
|
||||
{
|
||||
assert(name < MAXNAMES);
|
||||
return names[name];
|
||||
}
|
||||
|
||||
unsigned
|
||||
name_find(const char *namestr)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i=0; i<MAXNAMES; i++) {
|
||||
if (!strcmp(namestr, names[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
errx(1, "Encountered unknown/unexpected name %s", namestr);
|
||||
return 0;
|
||||
}
|
33
userland/testbin/frack/name.h
Normal file
33
userland/testbin/frack/name.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
const char *name_get(unsigned name);
|
||||
unsigned name_find(const char *namestr);
|
315
userland/testbin/frack/ops.c
Normal file
315
userland/testbin/frack/ops.c
Normal file
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "pool.h"
|
||||
#include "data.h"
|
||||
#include "do.h"
|
||||
#include "check.h"
|
||||
#include "ops.h"
|
||||
#include "main.h"
|
||||
|
||||
struct file {
|
||||
unsigned name;
|
||||
unsigned testcode;
|
||||
unsigned seq;
|
||||
int handle;
|
||||
};
|
||||
|
||||
struct dir {
|
||||
unsigned name;
|
||||
int handle;
|
||||
};
|
||||
|
||||
static int checkmode;
|
||||
|
||||
void
|
||||
setcheckmode(int mode)
|
||||
{
|
||||
checkmode = mode;
|
||||
if (checkmode) {
|
||||
check_setup();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// open directories
|
||||
|
||||
#define MAXDIRS 32
|
||||
DECLPOOL(dir, MAXDIRS);
|
||||
|
||||
struct dir *
|
||||
op_opendir(unsigned name)
|
||||
{
|
||||
struct dir *ret;
|
||||
|
||||
ret = POOLALLOC(dir);
|
||||
ret->name = name;
|
||||
if (checkmode) {
|
||||
ret->handle = -1;
|
||||
}
|
||||
else {
|
||||
ret->handle = do_opendir(name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
op_closedir(struct dir *d)
|
||||
{
|
||||
if (checkmode) {
|
||||
/* nothing */
|
||||
(void)d;
|
||||
}
|
||||
else {
|
||||
do_closedir(d->handle, d->name);
|
||||
}
|
||||
POOLFREE(dir, d);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// files
|
||||
|
||||
#define MAXFILES 32
|
||||
DECLPOOL(file, MAXFILES);
|
||||
|
||||
struct file *
|
||||
op_open(unsigned testcode, unsigned name, unsigned openflags)
|
||||
{
|
||||
struct file *ret;
|
||||
int dotrunc;
|
||||
|
||||
if (openflags == O_TRUNC) {
|
||||
openflags = 0;
|
||||
dotrunc = 1;
|
||||
}
|
||||
else {
|
||||
dotrunc = 0;
|
||||
}
|
||||
|
||||
assert(openflags == 0 || openflags == (O_CREAT|O_EXCL));
|
||||
|
||||
ret = POOLALLOC(file);
|
||||
ret->name = name;
|
||||
ret->testcode = testcode;
|
||||
ret->seq = 0;
|
||||
if (checkmode) {
|
||||
if (openflags) {
|
||||
ret->handle = check_createfile(name);
|
||||
}
|
||||
else {
|
||||
ret->handle = check_openfile(name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (openflags) {
|
||||
assert(dotrunc == 0);
|
||||
ret->handle = do_createfile(name);
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* XXX: as of 2013 OS/161 doesn't provide a
|
||||
* truncate call - neither truncate() nor
|
||||
* ftruncate()! You can only O_TRUNC. Oops...
|
||||
*/
|
||||
ret->handle = do_openfile(name, dotrunc);
|
||||
dotrunc = 0;
|
||||
}
|
||||
}
|
||||
if (dotrunc) {
|
||||
op_truncate(ret, 0);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
op_close(struct file *f)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_closefile(f->handle, f->name);
|
||||
}
|
||||
else {
|
||||
do_closefile(f->handle, f->name);
|
||||
}
|
||||
POOLFREE(file, f);
|
||||
}
|
||||
|
||||
void
|
||||
op_write(struct file *f, off_t pos, off_t len)
|
||||
{
|
||||
off_t amount;
|
||||
|
||||
while (len > 0) {
|
||||
amount = len;
|
||||
if (amount > DATA_MAXSIZE) {
|
||||
amount = DATA_MAXSIZE;
|
||||
}
|
||||
|
||||
if (checkmode) {
|
||||
check_write(f->handle, f->name, f->testcode, f->seq,
|
||||
pos, amount);
|
||||
}
|
||||
else {
|
||||
do_write(f->handle, f->name, f->testcode, f->seq,
|
||||
pos, amount);
|
||||
}
|
||||
f->seq++;
|
||||
pos += amount;
|
||||
len -= amount;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
op_truncate(struct file *f, off_t len)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_truncate(f->handle, f->name, len);
|
||||
}
|
||||
else {
|
||||
do_truncate(f->handle, f->name, len);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// dirops
|
||||
|
||||
void
|
||||
op_mkdir(unsigned name)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_mkdir(name);
|
||||
}
|
||||
else {
|
||||
do_mkdir(name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
op_rmdir(unsigned name)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_rmdir(name);
|
||||
}
|
||||
else {
|
||||
do_rmdir(name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
op_unlink(unsigned name)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_unlink(name);
|
||||
}
|
||||
else {
|
||||
do_unlink(name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
op_link(unsigned from, unsigned to)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_link(from, to);
|
||||
}
|
||||
else {
|
||||
do_link(from, to);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
op_rename(unsigned from, unsigned to)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_rename(from, to);
|
||||
}
|
||||
else {
|
||||
do_rename(from, to);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
op_renamexd(unsigned fromdir, unsigned from, unsigned todir, unsigned to)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_renamexd(fromdir, from, todir, to);
|
||||
}
|
||||
else {
|
||||
do_renamexd(fromdir, from, todir, to);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
op_chdir(unsigned name)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_chdir(name);
|
||||
}
|
||||
else {
|
||||
do_chdir(name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
op_chdirup(void)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_chdirup();
|
||||
}
|
||||
else {
|
||||
do_chdirup();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// other
|
||||
|
||||
void
|
||||
op_sync(void)
|
||||
{
|
||||
if (checkmode) {
|
||||
check_sync();
|
||||
}
|
||||
else {
|
||||
do_sync();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
complete(void)
|
||||
{
|
||||
if (checkmode) {
|
||||
checkfs();
|
||||
}
|
||||
}
|
48
userland/testbin/frack/ops.h
Normal file
48
userland/testbin/frack/ops.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
struct file;
|
||||
struct dir;
|
||||
|
||||
struct dir *op_opendir(unsigned);
|
||||
void op_closedir(struct dir *);
|
||||
struct file *op_open(unsigned, unsigned, unsigned);
|
||||
void op_close(struct file *);
|
||||
void op_write(struct file *, off_t, off_t);
|
||||
void op_truncate(struct file *, off_t);
|
||||
void op_sync(void);
|
||||
void op_mkdir(unsigned);
|
||||
void op_rmdir(unsigned);
|
||||
void op_unlink(unsigned);
|
||||
void op_link(unsigned, unsigned);
|
||||
void op_rename(unsigned, unsigned);
|
||||
void op_renamexd(unsigned, unsigned, unsigned, unsigned);
|
||||
void op_chdir(unsigned);
|
||||
void op_chdirup(void);
|
70
userland/testbin/frack/pool.c
Normal file
70
userland/testbin/frack/pool.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "pool.h"
|
||||
|
||||
unsigned
|
||||
poolalloc(struct poolctl *pool)
|
||||
{
|
||||
uint32_t mask;
|
||||
unsigned j, i;
|
||||
|
||||
assert(pool->max % 32 == 0);
|
||||
for (j=0; j<pool->max/32; j++) {
|
||||
for (mask=1, i=0; i<32; mask<<=1, i++) {
|
||||
if ((pool->inuse[j] & mask) == 0) {
|
||||
pool->inuse[j] |= mask;
|
||||
return j*32 + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
errx(1, "Too many %s -- increase %s in %s",
|
||||
pool->itemtype, pool->maxname, pool->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
poolfree(struct poolctl *pool, unsigned num)
|
||||
{
|
||||
uint32_t mask;
|
||||
unsigned pos;
|
||||
|
||||
assert(num < pool->max);
|
||||
|
||||
pos = num / 32;
|
||||
mask = 1 << (num % 32);
|
||||
|
||||
assert(pool->inuse[pos] & mask);
|
||||
pool->inuse[pos] &= ~(uint32_t)mask;
|
||||
}
|
57
userland/testbin/frack/pool.h
Normal file
57
userland/testbin/frack/pool.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
struct poolctl {
|
||||
uint32_t *inuse;
|
||||
unsigned max;
|
||||
const char *itemtype;
|
||||
const char *maxname;
|
||||
const char *file;
|
||||
};
|
||||
|
||||
#define DIVROUNDUP(a, b) (((a) + (b) - 1) / (b))
|
||||
#define ROUNDUP(a, b) (DIVROUNDUP(a, b) * (b))
|
||||
|
||||
#define DECLPOOL(T, MAX) \
|
||||
static struct T pool_space_##T[ROUNDUP(MAX, 32)]; \
|
||||
static uint32_t pool_inuse_##T[DIVROUNDUP(MAX, 32)]; \
|
||||
static struct poolctl pool_##T = { \
|
||||
.inuse = pool_inuse_##T, \
|
||||
.max = ROUNDUP(MAX, 32), \
|
||||
.itemtype = "struct " #T, \
|
||||
.maxname = #MAX, \
|
||||
.file = __FILE__ \
|
||||
}
|
||||
|
||||
#define POOLALLOC(T) (&pool_space_##T[poolalloc(&pool_##T)])
|
||||
#define POOLFREE(T, x) (poolfree(&pool_##T, (x) - pool_space_##T))
|
||||
|
||||
unsigned poolalloc(struct poolctl *pool);
|
||||
void poolfree(struct poolctl *pool, unsigned ix);
|
1794
userland/testbin/frack/workloads.c
Normal file
1794
userland/testbin/frack/workloads.c
Normal file
File diff suppressed because it is too large
Load Diff
153
userland/testbin/frack/workloads.h
Normal file
153
userland/testbin/frack/workloads.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2013
|
||||
* The President and Fellows of Harvard College.
|
||||
* Written by David A. Holland.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* The VFS-interface operations that can write to the fs are:
|
||||
*
|
||||
* sync
|
||||
* fsync
|
||||
* write
|
||||
* reclaim
|
||||
* truncate
|
||||
* creat
|
||||
* symlink (not supported by default and which we are going to ignore)
|
||||
* mkdir
|
||||
* link
|
||||
* remove
|
||||
* rmdir
|
||||
* rename
|
||||
*
|
||||
* The sync operations are not interesting by themselves. Also,
|
||||
* because the VFS-level unmount operation works by first syncing and
|
||||
* then doing an unmount (which by default at least asserts nothing
|
||||
* further needs to be written out) there is nothing to be gained by
|
||||
* combining sync with write operations and seeing if the behavior is
|
||||
* different: if sync doesn't produce a clean fs, unmount won't
|
||||
* either, and vice versa.
|
||||
*
|
||||
* This means there are basically the following families of cases to
|
||||
* consider:
|
||||
* - writing to files in various ways and patterns
|
||||
* - truncating files
|
||||
* - directory ops that create things
|
||||
* - directory ops that remove things (various combinations with reclaim)
|
||||
* - link and rename
|
||||
*/
|
||||
|
||||
/*
|
||||
* writing
|
||||
*/
|
||||
|
||||
void wl_createwrite(const char *size);
|
||||
void wl_rewrite(const char *size);
|
||||
void wl_randupdate(const char *size);
|
||||
void wl_truncwrite(const char *size);
|
||||
void wl_makehole(const char *size);
|
||||
void wl_fillhole(const char *size);
|
||||
void wl_truncfill(const char *size);
|
||||
void wl_append(const char *size);
|
||||
|
||||
/*
|
||||
* truncating
|
||||
*/
|
||||
void wl_trunczero(const char *size);
|
||||
void wl_trunconeblock(const char *size);
|
||||
void wl_truncsmallersize(const char *size);
|
||||
void wl_trunclargersize(const char *size);
|
||||
void wl_appendandtrunczero(const char *size);
|
||||
void wl_appendandtruncpartly(const char *size);
|
||||
|
||||
/*
|
||||
* creating
|
||||
*/
|
||||
void wl_mkfile(void);
|
||||
void wl_mkdir(void);
|
||||
void wl_mkmanyfile(void);
|
||||
void wl_mkmanydir(void);
|
||||
void wl_mktree(void);
|
||||
void wl_mkrandtree(const char *seed);
|
||||
|
||||
/*
|
||||
* deleting
|
||||
*/
|
||||
void wl_rmfile(void);
|
||||
void wl_rmdir(void);
|
||||
void wl_rmfiledelayed(void);
|
||||
void wl_rmfiledelayedappend(void);
|
||||
void wl_rmdirdelayed(void);
|
||||
void wl_rmmanyfile(void);
|
||||
void wl_rmmanyfiledelayed(void);
|
||||
void wl_rmmanyfiledelayedandappend(void);
|
||||
void wl_rmmanydir(void);
|
||||
void wl_rmmanydirdelayed(void);
|
||||
void wl_rmtree(void);
|
||||
void wl_rmrandtree(const char *seed);
|
||||
|
||||
/*
|
||||
* link
|
||||
*/
|
||||
void wl_linkfile(void);
|
||||
void wl_linkmanyfile(void);
|
||||
void wl_unlinkfile(void);
|
||||
void wl_unlinkmanyfile(void);
|
||||
void wl_linkunlinkfile(void);
|
||||
|
||||
/*
|
||||
* rename
|
||||
*/
|
||||
void wl_renamefile(void);
|
||||
void wl_renamedir(void);
|
||||
void wl_renamesubtree(void);
|
||||
void wl_renamexdfile(void);
|
||||
void wl_renamexddir(void);
|
||||
void wl_renamexdsubtree(void);
|
||||
void wl_renamemanyfile(void);
|
||||
void wl_renamemanydir(void);
|
||||
void wl_renamemanysubtree(void);
|
||||
|
||||
/*
|
||||
* Combo ops
|
||||
*/
|
||||
void wl_copyandrename(void);
|
||||
void wl_untar(void);
|
||||
void wl_compile(void);
|
||||
void wl_cvsupdate(void);
|
||||
|
||||
/*
|
||||
* Randomized op sequences
|
||||
*/
|
||||
void wl_writefileseq(const char *seed);
|
||||
void wl_writetruncseq(const char *seed);
|
||||
void wl_mkrmseq(const char *seed);
|
||||
void wl_linkunlinkseq(const char *seed);
|
||||
void wl_renameseq(const char *seed);
|
||||
void wl_diropseq(const char *seed);
|
||||
void wl_genseq(const char *seed);
|
11
userland/testbin/guzzle/Makefile
Normal file
11
userland/testbin/guzzle/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Makefile for guzzle
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=guzzle
|
||||
SRCS=guzzle.c
|
||||
BINDIR=/testbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
62
userland/testbin/guzzle/guzzle.c
Normal file
62
userland/testbin/guzzle/guzzle.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* guzzle: Sit in the background in a long loop and display
|
||||
* characters on the console occasionally.
|
||||
*
|
||||
* This is intended to help with scheduler testing.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define TOP 1<<25 /* real long loop */
|
||||
|
||||
/* This program is a ridiculous, compute-bound program */
|
||||
/* We should schedule this at low priorities. */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
volatile int i;
|
||||
int ch = '+';
|
||||
|
||||
if (argc == 2) {
|
||||
ch = argv[1][0];
|
||||
}
|
||||
|
||||
for (i=0; i<TOP; i++) { /* tight loop */
|
||||
/* that eats up cycles */
|
||||
if ( (i%10000) == 0) {
|
||||
putchar(ch);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
13
userland/testbin/hash/Makefile
Normal file
13
userland/testbin/hash/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
# Makefile for hash
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=hash
|
||||
SRCS=hash.c
|
||||
BINDIR=/testbin
|
||||
HOSTBINDIR=/hostbin
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
.include "$(TOP)/mk/os161.hostprog.mk"
|
||||
|
83
userland/testbin/hash/hash.c
Normal file
83
userland/testbin/hash/hash.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* hash: Takes a file and computes a "hash" value by adding together all
|
||||
* the values in the file mod some largish prime.
|
||||
*
|
||||
* Once the basic system calls are complete, this should work on any
|
||||
* file the system supports. However, it's probably of most use for
|
||||
* testing your file system code.
|
||||
*
|
||||
* This should really be replaced with a real hash, like MD5 or SHA-1.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <err.h>
|
||||
|
||||
#ifdef HOST
|
||||
#include "hostcompat.h"
|
||||
#endif
|
||||
|
||||
#define HASHP 104729
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
char readbuf[1];
|
||||
int j = 0;
|
||||
|
||||
#ifdef HOST
|
||||
hostcompat_init(argc, argv);
|
||||
#endif
|
||||
|
||||
if (argc != 2) {
|
||||
errx(1, "Usage: hash filename");
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDONLY, 0664);
|
||||
|
||||
if (fd<0) {
|
||||
err(1, "%s", argv[1]);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (read(fd, readbuf, 1) <= 0) break;
|
||||
j = ((j*8) + (int) readbuf[0]) % HASHP;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
printf("Hash : %d\n", j);
|
||||
|
||||
return 0;
|
||||
}
|
12
userland/testbin/hog/Makefile
Normal file
12
userland/testbin/hog/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
# Makefile for hog
|
||||
|
||||
TOP=../../..
|
||||
.include "$(TOP)/mk/os161.config.mk"
|
||||
|
||||
PROG=hog
|
||||
SRCS=hog.c
|
||||
BINDIR=/testbin
|
||||
|
||||
|
||||
.include "$(TOP)/mk/os161.prog.mk"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user