]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: move test_parse_syscall_and_errno() to test-seccomp.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 8 Mar 2021 02:09:37 +0000 (11:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 8 Mar 2021 12:22:24 +0000 (21:22 +0900)
src/test/meson.build
src/test/test-parse-util.c
src/test/test-seccomp.c

index 62e31fd830993f60ef56a8ecffb9ef739e698b8e..ff40a8d10ddd0452db642b953d53b2aecc4d0485 100644 (file)
@@ -224,9 +224,7 @@ tests += [
 
         [['src/test/test-parse-argument.c']],
 
-        [['src/test/test-parse-util.c'],
-         [],
-         [libseccomp]],
+        [['src/test/test-parse-util.c']],
 
         [['src/test/test-sysctl-util.c']],
 
index 756934acad557b53e4e53c6355890a370033b656..b1b23e2fbfada53a86857adb595ca6fb64a802cd 100644 (file)
@@ -11,9 +11,6 @@
 #include "log.h"
 #include "parse-util.h"
 #include "string-util.h"
-#if HAVE_SECCOMP
-#include "seccomp-util.h"
-#endif
 
 static void test_parse_boolean(void) {
         assert_se(parse_boolean("1") == 1);
@@ -783,60 +780,6 @@ static void test_parse_errno(void) {
         assert_se(parse_errno("EINVALaaa") == -EINVAL);
 }
 
-static void test_parse_syscall_and_errno(void) {
-#if HAVE_SECCOMP
-        _cleanup_free_ char *n = NULL;
-        int e;
-
-        assert_se(parse_syscall_and_errno("uname:EILSEQ", &n, &e) >= 0);
-        assert_se(streq(n, "uname"));
-        assert_se(e == errno_from_name("EILSEQ") && e >= 0);
-        n = mfree(n);
-
-        assert_se(parse_syscall_and_errno("uname:EINVAL", &n, &e) >= 0);
-        assert_se(streq(n, "uname"));
-        assert_se(e == errno_from_name("EINVAL") && e >= 0);
-        n = mfree(n);
-
-        assert_se(parse_syscall_and_errno("@sync:4095", &n, &e) >= 0);
-        assert_se(streq(n, "@sync"));
-        assert_se(e == 4095);
-        n = mfree(n);
-
-        /* If errno is omitted, then e is set to -1 */
-        assert_se(parse_syscall_and_errno("mount", &n, &e) >= 0);
-        assert_se(streq(n, "mount"));
-        assert_se(e == -1);
-        n = mfree(n);
-
-        /* parse_syscall_and_errno() does not check the syscall name is valid or not. */
-        assert_se(parse_syscall_and_errno("hoge:255", &n, &e) >= 0);
-        assert_se(streq(n, "hoge"));
-        assert_se(e == 255);
-        n = mfree(n);
-
-        assert_se(parse_syscall_and_errno("hoge:kill", &n, &e) >= 0);
-        assert_se(streq(n, "hoge"));
-        assert_se(e == SECCOMP_ERROR_NUMBER_KILL);
-        n = mfree(n);
-
-        /* The function checks the syscall name is empty or not. */
-        assert_se(parse_syscall_and_errno("", &n, &e) == -EINVAL);
-        assert_se(parse_syscall_and_errno(":255", &n, &e) == -EINVAL);
-
-        /* errno must be a valid errno name or number between 0 and ERRNO_MAX == 4095, or "kill" */
-        assert_se(parse_syscall_and_errno("hoge:4096", &n, &e) == -ERANGE);
-        assert_se(parse_syscall_and_errno("hoge:-3", &n, &e) == -ERANGE);
-        assert_se(parse_syscall_and_errno("hoge:12.3", &n, &e) == -EINVAL);
-        assert_se(parse_syscall_and_errno("hoge:123junk", &n, &e) == -EINVAL);
-        assert_se(parse_syscall_and_errno("hoge:junk123", &n, &e) == -EINVAL);
-        assert_se(parse_syscall_and_errno("hoge:255:EILSEQ", &n, &e) == -EINVAL);
-        assert_se(parse_syscall_and_errno("hoge:-EINVAL", &n, &e) == -EINVAL);
-        assert_se(parse_syscall_and_errno("hoge:EINVALaaa", &n, &e) == -EINVAL);
-        assert_se(parse_syscall_and_errno("hoge:", &n, &e) == -EINVAL);
-#endif
-}
-
 static void test_parse_mtu(void) {
         uint32_t mtu = 0;
 
@@ -914,7 +857,6 @@ int main(int argc, char *argv[]) {
         test_parse_nice();
         test_parse_dev();
         test_parse_errno();
-        test_parse_syscall_and_errno();
         test_parse_mtu();
         test_parse_loadavg_fixed_point();
 
index 10393b6a7cf8989653e52f5c26e5d309c36d0d5a..6aa91ae8ecb34c01f8341e1d14810a4d3872f19d 100644 (file)
 #  define SECCOMP_RESTRICT_ADDRESS_FAMILIES_BROKEN 0
 #endif
 
+static void test_parse_syscall_and_errno(void) {
+        _cleanup_free_ char *n = NULL;
+        int e;
+
+        assert_se(parse_syscall_and_errno("uname:EILSEQ", &n, &e) >= 0);
+        assert_se(streq(n, "uname"));
+        assert_se(e == errno_from_name("EILSEQ") && e >= 0);
+        n = mfree(n);
+
+        assert_se(parse_syscall_and_errno("uname:EINVAL", &n, &e) >= 0);
+        assert_se(streq(n, "uname"));
+        assert_se(e == errno_from_name("EINVAL") && e >= 0);
+        n = mfree(n);
+
+        assert_se(parse_syscall_and_errno("@sync:4095", &n, &e) >= 0);
+        assert_se(streq(n, "@sync"));
+        assert_se(e == 4095);
+        n = mfree(n);
+
+        /* If errno is omitted, then e is set to -1 */
+        assert_se(parse_syscall_and_errno("mount", &n, &e) >= 0);
+        assert_se(streq(n, "mount"));
+        assert_se(e == -1);
+        n = mfree(n);
+
+        /* parse_syscall_and_errno() does not check the syscall name is valid or not. */
+        assert_se(parse_syscall_and_errno("hoge:255", &n, &e) >= 0);
+        assert_se(streq(n, "hoge"));
+        assert_se(e == 255);
+        n = mfree(n);
+
+        assert_se(parse_syscall_and_errno("hoge:kill", &n, &e) >= 0);
+        assert_se(streq(n, "hoge"));
+        assert_se(e == SECCOMP_ERROR_NUMBER_KILL);
+        n = mfree(n);
+
+        /* The function checks the syscall name is empty or not. */
+        assert_se(parse_syscall_and_errno("", &n, &e) == -EINVAL);
+        assert_se(parse_syscall_and_errno(":255", &n, &e) == -EINVAL);
+
+        /* errno must be a valid errno name or number between 0 and ERRNO_MAX == 4095, or "kill" */
+        assert_se(parse_syscall_and_errno("hoge:4096", &n, &e) == -ERANGE);
+        assert_se(parse_syscall_and_errno("hoge:-3", &n, &e) == -ERANGE);
+        assert_se(parse_syscall_and_errno("hoge:12.3", &n, &e) == -EINVAL);
+        assert_se(parse_syscall_and_errno("hoge:123junk", &n, &e) == -EINVAL);
+        assert_se(parse_syscall_and_errno("hoge:junk123", &n, &e) == -EINVAL);
+        assert_se(parse_syscall_and_errno("hoge:255:EILSEQ", &n, &e) == -EINVAL);
+        assert_se(parse_syscall_and_errno("hoge:-EINVAL", &n, &e) == -EINVAL);
+        assert_se(parse_syscall_and_errno("hoge:EINVALaaa", &n, &e) == -EINVAL);
+        assert_se(parse_syscall_and_errno("hoge:", &n, &e) == -EINVAL);
+}
+
 static void test_seccomp_arch_to_string(void) {
         uint32_t a, b;
         const char *name;
@@ -1075,6 +1127,7 @@ static void test_restrict_suid_sgid(void) {
 int main(int argc, char *argv[]) {
         test_setup_logging(LOG_DEBUG);
 
+        test_parse_syscall_and_errno();
         test_seccomp_arch_to_string();
         test_architecture_table();
         test_syscall_filter_set_find();