tests added
[swifty.git] / src / kernel / test / test_common.c
1 /*
2  * Test suite functions.
3  *
4  * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include <sys/types.h>
12 #include <unistd.h>
13 #include <sys/wait.h>
14
15 #include "util.h"
16 #include "test.h"
17
18 /* Run test function f in another process. */
19 void run_as_child_process(test_fn f)
20 {
21         pid_t pid;
22         int status;
23         int rc;
24
25         pid = fork();
26         switch (pid) {
27         case -1:        /* error */
28                 ERR("fork");
29                 exit(EXIT_FAILURE);
30         
31         case 0:         /* child process */
32                 /* Run test function. */
33                 f();
34                 exit(EXIT_SUCCESS);
35                 break;
36         
37         default:        /* parent process */
38                 break;
39         }
40
41         /* Wait for child process. */
42         rc = waitpid(pid, &status, 0);
43         DIE(rc < 0, "waitpid");
44 }