From 559e5429ed8dfd548157d9fb6f9dfb45c62d7ebf Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Mon, 29 May 2017 01:42:08 +0200 Subject: [PATCH] newlib: tests for sigchld --- qa/lib/newlib/200-signals.c | 57 +++++++++++++++++++++----------- qa/lib/newlib/build.json | 1 + qa/lib/newlib/libposix_sigchld.c | 45 +++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 qa/lib/newlib/libposix_sigchld.c diff --git a/qa/lib/newlib/200-signals.c b/qa/lib/newlib/200-signals.c index 6b31d87..5b817be 100644 --- a/qa/lib/newlib/200-signals.c +++ b/qa/lib/newlib/200-signals.c @@ -4,13 +4,40 @@ #include #include -void sighup(); /* routines child will call upon sigtrap */ -void sigint(); -void sigquit(); +int child, cstatus; + +void sighup() { + signal(SIGHUP,sighup); /* reset signal */ + printf("CHILD: I have received a SIGHUP\n"); +} + +void sigint() { + signal(SIGINT,sigint); /* reset signal */ + printf("CHILD: I have received a SIGINT\n"); +} + +void sigquit() { + printf("My DADDY has Killed me!!!\n"); + exit(0); +} + +void sigchld() { + printf("PARENT: got SIGCHLD\n"); +#ifdef WITH_SIGCHLD + child = wait(&cstatus); + if(cstatus == 0) + exit(0); + else + { + printf("PARENT: child exited with status %d\n", cstatus); + exit(1); + } +#endif +} int main() { - int pid, p[2], child, cstatus; + int pid, p[2]; char dummy[1]; /* get child process */ @@ -37,6 +64,7 @@ main() { } else /* parent */ { + signal(SIGCHLD,sigchld); close(p[1]); if(read(p[0], &dummy, 1) > 0){ printf("sync read received data"); @@ -51,6 +79,11 @@ main() { sleep(3); /* pause for 3 secs */ printf("\nPARENT: sending SIGQUIT\n\n"); kill(pid,SIGQUIT); + +#ifdef WITH_SIGCHLD + sleep(10000); + exit(1); +#else child = wait(&cstatus); if(child == pid && cstatus == 0) exit(0); @@ -59,20 +92,6 @@ main() { printf("PARENT: child exited with status %d\n", cstatus); exit(1); } +#endif } } - -void sighup() { - signal(SIGHUP,sighup); /* reset signal */ - printf("CHILD: I have received a SIGHUP\n"); -} - -void sigint() { - signal(SIGINT,sigint); /* reset signal */ - printf("CHILD: I have received a SIGINT\n"); -} - -void sigquit() { - printf("My DADDY has Killed me!!!\n"); - exit(0); -} diff --git a/qa/lib/newlib/build.json b/qa/lib/newlib/build.json index 6fa3eca..ef652bd 100644 --- a/qa/lib/newlib/build.json +++ b/qa/lib/newlib/build.json @@ -54,6 +54,7 @@ "/arch/$ARCH/lib/newlib/libg.a", "-I", "/sys/posix/newlib", "-O2", + "-DWITH_SIGCHLD", "-std=gnu11" ], "Oflags": [ diff --git a/qa/lib/newlib/libposix_sigchld.c b/qa/lib/newlib/libposix_sigchld.c new file mode 100644 index 0000000..2380bcd --- /dev/null +++ b/qa/lib/newlib/libposix_sigchld.c @@ -0,0 +1,45 @@ +/* + * This file is part of Jehanne. + * + * Copyright (C) 2017 Giacomo Tesio + * + * This is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3 of the License. + * + * Jehanne is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Jehanne. If not, see . + */ +#include +#include +#include + +static char* +qa_exit_translator(int status) +{ + if(jehanne_getpid() == jehanne_getmainpid()){ + /* the QA test may fork, but only the main process + * should return PASS/FAIL + */ + if(status == 0){ + jehanne_print("PASS\n"); + return "PASS"; + } else { + jehanne_print("FAIL: " __POSIX_EXIT_PREFIX "%d\n", status); + return "FAIL"; + } + } + return nil; +} + +void +__application_newlib_init(void) +{ + libposix_translate_exit_status(qa_exit_translator); + libposix_emulate_SIGCHLD(); +}