summaryrefslogtreecommitdiffstats
path: root/src/tests/userprog/multi-recurse.c
blob: 7172ec3cb6ce83c7df082c483cbaa9545f57e8f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* Executes itself recursively to the depth indicated by the
   first command-line argument. */

#include <debug.h>
#include <stdlib.h>
#include <stdio.h>
#include <syscall.h>
#include "tests/lib.h"

const char *test_name = "multi-recurse";

int
main (int argc UNUSED, char *argv[]) 
{
  int n = atoi (argv[1]);

  msg ("begin %d", n);
  if (n != 0) 
    {
      char child_cmd[128];
      pid_t child_pid;
      int code;
      
      snprintf (child_cmd, sizeof child_cmd, "multi-recurse %d", n - 1);
      CHECK ((child_pid = exec (child_cmd)) != -1, "exec(\"%s\")", child_cmd);

      code = wait (child_pid);
      if (code != n - 1)
        fail ("wait(exec(\"%s\")) returned %d", child_cmd, code);
    }
  
  msg ("end %d", n);
  return n;
}