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