Luca Dariz, le jeu. 28 déc. 2023 20:42:58 +0100, a ecrit:
> ---
> tests/test-machmsg.c | 390 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 390 insertions(+)
> create mode 100644 tests/test-machmsg.c
>
> diff --git a/tests/test-machmsg.c b/tests/test-machmsg.c
> new file mode 100644
> index 00000000..c262f5f4
> --- /dev/null
> +++ b/tests/test-machmsg.c
> @@ -0,0 +1,390 @@
> +
> +#include <mach/message.h>
> +#include <mach/mach_types.h>
> +#include <mach/vm_param.h>
> +
> +#include <syscalls.h>
> +#include <testlib.h>
> +
> +#include <mach.user.h>
> +#include <mach_port.user.h>
> +#include <mach_host.user.h>
> +
> +#define ECHO_MAX_BODY_LEN 256
> +
> +static uint32_t align(uint32_t val, size_t aln)
> +{
> + // we should check aln is a power of 2
> + aln--;
> + return (val + aln) & (~aln);
> +}
> +
> +#define align_inline(val, n) { val = align(val, n); }
Rather name it ALIGN_INLINE, so people don't mistake this for a
function (that doesn't have side-effects on its parameters).
> +void
> +run_test_simple(void *msg, mach_msg_size_t msglen, mach_msg_id_t msgid)
> +{
> + mach_msg_header_t *head = msg;
> + mach_port_t port, receive;
> + int err;
> +
> + err = syscall_mach_port_allocate (mach_task_self (),
> + MACH_PORT_RIGHT_RECEIVE, &port);
> + ASSERT_RET(err, "syscall_mach_port_allocate");
> +
> + err = syscall_mach_port_allocate (mach_task_self (),
> + MACH_PORT_RIGHT_RECEIVE, &receive);
> + ASSERT_RET(err, "syscall_mach_port_allocate 2");
> +
> + struct echo_params params;
> + params.rx_port = port;
> + params.rx_size = msglen;
> + params.rx_number = 1;
> + test_thread_start (mach_task_self (), echo_thread, ¶ms);
> + msleep(100);
Is this msleep really needed? If yes, this is racy. If it's just to make
the test a bit more stressful, then ok.
Samuel