diff options
author | Luca Dariz <luca@orpolo.org> | 2024-01-11 22:08:57 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2024-01-13 22:42:53 +0100 |
commit | e813641e2fef0fba5a2de9e5a44fd00ab95a86d0 (patch) | |
tree | c617b8841d38d7aa74f4fccd353b81bab83df11f /tests/include | |
parent | 7538b56278a95d87b9a4ddec01e5679376cc5b13 (diff) | |
download | gnumach-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')
-rw-r--r-- | tests/include/device/cons.h | 27 | ||||
l--------- | tests/include/kern/printf.h | 1 | ||||
-rw-r--r-- | tests/include/mach/mig_support.h | 71 | ||||
-rw-r--r-- | tests/include/syscalls.h | 83 | ||||
-rw-r--r-- | tests/include/testlib.h | 74 | ||||
l--------- | tests/include/util/atoi.h | 1 |
6 files changed, 257 insertions, 0 deletions
diff --git a/tests/include/device/cons.h b/tests/include/device/cons.h new file mode 100644 index 00000000..f4d8fe16 --- /dev/null +++ b/tests/include/device/cons.h @@ -0,0 +1,27 @@ +/* + * 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 CONS_H +#define CONS_H + +#include <mach/machine/vm_types.h> + +void cnputc(char c, vm_offset_t cookie); +static inline int cngetc() { return 0; } + +#endif /* CONS_H */ diff --git a/tests/include/kern/printf.h b/tests/include/kern/printf.h new file mode 120000 index 00000000..c61f3e0e --- /dev/null +++ b/tests/include/kern/printf.h @@ -0,0 +1 @@ +../../../kern/printf.h
\ No newline at end of file diff --git a/tests/include/mach/mig_support.h b/tests/include/mach/mig_support.h new file mode 100644 index 00000000..bf670083 --- /dev/null +++ b/tests/include/mach/mig_support.h @@ -0,0 +1,71 @@ +/* + * Mach Operating System + * Copyright (c) 1992 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ +/* + * Abstract: + * MIG helpers for gnumach tests, mainly copied from glibc + * + */ + +#ifndef _MACH_MIG_SUPPORT_H_ +#define _MACH_MIG_SUPPORT_H_ + +#include <string.h> + +#include <mach/message.h> +#include <mach/mach_types.h> + +#include <syscalls.h> + +static inline void mig_init(void *_first) +{} + +static inline void mig_allocate(vm_address_t *addr, vm_size_t size) +{ + if (syscall_vm_allocate(mach_task_self(), addr, size, 1) != KERN_SUCCESS) + *addr = 0; +} +static inline void mig_deallocate(vm_address_t addr, vm_size_t size) +{ + syscall_vm_deallocate (mach_task_self(), addr, size); +} +static inline void mig_dealloc_reply_port(mach_port_t port) +{} +static inline void mig_put_reply_port(mach_port_t port) +{} +static inline mach_port_t mig_get_reply_port(void) +{ + return mach_reply_port(); +} +static inline void mig_reply_setup(const mach_msg_header_t *_request, + mach_msg_header_t *reply) +{} + +static inline vm_size_t mig_strncpy (char *dst, const char *src, vm_size_t len) +{ + return dst - strncpy(dst, src, len); +} + +#endif /* not defined(_MACH_MIG_SUPPORT_H_) */ diff --git a/tests/include/syscalls.h b/tests/include/syscalls.h new file mode 100644 index 00000000..f958154c --- /dev/null +++ b/tests/include/syscalls.h @@ -0,0 +1,83 @@ +/* + * Mach Operating System + * Copyright (c) 1992 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ +/* + * Abstract: + * Syscall functions + * + */ + +#ifndef _SYSCALLS_ +#define _SYSCALLS_ + +#include <device/device_types.h> +#include <mach/message.h> + +// TODO: there is probably a better way to define these + +#define MACH_SYSCALL0(syscallid, retval, name) \ + retval name(void) __attribute__((naked)); + +#define MACH_SYSCALL1(syscallid, retval, name, arg1) \ + retval name(arg1 a1) __attribute__((naked)); + +#define MACH_SYSCALL2(syscallid, retval, name, arg1, arg2) \ + retval name(arg1 a1, arg2 a2) __attribute__((naked)); + +#define MACH_SYSCALL3(syscallid, retval, name, arg1, arg2, arg3) \ + retval name(arg1 a1, arg2 a2, arg3 a3) __attribute__((naked)); + +#define MACH_SYSCALL4(syscallid, retval, name, arg1, arg2, arg3, arg4) \ + retval name(arg1 a1, arg2 a2, arg3 a3, arg4 a4) __attribute__((naked)); + +#define MACH_SYSCALL6(syscallid, retval, name, arg1, arg2, arg3, arg4, arg5, arg6) \ + retval name(arg1 a1, arg2 a2, arg3 a3, arg4 a4, arg5 a5, arg6 a6) __attribute__((naked)); + +#define MACH_SYSCALL7(syscallid, retval, name, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ + retval name(arg1 a1, arg2 a2, arg3 a3, arg4 a4, arg5 a5, arg6 a6, arg7 a7) __attribute__((naked)); + +#define mach_msg mach_msg_trap + +MACH_SYSCALL0(26, mach_port_name_t, mach_reply_port) +MACH_SYSCALL0(27, mach_port_name_t, mach_thread_self) +MACH_SYSCALL0(28, mach_port_name_t, mach_task_self) +MACH_SYSCALL0(29, mach_port_name_t, mach_host_self) +MACH_SYSCALL1(30, void, mach_print, const char*) +MACH_SYSCALL0(31, kern_return_t, invalid_syscall) +MACH_SYSCALL4(65, kern_return_t, syscall_vm_allocate, mach_port_t, vm_offset_t*, vm_size_t, boolean_t) +MACH_SYSCALL3(66, kern_return_t, syscall_vm_deallocate, mach_port_t, vm_offset_t, vm_size_t) +MACH_SYSCALL3(72, kern_return_t, syscall_mach_port_allocate, mach_port_t, mach_port_right_t, mach_port_t*) +MACH_SYSCALL2(73, kern_return_t, syscall_mach_port_deallocate, mach_port_t, mach_port_t) + +/* + todo: swtch_pri swtch ... + these seem obsolete: evc_wait + evc_wait_clear syscall_device_writev_request + syscall_device_write_request ... + */ +MACH_SYSCALL6(40, io_return_t, syscall_device_write_request, mach_port_name_t, + mach_port_name_t, dev_mode_t, recnum_t, vm_offset_t, vm_size_t) + +#endif /* SYSCALLS */ 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 */ diff --git a/tests/include/util/atoi.h b/tests/include/util/atoi.h new file mode 120000 index 00000000..c32c2582 --- /dev/null +++ b/tests/include/util/atoi.h @@ -0,0 +1 @@ +../../../util/atoi.h
\ No newline at end of file |