Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / userprog / child-rox.c
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <syscall.h>
5 #include "tests/lib.h"
6
7 const char *test_name = "child-rox";
8
9 static void
10 try_write (void) 
11 {
12   int handle;
13   char buffer[19];
14
15   quiet = true;
16   CHECK ((handle = open ("child-rox")) > 1, "open \"child-rox\"");
17   quiet = false;
18
19   CHECK (write (handle, buffer, sizeof buffer) == 0,
20          "try to write \"child-rox\"");
21   
22   close (handle);
23 }
24
25 int
26 main (int argc UNUSED, char *argv[]) 
27 {
28   msg ("begin");
29   try_write ();
30
31   if (!isdigit (*argv[1]))
32     fail ("bad command-line arguments");
33   if (atoi (argv[1]) > 1) 
34     {
35       char cmd[128];
36       int child;
37       
38       snprintf (cmd, sizeof cmd, "child-rox %d", atoi (argv[1]) - 1);
39       CHECK ((child = exec (cmd)) != -1, "exec \"%s\"", cmd);
40       quiet = true;
41       CHECK (wait (child) == 12, "wait for \"child-rox\"");
42       quiet = false;
43     }
44
45   try_write ();
46   msg ("end");
47
48   return 12;
49 }