11int ipc_test_messages(
void);
12int ipc_test_semaphores(
void);
13int ipc_test_mqueues(
void);
14int ipc_test_shared_memory(
void);
15int ipc_test_shared_memory_exec(
int argc,
char** argv);
16int ipc_test_mqueue_exec(
int argc,
char** argv);
18static int run(
const char* name,
int (*test)(
void)) {
19 printf(
"IPC-CONTRACT: BEGIN %s\n", name);
31 _exit(result ? 1 : 0);
33 struct timespec started, now;
34 clock_gettime(CLOCK_MONOTONIC, &started);
37 pid_t result = waitpid(child, &status, WNOHANG);
38 if (result == child) {
39 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
40 printf(
"IPC-CONTRACT: PASS %s\n", name);
43 printf(
"IPC-CONTRACT: FAIL %s status=%d\n", name, status);
46 if (result < 0 && errno != EINTR) {
51 clock_gettime(CLOCK_MONOTONIC, &now);
52 if (now.tv_sec - started.tv_sec > 100) {
54 while (waitpid(child, &status, 0) < 0 && errno == EINTR) {
56 printf(
"IPC-CONTRACT: FAIL %s timeout\n", name);
59 struct timespec pause = {0, 10000000};
60 nanosleep(&pause, NULL);
64int main(
int argc,
char** argv) {
65 if (argc > 1 && !strcmp(argv[1],
"shm-exec")) {
66 return ipc_test_shared_memory_exec(argc, argv);
68 if (argc > 1 && !strcmp(argv[1],
"mq-exec")) {
69 return ipc_test_mqueue_exec(argc, argv);
74 } suites[] = {{
"messages", ipc_test_messages},
75 {
"semaphores", ipc_test_semaphores},
76 {
"mqueues", ipc_test_mqueues},
77 {
"shared-memory", ipc_test_shared_memory}};
79 for (
unsigned i = 0; i <
sizeof suites /
sizeof suites[0]; ++i) {
80 if (argc > 1 && strcmp(argv[1], suites[i].name)) {
84 if (run(suites[i].name, suites[i].test)) {
89 fprintf(stderr,
"Unknown IPC contract suite\n");
92 puts(
"IPC-CONTRACT: END PASS");