diff options
author | Alice Frosi <afrosi@redhat.com> | 2023-05-05 17:04:15 +0200 |
---|---|---|
committer | Alice Frosi <afrosi@redhat.com> | 2023-05-08 14:47:22 +0200 |
commit | 384d09cd3d2e62bae19b59b615bc57b7a23d0b0a (patch) | |
tree | 3b6ba748a07d8e7e1b687314517e3379c59a69e3 /tests | |
parent | c29157e78df7fa335c56d0d7f2cca7dc50bfffd6 (diff) | |
download | seitan-384d09cd3d2e62bae19b59b615bc57b7a23d0b0a.tar seitan-384d09cd3d2e62bae19b59b615bc57b7a23d0b0a.tar.gz seitan-384d09cd3d2e62bae19b59b615bc57b7a23d0b0a.tar.bz2 seitan-384d09cd3d2e62bae19b59b615bc57b7a23d0b0a.tar.lz seitan-384d09cd3d2e62bae19b59b615bc57b7a23d0b0a.tar.xz seitan-384d09cd3d2e62bae19b59b615bc57b7a23d0b0a.tar.zst seitan-384d09cd3d2e62bae19b59b615bc57b7a23d0b0a.zip |
test: fix operations
Adjust the tests after the refactoring and to use struct gluten_offset
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/Makefile | 9 | ||||
-rw-r--r-- | tests/unit/test_op_call.c | 4 | ||||
-rw-r--r-- | tests/unit/test_operations.c | 449 | ||||
-rw-r--r-- | tests/unit/testutil.h | 40 | ||||
-rw-r--r-- | tests/unit/util.c | 16 |
5 files changed, 244 insertions, 274 deletions
diff --git a/tests/unit/Makefile b/tests/unit/Makefile index ef702dc..202e198 100644 --- a/tests/unit/Makefile +++ b/tests/unit/Makefile @@ -2,6 +2,7 @@ # Copyright 2023 Red Hat GmbH # Author: Alice Frosi <afrosi@redhat.com> +MAIN_DIR := ../../ COMMON_DIR := ../../common OP_DIR := ../../ COOKER_DIR := ../../cooker @@ -19,8 +20,8 @@ HEADERS_OP_CALL := $(COMMON_DIR)/gluten.h $(OP_DIR)/operations.h SRCS_OP_CALL := $(OP_DIR)/operations.c HEADERS_OP := $(COMMON_DIR)/gluten.h $(OP_DIR)/operations.h \ - $(COMMON_DIR)/common.h testutil.h -SRCS_OP := $(COMMON_DIR)/common.c $(OP_DIR)/operations.c util.c + $(COMMON_DIR)/common.h testutil.h $(COMMON_DIR)/util.h +SRCS_OP := $(COMMON_DIR)/common.c $(OP_DIR)/operations.c util.c $(COMMON_DIR)/util.c TARGET := $(shell $(CC) -dumpmachine) TARGET_ARCH := $(shell echo $(TARGET) | cut -f1 -d- | tr [A-Z] [a-z]) @@ -32,9 +33,9 @@ AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/PPC64/PPC/') AUDIT_ARCH := $(shell echo $(AUDIT_ARCH) | sed 's/PPCLE/PPC64LE/') CFLAGS += -Wall -Wextra -pedantic -CFLAGS += -I$(COMMON_DIR) -I$(OP_DIR) -I$(COOKER_DIR) -I$(DBG_DIR) +CFLAGS += -I$(MAIN_DIR) -I$(OP_DIR) -I$(DBG_DIR) CFLAGS += -lcheck -CFLAGS += -DSEITAN_AUDIT_ARCH=AUDIT_ARCH_$(AUDIT_ARCH) -DTMP_DATA_SIZE=1000000 +CFLAGS += -DSEITAN_AUDIT_ARCH=AUDIT_ARCH_$(AUDIT_ARCH) test: test-filter test-operations test-op-call diff --git a/tests/unit/test_op_call.c b/tests/unit/test_op_call.c index 9a89599..7f4b367 100644 --- a/tests/unit/test_op_call.c +++ b/tests/unit/test_op_call.c @@ -17,7 +17,7 @@ #include <check.h> -#include "gluten.h" +#include "common/gluten.h" #include "operations.h" struct args_write_file { @@ -122,7 +122,7 @@ START_TEST(test_with_open_read_ns) call.context.ns[i].type = NS_NONE; call.context.ns[NS_MOUNT].type = NS_SPEC_PID; pid = create_func_ns(write_file_clone, (void *)&args, call.context.ns); - call.context.ns[NS_MOUNT].pid = pid; + call.context.ns[NS_MOUNT].id.pid = pid; call.nr = SYS_open; call.args[0] = (void *)&test_file; call.args[1] = (void *)(long)flags; diff --git a/tests/unit/test_operations.c b/tests/unit/test_operations.c index e50a256..9c3cf94 100644 --- a/tests/unit/test_operations.c +++ b/tests/unit/test_operations.c @@ -25,9 +25,8 @@ #include <check.h> -#include "gluten.h" #include "operations.h" -#include "common.h" +#include "common/common.h" #include "testutil.h" #define MAX_TEST_PATH 250 @@ -83,237 +82,172 @@ void setup_target_connect() setup(); } -START_TEST(test_act_continue) +START_TEST(test_op_continue) { - struct op operations[] = { - { .type = OP_CONT }, - }; - int ret = do_operations(NULL, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); + ck_assert_msg(op_continue(&req, notifyfd, NULL, NULL) == 0, + strerror(errno)); ck_assert_int_eq(at->err, 0); } END_TEST -START_TEST(test_act_block) +START_TEST(test_op_block) { - struct op operations[] = { - { - .type = OP_BLOCK, - .block = { .error = -1 }, - }, - }; - int ret = do_operations(NULL, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); + struct op_block op = { -1 }; + + ck_assert_msg(op_block(&req, notifyfd, NULL, &op) == 0, + strerror(errno)); /* * The tests use getpid that returns the error with ret and it is always * successful */ - check_target_result(operations[0].block.error, 1, false); + check_target_result(op.error, 1, false); } END_TEST -START_TEST(test_act_return) +static void test_op_return(enum gluten_offset_type type, uint16_t offset) { - struct op operations[] = { - { - .type = OP_RETURN, - .ret = { .type = IMMEDIATE, .value = 1 }, - }, - }; - int ret = do_operations(NULL, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); - check_target_result(1, 0, false); + struct op_return op = { { type, offset } }; + int64_t v = 2; + + ck_write_gluten(gluten, op.val, v); + ck_assert_msg(op_return(&req, notifyfd, &gluten, &op) == 0, + strerror(errno)); + check_target_result(v, 0, false); } -END_TEST -START_TEST(test_act_return_ref) +START_TEST(test_op_return_ro_data) { - int64_t v = 2; - uint16_t offset = 4; - struct op operations[] = { - { - .type = OP_RETURN, - .ret = { .type = REFERENCE, .value_off = offset }, - }, - }; - memcpy((uint16_t *)&tmp_data + offset, &v, sizeof(v)); + test_op_return(OFFSET_RO_DATA, 4); +} +END_TEST - int ret = do_operations(&tmp_data, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); - check_target_result(v, 0, false); +START_TEST(test_op_return_data) +{ + test_op_return(OFFSET_DATA, 4); } END_TEST -START_TEST(test_act_call) +START_TEST(test_op_call) { struct op operations[] = { - { - .type = OP_CALL, - .call = { .nr = __NR_getppid, .has_ret = false }, - }, - { .type = OP_CONT }, + { OP_CALL, { .call = { __NR_getppid, false } } }, + { OP_CONT, { { 0 } } }, + { OP_END, { { 0 } } }, + { 0 }, }; - int ret = do_operations(NULL, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); + + eval(&gluten, operations, &req, notifyfd); check_target_result(1, 0, true); } END_TEST -START_TEST(test_act_call_ret) +START_TEST(test_op_call_ret) { + long r; struct op operations[] = { - { - .type = OP_CALL, - .call = { .nr = __NR_getppid, - .has_ret = true, - .ret_off = 2 }, - }, - { .type = OP_CONT }, + { OP_CALL, + { .call = { __NR_getppid, true, + .ret = { .type = OFFSET_DATA, .offset = 0 } } } }, + { OP_CONT, { { 0 } } }, + { OP_END, { { 0 } } }, + { 0 }, }; - int ret = do_operations(&tmp_data, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - long r; - ck_assert_msg(ret == 0, strerror(errno)); + + eval(&gluten, operations, &req, notifyfd); check_target_result(1, 0, true); - memcpy(&r, &tmp_data[2], sizeof(r)); - ck_assert_int_eq(r, getpid()); + ck_read_gluten(gluten, operations[0].op.call.ret, r); + ck_assert(r == getpid()); } END_TEST -static void test_inject(struct op operations[], int n, bool reference) +static void test_inject(enum gluten_offset_type type, bool atomic) { - uint16_t new_off = 2, old_off = 4; - int fd_inj; + struct op_inject op = { { type, 0 }, { type, 4 } }; int test_fd = 3; - int ret; + int fd_inj; fd_inj = create_test_fd(); ck_assert_int_ge(fd_inj, 0); - if (reference) { - memcpy((uint16_t *)&tmp_data + new_off, &fd_inj, - sizeof(fd_inj)); - memcpy((uint16_t *)&tmp_data + old_off, &test_fd, - sizeof(test_fd)); - - operations[0].inj.newfd.fd_off = new_off; - operations[0].inj.newfd.type = REFERENCE; - operations[0].inj.oldfd.fd_off = old_off; - operations[0].inj.oldfd.type = REFERENCE; - } else { - operations[0].inj.newfd.fd = fd_inj; - operations[0].inj.newfd.type = IMMEDIATE; - operations[0].inj.oldfd.fd = test_fd; - operations[0].inj.oldfd.type = IMMEDIATE; - } - - ret = do_operations(&tmp_data, operations, &req, n, notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); + ck_write_gluten(gluten, op.old_fd, test_fd); + ck_write_gluten(gluten, op.new_fd, fd_inj); + + if (atomic) + op_inject(&req, notifyfd, &gluten, &op); + else + op_inject_a(&req, notifyfd, &gluten, &op); check_target_fd(pid, test_fd); } -START_TEST(test_act_inject_a) +START_TEST(test_op_inject_a) { - struct op operations[] = { { .type = OP_INJECT_A } }; - test_inject(operations, sizeof(operations) / sizeof(operations[0]), false); + test_inject(OFFSET_RO_DATA, true); } END_TEST -START_TEST(test_act_inject_a_ref) +START_TEST(test_op_inject_a_ref) { - struct op operations[] = { { .type = OP_INJECT_A } }; - test_inject(operations, sizeof(operations) / sizeof(operations[0]), true); + test_inject(OFFSET_DATA, true); } END_TEST -START_TEST(test_act_inject) +START_TEST(test_op_inject) { - struct op operations[] = { { .type = OP_INJECT } }; - test_inject(operations, sizeof(operations) / sizeof(operations[0]), false); + test_inject(OFFSET_RO_DATA, false); } END_TEST -START_TEST(test_act_inject_ref) +START_TEST(test_op_inject_ref) { - struct op operations[] = { { .type = OP_INJECT } }; - test_inject(operations, sizeof(operations) / sizeof(operations[0]), true); + test_inject(OFFSET_DATA, false); } END_TEST -START_TEST(test_op_copy) +START_TEST(test_op_load) { struct op operations[] = { - { .type = OP_COPY_ARGS }, - { - .type = OP_RETURN, - .ret = { .type = IMMEDIATE, .value = 0 }, - }, + { OP_LOAD, + { .load = { { OFFSET_SECCOMP_DATA, 1 }, + { OFFSET_DATA, 0 }, + sizeof(struct sockaddr_un) } } }, + { OP_RETURN, + { .ret = { { OFFSET_DATA, sizeof(struct sockaddr_un) } } } }, + { OP_END, { { 0 } } }, + { 0 }, }; - struct op_copy_args *o = &operations[0].copy; - struct sockaddr_un *addr; - socklen_t *len, expect; - int ret; - - o->args[0] = (struct copy_arg){ .args_off = 0, - .type = IMMEDIATE, - .size = sizeof(int) }; - o->args[1] = - (struct copy_arg){ .args_off = sizeof(int) / sizeof(uint16_t), - .type = REFERENCE, - .size = sizeof(struct sockaddr_un) }; - o->args[2] = (struct copy_arg){ .args_off = o->args[1].args_off + - sizeof(struct sockaddr_un) / - sizeof(uint16_t), - .type = IMMEDIATE, - .size = sizeof(socklen_t) }; - ret = do_operations(&tmp_data, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); - check_target_result(0, 0, false); - addr = (struct sockaddr_un *)(tmp_data + o->args[1].args_off); - ck_assert_str_eq(addr->sun_path, "/tmp/test.sock"); - ck_assert(addr->sun_family == AF_UNIX); - expect = sizeof(addr->sun_path); - len = (socklen_t *)(tmp_data + o->args[2].args_off); - ck_assert_msg(*len == expect, "expect len %x to be equal to %x", *len, - expect); + struct sockaddr_un addr; + int v = 2; + + ck_write_gluten(gluten, operations[1].op.ret.val, v); + eval(&gluten, operations, &req, notifyfd); + check_target_result(v, 0, false); + + ck_read_gluten(gluten, operations[0].op.load.dst, addr); + ck_assert_str_eq(addr.sun_path, "/tmp/test.sock"); + ck_assert(addr.sun_family == AF_UNIX); } END_TEST static void test_op_cmp_int(int a, int b, enum op_cmp_type cmp) { struct op operations[] = { - { .type = OP_CMP, - .cmp = { .s1_off = 0, - .s2_off = sizeof(a) / sizeof(uint16_t), - .size = sizeof(a), - .cmp = cmp, - .jmp = 2 } }, - { .type = OP_CONT }, - { .type = OP_END }, - { .type = OP_BLOCK, .block = { .error = -1 } }, + { OP_CMP, + { .cmp = { { OFFSET_DATA, 0 }, + { OFFSET_DATA, 10 }, + sizeof(int), + cmp, + 3 } } }, + { OP_BLOCK, { .block = { -1 } } }, + { OP_END, { { 0 } } }, + { OP_CONT, { { 0 } } }, + { OP_END, { { 0 } } }, + { 0 }, }; - int ret; - memcpy((uint16_t *)&tmp_data + operations[0].cmp.s1_off, &a, sizeof(a)); - memcpy((uint16_t *)&tmp_data + operations[0].cmp.s2_off, &b, sizeof(b)); + ck_write_gluten(gluten, operations[0].op.cmp.x, a); + ck_write_gluten(gluten, operations[0].op.cmp.y, b); - ret = do_operations(&tmp_data, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); - ck_assert_int_eq(at->err, 0); + eval(&gluten, operations, &req, notifyfd); + check_target_result_nonegative(); } START_TEST(test_op_cmp_int_eq) @@ -330,7 +264,7 @@ END_TEST START_TEST(test_op_cmp_int_gt) { - test_op_cmp_int(1, 2, CMP_GT); + test_op_cmp_int(2, 1, CMP_GT); } END_TEST @@ -342,7 +276,7 @@ END_TEST START_TEST(test_op_cmp_int_lt) { - test_op_cmp_int(2, 1, CMP_LT); + test_op_cmp_int(1, 2, CMP_LT); } END_TEST @@ -354,82 +288,74 @@ END_TEST START_TEST(test_op_cmp_string_eq) { - char s[30] = "Hello Test!!"; + char s1[30] = "Hello Test!!"; + char s2[30] = "Hello Test!!"; struct op operations[] = { - { .type = OP_CMP, - .cmp = { .s1_off = 0, - .s2_off = sizeof(s) / sizeof(uint16_t), - .size = sizeof(s), - .cmp = CMP_EQ, - .jmp = 2 } }, - { .type = OP_CONT }, - { .type = OP_END }, - { .type = OP_BLOCK, .block = { .error = -1 } }, + { OP_CMP, + { .cmp = { { OFFSET_DATA, 0 }, + { OFFSET_DATA, 30 }, + sizeof(s1), + CMP_EQ, + 3 } } }, + { OP_BLOCK, { .block = { -1 } } }, + { OP_END, { { 0 } } }, + { OP_CONT, { { 0 } } }, + { OP_END, { { 0 } } }, + { 0 }, }; - int ret; - - memcpy((uint16_t *)&tmp_data + operations[0].cmp.s1_off, &s, sizeof(s)); - memcpy((uint16_t *)&tmp_data + operations[0].cmp.s2_off, &s, sizeof(s)); + ck_write_gluten(gluten, operations[0].op.cmp.x, s1); + ck_write_gluten(gluten, operations[0].op.cmp.y, s2); - ret = do_operations(&tmp_data, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); - ck_assert_int_eq(at->err, 0); + eval(&gluten, operations, &req, notifyfd); + check_target_result_nonegative(); } END_TEST START_TEST(test_op_cmp_string_false) { char s1[30] = "Hello Test!!"; - char s2[30] = "Hello World!!"; + char s2[30] = "Hello Tost!!"; struct op operations[] = { - { .type = OP_CMP, - .cmp = { .s1_off = 0, - .s2_off = sizeof(s1) / sizeof(uint16_t), - .size = sizeof(s1), - .cmp = CMP_EQ, - .jmp = 2 } }, - { .type = OP_BLOCK, .block = { .error = -1 } }, - { .type = OP_END }, - { .type = OP_CONT }, + { OP_CMP, + { .cmp = { { OFFSET_DATA, 0 }, + { OFFSET_DATA, 30 }, + sizeof(s1), + CMP_EQ, + 2 } } }, + { OP_CONT, { { 0 } } }, + { OP_END, { { 0 } } }, + { OP_BLOCK, { .block = { -1 } } }, + { OP_END, { { 0 } } }, + { 0 }, }; - int ret; - memcpy((uint16_t *)&tmp_data + operations[0].cmp.s1_off, &s1, - sizeof(s1)); - memcpy((uint16_t *)&tmp_data + operations[0].cmp.s2_off, &s2, - sizeof(s2)); + ck_write_gluten(gluten, operations[0].op.cmp.x, s1); + ck_write_gluten(gluten, operations[0].op.cmp.y, s2); - ret = do_operations(&tmp_data, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); - ck_assert_int_eq(at->err, 0); + eval(&gluten, operations, &req, notifyfd); + check_target_result_nonegative(); } END_TEST START_TEST(test_op_resolvedfd_eq) { struct op operations[] = { - { .type = OP_RESOLVEDFD, - .resfd = { .fd_off = 0, - .path_off = sizeof(int) / sizeof(uint16_t), - .path_size = sizeof(path), - .jmp = 2 } }, - { .type = OP_CONT }, - { .type = OP_END }, - { .type = OP_BLOCK, .block = { .error = -1 } }, + { OP_RESOLVEDFD, + { .resfd = { { OFFSET_DATA, 0 }, + { OFFSET_DATA, 4 }, + sizeof(path), + 3 } } }, + { OP_BLOCK, { .block = { -1 } } }, + { OP_END, { { 0 } } }, + { OP_CONT, { { 0 } } }, + { OP_END, { { 0 } } }, + { 0 }, }; - memcpy((uint16_t *)&tmp_data + operations[0].resfd.fd_off, &at->fd, - sizeof(at->fd)); - memcpy((uint16_t *)&tmp_data + operations[0].resfd.path_off, &path, - sizeof(path)); - int ret = do_operations(&tmp_data, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); + ck_write_gluten(gluten, operations[0].op.resfd.fd, at->fd); + ck_write_gluten(gluten, operations[0].op.resfd.path, path); + + eval(&gluten, operations, &req, notifyfd); check_target_result(-1, 1, false); } END_TEST @@ -438,27 +364,26 @@ START_TEST(test_op_resolvedfd_neq) { char path2[] = "/tmp/seitan-test-wrong"; struct op operations[] = { - { .type = OP_RESOLVEDFD, - .resfd = { .fd_off = 0, - .path_off = sizeof(int) / sizeof(uint16_t), - .path_size = sizeof(path2), - .jmp = 2 } }, - { .type = OP_CONT }, - { .type = OP_END }, - { .type = OP_BLOCK, .block = { .error = -1 } }, + { OP_RESOLVEDFD, + { .resfd = { { OFFSET_DATA, 0 }, + { OFFSET_DATA, 4 }, + sizeof(path), + 3 } } }, + { OP_BLOCK, { .block = { -1 } } }, + { OP_END, { { 0 } } }, + { OP_CONT, { { 0 } } }, + { OP_END, { { 0 } } }, + { 0 }, }; - memcpy((uint16_t *)&tmp_data + operations[0].resfd.fd_off, &at->fd, - sizeof(at->fd)); - memcpy((uint16_t *)&tmp_data + operations[0].resfd.path_off, &path2, - sizeof(path2)); - int ret = do_operations(&tmp_data, operations, &req, - sizeof(operations) / sizeof(operations[0]), - notifyfd); - ck_assert_msg(ret == 0, strerror(errno)); + + ck_write_gluten(gluten, operations[0].op.resfd.fd, at->fd); + ck_write_gluten(gluten, operations[0].op.resfd.path, path2); + + eval(&gluten, operations, &req, notifyfd); + check_target_result(-1, 1, false); } END_TEST - Suite *op_call_suite(void) { Suite *s; @@ -466,55 +391,55 @@ Suite *op_call_suite(void) TCase *cont, *block, *ret, *call, *resolvedfd; TCase *cmp, *cmpint; TCase *inject, *inject_a; - TCase *copy; + TCase *load; s = suite_create("Perform operations"); - cont = tcase_create("a_continue"); + cont = tcase_create("op_continue"); tcase_add_checked_fixture(cont, setup_without_fd, teardown); tcase_set_timeout(cont, timeout); - tcase_add_test(cont, test_act_continue); + tcase_add_test(cont, test_op_continue); suite_add_tcase(s, cont); - ret = tcase_create("a_return"); - tcase_add_checked_fixture(ret, setup_without_fd, teardown); - tcase_set_timeout(ret, timeout); - tcase_add_test(ret, test_act_return); - tcase_add_test(ret, test_act_return_ref); - suite_add_tcase(s, ret); - - block = tcase_create("a_block"); + block = tcase_create("op_block"); tcase_add_checked_fixture(block, setup_without_fd, teardown); tcase_set_timeout(block, timeout); - tcase_add_test(block, test_act_block); + tcase_add_test(block, test_op_block); suite_add_tcase(s, block); - call = tcase_create("a_call"); + ret = tcase_create("op_return"); + tcase_add_checked_fixture(ret, setup_without_fd, teardown); + tcase_set_timeout(ret, timeout); + tcase_add_test(ret, test_op_return_ro_data); + tcase_add_test(ret, test_op_return_data); + suite_add_tcase(s, ret); + + call = tcase_create("op_call"); tcase_add_checked_fixture(call, setup_without_fd, teardown); tcase_set_timeout(call, timeout); - tcase_add_test(call, test_act_call); - tcase_add_test(call, test_act_call_ret); + tcase_add_test(call, test_op_call); + tcase_add_test(call, test_op_call_ret); suite_add_tcase(s, call); - inject = tcase_create("a_inject"); + inject = tcase_create("op_inject"); tcase_add_checked_fixture(inject, setup_fd, teardown); tcase_set_timeout(inject, timeout); - tcase_add_test(inject, test_act_inject); - tcase_add_test(inject, test_act_inject_ref); + tcase_add_test(inject, test_op_inject); + tcase_add_test(inject, test_op_inject_ref); suite_add_tcase(s, inject); - inject_a = tcase_create("a_inject_a"); + inject_a = tcase_create("op_inject_a"); tcase_add_checked_fixture(inject_a, setup_fd, teardown); tcase_set_timeout(inject_a, timeout); - tcase_add_test(inject_a, test_act_inject_a); - tcase_add_test(inject_a, test_act_inject_a_ref); + tcase_add_test(inject_a, test_op_inject_a); + tcase_add_test(inject_a, test_op_inject_a_ref); suite_add_tcase(s, inject_a); - copy = tcase_create("op_copy"); - tcase_add_checked_fixture(copy, setup_target_connect, teardown); - tcase_set_timeout(copy, 120); - tcase_add_test(copy, test_op_copy); - suite_add_tcase(s, copy); + load = tcase_create("op_load"); + tcase_add_checked_fixture(load, setup_target_connect, teardown); + tcase_set_timeout(load, 120); + tcase_add_test(load, test_op_load); + suite_add_tcase(s, load); cmp = tcase_create("op_cmp"); tcase_add_checked_fixture(cmp, setup_without_fd, teardown); 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 <limits.h> #include <check.h> -#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 */ diff --git a/tests/unit/util.c b/tests/unit/util.c index f552ea2..45171f2 100644 --- a/tests/unit/util.c +++ b/tests/unit/util.c @@ -21,8 +21,7 @@ #include <sys/socket.h> #include "testutil.h" -#include "common.h" -#include "filter.h" +#include "common/common.h" struct seccomp_notif req; int notifyfd; @@ -30,7 +29,7 @@ struct args_target *at; int pipefd[2]; pid_t pid; char path[PATH_MAX] = "/tmp/test-seitan"; -uint16_t tmp_data[TMP_DATA_SIZE]; +struct gluten gluten; int install_notification_filter(struct args_target *at) { @@ -155,6 +154,17 @@ void check_target_result(long ret, int err, bool ignore_ret) ck_assert_int_eq(close(pipefd[0]), 0); } +void check_target_result_nonegative() +{ + int buf; + + read(pipefd[0], &buf, 1); + ck_assert_msg(at->ret > -1, + "expect return value %ld to be greater then -1", at->ret); + ck_assert_int_eq(at->err, 0); + ck_assert_int_eq(close(pipefd[0]), 0); +} + void continue_target() { struct seccomp_notif_resp resp; |