A pread user test, fix a XXX

上级 41352a11
......@@ -79,12 +79,16 @@ ssize_t
sys_pread(int fd, void *ubuf, size_t count, off_t offset)
{
struct file *f;
uptr i = (uptr)ubuf;
int r;
if(fd < 0 || fd >= NOFILE || (f=myproc()->ofile[fd]) == 0)
return -1;
// XXX(sbw) assuming ubuf is ok
for(uptr va = PGROUNDDOWN(i); va < i+count; va = va + PGSIZE)
if(pagefault(myproc()->vmap, va, 0) < 0)
return -1;
if(f->type == file::FD_INODE){
ilock(f->ip, 0);
if(f->ip->type == 0)
......
......@@ -1544,6 +1544,50 @@ unopentest(void)
printf(stdout, "concurrent unlink/open ok\n");
}
void
preads(void)
{
static const int fsize = (64 << 10);
static const int bsize = 4096;
static const int nprocs = 4;
static const int iters = 100;
static char buf[bsize];
int fd;
int pid;
printf(1, "concurrent preads\n");
fd = open("preads.x", O_CREATE|O_RDWR);
if (fd < 0)
die("preads: open failed");
for (int i = 0; i < fsize/bsize; i++)
if (write(fd, buf, bsize) != bsize)
die("preads: write failed");
close(fd);
for (int i = 0; i < nprocs; i++) {
pid = fork(0);
if (pid < 0)
die("preads: fork failed");
if (pid == 0)
break;
}
for (int k = 0; k < iters; k++) {
fd = open("preads.x", O_RDONLY);
for (int i = 0; i < fsize; i+=bsize)
if (pread(fd, buf, bsize, i) != bsize)
die("preads: pread failed");
close(fd);
}
if (pid == 0)
exit();
printf(1, "concurrent preads OK\n");
}
int
main(int argc, char *argv[])
{
......@@ -1567,6 +1611,7 @@ main(int argc, char *argv[])
writetest();
writetest1();
createtest();
preads();
// mem();
pipe1();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论