Browse Source

newlib: run first QA checks

Giacomo Tesio 7 years ago
parent
commit
c2982db8a2
6 changed files with 134 additions and 0 deletions
  1. 1 0
      build.json
  2. 1 0
      qa/build.json
  3. 37 0
      qa/lib/newlib/build.json
  4. 48 0
      qa/lib/newlib/fork0.c
  5. 7 0
      qa/lib/newlib/hello.c
  6. 40 0
      qa/lib/newlib/libposix_customization.c

+ 1 - 0
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/"
 		]
 	}

+ 1 - 0
qa/build.json

@@ -4,6 +4,7 @@
 			"kern/",
 			"lib/c/",
 			"lib/thread/",
+			"lib/newlib",
 			"gnu/gcc/"
 		]
 	}

+ 37 - 0
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"
+		]
+	}
+}

+ 48 - 0
qa/lib/newlib/fork0.c

@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+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;
+}
+

+ 7 - 0
qa/lib/newlib/hello.c

@@ -0,0 +1,7 @@
+/* let's start with a K&R classic */
+#include <stdio.h>
+int main()
+{
+   printf("hello, world\n");
+   return 0;
+}

+ 40 - 0
qa/lib/newlib/libposix_customization.c

@@ -0,0 +1,40 @@
+/*
+ * This file is part of Jehanne.
+ *
+ * Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+#include <u.h>
+#include <libc.h>
+#include <posix.h>
+
+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);
+}