aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2023-04-13 16:26:19 +0200
committerAlice Frosi <afrosi@redhat.com>2023-04-13 16:26:19 +0200
commitfdaf7901b9d8c6c598f260c245213b5a759210f0 (patch)
treea7f6583a50a340f8035687b13bca062f1b3dc033
parent917ca7a3bb60c6d992fb04ece1163870d16f3fce (diff)
downloadseitan-fdaf7901b9d8c6c598f260c245213b5a759210f0.tar
seitan-fdaf7901b9d8c6c598f260c245213b5a759210f0.tar.gz
seitan-fdaf7901b9d8c6c598f260c245213b5a759210f0.tar.bz2
seitan-fdaf7901b9d8c6c598f260c245213b5a759210f0.tar.lz
seitan-fdaf7901b9d8c6c598f260c245213b5a759210f0.tar.xz
seitan-fdaf7901b9d8c6c598f260c245213b5a759210f0.tar.zst
seitan-fdaf7901b9d8c6c598f260c245213b5a759210f0.zip
Fix tests
-rw-r--r--tests/unit/test_filter.c31
-rw-r--r--tests/unit/test_filter_build.c1
-rw-r--r--tests/unit/test_operations.c11
-rw-r--r--tests/unit/testutil.h1
-rw-r--r--tests/unit/util.c20
5 files changed, 35 insertions, 29 deletions
diff --git a/tests/unit/test_filter.c b/tests/unit/test_filter.c
index 0ece692..397f6cc 100644
--- a/tests/unit/test_filter.c
+++ b/tests/unit/test_filter.c
@@ -58,6 +58,24 @@ START_TEST(with_getsid)
at->args[0].type = U32;
at->args[0].value.v32 = id;
at->args[0].cmp = EQ;
+ at->targs[0] = (void *)(long)id;
+ at->install_filter = generate_install_filter;
+ setup();
+ mock_syscall_target();
+}
+END_TEST
+
+START_TEST(with_getsid_gt)
+{
+ at = mmap(NULL, sizeof(struct args_target), PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ at->check_fd = false;
+ at->nr = __NR_getsid;
+ set_args_no_check(at);
+ at->args[0].type = U32;
+ at->args[0].value.v32 = 0x1;
+ at->args[0].cmp = GT;
+ at->targs[0] = (void *)(long)0x10;
at->install_filter = generate_install_filter;
setup();
mock_syscall_target();
@@ -79,6 +97,8 @@ START_TEST(with_getpriority)
at->args[1].value.v32 = who;
at->args[1].type = U32;
at->args[1].cmp = EQ;
+ at->targs[0] = (void *)(long)which;
+ at->targs[1] = (void *)(long)who;
at->install_filter = generate_install_filter;
setup();
mock_syscall_target();
@@ -91,7 +111,7 @@ static int target_lseek()
/* Open the device on the target, but the arg0 isn't in the filter */
ck_assert_int_ge(fd, 0);
- at->args[0].value.v64 = fd;
+ at->targs[0] = (void *)(long)fd;
return target();
}
@@ -106,6 +126,7 @@ static void test_lseek(off_t offset)
at->args[1].value.v64 = offset;
at->args[1].type = U64;
at->args[1].cmp = EQ;
+ at->targs[1] = (void *)(long)offset;
at->install_filter = generate_install_filter;
setup();
mock_syscall_target();
@@ -127,7 +148,7 @@ Suite *op_call_suite(void)
{
Suite *s;
int timeout = 30;
- TCase *simple, *args32, *args64;
+ TCase *simple, *args32, *args64, *gt32;
s = suite_create("Test filter with target");
@@ -151,6 +172,12 @@ Suite *op_call_suite(void)
tcase_add_test(args64, with_lseek_hi);
suite_add_tcase(s, args64);
+ gt32 = tcase_create("with args 32 bit and gt");
+ tcase_add_checked_fixture(gt32, NULL, teardown);
+ tcase_set_timeout(gt32, timeout);
+ tcase_add_test(gt32, with_getsid_gt);
+ suite_add_tcase(s, gt32);
+
return s;
}
diff --git a/tests/unit/test_filter_build.c b/tests/unit/test_filter_build.c
index bf79e3f..343d020 100644
--- a/tests/unit/test_filter_build.c
+++ b/tests/unit/test_filter_build.c
@@ -100,7 +100,6 @@ START_TEST(test_single_instr_two_args)
};
size = create_bfp_program(table, result,
sizeof(table) / sizeof(table[0]));
- bpf_disasm_all(result, size);
ck_assert_uint_eq(size, sizeof(expected) / sizeof(expected[0]));
ck_assert(filter_eq(expected, result,
sizeof(expected) / sizeof(expected[0])));
diff --git a/tests/unit/test_operations.c b/tests/unit/test_operations.c
index 13f767c..6ef451f 100644
--- a/tests/unit/test_operations.c
+++ b/tests/unit/test_operations.c
@@ -64,10 +64,8 @@ void setup_path()
void setup_target_connect()
{
struct sockaddr_un addr;
- socklen_t len;
int fd;
- len = sizeof(char) * 108;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
ck_assert_int_ge(fd, 0);
memset(&addr, 0, sizeof(addr));
@@ -77,12 +75,9 @@ void setup_target_connect()
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
at->check_fd = false;
at->nr = __NR_connect;
- at->args[0].value.v32 = fd;
- at->args[0].type = U32;
- at->args[1].value.v64 = &addr;
- at->args[1].type = U64;
- at->args[2].value.v32 = len;
- at->args[2].type = U32;
+ at->targs[0] = (void *)(long)fd;
+ at->targs[1] = (void *)&addr;
+ at->targs[2] = (void *)(long)(sizeof(char) * 108);
at->install_filter = install_notification_filter;
setup();
}
diff --git a/tests/unit/testutil.h b/tests/unit/testutil.h
index c2f2153..d6a1c46 100644
--- a/tests/unit/testutil.h
+++ b/tests/unit/testutil.h
@@ -20,6 +20,7 @@ struct args_target {
int fd;
int nr;
struct arg args[6];
+ void *targs[6];
int (*install_filter)(struct args_target *at);
int (*target)(void *);
};
diff --git a/tests/unit/util.c b/tests/unit/util.c
index 3406c3b..b2f89e4 100644
--- a/tests/unit/util.c
+++ b/tests/unit/util.c
@@ -49,31 +49,15 @@ int install_notification_filter(struct args_target *at)
filter, (unsigned short)(sizeof(filter) / sizeof(filter[0])));
}
-static void parse_args_target(void *args[])
-{
- for (unsigned int i = 0; i < 6; i++) {
- switch (at->args[i].type) {
- case U64:
- args[i] = (void *)at->args[i].value.v64;
- break;
- case U32:
- args[i] = (void *)(long)at->args[i].value.v32;
- break;
- }
- }
-}
-
int target()
{
- void *args[6];
int buf = 0;
if (at->install_filter(at) < 0) {
return -1;
}
- parse_args_target(args);
- at->ret = syscall(at->nr, args[0], args[1], args[2], args[3], args[4],
- args[5]);
+ at->ret = syscall(at->nr, at->targs[0], at->targs[1], at->targs[2],
+ at->targs[3], at->targs[4], at->targs[5]);
at->err = errno;
if (at->open_path) {
if ((at->fd = open(path, O_CREAT | O_RDONLY)) < 0) {