xref: /linux/tools/testing/selftests/arm64/signal/test_signals.h (revision b83deaa741558babf4b8d51d34f6637ccfff1b26)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2019 ARM Limited */
3 
4 #ifndef __TEST_SIGNALS_H__
5 #define __TEST_SIGNALS_H__
6 
7 #include <signal.h>
8 #include <stdbool.h>
9 #include <ucontext.h>
10 
11 /*
12  * Using ARCH specific and sanitized Kernel headers installed by KSFT
13  * framework since we asked for it by setting flag KSFT_KHDR_INSTALL
14  * in our Makefile.
15  */
16 #include <asm/ptrace.h>
17 #include <asm/hwcap.h>
18 
19 #define __stringify_1(x...)	#x
20 #define __stringify(x...)	__stringify_1(x)
21 
22 #define get_regval(regname, out)			\
23 {							\
24 	asm volatile("mrs %0, " __stringify(regname)	\
25 	: "=r" (out)					\
26 	:						\
27 	: "memory");					\
28 }
29 
30 /*
31  * Feature flags used in tdescr.feats_required to specify
32  * any feature by the test
33  */
34 enum {
35 	FSSBS_BIT,
36 	FSVE_BIT,
37 	FMAX_END
38 };
39 
40 #define FEAT_SSBS		(1UL << FSSBS_BIT)
41 #define FEAT_SVE		(1UL << FSVE_BIT)
42 
43 /*
44  * A descriptor used to describe and configure a test case.
45  * Fields with a non-trivial meaning are described inline in the following.
46  */
47 struct tdescr {
48 	/* KEEP THIS FIELD FIRST for easier lookup from assembly */
49 	void			*token;
50 	/* when disabled token based sanity checking is skipped in handler */
51 	bool			sanity_disabled;
52 	/* just a name for the test-case; manadatory field */
53 	char			*name;
54 	char			*descr;
55 	unsigned long		feats_required;
56 	unsigned long		feats_incompatible;
57 	/* bitmask of effectively supported feats: populated at run-time */
58 	unsigned long		feats_supported;
59 	bool			initialized;
60 	unsigned int		minsigstksz;
61 	/* signum used as a test trigger. Zero if no trigger-signal is used */
62 	int			sig_trig;
63 	/*
64 	 * signum considered as a successful test completion.
65 	 * Zero when no signal is expected on success
66 	 */
67 	int			sig_ok;
68 	/* signum expected on unsupported CPU features. */
69 	int			sig_unsupp;
70 	/* a timeout in second for test completion */
71 	unsigned int		timeout;
72 	bool			triggered;
73 	bool			pass;
74 	unsigned int		result;
75 	/* optional sa_flags for the installed handler */
76 	int			sa_flags;
77 	ucontext_t		saved_uc;
78 	/* used by get_current_ctx() */
79 	size_t			live_sz;
80 	ucontext_t		*live_uc;
81 	volatile sig_atomic_t	live_uc_valid;
82 	/* optional test private data */
83 	void			*priv;
84 
85 	/* a custom setup: called alternatively to default_setup */
86 	int (*setup)(struct tdescr *td);
87 	/* a custom init: called by default test init after test_setup */
88 	bool (*init)(struct tdescr *td);
89 	/* a custom cleanup function called before test exits */
90 	void (*cleanup)(struct tdescr *td);
91 	/* an optional function to be used as a trigger for starting test */
92 	int (*trigger)(struct tdescr *td);
93 	/*
94 	 * the actual test-core: invoked differently depending on the
95 	 * presence of the trigger function above; this is mandatory
96 	 */
97 	int (*run)(struct tdescr *td, siginfo_t *si, ucontext_t *uc);
98 	/* an optional function for custom results' processing */
99 	void (*check_result)(struct tdescr *td);
100 };
101 
102 extern struct tdescr tde;
103 #endif
104