diff options
author | Robert Morris <[email protected]> | 2019-07-11 05:41:59 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2019-07-11 05:41:59 -0400 |
commit | 7797a384236cee31b924d27d8f814ef9543662cd (patch) | |
tree | c6222d9a40f9ce0bc9f589525d33e882f1670a6b /user | |
parent | 4bc900e78bdbff3ba22ccccd26833cf70fd300b1 (diff) | |
download | xv6-labs-7797a384236cee31b924d27d8f814ef9543662cd.tar.gz xv6-labs-7797a384236cee31b924d27d8f814ef9543662cd.tar.bz2 xv6-labs-7797a384236cee31b924d27d8f814ef9543662cd.zip |
another test, to help with locking exercises
Diffstat (limited to 'user')
-rw-r--r-- | user/usertests.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/user/usertests.c b/user/usertests.c index 9d46b1a..5cc5099 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -506,6 +506,44 @@ twochildren(void) printf(1, "twochildren ok\n"); } +// concurrent forks to try to expose locking bugs. +void +forkfork(void) +{ + int ppid = getpid(); + + printf(1, "forkfork test\n"); + + for(int i = 0; i < 2; i++){ + int pid = fork(); + if(pid < 0){ + printf(1, "fork failed"); + exit(); + } + if(pid == 0){ + for(int j = 0; j < 200; j++){ + int pid1 = fork(); + if(pid1 < 0){ + printf(1, "fork failed\n"); + kill(ppid); + exit(); + } + if(pid1 == 0){ + exit(); + } + wait(); + } + exit(); + } + } + + for(int i = 0; i < 2; i++){ + wait(); + } + + printf(1, "forkfork ok\n"); +} + void forkforkfork(void) { @@ -1858,6 +1896,7 @@ main(int argc, char *argv[]) reparent(); twochildren(); + forkfork(); forkforkfork(); argptest(); |