#include "param.h"
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "fcntl.h"
#include "syscall.h"
#include "traps.h"
#include "memlayout.h"
char buf[8192];
char name[3];
char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
int stdout = 1;
// does chdir() call iput(p->cwd) in a transaction?
void
iputtest(void)
{
printf(stdout, "iput test\n");
if(mkdir("iputdir") < 0){
printf(stdout, "mkdir failed\n");
exit();
}
if(chdir("iputdir") < 0){
printf(stdout, "chdir iputdir failed\n");
exit();
}
if(unlink("../iputdir") < 0){
printf(stdout, "unlink ../iputdir failed\n");
exit();
}
if(chdir("/") < 0){
printf(stdout, "chdir / failed\n");
exit();
}
printf(stdout, "iput test ok\n");
}
// does exit() call iput(p->cwd) in a transaction?
void
exitiputtest(void)
{
int pid;
printf(stdout, "exitiput test\n");
pid = fork();
if(pid < 0){
printf(stdout, "fork failed\n");
exit();
}
if(pid == 0){
if(mkdir("iputdir") < 0){
printf(stdout, "mkdir failed\n");
exit();
}
if(chdir("iputdir") < 0){
printf(stdout, "child chdir failed\n");
exit();
}
if(unlink("../iputdir") < 0){
printf(stdout, "unlink ../iputdir failed\n");
exit();
}
exit();
}
wait();
printf(stdout, "exitiput test ok\n");
}
// does the error path in open() for attempt to write a
// directory call iput() in a transaction?
// needs a hacked kernel that pauses just after the namei()
// call in sys_open():
// if((ip = namei(path)) == 0)
// return -1;
// {
// int i;
// for(i = 0; i < 10000; i++)
// yield();
// }
void
openiputtest(void)
{
int pid;
printf(stdout, "openiput test\n");
if(mkdir("oidir") < 0){
printf(stdout, "mkdir oidir failed\n");
exit();
}
pid = fork();
if(pid < 0){
printf(stdout, "fork failed\n");
exit();
}
if(pid == 0){
int fd = open("oidir", O_RDWR);
if(fd >= 0){
printf(stdout, "open directory for write succeeded\n");
exit();
}
exit();
}
sleep(1);
if(unlink("oidir") != 0){
printf(stdout, "unlink failed\n");
exit();
}
wait();
printf(stdout, "openiput test ok\n");
}
// simple file system tests
void
opentest(void)
{
int fd;
printf(stdout, "open test\n");
fd = open("echo", 0);
if(fd < 0){
printf(stdout, "open echo failed!\n");
exit();
}
close(fd);
fd = open("doesnotexist", 0);
if(fd >= 0){
printf(stdout, "open doesnotexist succeeded!\n");
exit();
}
printf(stdout, "open test ok\n");
}
void
writetest(void)
{
int fd;
int i;
printf(stdout, "small file test\n");
fd = open("small", O_CREATE|O_RDWR);
if(fd >= 0){
printf(stdout, "creat small succeeded; ok\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 ok\n");
close(fd);
fd = open("small", O_RDONLY);
if(fd >= 0){
printf(stdout, "open small succeeded ok\n");
} else {
printf(stdout, "error: open small failed!\n");
exit();
}
i = read(fd, buf, 2000);
if(i == 2000){
printf(stdout, "read succeeded ok\n");
} else {
printf(stdout, "read failed\n");
exit();
}
close(fd);
if(unlink("small") < 0){
printf(stdout, "unlink small failed\n");
exit();
}
printf(stdout, "small file test ok\n");
}
void
writetest1(void)
{
int i, fd, n;
printf(stdout, "big files test\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();
}
printf(stdout, "big files ok\n");
}
void
createtest(void)
{
int i, fd;
printf(stdout, "many creates, followed by unlink test\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);
}
printf(stdout, "many creates, followed by unlink; ok\n");
}
void dirtest(void)
{
printf(stdout, "mkdir test\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();
}
printf(stdout, "mkdir test ok\n");
}
void
exectest(void)
{
printf(stdout, "exec test\n");
if(exec("echo", echoargv) < 0){
printf(stdout, "exec echo failed\n");
exit();
}
}
// simple fork and pipe read/write
void
pipe1(void)
{
int fds[2], pid;
int seq, i, n, cc, total;
if(pipe(fds) != 0){
printf(1, "pipe() failed\n");
exit();
}
pid = fork();
seq = 0;
if(pid == 0){
close(fds[0]);
for(n = 0; n < 5; n++){
for(i = 0; i < 1033; i++)
buf[i] = seq++;
if(write(fds[1], buf, 1033) != 1033){
printf(1, "pipe1 oops 1\n");
exit();
}
}
exit();
} else if(pid > 0){
close(fds[1]);
total = 0;
cc = 1;
while((n = read(fds[0], buf, cc)) > 0){
for(i = 0; i < n; i++){
if((buf[i] & 0xff) != (seq++ & 0xff)){
printf(1, "pipe1 oops 2\n");
return;
}
}
total += n;
cc = cc * 2;
if(cc > sizeof(buf))
cc = sizeof(buf);
}
if(total != 5 * 1033){
printf(1, "pipe1 oops 3 total %d\n", total);
exit();
}
close(fds[0]);
wait();
} else {
printf(1, "fork() failed\n");
exit();
}
printf(1, "pipe1 ok\n");
}
// meant to be run w/ at most two CPUs
void
preempt(void)
{
int pid1, pid2, pid3;
int pfds[2];
printf(1, "preempt: ");
pid1 = fork();
if(pid1 == 0)
for(;;)
;
pid2 = fork();
if(pid2 == 0)
for(;;)
;
pipe(pfds);
pid3 = fork();
if(pid3 == 0){
close(pfds[0]);
if(write(pfds[1], "x", 1) != 1)
printf(1, "preempt write error");
close(pfds[1]);
for(;;)
;
}
close(pfds[1]);
if(read(pfds[0], buf, sizeof(buf)) != 1){
printf(1, "preempt read error");
return;
}
close(pfds[0]);
printf(1, "kill... ");
kill(pid1);
kill(pid2);
kill(pid3);
printf(1, "wait... ");
wait();
wait();
wait();
printf(1, "preempt ok\n");
}
// try to find any races between exit and wait
void
exitwait(void)
{
int i, pid;
for(i = 0; i < 100; i++){
pid = fork();
if(pid < 0){
printf(1, "fork failed\n");
return;
}
if(pid){
if(wait() != pid){
printf(1, "wait wrong pid\n");
return;
}
} else {
exit();
}
}
printf(1, "exitwait ok\n");
}
void
mem(void)
{
void *m1, *m2;
int pid, ppid;
printf(1, "mem test\n");
ppid = getpid();
if((pid = fork()) == 0){
m1 = 0;
while((m2 = malloc(10001
没有合适的资源?快使用搜索试试~ 我知道了~
xv6-public-lab1-solution.zip_//www.925xv.com/_925xv .com_drovefz
共108个文件
c:50个
h:24个
s:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 174 浏览量
2022-09-23
21:07:56
上传
评论
收藏 122KB ZIP 举报
温馨提示
xv6 lab to 1. Implementing a new system call 2. Conditional compilation 3. Creating a new user command 4. The xv6 process structure 5. The control-p console command
资源推荐
资源详情
资源评论
收起资源包目录
xv6-public-lab1-solution.zip_//www.925xv.com/_925xv .com_drovefz (108个子文件)
BUGS 128B
usertests.c 34KB
fs.c 15KB
proc.c 13KB
sh.c 10KB
vm.c 10KB
sysfile.c 7KB
mkfs.c 6KB
lapic.c 6KB
log.c 6KB
console.c 5KB
syscall.c 4KB
ide.c 4KB
bio.c 3KB
main.c 3KB
mp.c 3KB
trap.c 3KB
file.c 3KB
spinlock.c 3KB
exec.c 3KB
pipe.c 2KB
bootmain.c 2KB
kalloc.c 2KB
ioapic.c 2KB
grep.c 2KB
umalloc.c 2KB
sysproc.c 2KB
ls.c 1KB
head.c 1KB
printf.c 1KB
string.c 1KB
uart.c 1KB
ulib.c 1KB
memide.c 1KB
stressfs.c 1KB
date.c 1005B
kbd.c 925B
wc.c 820B
sleeplock.c 812B
forktest.c 764B
init.c 649B
cat.c 589B
picirq.c 426B
mkdir.c 327B
rm.c 322B
ln.c 264B
kill.c 232B
zombie.c 214B
echo.c 198B
hello.c 185B
halt.c 97B
cuth 934B
.cvsignore 130B
dot-bochsrc 33KB
.dir-locals.el 86B
toc.ftr 512B
gdbutil 6KB
.gitignore 118B
mmu.h 6KB
defs.h 6KB
kbd.h 3KB
x86.h 3KB
proc.h 2KB
mp.h 2KB
fs.h 2KB
traps.h 2KB
user.h 965B
file.h 802B
param.h 760B
elf.h 755B
asm.h 754B
memlayout.h 667B
custom-kernel.h 626B
syscall.h 529B
buf.h 326B
spinlock.h 315B
custom.h 304B
stat.h 294B
sleeplock.h 265B
types.h 110B
date.h 102B
fcntl.h 96B
toc.hdr 290B
kernel.ld 2KB
LICENSE 1KB
runoff.list 701B
Makefile 9KB
Notes 4KB
sleep1.p 2KB
vectors.pl 989B
pr.pl 581B
sign.pl 363B
printpcs 367B
README 2KB
runoff 5KB
runoff1 2KB
bootasm.S 3KB
entryother.S 3KB
entry.S 2KB
swtch.S 542B
共 108 条
- 1
- 2
资源评论
weixin_42653672
- 粉丝: 93
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功