Bump version to 1.2.5
[uid_wrapper.git] / tests / test_syscall.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 <string.h>
9 #include <sys/time.h>
10 #include <unistd.h>
11
12 #ifdef HAVE_SYS_SYSCALL_H
13 #include <sys/syscall.h>
14 #endif
15 #ifdef HAVE_SYSCALL_H
16 #include <syscall.h>
17 #endif
18
19 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
20
21 static void test_uwrap_syscall(void **state)
22 {
23         long int rc;
24         struct timeval tv1, tv2;
25         struct timezone tz1, tz2;
26
27         (void) state; /* unused */
28
29 #ifdef __alpha__
30         rc = syscall(SYS_getxpid);
31 #else
32         rc = syscall(SYS_getpid);
33 #endif
34         assert_int_equal(rc, getpid());
35
36         ZERO_STRUCT(tv1);
37         ZERO_STRUCT(tv2);
38         ZERO_STRUCT(tz1);
39         ZERO_STRUCT(tz2);
40
41         rc = gettimeofday(&tv1, &tz1);
42         assert_int_equal(rc, 0);
43
44 #ifdef OSX
45         tv2.tv_sec = syscall(SYS_gettimeofday, &tv2, NULL);
46 #else
47         rc = syscall(SYS_gettimeofday, &tv2, &tz2);
48         assert_int_equal(rc, 0);
49         assert_int_equal(tz1.tz_dsttime, tz2.tz_dsttime);
50         assert_int_equal(tz1.tz_minuteswest, tz2.tz_minuteswest);
51 #endif
52
53         assert_int_equal(tv1.tv_sec, tv2.tv_sec);
54 }
55
56 int main(void) {
57         int rc;
58
59         const struct CMUnitTest uwrap_tests[] = {
60                 cmocka_unit_test(test_uwrap_syscall),
61         };
62
63         rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
64
65         return rc;
66 }