aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2023-02-27 13:19:19 +0100
committerAlice Frosi <afrosi@redhat.com>2023-02-27 14:15:43 +0100
commit0f4a78ff9e9fcff894044e15373d8348659cb4c3 (patch)
treee317433b6eac8d075172fe6f0056a1d07fce2ce9
parent52e2835061429d93abacf8d1cf00f7da69e7a853 (diff)
downloadseitan-0f4a78ff9e9fcff894044e15373d8348659cb4c3.tar
seitan-0f4a78ff9e9fcff894044e15373d8348659cb4c3.tar.gz
seitan-0f4a78ff9e9fcff894044e15373d8348659cb4c3.tar.bz2
seitan-0f4a78ff9e9fcff894044e15373d8348659cb4c3.tar.lz
seitan-0f4a78ff9e9fcff894044e15373d8348659cb4c3.tar.xz
seitan-0f4a78ff9e9fcff894044e15373d8348659cb4c3.tar.zst
seitan-0f4a78ff9e9fcff894044e15373d8348659cb4c3.zip
tests: add test for op_cmp
-rw-r--r--tests/unit/test_operations.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/tests/unit/test_operations.c b/tests/unit/test_operations.c
index 3a6de8a..d43b54c 100644
--- a/tests/unit/test_operations.c
+++ b/tests/unit/test_operations.c
@@ -446,11 +446,66 @@ START_TEST(test_op_copy)
}
END_TEST
+START_TEST(test_op_cmp_eq)
+{
+ char s[30] = "Hello Test!!";
+ struct op operations[] = {
+ { .type = OP_CMP,
+ .cmp = { .s1_off = 0,
+ .s2_off = sizeof(s) / sizeof(uint16_t),
+ .size = sizeof(s),
+ .jmp = 2 } },
+ { .type = OP_CONT },
+ { .type = OP_END },
+ { .type = OP_BLOCK, .block = { .error = -1 } },
+ };
+ 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));
+
+ ret = do_operations(&tmp_data, operations, &req,
+ sizeof(operations) / sizeof(operations[0]), -1,
+ notifyfd, req.id);
+ ck_assert_msg(ret == 0, strerror(errno));
+ ck_assert_int_eq(at->err, 0);
+}
+END_TEST
+
+START_TEST(test_op_cmp_neq)
+{
+ char s1[30] = "Hello Test!!";
+ char s2[30] = "Hello World!!";
+ struct op operations[] = {
+ { .type = OP_CMP,
+ .cmp = { .s1_off = 0,
+ .s2_off = sizeof(s1) / sizeof(uint16_t),
+ .size = sizeof(s1),
+ .jmp = 2 } },
+ { .type = OP_CONT },
+ { .type = OP_END },
+ { .type = OP_BLOCK, .block = { .error = -1 } },
+ };
+ 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));
+
+ ret = do_operations(&tmp_data, operations, &req,
+ sizeof(operations) / sizeof(operations[0]), -1,
+ notifyfd, req.id);
+ ck_assert_msg(ret == 0, strerror(errno));
+ check_target_result(-1, 1, false);
+}
+END_TEST
+
Suite *op_call_suite(void)
{
Suite *s;
int timeout = 30;
- TCase *cont, *block, *ret, *call;
+ TCase *cont, *block, *ret, *call, *cmp;
TCase *inject, *inject_a;
TCase *copy;
@@ -502,6 +557,13 @@ Suite *op_call_suite(void)
tcase_add_test(copy, test_op_copy);
suite_add_tcase(s, copy);
+ cmp = tcase_create("op_cmp");
+ tcase_add_checked_fixture(cmp, setup_without_fd, teardown);
+ tcase_set_timeout(cmp, timeout);
+ tcase_add_test(cmp, test_op_cmp_eq);
+ tcase_add_test(cmp, test_op_cmp_neq);
+ suite_add_tcase(s, cmp);
+
return s;
}