tests: test uid_wrapper_syscall_{valid,va} interaction using swrap_fake_uid_wrapper.so
[socket_wrapper.git] / tests / test_syscall_uwrap.c
1 #include "config.h"
2
3 #include <stdarg.h>
4 #include <stddef.h>
5 #include <setjmp.h>
6 #include <cmocka.h>
7
8 #include <stdbool.h>
9 #include <string.h>
10 #include <sys/time.h>
11 #include <unistd.h>
12 #include <errno.h>
13 #include <signal.h>
14
15 #ifdef HAVE_SYS_SYSCALL_H
16 #include <sys/syscall.h>
17 #endif
18 #ifdef HAVE_SYSCALL_H
19 #include <syscall.h>
20 #endif
21
22 #include "swrap_fake_uid_wrapper.h"
23
24 static void test_swrap_syscall_uwrap(void **state)
25 {
26         long int rc;
27
28         (void)state; /* unused */
29
30         rc = syscall(__FAKE_UID_WRAPPER_SYSCALL_NO);
31         assert_int_equal(rc, __FAKE_UID_WRAPPER_SYSCALL_RC);
32
33         /*
34          * FreeBSD raises also a signal SIGSYS, so ignore it or the cmocka
35          * exception handler will catch it.
36          */
37         signal(SIGSYS, SIG_IGN);
38         rc = syscall(__FAKE_UID_WRAPPER_SYSCALL_NO+1);
39         signal(SIGSYS, SIG_DFL);
40         assert_int_equal(rc, -1);
41         assert_int_equal(errno, ENOSYS);
42 }
43
44 int main(void) {
45         int rc;
46
47         const struct CMUnitTest swrap_tests[] = {
48                 cmocka_unit_test(test_swrap_syscall_uwrap),
49         };
50
51         rc = cmocka_run_group_tests(swrap_tests, NULL, NULL);
52
53         return rc;
54 }