aboutsummaryrefslogtreecommitdiff
path: root/tests/include/testlib.h
diff options
context:
space:
mode:
authorLuca Dariz <luca@orpolo.org>2024-01-11 22:08:57 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2024-01-13 22:42:53 +0100
commite813641e2fef0fba5a2de9e5a44fd00ab95a86d0 (patch)
treec617b8841d38d7aa74f4fccd353b81bab83df11f /tests/include/testlib.h
parent7538b56278a95d87b9a4ddec01e5679376cc5b13 (diff)
downloadgnumach-e813641e2fef0fba5a2de9e5a44fd00ab95a86d0.tar.gz
gnumach-e813641e2fef0fba5a2de9e5a44fd00ab95a86d0.tar.bz2
gnumach-e813641e2fef0fba5a2de9e5a44fd00ab95a86d0.zip
add basic user-space tests with qemu
* configure.ac: move test fragment to have USER32 * tests/Makefrag.am: add user tests * tests/README: add basic info on how to run and debug user tests * tests/configfrag.ac: allow the test compiler/flags to be autoconfigured or customized * tests/grub.cfg.single.template: add minimal grub config to boot a module * tests/include/device/cons.h: add a simplified version of device/cons.h usable for tests * tests/include/kern/printf.h: symlink to kern/printf.h * tests/include/mach/mig_support.h: add basic version for user-space tests * tests/include/syscalls.h: add prototypes for syscalls used in tests. * tests/include/testlib.h: add definitions for common test functionalities * tests/include/util/atoi.h: symlink to util/atoi.h * tests/run-qemu.sh.template: add a simple qemu test runner * tests/start.S: add arch-specific entry point * tests/syscalls.S: generate syscalls entry points * tests/test-hello.c: add basic smoke test * tests/testlib.c: add the minimal functionality to run a user-space executable and reboot the system, and some test helpers. * tests/user-qemu.mk: add rules to build simple user-space test modules, including generating mig stubs. The tests reuse some kernel code (like printf(), mach_atoi(), mem*(), str*() functions) so we can use the freestanding environment and not depend on glibc. Message-ID: <20240111210907.419689-1-luca@orpolo.org>
Diffstat (limited to 'tests/include/testlib.h')
-rw-r--r--tests/include/testlib.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/include/testlib.h b/tests/include/testlib.h
new file mode 100644
index 00000000..e492f2f6
--- /dev/null
+++ b/tests/include/testlib.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2024 Free Software Foundation
+ *
+ * This program is free software ; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation ; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License
+ * along with the program ; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef TESTLIB_H
+#define TESTLIB_H
+
+// in freestanding we can only use a few standard headers
+// float.h iso646.h limits.h stdarg.h stdbool.h stddef.h stdint.h
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stdbool.h>
+
+#include <string.h> // we shouldn't include this from gcc, but it seems to be ok
+
+#include <mach/mach_types.h>
+#include <kern/printf.h>
+#include <util/atoi.h>
+#include <syscalls.h>
+
+#define ASSERT(cond, msg) do { \
+ if (!(cond)) \
+ { \
+ printf("%s: " #cond " failed: %s\n", \
+ TEST_FAILURE_MARKER, (msg)); \
+ halt(); \
+ } \
+ } while (0)
+
+#define ASSERT_RET(ret, msg) do { \
+ if ((ret) != KERN_SUCCESS) \
+ { \
+ printf("%s %s (0x%x): %s\n", \
+ TEST_FAILURE_MARKER, e2s((ret)), (ret), (msg)); \
+ halt(); \
+ } \
+ } while (0)
+
+#define FAILURE(msg) do { \
+ printf("%s: %s\n", TEST_FAILURE_MARKER, (msg)); \
+ halt(); \
+ } while (0)
+
+
+extern const char* TEST_SUCCESS_MARKER;
+extern const char* TEST_FAILURE_MARKER;
+
+const char* e2s(int err);
+const char* e2s_gnumach(int err);
+void halt();
+int msleep(uint32_t timeout);
+
+mach_port_t host_priv(void);
+mach_port_t device_priv(void);
+
+int main(int argc, char *argv[], int envc, char *envp[]);
+
+#endif /* TESTLIB_H */