Rationalize some constants in usertests
This commit is contained in:
parent
d98ddadd79
commit
b564fca246
149
user/usertests.c
149
user/usertests.c
|
@ -8,7 +8,9 @@
|
||||||
#include "kernel/memlayout.h"
|
#include "kernel/memlayout.h"
|
||||||
#include "kernel/riscv.h"
|
#include "kernel/riscv.h"
|
||||||
|
|
||||||
char buf[8192];
|
#define BUFSZ (MAXOPBLOCKS+2)*BSIZE
|
||||||
|
|
||||||
|
char buf[BUFSZ];
|
||||||
char name[3];
|
char name[3];
|
||||||
char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
|
char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
|
||||||
int stdout = 1;
|
int stdout = 1;
|
||||||
|
@ -140,7 +142,8 @@ writetest(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int i;
|
int i;
|
||||||
|
enum { N=100, SZ=10 };
|
||||||
|
|
||||||
printf(stdout, "small file test\n");
|
printf(stdout, "small file test\n");
|
||||||
fd = open("small", O_CREATE|O_RDWR);
|
fd = open("small", O_CREATE|O_RDWR);
|
||||||
if(fd >= 0){
|
if(fd >= 0){
|
||||||
|
@ -149,12 +152,12 @@ writetest(void)
|
||||||
printf(stdout, "error: creat small failed!\n");
|
printf(stdout, "error: creat small failed!\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
for(i = 0; i < 100; i++){
|
for(i = 0; i < N; i++){
|
||||||
if(write(fd, "aaaaaaaaaa", 10) != 10){
|
if(write(fd, "aaaaaaaaaa", SZ) != SZ){
|
||||||
printf(stdout, "error: write aa %d new file failed\n", i);
|
printf(stdout, "error: write aa %d new file failed\n", i);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
if(write(fd, "bbbbbbbbbb", 10) != 10){
|
if(write(fd, "bbbbbbbbbb", SZ) != SZ){
|
||||||
printf(stdout, "error: write bb %d new file failed\n", i);
|
printf(stdout, "error: write bb %d new file failed\n", i);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -168,8 +171,8 @@ writetest(void)
|
||||||
printf(stdout, "error: open small failed!\n");
|
printf(stdout, "error: open small failed!\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
i = read(fd, buf, 2000);
|
i = read(fd, buf, N*SZ*2);
|
||||||
if(i == 2000){
|
if(i == N*SZ*2){
|
||||||
printf(stdout, "read succeeded ok\n");
|
printf(stdout, "read succeeded ok\n");
|
||||||
} else {
|
} else {
|
||||||
printf(stdout, "read failed\n");
|
printf(stdout, "read failed\n");
|
||||||
|
@ -199,7 +202,7 @@ writetest1(void)
|
||||||
|
|
||||||
for(i = 0; i < MAXFILE; i++){
|
for(i = 0; i < MAXFILE; i++){
|
||||||
((int*)buf)[0] = i;
|
((int*)buf)[0] = i;
|
||||||
if(write(fd, buf, 512) != 512){
|
if(write(fd, buf, BSIZE) != BSIZE){
|
||||||
printf(stdout, "error: write big file failed\n", i);
|
printf(stdout, "error: write big file failed\n", i);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -215,14 +218,14 @@ writetest1(void)
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
for(;;){
|
for(;;){
|
||||||
i = read(fd, buf, 512);
|
i = read(fd, buf, BSIZE);
|
||||||
if(i == 0){
|
if(i == 0){
|
||||||
if(n == MAXFILE - 1){
|
if(n == MAXFILE - 1){
|
||||||
printf(stdout, "read only %d blocks from big", n);
|
printf(stdout, "read only %d blocks from big", n);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if(i != 512){
|
} else if(i != BSIZE){
|
||||||
printf(stdout, "read failed %d\n", i);
|
printf(stdout, "read failed %d\n", i);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -245,19 +248,20 @@ void
|
||||||
createtest(void)
|
createtest(void)
|
||||||
{
|
{
|
||||||
int i, fd;
|
int i, fd;
|
||||||
|
enum { N=52 };
|
||||||
|
|
||||||
printf(stdout, "many creates, followed by unlink test\n");
|
printf(stdout, "many creates, followed by unlink test\n");
|
||||||
|
|
||||||
name[0] = 'a';
|
name[0] = 'a';
|
||||||
name[2] = '\0';
|
name[2] = '\0';
|
||||||
for(i = 0; i < 52; i++){
|
for(i = 0; i < N; i++){
|
||||||
name[1] = '0' + i;
|
name[1] = '0' + i;
|
||||||
fd = open(name, O_CREATE|O_RDWR);
|
fd = open(name, O_CREATE|O_RDWR);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
name[0] = 'a';
|
name[0] = 'a';
|
||||||
name[2] = '\0';
|
name[2] = '\0';
|
||||||
for(i = 0; i < 52; i++){
|
for(i = 0; i < N; i++){
|
||||||
name[1] = '0' + i;
|
name[1] = '0' + i;
|
||||||
unlink(name);
|
unlink(name);
|
||||||
}
|
}
|
||||||
|
@ -307,7 +311,8 @@ pipe1(void)
|
||||||
{
|
{
|
||||||
int fds[2], pid;
|
int fds[2], pid;
|
||||||
int seq, i, n, cc, total;
|
int seq, i, n, cc, total;
|
||||||
|
enum { N=5, SZ=1033 };
|
||||||
|
|
||||||
if(pipe(fds) != 0){
|
if(pipe(fds) != 0){
|
||||||
printf(1, "pipe() failed\n");
|
printf(1, "pipe() failed\n");
|
||||||
exit();
|
exit();
|
||||||
|
@ -316,10 +321,10 @@ pipe1(void)
|
||||||
seq = 0;
|
seq = 0;
|
||||||
if(pid == 0){
|
if(pid == 0){
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
for(n = 0; n < 5; n++){
|
for(n = 0; n < N; n++){
|
||||||
for(i = 0; i < 1033; i++)
|
for(i = 0; i < SZ; i++)
|
||||||
buf[i] = seq++;
|
buf[i] = seq++;
|
||||||
if(write(fds[1], buf, 1033) != 1033){
|
if(write(fds[1], buf, SZ) != SZ){
|
||||||
printf(1, "pipe1 oops 1\n");
|
printf(1, "pipe1 oops 1\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -341,7 +346,7 @@ pipe1(void)
|
||||||
if(cc > sizeof(buf))
|
if(cc > sizeof(buf))
|
||||||
cc = sizeof(buf);
|
cc = sizeof(buf);
|
||||||
}
|
}
|
||||||
if(total != 5 * 1033){
|
if(total != N * SZ){
|
||||||
printf(1, "pipe1 oops 3 total %d\n", total);
|
printf(1, "pipe1 oops 3 total %d\n", total);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -512,10 +517,11 @@ void
|
||||||
forkfork(void)
|
forkfork(void)
|
||||||
{
|
{
|
||||||
int ppid = getpid();
|
int ppid = getpid();
|
||||||
|
enum { N=2 };
|
||||||
|
|
||||||
printf(1, "forkfork test\n");
|
printf(1, "forkfork test\n");
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++){
|
for(int i = 0; i < N; i++){
|
||||||
int pid = fork();
|
int pid = fork();
|
||||||
if(pid < 0){
|
if(pid < 0){
|
||||||
printf(1, "fork failed");
|
printf(1, "fork failed");
|
||||||
|
@ -538,7 +544,7 @@ forkfork(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++){
|
for(int i = 0; i < N; i++){
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +626,8 @@ void
|
||||||
sharedfd(void)
|
sharedfd(void)
|
||||||
{
|
{
|
||||||
int fd, pid, i, n, nc, np;
|
int fd, pid, i, n, nc, np;
|
||||||
char buf[10];
|
enum { N = 1000, SZ=10};
|
||||||
|
char buf[SZ];
|
||||||
|
|
||||||
printf(1, "sharedfd test\n");
|
printf(1, "sharedfd test\n");
|
||||||
|
|
||||||
|
@ -632,7 +639,7 @@ sharedfd(void)
|
||||||
}
|
}
|
||||||
pid = fork();
|
pid = fork();
|
||||||
memset(buf, pid==0?'c':'p', sizeof(buf));
|
memset(buf, pid==0?'c':'p', sizeof(buf));
|
||||||
for(i = 0; i < 1000; i++){
|
for(i = 0; i < N; i++){
|
||||||
if(write(fd, buf, sizeof(buf)) != sizeof(buf)){
|
if(write(fd, buf, sizeof(buf)) != sizeof(buf)){
|
||||||
printf(1, "fstests: write sharedfd failed\n");
|
printf(1, "fstests: write sharedfd failed\n");
|
||||||
break;
|
break;
|
||||||
|
@ -659,7 +666,7 @@ sharedfd(void)
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
unlink("sharedfd");
|
unlink("sharedfd");
|
||||||
if(nc == 10000 && np == 10000){
|
if(nc == N*SZ && np == N*SZ){
|
||||||
printf(1, "sharedfd ok\n");
|
printf(1, "sharedfd ok\n");
|
||||||
} else {
|
} else {
|
||||||
printf(1, "sharedfd oops %d %d\n", nc, np);
|
printf(1, "sharedfd oops %d %d\n", nc, np);
|
||||||
|
@ -675,10 +682,11 @@ fourfiles(void)
|
||||||
int fd, pid, i, j, n, total, pi;
|
int fd, pid, i, j, n, total, pi;
|
||||||
char *names[] = { "f0", "f1", "f2", "f3" };
|
char *names[] = { "f0", "f1", "f2", "f3" };
|
||||||
char *fname;
|
char *fname;
|
||||||
|
enum { N=12, NCHILD=4, SZ=500 };
|
||||||
|
|
||||||
printf(1, "fourfiles test\n");
|
printf(1, "fourfiles test\n");
|
||||||
|
|
||||||
for(pi = 0; pi < 4; pi++){
|
for(pi = 0; pi < NCHILD; pi++){
|
||||||
fname = names[pi];
|
fname = names[pi];
|
||||||
unlink(fname);
|
unlink(fname);
|
||||||
|
|
||||||
|
@ -695,9 +703,9 @@ fourfiles(void)
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buf, '0'+pi, 512);
|
memset(buf, '0'+pi, SZ);
|
||||||
for(i = 0; i < 12; i++){
|
for(i = 0; i < N; i++){
|
||||||
if((n = write(fd, buf, 500)) != 500){
|
if((n = write(fd, buf, SZ)) != SZ){
|
||||||
printf(1, "write failed %d\n", n);
|
printf(1, "write failed %d\n", n);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -706,11 +714,11 @@ fourfiles(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(pi = 0; pi < 4; pi++){
|
for(pi = 0; pi < NCHILD; pi++){
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 2; i++){
|
for(i = 0; i < NCHILD; i++){
|
||||||
fname = names[i];
|
fname = names[i];
|
||||||
fd = open(fname, 0);
|
fd = open(fname, 0);
|
||||||
total = 0;
|
total = 0;
|
||||||
|
@ -724,7 +732,7 @@ fourfiles(void)
|
||||||
total += n;
|
total += n;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
if(total != 12*500){
|
if(total != N*SZ){
|
||||||
printf(1, "wrong length %d\n", total);
|
printf(1, "wrong length %d\n", total);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -811,6 +819,7 @@ createdelete(void)
|
||||||
void
|
void
|
||||||
unlinkread(void)
|
unlinkread(void)
|
||||||
{
|
{
|
||||||
|
enum { SZ = 5 };
|
||||||
int fd, fd1;
|
int fd, fd1;
|
||||||
|
|
||||||
printf(1, "unlinkread test\n");
|
printf(1, "unlinkread test\n");
|
||||||
|
@ -819,7 +828,7 @@ unlinkread(void)
|
||||||
printf(1, "create unlinkread failed\n");
|
printf(1, "create unlinkread failed\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
write(fd, "hello", 5);
|
write(fd, "hello", SZ);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
fd = open("unlinkread", O_RDWR);
|
fd = open("unlinkread", O_RDWR);
|
||||||
|
@ -836,7 +845,7 @@ unlinkread(void)
|
||||||
write(fd1, "yyy", 3);
|
write(fd1, "yyy", 3);
|
||||||
close(fd1);
|
close(fd1);
|
||||||
|
|
||||||
if(read(fd, buf, sizeof(buf)) != 5){
|
if(read(fd, buf, sizeof(buf)) != SZ){
|
||||||
printf(1, "unlinkread read failed");
|
printf(1, "unlinkread read failed");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -856,6 +865,7 @@ unlinkread(void)
|
||||||
void
|
void
|
||||||
linktest(void)
|
linktest(void)
|
||||||
{
|
{
|
||||||
|
enum { SZ = 5 };
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
printf(1, "linktest\n");
|
printf(1, "linktest\n");
|
||||||
|
@ -868,7 +878,7 @@ linktest(void)
|
||||||
printf(1, "create lf1 failed\n");
|
printf(1, "create lf1 failed\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
if(write(fd, "hello", 5) != 5){
|
if(write(fd, "hello", SZ) != SZ){
|
||||||
printf(1, "write lf1 failed\n");
|
printf(1, "write lf1 failed\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -890,7 +900,7 @@ linktest(void)
|
||||||
printf(1, "open lf2 failed\n");
|
printf(1, "open lf2 failed\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
if(read(fd, buf, sizeof(buf)) != 5){
|
if(read(fd, buf, sizeof(buf)) != SZ){
|
||||||
printf(1, "read lf2 failed\n");
|
printf(1, "read lf2 failed\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -919,18 +929,19 @@ linktest(void)
|
||||||
void
|
void
|
||||||
concreate(void)
|
concreate(void)
|
||||||
{
|
{
|
||||||
|
enum { N = 40 };
|
||||||
char file[3];
|
char file[3];
|
||||||
int i, pid, n, fd;
|
int i, pid, n, fd;
|
||||||
char fa[40];
|
char fa[N];
|
||||||
struct {
|
struct {
|
||||||
ushort inum;
|
ushort inum;
|
||||||
char name[14];
|
char name[DIRSIZ];
|
||||||
} de;
|
} de;
|
||||||
|
|
||||||
printf(1, "concreate test\n");
|
printf(1, "concreate test\n");
|
||||||
file[0] = 'C';
|
file[0] = 'C';
|
||||||
file[2] = '\0';
|
file[2] = '\0';
|
||||||
for(i = 0; i < 40; i++){
|
for(i = 0; i < N; i++){
|
||||||
file[1] = '0' + i;
|
file[1] = '0' + i;
|
||||||
unlink(file);
|
unlink(file);
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
@ -974,12 +985,12 @@ concreate(void)
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if(n != 40){
|
if(n != N){
|
||||||
printf(1, "concreate not enough files in directory listing\n");
|
printf(1, "concreate not enough files in directory listing\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 40; i++){
|
for(i = 0; i < N; i++){
|
||||||
file[1] = '0' + i;
|
file[1] = '0' + i;
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid < 0){
|
if(pid < 0){
|
||||||
|
@ -1047,6 +1058,7 @@ linkunlink()
|
||||||
void
|
void
|
||||||
bigdir(void)
|
bigdir(void)
|
||||||
{
|
{
|
||||||
|
enum { N = 500 };
|
||||||
int i, fd;
|
int i, fd;
|
||||||
char name[10];
|
char name[10];
|
||||||
|
|
||||||
|
@ -1060,7 +1072,7 @@ bigdir(void)
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
for(i = 0; i < 500; i++){
|
for(i = 0; i < N; i++){
|
||||||
name[0] = 'x';
|
name[0] = 'x';
|
||||||
name[1] = '0' + (i / 64);
|
name[1] = '0' + (i / 64);
|
||||||
name[2] = '0' + (i % 64);
|
name[2] = '0' + (i % 64);
|
||||||
|
@ -1072,7 +1084,7 @@ bigdir(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink("bd");
|
unlink("bd");
|
||||||
for(i = 0; i < 500; i++){
|
for(i = 0; i < N; i++){
|
||||||
name[0] = 'x';
|
name[0] = 'x';
|
||||||
name[1] = '0' + (i / 64);
|
name[1] = '0' + (i / 64);
|
||||||
name[2] = '0' + (i % 64);
|
name[2] = '0' + (i % 64);
|
||||||
|
@ -1278,7 +1290,7 @@ bigwrite(void)
|
||||||
printf(1, "bigwrite test\n");
|
printf(1, "bigwrite test\n");
|
||||||
|
|
||||||
unlink("bigwrite");
|
unlink("bigwrite");
|
||||||
for(sz = 499; sz < 12*512; sz += 471){
|
for(sz = 499; sz < (MAXOPBLOCKS+2)*BSIZE; sz += 471){
|
||||||
fd = open("bigwrite", O_CREATE | O_RDWR);
|
fd = open("bigwrite", O_CREATE | O_RDWR);
|
||||||
if(fd < 0){
|
if(fd < 0){
|
||||||
printf(1, "cannot create bigwrite\n");
|
printf(1, "cannot create bigwrite\n");
|
||||||
|
@ -1302,6 +1314,7 @@ bigwrite(void)
|
||||||
void
|
void
|
||||||
bigfile(void)
|
bigfile(void)
|
||||||
{
|
{
|
||||||
|
enum { N = 20, SZ=600 };
|
||||||
int fd, i, total, cc;
|
int fd, i, total, cc;
|
||||||
|
|
||||||
printf(1, "bigfile test\n");
|
printf(1, "bigfile test\n");
|
||||||
|
@ -1312,9 +1325,9 @@ bigfile(void)
|
||||||
printf(1, "cannot create bigfile");
|
printf(1, "cannot create bigfile");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
for(i = 0; i < 20; i++){
|
for(i = 0; i < N; i++){
|
||||||
memset(buf, i, 600);
|
memset(buf, i, SZ);
|
||||||
if(write(fd, buf, 600) != 600){
|
if(write(fd, buf, SZ) != SZ){
|
||||||
printf(1, "write bigfile failed\n");
|
printf(1, "write bigfile failed\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -1328,25 +1341,25 @@ bigfile(void)
|
||||||
}
|
}
|
||||||
total = 0;
|
total = 0;
|
||||||
for(i = 0; ; i++){
|
for(i = 0; ; i++){
|
||||||
cc = read(fd, buf, 300);
|
cc = read(fd, buf, SZ/2);
|
||||||
if(cc < 0){
|
if(cc < 0){
|
||||||
printf(1, "read bigfile failed\n");
|
printf(1, "read bigfile failed\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
if(cc == 0)
|
if(cc == 0)
|
||||||
break;
|
break;
|
||||||
if(cc != 300){
|
if(cc != SZ/2){
|
||||||
printf(1, "short read bigfile\n");
|
printf(1, "short read bigfile\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
if(buf[0] != i/2 || buf[299] != i/2){
|
if(buf[0] != i/2 || buf[SZ/2-1] != i/2){
|
||||||
printf(1, "read bigfile wrong data\n");
|
printf(1, "read bigfile wrong data\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
total += cc;
|
total += cc;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
if(total != 20*600){
|
if(total != N*SZ){
|
||||||
printf(1, "read bigfile wrong total\n");
|
printf(1, "read bigfile wrong total\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -1502,8 +1515,7 @@ iref(void)
|
||||||
|
|
||||||
printf(1, "empty file name\n");
|
printf(1, "empty file name\n");
|
||||||
|
|
||||||
// the 50 is NINODE
|
for(i = 0; i < NINODE + 1; i++){
|
||||||
for(i = 0; i < 50 + 1; i++){
|
|
||||||
if(mkdir("irefd") != 0){
|
if(mkdir("irefd") != 0){
|
||||||
printf(1, "mkdir irefd failed\n");
|
printf(1, "mkdir irefd failed\n");
|
||||||
exit();
|
exit();
|
||||||
|
@ -1534,11 +1546,12 @@ iref(void)
|
||||||
void
|
void
|
||||||
forktest(void)
|
forktest(void)
|
||||||
{
|
{
|
||||||
|
enum{ N = 1000 };
|
||||||
int n, pid;
|
int n, pid;
|
||||||
|
|
||||||
printf(1, "fork test\n");
|
printf(1, "fork test\n");
|
||||||
|
|
||||||
for(n=0; n<1000; n++){
|
for(n=0; n<N; n++){
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid < 0)
|
if(pid < 0)
|
||||||
break;
|
break;
|
||||||
|
@ -1551,7 +1564,7 @@ forktest(void)
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n == 1000){
|
if(n == N){
|
||||||
printf(1, "fork claimed to work 1000 times!\n");
|
printf(1, "fork claimed to work 1000 times!\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -1574,18 +1587,18 @@ forktest(void)
|
||||||
void
|
void
|
||||||
sbrktest(void)
|
sbrktest(void)
|
||||||
{
|
{
|
||||||
|
enum { BIG=100*1024*1024, TOOMUCH=1024*1024*1024};
|
||||||
int i, fds[2], pids[10], pid, ppid;
|
int i, fds[2], pids[10], pid, ppid;
|
||||||
char *c, *oldbrk, scratch, *a, *b, *lastaddr, *p;
|
char *c, *oldbrk, scratch, *a, *b, *lastaddr, *p;
|
||||||
uint64 amt;
|
uint64 amt;
|
||||||
int fd;
|
int fd;
|
||||||
int n;
|
int n;
|
||||||
#define BIG (100*1024*1024)
|
|
||||||
|
|
||||||
printf(stdout, "sbrk test\n");
|
printf(stdout, "sbrk test\n");
|
||||||
oldbrk = sbrk(0);
|
oldbrk = sbrk(0);
|
||||||
|
|
||||||
// does sbrk() return the expected failure value?
|
// does sbrk() return the expected failure value?
|
||||||
a = sbrk(1024*1024*1024);
|
a = sbrk(TOOMUCH);
|
||||||
if(a != (char*)0xffffffffffffffffL){
|
if(a != (char*)0xffffffffffffffffL){
|
||||||
printf(stdout, "sbrk(<toomuch>) returned %p\n", a);
|
printf(stdout, "sbrk(<toomuch>) returned %p\n", a);
|
||||||
exit();
|
exit();
|
||||||
|
@ -1630,21 +1643,21 @@ sbrktest(void)
|
||||||
|
|
||||||
// can one de-allocate?
|
// can one de-allocate?
|
||||||
a = sbrk(0);
|
a = sbrk(0);
|
||||||
c = sbrk(-4096);
|
c = sbrk(-PGSIZE);
|
||||||
if(c == (char*)0xffffffffffffffffL){
|
if(c == (char*)0xffffffffffffffffL){
|
||||||
printf(stdout, "sbrk could not deallocate\n");
|
printf(stdout, "sbrk could not deallocate\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
c = sbrk(0);
|
c = sbrk(0);
|
||||||
if(c != a - 4096){
|
if(c != a - PGSIZE){
|
||||||
printf(stdout, "sbrk deallocation produced wrong address, a %x c %x\n", a, c);
|
printf(stdout, "sbrk deallocation produced wrong address, a %x c %x\n", a, c);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// can one re-allocate that page?
|
// can one re-allocate that page?
|
||||||
a = sbrk(0);
|
a = sbrk(0);
|
||||||
c = sbrk(4096);
|
c = sbrk(PGSIZE);
|
||||||
if(c != a || sbrk(0) != a + 4096){
|
if(c != a || sbrk(0) != a + PGSIZE){
|
||||||
printf(stdout, "sbrk re-allocation failed, a %x c %x\n", a, c);
|
printf(stdout, "sbrk re-allocation failed, a %x c %x\n", a, c);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -1697,7 +1710,7 @@ sbrktest(void)
|
||||||
|
|
||||||
// if those failed allocations freed up the pages they did allocate,
|
// if those failed allocations freed up the pages they did allocate,
|
||||||
// we'll be able to allocate here
|
// we'll be able to allocate here
|
||||||
c = sbrk(4096);
|
c = sbrk(PGSIZE);
|
||||||
for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){
|
for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){
|
||||||
if(pids[i] == -1)
|
if(pids[i] == -1)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1723,7 +1736,7 @@ sbrktest(void)
|
||||||
a = sbrk(0);
|
a = sbrk(0);
|
||||||
sbrk(10*BIG);
|
sbrk(10*BIG);
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (i = 0; i < 10*BIG; i += 4096) {
|
for (i = 0; i < 10*BIG; i += PGSIZE) {
|
||||||
n += *(a+i);
|
n += *(a+i);
|
||||||
}
|
}
|
||||||
printf(stdout, "allocate a lot of memory succeeded %d\n", n);
|
printf(stdout, "allocate a lot of memory succeeded %d\n", n);
|
||||||
|
@ -1733,7 +1746,7 @@ sbrktest(void)
|
||||||
wait();
|
wait();
|
||||||
|
|
||||||
// test reads from allocated memory
|
// test reads from allocated memory
|
||||||
a = sbrk(4096);
|
a = sbrk(PGSIZE);
|
||||||
fd = open("sbrk", O_CREATE|O_WRONLY);
|
fd = open("sbrk", O_CREATE|O_WRONLY);
|
||||||
unlink("sbrk");
|
unlink("sbrk");
|
||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
|
@ -1747,7 +1760,7 @@ sbrktest(void)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
// test writes to allocated memory
|
// test writes to allocated memory
|
||||||
a = sbrk(4096);
|
a = sbrk(PGSIZE);
|
||||||
if(pipe((int *) a) != 0){
|
if(pipe((int *) a) != 0){
|
||||||
printf(1, "pipe() failed\n");
|
printf(1, "pipe() failed\n");
|
||||||
exit();
|
exit();
|
||||||
|
@ -1782,7 +1795,7 @@ validatetest(void)
|
||||||
printf(stdout, "validate test\n");
|
printf(stdout, "validate test\n");
|
||||||
hi = 1100*1024;
|
hi = 1100*1024;
|
||||||
|
|
||||||
for(p = 0; p <= (uint)hi; p += 4096){
|
for(p = 0; p <= (uint)hi; p += PGSIZE){
|
||||||
if((pid = fork()) == 0){
|
if((pid = fork()) == 0){
|
||||||
// try to crash the kernel by passing in a badly placed integer
|
// try to crash the kernel by passing in a badly placed integer
|
||||||
validateint((int*)p);
|
validateint((int*)p);
|
||||||
|
@ -1882,8 +1895,8 @@ fsfull()
|
||||||
}
|
}
|
||||||
int total = 0;
|
int total = 0;
|
||||||
while(1){
|
while(1){
|
||||||
int cc = write(fd, buf, 512);
|
int cc = write(fd, buf, BSIZE);
|
||||||
if(cc < 512)
|
if(cc < BSIZE)
|
||||||
break;
|
break;
|
||||||
total += cc;
|
total += cc;
|
||||||
fsblocks++;
|
fsblocks++;
|
||||||
|
@ -1942,7 +1955,7 @@ stacktest()
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
char *sp = (char *) r_sp();
|
char *sp = (char *) r_sp();
|
||||||
sp -= 4096;
|
sp -= PGSIZE;
|
||||||
// the *sp should cause a trap.
|
// the *sp should cause a trap.
|
||||||
printf(1, "stacktest: read below stack %p\n", *sp);
|
printf(1, "stacktest: read below stack %p\n", *sp);
|
||||||
printf(1, "stacktest: test FAILED\n");
|
printf(1, "stacktest: test FAILED\n");
|
||||||
|
|
Loading…
Reference in a new issue