diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/56-basic-iterate_syscalls.c | 90 | ||||
-rwxr-xr-x | tests/56-basic-iterate_syscalls.py | 65 | ||||
-rw-r--r-- | tests/56-basic-iterate_syscalls.tests | 11 | ||||
-rw-r--r-- | tests/Makefile.am | 9 |
5 files changed, 173 insertions, 3 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index bd00e14..c536766 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -61,3 +61,4 @@ util.pyc 53-sim-binary_tree 54-live-binary_tree 55-basic-pfc_binary_tree +56-basic-iterate_syscalls diff --git a/tests/56-basic-iterate_syscalls.c b/tests/56-basic-iterate_syscalls.c new file mode 100644 index 0000000..5e7ab67 --- /dev/null +++ b/tests/56-basic-iterate_syscalls.c @@ -0,0 +1,90 @@ +/** + * Seccomp Library test program + * + * Copyright (c) 2020 Red Hat <gscrivan@redhat.com> + * Author: Giuseppe Scrivano <gscrivan@redhat.com> + */ + +/* + * This library is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License as + * published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, see <http://www.gnu.org/licenses>. + */ + +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#include <seccomp.h> + +unsigned int arch_list[] = { + SCMP_ARCH_NATIVE, + SCMP_ARCH_X86, + SCMP_ARCH_X86_64, + SCMP_ARCH_X32, + SCMP_ARCH_ARM, + SCMP_ARCH_AARCH64, + SCMP_ARCH_MIPS, + SCMP_ARCH_MIPS64, + SCMP_ARCH_MIPS64N32, + SCMP_ARCH_MIPSEL, + SCMP_ARCH_MIPSEL64, + SCMP_ARCH_MIPSEL64N32, + SCMP_ARCH_PPC, + SCMP_ARCH_PPC64, + SCMP_ARCH_PPC64LE, + SCMP_ARCH_S390, + SCMP_ARCH_S390X, + SCMP_ARCH_PARISC, + SCMP_ARCH_PARISC64, + SCMP_ARCH_RISCV64, + -1 +}; + +static int test_arch(int arch, int init) +{ + int n, iter = 0; + + for (iter = init; iter < init + 1000; iter++) { + char *name; + + name = seccomp_syscall_resolve_num_arch(arch, iter); + if (name == NULL) + continue; + + n = seccomp_syscall_resolve_name_arch(arch, name); + if (n != iter) + return 1; + } + return 0; +} + +int main(int argc, char *argv[]) +{ + int iter = 0; + + for (iter = 0; arch_list[iter] != -1; iter++) { + int init = 0; + if (arch_list[iter] == SCMP_ARCH_X32) + init = 0x40000000; + else if (arch_list[iter] == SCMP_ARCH_MIPS) + init = 4000; + else if (arch_list[iter] == SCMP_ARCH_MIPS64) + init = 5000; + else if (arch_list[iter] == SCMP_ARCH_MIPS64N32) + init = 6000; + if (test_arch(arch_list[iter], init) < 0) + return 1; + } + + return 0; +} diff --git a/tests/56-basic-iterate_syscalls.py b/tests/56-basic-iterate_syscalls.py new file mode 100755 index 0000000..77a5b89 --- /dev/null +++ b/tests/56-basic-iterate_syscalls.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +# +# Seccomp Library test program +# +# Copyright (c) 2020 Red Hat <gscrivan@redhat.com> +# Author: Giuseppe Scrivano <gscrivan@redhat.com> +# + +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of version 2.1 of the GNU Lesser General Public License as +# published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License +# for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, see <http://www.gnu.org/licenses>. +# + +import argparse +import sys + +import util + +from seccomp import * + +arch_list = ["x86", + "x86_64", + "x32", + "arm", + "aarch64", + "mipsel", + "mipsel64", + "mipsel64n32", + "ppc64le", + "riscv64"] + +def test_arch(arch, init): + for i in range(init, init + 1000): + sys_name = resolve_syscall(arch, i) + if sys_name is None: + continue + n = resolve_syscall(i, sys_name) + if i != n: + raise RuntimeError("Test failure") + +def test(): + for i in arch_list: + init = 0 + if i == "x32": + init = 0x40000000 + elif i == "mipsel": + init = 4000 + elif i == "mipsel64": + init = 5000 + elif i == "mipsel64n32": + init = 6000 + test_arch(Arch(i), init) + +# kate: syntax python; +# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off; diff --git a/tests/56-basic-iterate_syscalls.tests b/tests/56-basic-iterate_syscalls.tests new file mode 100644 index 0000000..a84415a --- /dev/null +++ b/tests/56-basic-iterate_syscalls.tests @@ -0,0 +1,11 @@ +# +# libseccomp regression test automation data +# +# Copyright (c) 2020 Red Hat <gscrivan@redhat.com> +# Author: Giuseppe Scrivano <gscrivan@redhat.com> +# + +test type: basic + +# Test command +56-basic-iterate_syscalls diff --git a/tests/Makefile.am b/tests/Makefile.am index 4bd19c8..a135278 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -94,7 +94,8 @@ check_PROGRAMS = \ 52-basic-load \ 53-sim-binary_tree \ 54-live-binary_tree \ - 55-basic-pfc_binary_tree + 55-basic-pfc_binary_tree \ + 56-basic-iterate_syscalls EXTRA_DIST_TESTPYTHON = \ util.py \ @@ -150,7 +151,8 @@ EXTRA_DIST_TESTPYTHON = \ 51-live-user_notification.py \ 52-basic-load.py \ 53-sim-binary_tree.py \ - 54-live-binary_tree.py + 54-live-binary_tree.py \ + 56-basic-iterate_syscalls.py EXTRA_DIST_TESTCFGS = \ 01-sim-allow.tests \ @@ -207,7 +209,8 @@ EXTRA_DIST_TESTCFGS = \ 52-basic-load.tests \ 53-sim-binary_tree.tests \ 54-live-binary_tree.tests \ - 55-basic-pfc_binary_tree.tests + 55-basic-pfc_binary_tree.tests \ + 56-basic-iterate_syscalls.tests EXTRA_DIST_TESTSCRIPTS = \ 38-basic-pfc_coverage.sh 38-basic-pfc_coverage.pfc \ |