tests: Move syscall test to own test
authorAndreas Schneider <asn@samba.org>
Fri, 14 Aug 2015 06:20:57 +0000 (08:20 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 17 Aug 2015 08:44:32 +0000 (10:44 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
tests/CMakeLists.txt
tests/test_syscall.c [new file with mode: 0644]
tests/testsuite.c

index 3113f99b0f9d36f62a6b466312ab1830496e38db..13bd3464855bbbce1166a092d0d41fe89f5cc606 100644 (file)
@@ -20,7 +20,8 @@ set(TESTSUITE_LIBRARIES ${UWRAP_REQUIRED_LIBRARIES} ${CMOCKA_LIBRARY})
 set(UWRAP_TESTS
     testsuite
     test_uid
-    test_gid)
+    test_gid
+    test_syscall)
 
 foreach(_UWRAP_TEST ${UWRAP_TESTS})
     add_cmocka_test(${_UWRAP_TEST} ${_UWRAP_TEST}.c ${TESTSUITE_LIBRARIES})
diff --git a/tests/test_syscall.c b/tests/test_syscall.c
new file mode 100644 (file)
index 0000000..c43f1f9
--- /dev/null
@@ -0,0 +1,62 @@
+#include "config.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYSCALL_H
+#include <syscall.h>
+#endif
+
+#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+
+static void test_uwrap_syscall(void **state)
+{
+       long int rc;
+       struct timeval tv1, tv2;
+       struct timezone tz1, tz2;
+
+       (void) state; /* unused */
+
+       rc = syscall(SYS_getpid);
+       assert_int_equal(rc, getpid());
+
+       ZERO_STRUCT(tv1);
+       ZERO_STRUCT(tv2);
+       ZERO_STRUCT(tz1);
+       ZERO_STRUCT(tz2);
+
+       rc = gettimeofday(&tv1, &tz1);
+       assert_int_equal(rc, 0);
+
+#ifdef OSX
+       tv2.tv_sec = syscall(SYS_gettimeofday, &tv2, NULL);
+#else
+       rc = syscall(SYS_gettimeofday, &tv2, &tz2);
+       assert_int_equal(rc, 0);
+       assert_int_equal(tz1.tz_dsttime, tz2.tz_dsttime);
+       assert_int_equal(tz1.tz_minuteswest, tz2.tz_minuteswest);
+#endif
+
+       assert_int_equal(tv1.tv_sec, tv2.tv_sec);
+}
+
+int main(void) {
+       int rc;
+
+       const struct CMUnitTest uwrap_tests[] = {
+               cmocka_unit_test(test_uwrap_syscall),
+       };
+
+       rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
+
+       return rc;
+}
index 3105ec56ec98641e8d5f944774bbeb374b5103ea..66cc88a36efff15b6f2b0139aebddada363bbfeb 100644 (file)
 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
-static void test_uwrap_syscall(void **state)
-{
-       long int rc;
-       struct timeval tv1, tv2;
-       struct timezone tz1, tz2;
-
-       (void) state; /* unused */
-
-       rc = syscall(SYS_getpid);
-       assert_int_equal(rc, getpid());
-
-       ZERO_STRUCT(tv1);
-       ZERO_STRUCT(tv2);
-       ZERO_STRUCT(tz1);
-       ZERO_STRUCT(tz2);
-
-       rc = gettimeofday(&tv1, &tz1);
-       assert_int_equal(rc, 0);
-
-#ifdef OSX
-       tv2.tv_sec = syscall(SYS_gettimeofday, &tv2, NULL);
-#else
-       rc = syscall(SYS_gettimeofday, &tv2, &tz2);
-       assert_int_equal(rc, 0);
-       assert_int_equal(tz1.tz_dsttime, tz2.tz_dsttime);
-       assert_int_equal(tz1.tz_minuteswest, tz2.tz_minuteswest);
-#endif
-
-       assert_int_equal(tv1.tv_sec, tv2.tv_sec);
-}
-
 static void test_uwrap_syscall_setreuid(void **state)
 {
        long int rc;
@@ -233,7 +202,6 @@ int main(void) {
        int rc;
 
        const struct CMUnitTest uwrap_tests[] = {
-               cmocka_unit_test(test_uwrap_syscall),
                cmocka_unit_test(test_uwrap_syscall_setreuid),
                cmocka_unit_test(test_uwrap_syscall_setresuid),
                cmocka_unit_test(test_uwrap_syscall_setregid),