[LTP] [PATCH v2] Add case about arch_prctl syscall.
Cyril Hrubis
chrubis@suse.cz
Fri Apr 19 17:46:00 CEST 2024
Hi!
First of all do 'make check' in the directory with the test source and
fix all errors and warnings.
> Signed-off-by: Lu Fei <lufei@uniontech.com>
> ---
> configure.ac | 1 +
> .../kernel/syscalls/arch_prctl/.gitignore | 1 +
> testcases/kernel/syscalls/arch_prctl/Makefile | 8 +++
> .../kernel/syscalls/arch_prctl/arch_prctl01.c | 56 +++++++++++++++++++
This is missing a runtest entry, i.e. line in the runtest/syscalls file
that tells the test execution framework to run the test.
> 4 files changed, 66 insertions(+)
> create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
> create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
> create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
>
> diff --git a/configure.ac b/configure.ac
> index 1d7e862d8..0dcaddc0f 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
>
> AC_CHECK_HEADERS_ONCE([ \
> asm/ldt.h \
> + asm/prctl.h \
> cpuid.h \
> emmintrin.h \
> ifaddrs.h \
> diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
> new file mode 100644
> index 000000000..24871e249
> --- /dev/null
> +++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
> @@ -0,0 +1 @@
> +/arch_prctl01
> diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
> new file mode 100644
> index 000000000..272949d57
> --- /dev/null
> +++ b/testcases/kernel/syscalls/arch_prctl/Makefile
> @@ -0,0 +1,8 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
> +
> +top_srcdir ?= ../../../..
> +
> +include $(top_srcdir)/include/mk/testcases.mk
> +
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
> new file mode 100644
> index 000000000..06b3d99b8
> --- /dev/null
> +++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
> @@ -0,0 +1,56 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
> + * Author: Lu Fei <lufei@uniontech.com>
> + */
> +
> +/*
This has to be /*\ so that the docparse comment gets picked up by the
documentation parser and shows up in docparse/metadata.html
> + * [Description]
> + *
> + * Simple test on arch_prctl to set and get cpuid instruction of test thread.
> + */
> +
> +# include "tst_test.h"
> +# include "lapi/syscalls.h"
> +# include <stdlib.h>
> +# ifdef HAVE_ASM_PRCTL_H
> +# include <asm/prctl.h>
No spaces after # here please.
> +static int arch_prctl_get(int code, unsigned long *addr) {
> + return tst_syscall(__NR_arch_prctl, code, *addr);
> +}
> +
> +static int arch_prctl_set(int code, unsigned long addr) {
> + return tst_syscall(__NR_arch_prctl, code, addr);
> +}
> +
> +static int tc[] = {0,1};
> +
> +static void run(unsigned int index){
> +
> + unsigned long *addr = malloc(sizeof(long));
This does not need to be allocated, we can just do unsigned long addr
and pass &addr to the calls.
> + TEST(arch_prctl_set(ARCH_SET_CPUID, tc[index]));
> +
> + if (TST_RET == 0)
> + tst_res(TPASS, "set %s cpuid",tc[index] ? "enable" : "disable");
> + else
> + tst_res(TFAIL, "failed to set cpuid");
This should use TST_EXP_PASS(arch_prctl_set(...))
> + TEST(arch_prctl_get(ARCH_GET_CPUID, addr));
This as well.
> + if (TST_RET == tc[index])
This is wrong, the value should be stored the addr parameter, TST_RET
should be 0 on success.
> + tst_res(TPASS, "get cpuid succeed.");
> + else
> + tst_res(TFAIL, "get cpuid failed.");
> +}
> +
> +static struct tst_test test = {
> + .test = run,
> + .tcnt = 2,
> + .min_kver = "4.11",
This should have .supported_archs = {"x86", "x86-64", NULL},
> +};
> +
> +#else /* HAVE_ASM_PRCTL_H */
> +TST_TEST_TCONF("missing <asm/prctl.h>");
> +#endif
> --
> 2.39.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list