aboutgitcodelistschat:MatrixIRC
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_errors.c38
-rw-r--r--tests/unit/test_operations.c16
2 files changed, 32 insertions, 22 deletions
diff --git a/tests/unit/test_errors.c b/tests/unit/test_errors.c
index d00d42e..ca6fcb0 100644
--- a/tests/unit/test_errors.c
+++ b/tests/unit/test_errors.c
@@ -1,4 +1,3 @@
-#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/syscall.h>
@@ -31,6 +30,7 @@ START_TEST(test_bound_check)
{
struct op ops[] = {
{ OP_RETURN, { { 0 } } },
+ { OP_END, { { 0 } } },
};
ops[0].op.ret.val.offset = test_max_size_data[_i].offset;
ops[0].op.ret.val.type = test_max_size_data[_i].type;
@@ -45,9 +45,10 @@ START_TEST(test_write_op_return)
{ .call = { .nr = __NR_getpid,
.has_ret = true,
.ret = { OFFSET_DATA, DATA_SIZE - 1 } } } },
+ { OP_END, { { 0 } } },
};
- eval(&gluten, ops, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, ops, &req, notifyfd), -1);
}
START_TEST(test_write_op_load)
@@ -58,20 +59,28 @@ START_TEST(test_write_op_load)
{ .load = { { OFFSET_SECCOMP_DATA, 1 },
{ OFFSET_DATA, DATA_SIZE - 1 },
sizeof(a) } } },
+ { OP_END, { { 0 } } },
};
- eval(&gluten, ops, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, ops, &req, notifyfd), -1);
}
+struct gluten_offset test_max_size_read_data[] = {
+ { OFFSET_DATA, DATA_SIZE },
+ { OFFSET_RO_DATA, RO_DATA_SIZE },
+ { OFFSET_SECCOMP_DATA, 6 },
+};
+
START_TEST(test_read_op_return)
{
struct op ops[] = {
{ OP_RETURN, { { 0 } } },
+ { OP_END, { { 0 } } },
};
- ops[0].op.ret.val.offset = test_max_size_data[_i].offset - 1;
- ops[0].op.ret.val.type = test_max_size_data[_i].type;
+ ops[0].op.ret.val.offset = test_max_size_read_data[_i].offset - 1;
+ ops[0].op.ret.val.type = test_max_size_read_data[_i].type;
- eval(&gluten, ops, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, ops, &req, notifyfd), -1);
}
Suite *error_suite(void)
@@ -82,21 +91,22 @@ Suite *error_suite(void)
s = suite_create("Error handling");
bounds = tcase_create("bound checks");
- tcase_add_loop_exit_test(bounds, test_bound_check, EXIT_FAILURE, 0,
- sizeof(test_max_size_data) /
- sizeof(test_max_size_data[0]));
+ tcase_add_loop_test(bounds, test_bound_check, 0,
+ sizeof(test_max_size_data) /
+ sizeof(test_max_size_data[0]));
suite_add_tcase(s, bounds);
gwrite = tcase_create("write gluten");
tcase_add_checked_fixture(gwrite, setup_error_check, teardown);
- tcase_add_exit_test(gwrite, test_write_op_return, EXIT_FAILURE);
- tcase_add_exit_test(gwrite, test_write_op_load, EXIT_FAILURE);
+ tcase_add_test(gwrite, test_write_op_return);
+ tcase_add_test(gwrite, test_write_op_load);
suite_add_tcase(s, gwrite);
gread = tcase_create("read gluten");
- tcase_add_loop_exit_test(gread, test_read_op_return, EXIT_FAILURE, 0,
- sizeof(test_max_size_data) /
- sizeof(test_max_size_data[0]));
+ tcase_add_checked_fixture(gread, setup_error_check, teardown);
+ tcase_add_loop_test(gread, test_read_op_return, 0,
+ sizeof(test_max_size_read_data) /
+ sizeof(test_max_size_read_data[0]));
suite_add_tcase(s, gread);
return s;
diff --git a/tests/unit/test_operations.c b/tests/unit/test_operations.c
index 9c3cf94..0e22754 100644
--- a/tests/unit/test_operations.c
+++ b/tests/unit/test_operations.c
@@ -136,7 +136,7 @@ START_TEST(test_op_call)
{ 0 },
};
- eval(&gluten, operations, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, operations, &req, notifyfd), 0);
check_target_result(1, 0, true);
}
END_TEST
@@ -153,7 +153,7 @@ START_TEST(test_op_call_ret)
{ 0 },
};
- eval(&gluten, operations, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, operations, &req, notifyfd), 0);
check_target_result(1, 0, true);
ck_read_gluten(gluten, operations[0].op.call.ret, r);
ck_assert(r == getpid());
@@ -218,7 +218,7 @@ START_TEST(test_op_load)
int v = 2;
ck_write_gluten(gluten, operations[1].op.ret.val, v);
- eval(&gluten, operations, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, operations, &req, notifyfd), 0);
check_target_result(v, 0, false);
ck_read_gluten(gluten, operations[0].op.load.dst, addr);
@@ -246,7 +246,7 @@ static void test_op_cmp_int(int a, int b, enum op_cmp_type cmp)
ck_write_gluten(gluten, operations[0].op.cmp.x, a);
ck_write_gluten(gluten, operations[0].op.cmp.y, b);
- eval(&gluten, operations, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, operations, &req, notifyfd), 0);
check_target_result_nonegative();
}
@@ -306,7 +306,7 @@ START_TEST(test_op_cmp_string_eq)
ck_write_gluten(gluten, operations[0].op.cmp.x, s1);
ck_write_gluten(gluten, operations[0].op.cmp.y, s2);
- eval(&gluten, operations, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, operations, &req, notifyfd), 0);
check_target_result_nonegative();
}
END_TEST
@@ -332,7 +332,7 @@ START_TEST(test_op_cmp_string_false)
ck_write_gluten(gluten, operations[0].op.cmp.x, s1);
ck_write_gluten(gluten, operations[0].op.cmp.y, s2);
- eval(&gluten, operations, &req, notifyfd);
+ ck_assert_int_eq(eval(&gluten, operations, &req, notifyfd), 0);
check_target_result_nonegative();
}
END_TEST
@@ -355,7 +355,7 @@ START_TEST(test_op_resolvedfd_eq)
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);
+ ck_assert_int_eq(eval(&gluten, operations, &req, notifyfd), 0);
check_target_result(-1, 1, false);
}
END_TEST
@@ -379,7 +379,7 @@ START_TEST(test_op_resolvedfd_neq)
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);
+ ck_assert_int_eq(eval(&gluten, operations, &req, notifyfd), 0);
check_target_result(-1, 1, false);
}
END_TEST