diff options
Diffstat (limited to 'pintos-progos/tests/userprog/child-rox.c')
| -rw-r--r-- | pintos-progos/tests/userprog/child-rox.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/pintos-progos/tests/userprog/child-rox.c b/pintos-progos/tests/userprog/child-rox.c new file mode 100644 index 0000000..aba808b --- /dev/null +++ b/pintos-progos/tests/userprog/child-rox.c | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | /* Child process run by rox-child and rox-multichild tests. | ||
| 2 | Opens and tries to write to its own executable, verifying that | ||
| 3 | that is disallowed. | ||
| 4 | Then recursively executes itself to the depth indicated by the | ||
| 5 | first command-line argument. */ | ||
| 6 | |||
| 7 | #include <ctype.h> | ||
| 8 | #include <stdio.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <syscall.h> | ||
| 11 | #include "tests/lib.h" | ||
| 12 | |||
| 13 | const char *test_name = "child-rox"; | ||
| 14 | |||
| 15 | static void | ||
| 16 | try_write (void) | ||
| 17 | { | ||
| 18 | int handle; | ||
| 19 | char buffer[19]; | ||
| 20 | |||
| 21 | quiet = true; | ||
| 22 | CHECK ((handle = open ("child-rox")) > 1, "open \"child-rox\""); | ||
| 23 | quiet = false; | ||
| 24 | |||
| 25 | CHECK (write (handle, buffer, sizeof buffer) == 0, | ||
| 26 | "try to write \"child-rox\""); | ||
| 27 | |||
| 28 | close (handle); | ||
| 29 | } | ||
| 30 | |||
| 31 | int | ||
| 32 | main (int argc UNUSED, char *argv[]) | ||
| 33 | { | ||
| 34 | msg ("begin"); | ||
| 35 | try_write (); | ||
| 36 | |||
| 37 | if (!isdigit (*argv[1])) | ||
| 38 | fail ("bad command-line arguments"); | ||
| 39 | if (atoi (argv[1]) > 1) | ||
| 40 | { | ||
| 41 | char cmd[128]; | ||
| 42 | int child; | ||
| 43 | |||
| 44 | snprintf (cmd, sizeof cmd, "child-rox %d", atoi (argv[1]) - 1); | ||
| 45 | CHECK ((child = exec (cmd)) != -1, "exec \"%s\"", cmd); | ||
| 46 | quiet = true; | ||
| 47 | CHECK (wait (child) == 12, "wait for \"child-rox\""); | ||
| 48 | quiet = false; | ||
| 49 | } | ||
| 50 | |||
| 51 | try_write (); | ||
| 52 | msg ("end"); | ||
| 53 | |||
| 54 | return 12; | ||
| 55 | } | ||
