On Thu, Jun 26, 2025 at 09:57:14PM +0200, Benjamin Berg wrote:
> From: Benjamin Berg <benjamin.b...@intel.com>
> 
> This tests checks whether floating point registers are properly saved
> into the signal context and restored again. The test works by having a
> known value at the top of the FP register stack and in the first xmm
> register. Then SIGUSR1 is triggered and both of these registers are
> modified by changing the values in the mcontext.
> 
> Signed-off-by: Benjamin Berg <benjamin.b...@intel.com>
> ---
>  arch/x86/um/Makefile                     |   2 +
>  arch/x86/um/tests/Makefile               |  12 +++
>  arch/x86/um/tests/registers.c            |  22 +++++
>  arch/x86/um/tests/test-fp-save-restore.c | 118 +++++++++++++++++++++++
>  4 files changed, 154 insertions(+)
>  create mode 100644 arch/x86/um/tests/Makefile
>  create mode 100644 arch/x86/um/tests/registers.c
>  create mode 100644 arch/x86/um/tests/test-fp-save-restore.c
> 
> diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile
> index b42c31cd2390..410f5526f1f4 100644
> --- a/arch/x86/um/Makefile
> +++ b/arch/x86/um/Makefile
> @@ -15,6 +15,8 @@ obj-y = bugs_$(BITS).o delay.o fault.o \
>       sys_call_table_$(BITS).o sysrq_$(BITS).o tls_$(BITS).o \
>       mem_$(BITS).o subarch.o os-Linux/
>  
> +obj-y += tests/
> +
>  ifeq ($(CONFIG_X86_32),y)
>  
>  obj-y += syscalls_32.o
> diff --git a/arch/x86/um/tests/Makefile b/arch/x86/um/tests/Makefile
> new file mode 100644
> index 000000000000..c3a868b078f3
> --- /dev/null
> +++ b/arch/x86/um/tests/Makefile
> @@ -0,0 +1,12 @@
> +include $(srctree)/init/Makefile.nolibc
> +
> +ccflags-y := -I$(obj)

As mentiond before, I'd like to find out why you need this.

> +um-tests-y += registers.o
> +
> +userprogs += test-fp-save-restore
> +test-fp-save-restore-userccflags := -static $(NOLIBC_USERCFLAGS) -msse
> +
> +obj-$(CONFIG_KUNIT_UAPI) += um-tests.o

Create a dedicated Kconfig option for this.
Not everybody who has enabled the framework wants to include these testcases.
Also the tests can stay in a module even if CONFIG_KUNIT_UAPI=y.

> +
> +$(obj)/registers.o: $(obj)/test-fp-save-restore
> diff --git a/arch/x86/um/tests/registers.c b/arch/x86/um/tests/registers.c
> new file mode 100644
> index 000000000000..2c4e55da043c
> --- /dev/null
> +++ b/arch/x86/um/tests/registers.c
> @@ -0,0 +1,22 @@
> +#include <kunit/test.h>

> +#include <kunit/test-bug.h>

Unnecessary.

> +#include <kunit/uapi.h>
> +
> +static void test_mcontext(struct kunit *test)
> +{
> +     KUNIT_UAPI_EMBED_BLOB(test_fp_save_restore, "test-fp-save-restore");

Any reason to have different names between the userprog and the testcase?
Keeping them consistent will make it easier for the user.

> +
> +     kunit_uapi_run_kselftest(test, &test_fp_save_restore);
> +}
> +
> +static struct kunit_case register_test_cases[] = {
> +     KUNIT_CASE(test_mcontext),
> +     {}
> +};
> +
> +static struct kunit_suite register_test_suite = {
> +     .name = "um_registers",
> +     .test_cases = register_test_cases,
> +};
> +
> +kunit_test_suites(&register_test_suite);
> diff --git a/arch/x86/um/tests/test-fp-save-restore.c 
> b/arch/x86/um/tests/test-fp-save-restore.c
> new file mode 100644
> index 000000000000..28a32ca374fe
> --- /dev/null
> +++ b/arch/x86/um/tests/test-fp-save-restore.c
> @@ -0,0 +1,118 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Test FP register handling in userspace mcontext.
> + *
> + * Copyright (C) 2025 Intel Corporation
> + */
> +
> +#include <math.h>
> +#include <signal.h>

> +#include <types.h>

types.h is specific to nolibc. Can probably just be dropped.

> +#include <unistd.h>
> +#include <string.h>
> +#include <sys.h>

sys.h is specific to nolibc. Use a standard header instead.

> +#include <asm/sigcontext.h>
> +#include <asm/ucontext.h>
> +
> +#include "../../../tools/testing/selftests/kselftest.h"

I can't say anything about the actual tests.

<snip>

Reply via email to