diff options
author | Frans Kaashoek <[email protected]> | 2019-07-24 08:37:26 -0400 |
---|---|---|
committer | Frans Kaashoek <[email protected]> | 2019-07-24 08:37:43 -0400 |
commit | 0387e2156f10130148a44d9389393ec537e3b134 (patch) | |
tree | ed6b97519a886c5f44f7f30b09cacc5309fee74c /user | |
parent | 936afc6e1a2ac7149d956b000373f248d49d5196 (diff) | |
download | xv6-labs-0387e2156f10130148a44d9389393ec537e3b134.tar.gz xv6-labs-0387e2156f10130148a44d9389393ec537e3b134.tar.bz2 xv6-labs-0387e2156f10130148a44d9389393ec537e3b134.zip |
Add a few sbrktest for lazy allocatioin lab
Diffstat (limited to 'user')
-rw-r--r-- | user/usertests.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/user/usertests.c b/user/usertests.c index 42065f4..3d8786c 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -1577,6 +1577,8 @@ sbrktest(void) int i, fds[2], pids[10], pid, ppid; char *c, *oldbrk, scratch, *a, *b, *lastaddr, *p; uint64 amt; + int fd; + int n; #define BIG (100*1024*1024) printf(stdout, "sbrk test\n"); @@ -1707,6 +1709,50 @@ sbrktest(void) exit(); } + // test running fork with the above allocated page + ppid = getpid(); + pid = fork(); + if(pid < 0){ + printf(stdout, "fork failed\n"); + exit(); + } + + // test out of memory during sbrk + if(pid == 0){ + // allocate a lot of memory + a = sbrk(0); + sbrk(10*BIG); + int n = 0; + for (i = 0; i < 10*BIG; i += 4096) { + n += *(a+i); + } + printf(stdout, "allocate a lot of memory succeeded %d\n", n); + kill(ppid); + exit(); + } + wait(); + + // test reads from allocated memory + a = sbrk(4096); + fd = open("sbrk", O_CREATE|O_WRONLY); + unlink("sbrk"); + if(fd < 0) { + printf(stdout, "open sbrk failed\n"); + exit(); + } + if ((n = write(fd, a, 10)) < 0) { + printf(stdout, "write sbrk failed\n"); + exit(); + } + close(fd); + + // test writes to allocated memory + a = sbrk(4096); + if(pipe((int *) a) != 0){ + printf(1, "pipe() failed\n"); + exit(); + } + if(sbrk(0) > oldbrk) sbrk(-(sbrk(0) - oldbrk)); |