From 384d09cd3d2e62bae19b59b615bc57b7a23d0b0a Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Fri, 5 May 2023 17:04:15 +0200 Subject: test: fix operations Adjust the tests after the refactoring and to use struct gluten_offset --- tests/unit/testutil.h | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'tests/unit/testutil.h') diff --git a/tests/unit/testutil.h b/tests/unit/testutil.h index d6a1c46..45fe08f 100644 --- a/tests/unit/testutil.h +++ b/tests/unit/testutil.h @@ -8,10 +8,44 @@ #include #include -#include "filter.h" +#include "cooker/filter.h" + +#ifndef SEITAN_TEST +#define SEITAN_TEST +#endif +#include "common/gluten.h" #define STACK_SIZE (1024 * 1024 / 8) +static inline void *test_gluten_write_ptr(struct gluten *g, + const struct gluten_offset x) +{ + switch (x.type) { + case OFFSET_DATA: + return (char *)g->data + x.offset; + case OFFSET_RO_DATA: + return (char *)g->ro_data + x.offset; + case OFFSET_INSTRUCTION: + return (struct op *)(g->inst) + x.offset; + default: + return NULL; + } +} + +#define ck_write_gluten(gluten, value, ref) \ + do { \ + void *p = test_gluten_write_ptr(&gluten, value); \ + ck_assert_ptr_nonnull(p); \ + memcpy(p, &ref, sizeof(ref)); \ + } while (0) + +#define ck_read_gluten(gluten, value, ref) \ + do { \ + void *p = test_gluten_write_ptr(&gluten, value); \ + ck_assert_ptr_nonnull(p); \ + memcpy(&ref, p, sizeof(ref)); \ + } while (0) + struct args_target { long ret; int err; @@ -32,7 +66,7 @@ extern int pipefd[2]; extern pid_t pid; extern char path[PATH_MAX]; -extern uint16_t tmp_data[TMP_DATA_SIZE]; +extern struct gluten gluten; int target(); pid_t do_clone(int (*fn)(void *), void *arg); @@ -48,5 +82,5 @@ int install_notification_filter(struct args_target *at); void continue_target(); void mock_syscall_target(); void set_args_no_check(struct args_target *at); - +void check_target_result_nonegative(); #endif /* TESTUTIL_H */ -- cgit v1.2.3