Add sun4i ram controller definitions
[AROS.git] / test / clib / waitpid.c
blob4dcc7dfa2c0c65ee2cf789599db35c2796d149d7
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <sys/wait.h>
9 #include <aros/debug.h>
10 #include <errno.h>
11 #include "test.h"
13 #define EXIT_STATUS 123
15 int main()
17 pid_t pid;
18 pid_t wait_pid;
19 int status;
20 char *argv[] = { "Delay", "50", NULL };
21 char *envp[] = { NULL };
23 wait_pid = waitpid(666, NULL, 0);
24 TEST(wait_pid == -1);
25 TEST(errno == ECHILD);
27 pid = vfork();
28 if((int) pid > 0)
30 printf("Created child with pid %d\n", (int) pid);
31 printf("Waiting for child with pid %d to exit.\n", (int) pid);
32 wait_pid = waitpid(pid, &status, 0);
33 TEST((wait_pid == pid));
34 printf("Child %d exited with exit status %d\n", (int) wait_pid, status);
35 TEST((status == EXIT_STATUS));
37 else if(pid == 0)
39 printf("Exiting with status %d\n", EXIT_STATUS);
40 _exit(EXIT_STATUS);
42 else
44 TEST(0);
47 pid = vfork();
48 if((int) pid > 0)
50 printf("Created child with pid %d\n", (int) pid);
51 printf("Waiting for any child to exit.\n");
52 wait_pid = waitpid(-1, &status, 0);
53 TEST((wait_pid == pid));
54 printf("Child %d exited with exit status %d\n", (int) wait_pid, status);
55 TEST((status == EXIT_STATUS));
57 else if(pid == 0)
59 printf("Exiting with status %d\n", EXIT_STATUS);
60 _exit(EXIT_STATUS);
62 else
64 TEST(0);
67 pid = vfork();
68 if((int) pid > 0)
70 printf("Created child with pid %d\n", (int) pid);
71 printf("Waiting for any child to exit without hang.\n");
72 wait_pid = waitpid(-1, &status, WNOHANG);
73 if(wait_pid == 0)
74 wait_pid = waitpid(-1, &status, 0);
75 TEST((wait_pid == pid));
76 printf("Child %d exited with exit status %d\n", (int) wait_pid, status);
77 TEST((status == EXIT_STATUS));
79 else if(pid == 0)
81 printf("Exiting with status %d\n", EXIT_STATUS);
82 _exit(EXIT_STATUS);
84 else
86 TEST(0);
89 pid = vfork();
90 if((int) pid > 0)
92 printf("Created child with pid %d\n", (int) pid);
93 printf("Waiting for any child to exit without hang.\n");
94 wait_pid = waitpid(-1, &status, WNOHANG);
95 TEST((wait_pid == 0));
96 printf("Child didn't exit yet\n");
97 wait_pid = waitpid(-1, &status, 0);
98 TEST((wait_pid == pid));
99 printf("Child %d exited with exit status %d\n", (int) wait_pid, status);
100 TEST((status == 0));
103 else if(pid == 0)
105 execve("C:Delay", argv, envp);
106 _exit(-1);
108 else
110 TEST(0);
113 return 0;
116 void cleanup()