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