提交 a64cd813 创建 作者: kaashoek's avatar kaashoek

one regression test program

上级 1dca3afb
...@@ -84,18 +84,10 @@ vectors.S : vectors.pl ...@@ -84,18 +84,10 @@ vectors.S : vectors.pl
ULIB = ulib.o usys.o printf.o umalloc.o ULIB = ulib.o usys.o printf.o umalloc.o
user1 : user1.o $(ULIB)
$(LD) -N -e main -Ttext 0 -o user1 user1.o $(ULIB)
$(OBJDUMP) -S user1 > user1.asm
usertests : usertests.o $(ULIB) usertests : usertests.o $(ULIB)
$(LD) -N -e main -Ttext 0 -o usertests usertests.o $(ULIB) $(LD) -N -e main -Ttext 0 -o usertests usertests.o $(ULIB)
$(OBJDUMP) -S usertests > usertests.asm $(OBJDUMP) -S usertests > usertests.asm
fstests : fstests.o $(ULIB)
$(LD) -N -e main -Ttext 0 -o fstests fstests.o $(ULIB)
$(OBJDUMP) -S fstests > fstests.asm
_echo : echo.o $(ULIB) _echo : echo.o $(ULIB)
$(LD) -N -e main -Ttext 0 -o _echo echo.o $(ULIB) $(LD) -N -e main -Ttext 0 -o _echo echo.o $(ULIB)
$(OBJDUMP) -S _echo > echo.asm $(OBJDUMP) -S _echo > echo.asm
...@@ -104,10 +96,6 @@ _cat : cat.o $(ULIB) ...@@ -104,10 +96,6 @@ _cat : cat.o $(ULIB)
$(LD) -N -e main -Ttext 0 -o _cat cat.o $(ULIB) $(LD) -N -e main -Ttext 0 -o _cat cat.o $(ULIB)
$(OBJDUMP) -S _cat > cat.asm $(OBJDUMP) -S _cat > cat.asm
userfs : userfs.o $(ULIB)
$(LD) -N -e main -Ttext 0 -o userfs userfs.o $(ULIB)
$(OBJDUMP) -S userfs > userfs.asm
_init : init.o $(ULIB) _init : init.o $(ULIB)
$(LD) -N -e main -Ttext 0 -o _init init.o $(ULIB) $(LD) -N -e main -Ttext 0 -o _init init.o $(ULIB)
$(OBJDUMP) -S _init > init.asm $(OBJDUMP) -S _init > init.asm
...@@ -131,8 +119,8 @@ _rm : rm.o $(ULIB) ...@@ -131,8 +119,8 @@ _rm : rm.o $(ULIB)
mkfs : mkfs.c fs.h mkfs : mkfs.c fs.h
cc -o mkfs mkfs.c cc -o mkfs mkfs.c
fs.img : mkfs userfs usertests _echo _cat README _init _sh _ls _mkdir _rm fstests fs.img : mkfs usertests _echo _cat README _init _sh _ls _mkdir _rm fstests
./mkfs fs.img userfs usertests _echo _cat README _init _sh _ls _mkdir _rm fstests ./mkfs fs.img usertests _echo _cat README _init _sh _ls _mkdir _rm fstests
-include *.d -include *.d
...@@ -140,5 +128,5 @@ clean : ...@@ -140,5 +128,5 @@ clean :
/bin/rm -f rm /bin/rm -f rm
rm -f *.ps *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \ rm -f *.ps *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
*.o *.d *.asm vectors.S parport.out \ *.o *.d *.asm vectors.S parport.out \
bootblock kernel xv6.img user1 userfs usertests \ bootblock kernel xv6.img usertests \
fs.img mkfs echo init fstests fs.img mkfs echo init
差异被折叠。
#include "user.h"
char buf[32];
int
main(void)
{
int pid, fds[2], n;
pipe(fds);
pid = fork();
if(pid > 0){
write(fds[1], "xyz", 4);
puts("w");
} else {
n = read(fds[0], buf, sizeof(buf));
puts("r: ");
puts(buf);
puts("\n");
}
for(;;);
}
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "fcntl.h"
// simple file system tests
char buf[2000];
char name[3];
char *echo_args[] = { "echo", "hello", "goodbye", 0 };
char *cat_args[] = { "cat", "readme", 0 };
int stdout = 1;
void
opentest(void)
{
int fd;
fd = open("echo", 0);
if(fd >= 0){
printf(stdout, "open echo ok\n");
close(fd);
} else {
printf(stdout, "open echo failed!\n");
exit();
}
fd = open("doesnotexist", 0);
if(fd >= 0){
printf(stdout, "open doesnotexist succeeded!\n");
exit();
} else {
printf(stdout, "open doesnotexist failed\n");
}
}
void
writetest(void)
{
int fd;
int i;
fd = open("small", O_CREATE|O_RDWR);
if(fd >= 0){
printf(stdout, "creat small succeeded\n");
} else {
printf(stdout, "error: creat small failed!\n");
exit();
}
for(i = 0; i < 100; i++) {
if(write(fd, "aaaaaaaaaa", 10) != 10) {
printf(stdout, "error: write aa %d new file failed\n", i);
exit();
}
if(write(fd, "bbbbbbbbbb", 10) != 10) {
printf(stdout, "error: write bb %d new file failed\n", i);
exit();
}
}
printf(stdout, "writes done\n");
close(fd);
fd = open("small", O_RDONLY);
if(fd >= 0){
printf(stdout, "open small succeeded\n");
} else {
printf(stdout, "error: open small failed!\n");
exit();
}
i = read(fd, buf, 2000);
if(i == 2000) {
printf(stdout, "read succeeded\n");
} else {
printf(stdout, "read failed\n");
exit();
}
close(fd);
if(unlink("small") < 0) {
printf(stdout, "unlink small failed\n");
exit();
}
}
void
writetest1(void)
{
int i, fd, n;
printf(stdout, "big files\n");
fd = open("big", O_CREATE|O_RDWR);
if(fd < 0){
printf(stdout, "error: creat big failed!\n");
exit();
}
for(i = 0; i < MAXFILE; i++) {
((int*) buf)[0] = i;
if(write(fd, buf, 512) != 512) {
printf(stdout, "error: write big file failed\n", i);
exit();
}
}
close(fd);
fd = open("big", O_RDONLY);
if(fd < 0){
printf(stdout, "error: open big failed!\n");
exit();
}
n = 0;
for(;;) {
i = read(fd, buf, 512);
if(i == 0) {
if(n == MAXFILE - 1) {
printf(stdout, "read only %d blocks from big", n);
exit();
}
break;
} else if(i != 512) {
printf(stdout, "read failed %d\n", i);
exit();
}
if(((int*)buf)[0] != n) {
printf(stdout, "read content of block %d is %d\n",
n, ((int*)buf)[0]);
exit();
}
n++;
}
close(fd);
if(unlink("big") < 0) {
printf(stdout, "unlink big failed\n");
exit();
}
}
void
createtest(void)
{
int i, fd;
printf(stdout, "many creates, followed by unlink\n");
name[0] = 'a';
name[2] = '\0';
for(i = 0; i < 52; i++) {
name[1] = '0' + i;
fd = open(name, O_CREATE|O_RDWR);
close(fd);
}
name[0] = 'a';
name[2] = '\0';
for(i = 0; i < 52; i++) {
name[1] = '0' + i;
unlink(name);
}
}
void dirtest(void)
{
printf(stdout, "mkdir\n");
if(mkdir("dir0") < 0) {
printf(stdout, "mkdir failed\n");
exit();
}
if(chdir("dir0") < 0) {
printf(stdout, "chdir dir0 failed\n");
exit();
}
if(chdir("..") < 0) {
printf(stdout, "chdir .. failed\n");
exit();
}
if(unlink("dir0") < 0) {
printf(stdout, "unlink dir0 failed\n");
exit();
}
}
void
exectest(void)
{
if(exec("echo", echo_args) < 0) {
printf(stdout, "exec echo failed\n");
exit();
}
if(exec("cat", cat_args) < 0) {
printf(stdout, "exec cat failed\n");
exit();
}
}
int
main(void)
{
printf(stdout, "userfs is running\n");
opentest();
writetest();
writetest1();
createtest();
exectest();
return 0;
}
差异被折叠。
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论