#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;
// 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\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)) != 0){
*(char**)m2 = m1;
m1 = m2;
}
while(m1){
m2 = *(char**)m1;
free(m1);
m1 = m2;
}
m1 = malloc(1024*20);
if(m1 == 0){
printf(1, "couldn't allocate mem?!!\n");
kill(ppid);
exit();
}
free(m1);
printf(1, "mem ok\n");
exit();
} else {
wait();
}
}
// More file system tests
// two processes write to the same file descriptor
// is the offset shared? does inode locking work?
void
sharedfd(void)
{
int fd, pid, i, n, nc, np;
char buf[10];
printf(1, "sharedfd test\n");
unlink("sharedfd");
fd = open("sharedfd", O_CREATE|O_RDWR);
if(fd < 0){
printf(1, "fstests: cannot open sharedfd for writing");
return;
}
pid = fork();
memset(buf, pid==0?'c':'p', sizeof(buf));
for(i = 0; i < 1000; i++){
if(write(fd, buf, sizeof(buf)) != sizeof(buf)){
printf(1, "fstests: write sharedfd failed\n");
break;
}
}
if(pid == 0)
exit();
else
wait();
close(fd);
fd = open("sharedfd", 0);
if(fd < 0){
printf(1, "fstests: cannot open sharedfd for reading\n");
return;
}
nc = np = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
for(i = 0; i < sizeof(buf); i++){
if(buf[i] == 'c')
nc++;
if(buf[i] == 'p')
np++;
}
}
close(fd);
unlink("sharedfd");
if(nc == 10000 && np == 10000){
printf(1, "sharedfd ok\n");
} else {
printf(1, "sharedfd oops %d %d\n", nc, np);
exit();
}
}
// two processes write two different files at the same
// time, to test block allocation.
void
twofiles(void)
{
int fd, pid, i, j, n, total;
char *fname;
printf(1, "twofiles test\n");
unlink("f1");
unlink("f2");
pid = fork();
if(pid < 0){
printf(1, "fork failed\n");
exit();
}
fname = pid ? "f1" : "f2";
fd = open(fname, O_CREATE | O_RDWR);
if(fd < 0){
printf(1, "create failed\n");
exit();
}
memset(buf, pid?'p':'c', 512);
for(i =
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源内项目代码都是经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能。 在xv6的基础下改进单核调度算法和多核调度算法C语言实现源码.zip 在xv6的基础下改进单核调度算法和多核调度算法C语言实现源码.zip 在xv6的基础下改进单核调度算法和多核调度算法C语言实现源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
在xv6的基础下改进单核调度算法和多核调度算法C语言实现源码.zip (104个子文件)
BUGS 128B
usertests.c 31KB
fs.c 15KB
proc.c 10KB
vm.c 9KB
sh.c 8KB
sysfile.c 7KB
mkfs.c 6KB
lapic.c 5KB
console.c 5KB
log.c 4KB
mp.c 3KB
main.c 3KB
syscall.c 3KB
bio.c 3KB
ide.c 3KB
file.c 3KB
trap.c 3KB
spinlock.c 3KB
cpu_test.c 2KB
pipe.c 2KB
picirq.c 2KB
exec.c 2KB
bootmain.c 2KB
ioapic.c 2KB
kalloc.c 2KB
grep.c 2KB
umalloc.c 2KB
ls.c 2KB
printf.c 1KB
string.c 1KB
io_test.c 1KB
uart.c 1KB
ulib.c 1KB
memide.c 1KB
mem_test.c 1KB
sysproc.c 1KB
stressfs.c 1KB
timer.c 956B
kbd.c 925B
wc.c 820B
forktest.c 766B
init.c 649B
cat.c 513B
mkdir.c 327B
rm.c 322B
ln.c 264B
kill.c 232B
zombie.c 215B
echo.c 198B
cuth 934B
.cvsignore 130B
dot-bochsrc 33KB
.dir-locals.el 86B
toc.ftr 512B
gdbutil 6KB
.gitignore 118B
mmu.h 9KB
defs.h 5KB
kbd.h 3KB
proc.h 3KB
x86.h 3KB
mp.h 2KB
traps.h 2KB
fs.h 1KB
asm.h 936B
user.h 830B
memlayout.h 828B
file.h 767B
elf.h 755B
param.h 614B
syscall.h 486B
buf.h 340B
spinlock.h 317B
stat.h 294B
types.h 140B
fcntl.h 96B
toc.hdr 290B
kernel.ld 2KB
LICENSE 1KB
runoff.list 597B
Makefile 8KB
Notes 4KB
sleep1.p 2KB
symlink.patch 4KB
vectors.pl 989B
pr.pl 581B
sign.pl 363B
printpcs 367B
README 2KB
runoff 5KB
runoff1 2KB
bootasm.S 3KB
entryother.S 2KB
entry.S 2KB
trapasm.S 557B
usys.S 461B
swtch.S 461B
initcode.S 423B
show1 135B
共 104 条
- 1
- 2
资源评论
Make程序设计
- 粉丝: 5623
- 资源: 3567
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 农村信用社联合社计算机信息系统投产与变更管理办.docx
- 农村信用社联合社计算机信息系统数据管理办法.docx
- 利用SPSS作临床效度分析线上计算网站介绍-医学研究部统计谘.(医学PPT课件).ppt
- 利用Zabbix监控mysqldump定时备份数据库状态.docx
- 利用计算机解决问题的基本过程.doc
- 化工铁路通信工程总结.doc
- 北京大学网络教育软件工程作业.docx
- 医药公司(连锁店)计算机操作规程未新系统的自行按照旧制修改-新系统过制的编号加修模版.doc
- 医药公司(连锁店)计算机系统操作规程模版.doc
- 医药连锁门店计算机系统的操作和管理程序未新系统的自行按照旧制修改-新系统过制的编号加修模版.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功