7172ec3cb6ce83c7df082c483cbaa9545f57e8f9
[pintos-anon] / src / tests / userprog / multi-recurse.c
1 /* Executes itself recursively to the depth indicated by the
2    first command-line argument. */
3
4 #include <debug.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <syscall.h>
8 #include "tests/lib.h"
9
10 const char *test_name = "multi-recurse";
11
12 int
13 main (int argc UNUSED, char *argv[]) 
14 {
15   int n = atoi (argv[1]);
16
17   msg ("begin %d", n);
18   if (n != 0) 
19     {
20       char child_cmd[128];
21       pid_t child_pid;
22       int code;
23       
24       snprintf (child_cmd, sizeof child_cmd, "multi-recurse %d", n - 1);
25       CHECK ((child_pid = exec (child_cmd)) != -1, "exec(\"%s\")", child_cmd);
26
27       code = wait (child_pid);
28       if (code != n - 1)
29         fail ("wait(exec(\"%s\")) returned %d", child_cmd, code);
30     }
31   
32   msg ("end %d", n);
33   return n;
34 }