d4d50a64a7370ac9bd4ed0e0c3fbf3a931049e16
[pintos-anon] / src / tests / userprog / no-vm / multi-oom.c
1 /* Recursively executes itself until the child fails to execute.
2    We expect that at least 15 copies can run.
3    We also require that, if a process doesn't actually get to
4    start, exec() must return -1, not a valid PID. */
5
6 #include <debug.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <syscall.h>
10 #include "tests/lib.h"
11
12 const char *test_name = "multi-oom";
13
14 int
15 main (int argc UNUSED, char *argv[]) 
16 {
17   char child_cmd[128];
18   pid_t child_pid;
19   int n;
20
21   n = atoi (argv[1]);
22   if (n == 0)
23     n = atoi (argv[0]);
24     
25   msg ("begin %d", n);
26
27   snprintf (child_cmd, sizeof child_cmd, "multi-oom %d", n + 1);
28   child_pid = exec (child_cmd);
29   if (child_pid != -1) 
30     {
31       int code = wait (child_pid);
32       if (code != n + 1)
33         fail ("wait(exec(\"%s\")) returned %d", child_cmd, code);
34     }
35   else if (n < 15)
36     fail ("exec(\"%s\") returned -1 after only %d recursions", child_cmd, n);
37   
38   msg ("end %d", n);
39   return n;
40 }