From c2982db8a2c57a3250c129c28bb395715521ec4e Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Sat, 22 Apr 2017 00:46:55 +0200 Subject: [PATCH] newlib: run first QA checks --- build.json | 1 + qa/build.json | 1 + qa/lib/newlib/build.json | 37 ++++++++++++++++++++ qa/lib/newlib/fork0.c | 48 ++++++++++++++++++++++++++ qa/lib/newlib/hello.c | 7 ++++ qa/lib/newlib/libposix_customization.c | 40 +++++++++++++++++++++ 6 files changed, 134 insertions(+) create mode 100644 qa/lib/newlib/build.json create mode 100644 qa/lib/newlib/fork0.c create mode 100644 qa/lib/newlib/hello.c create mode 100644 qa/lib/newlib/libposix_customization.c diff --git a/build.json b/build.json index 85b2402..7e3d802 100644 --- a/build.json +++ b/build.json @@ -6,6 +6,7 @@ "/sys/src/cmd/cmds.json", "/sys/src/kern/amd64/workhorse.json", "/sys/src/kern/amd64/", + "/hacking/cross/pkgs/", "qa/" ] } diff --git a/qa/build.json b/qa/build.json index fdc8adb..71c3561 100644 --- a/qa/build.json +++ b/qa/build.json @@ -4,6 +4,7 @@ "kern/", "lib/c/", "lib/thread/", + "lib/newlib", "gnu/gcc/" ] } diff --git a/qa/lib/newlib/build.json b/qa/lib/newlib/build.json new file mode 100644 index 0000000..9aded1e --- /dev/null +++ b/qa/lib/newlib/build.json @@ -0,0 +1,37 @@ +{ + "SimplePOSIXTests": { + "Include": [ + "/arch/$ARCH/include/cflags.json" + ], + "Cflags": [ + "-fstack-check", + "-fstack-protector-all", + "/arch/$ARCH/lib/newlib/libc.a", + "/arch/$ARCH/lib/newlib/libm.a", + "/arch/$ARCH/lib/newlib/libg.a", + "-I", "/sys/posix/newlib", + "-O2", + "-std=gnu11" + ], + "Oflags": [ + "-static", + "-lposix", + "-lc" + ], + "Install": "/arch/$ARCH/qa/lib/newlib", + "Post": [ + "rm -f *.o", + "#cp *.rc $JEHANNE/arch/$ARCH/qa/lib/newlib/" + ], + "Pre": [ + "rm -f *.tag.*" + ], + "SourceFiles": [ + "libposix_customization.c" + ], + "SourceFilesCmd": [ + "hello.c", + "fork0.c" + ] + } +} diff --git a/qa/lib/newlib/fork0.c b/qa/lib/newlib/fork0.c new file mode 100644 index 0000000..518c4a7 --- /dev/null +++ b/qa/lib/newlib/fork0.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + int counter = 0; + int status; + + printf("parent: pid = %d; ppid = %d\n", getpid(), getppid()); + + pid_t pid = fork(); + + if (pid == 0) + { + // child process + printf("child: pid = %d; ppid = %d\n", getpid(), getppid()); + int i = 0; + for (; i < 5; ++i) + { + printf("child: counter=%d\n", ++counter); + } + } + else if (pid > 0) + { + // parent process + int j = 0; + for (; j < 5; ++j) + { + printf("parent: counter=%d\n", ++counter); + } + wait(&status); + if(status != 0){ + printf("parent: child exited with status %d\n", status); + return 2; + } + } + else + { + // fork failed + printf("parent: fork() failed!\n"); + return 1; + } + + return 0; +} + diff --git a/qa/lib/newlib/hello.c b/qa/lib/newlib/hello.c new file mode 100644 index 0000000..d262b63 --- /dev/null +++ b/qa/lib/newlib/hello.c @@ -0,0 +1,7 @@ +/* let's start with a K&R classic */ +#include +int main() +{ + printf("hello, world\n"); + return 0; +} diff --git a/qa/lib/newlib/libposix_customization.c b/qa/lib/newlib/libposix_customization.c new file mode 100644 index 0000000..fd82b0a --- /dev/null +++ b/qa/lib/newlib/libposix_customization.c @@ -0,0 +1,40 @@ +/* + * 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(status == 0){ + if(jehanne_getpid() == jehanne_getmainpid()){ + jehanne_print("PASS\n"); + return "PASS"; + } + return nil; + } + jehanne_print("FAIL: " __POSIX_EXIT_PREFIX "%d\n", status); + return "FAIL"; +} + +void +__application_newlib_init(void) +{ + libposix_translate_exit_status(qa_exit_translator); +}