xref: /linux/tools/testing/selftests/arm64/signal/test_signals.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
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 /*
12f2745dc0SGuillaume Tucker  * Using ARCH specific and sanitized Kernel headers from the tree.
13f96bf434SCristian Marussi  */
14f96bf434SCristian Marussi #include <asm/ptrace.h>
15f96bf434SCristian Marussi #include <asm/hwcap.h>
16f96bf434SCristian Marussi 
17f96bf434SCristian Marussi #define __stringify_1(x...)	#x
18f96bf434SCristian Marussi #define __stringify(x...)	__stringify_1(x)
19f96bf434SCristian Marussi 
20f96bf434SCristian Marussi #define get_regval(regname, out)			\
21f96bf434SCristian Marussi {							\
22f96bf434SCristian Marussi 	asm volatile("mrs %0, " __stringify(regname)	\
23f96bf434SCristian Marussi 	: "=r" (out)					\
24f96bf434SCristian Marussi 	:						\
25f96bf434SCristian Marussi 	: "memory");					\
26f96bf434SCristian Marussi }
27f96bf434SCristian Marussi 
28f96bf434SCristian Marussi /*
29f96bf434SCristian Marussi  * Feature flags used in tdescr.feats_required to specify
30f96bf434SCristian Marussi  * any feature by the test
31f96bf434SCristian Marussi  */
32f96bf434SCristian Marussi enum {
33f96bf434SCristian Marussi 	FSSBS_BIT,
34d4e4dc4fSMark Brown 	FSVE_BIT,
354963aeb3SMark Brown 	FSME_BIT,
364963aeb3SMark Brown 	FSME_FA64_BIT,
37*63829373SMark Brown 	FSME2_BIT,
38f96bf434SCristian Marussi 	FMAX_END
39f96bf434SCristian Marussi };
40f96bf434SCristian Marussi 
41f96bf434SCristian Marussi #define FEAT_SSBS		(1UL << FSSBS_BIT)
42d4e4dc4fSMark Brown #define FEAT_SVE		(1UL << FSVE_BIT)
434963aeb3SMark Brown #define FEAT_SME		(1UL << FSME_BIT)
444963aeb3SMark Brown #define FEAT_SME_FA64		(1UL << FSME_FA64_BIT)
45*63829373SMark Brown #define FEAT_SME2		(1UL << FSME2_BIT)
46f96bf434SCristian Marussi 
47f96bf434SCristian Marussi /*
48f96bf434SCristian Marussi  * A descriptor used to describe and configure a test case.
49f96bf434SCristian Marussi  * Fields with a non-trivial meaning are described inline in the following.
50f96bf434SCristian Marussi  */
51f96bf434SCristian Marussi struct tdescr {
52f96bf434SCristian Marussi 	/* KEEP THIS FIELD FIRST for easier lookup from assembly */
53f96bf434SCristian Marussi 	void			*token;
54f96bf434SCristian Marussi 	/* when disabled token based sanity checking is skipped in handler */
55f96bf434SCristian Marussi 	bool			sanity_disabled;
56f96bf434SCristian Marussi 	/* just a name for the test-case; manadatory field */
57f96bf434SCristian Marussi 	char			*name;
58f96bf434SCristian Marussi 	char			*descr;
59f96bf434SCristian Marussi 	unsigned long		feats_required;
6032de73e8SMark Brown 	unsigned long		feats_incompatible;
61f96bf434SCristian Marussi 	/* bitmask of effectively supported feats: populated at run-time */
62f96bf434SCristian Marussi 	unsigned long		feats_supported;
63f96bf434SCristian Marussi 	bool			initialized;
64f96bf434SCristian Marussi 	unsigned int		minsigstksz;
65f96bf434SCristian Marussi 	/* signum used as a test trigger. Zero if no trigger-signal is used */
66f96bf434SCristian Marussi 	int			sig_trig;
67f96bf434SCristian Marussi 	/*
68f96bf434SCristian Marussi 	 * signum considered as a successful test completion.
69f96bf434SCristian Marussi 	 * Zero when no signal is expected on success
70f96bf434SCristian Marussi 	 */
71f96bf434SCristian Marussi 	int			sig_ok;
72f96bf434SCristian Marussi 	/* signum expected on unsupported CPU features. */
73f96bf434SCristian Marussi 	int			sig_unsupp;
74f96bf434SCristian Marussi 	/* a timeout in second for test completion */
75f96bf434SCristian Marussi 	unsigned int		timeout;
76f96bf434SCristian Marussi 	bool			triggered;
77f96bf434SCristian Marussi 	bool			pass;
78837387a2SCristian Marussi 	unsigned int		result;
79f96bf434SCristian Marussi 	/* optional sa_flags for the installed handler */
80f96bf434SCristian Marussi 	int			sa_flags;
81f96bf434SCristian Marussi 	ucontext_t		saved_uc;
8234306b05SCristian Marussi 	/* used by get_current_ctx() */
8334306b05SCristian Marussi 	size_t			live_sz;
8434306b05SCristian Marussi 	ucontext_t		*live_uc;
8534306b05SCristian Marussi 	volatile sig_atomic_t	live_uc_valid;
86f96bf434SCristian Marussi 	/* optional test private data */
87f96bf434SCristian Marussi 	void			*priv;
88f96bf434SCristian Marussi 
89837387a2SCristian Marussi 	/* a custom setup: called alternatively to default_setup */
90f96bf434SCristian Marussi 	int (*setup)(struct tdescr *td);
91837387a2SCristian Marussi 	/* a custom init: called by default test init after test_setup */
92837387a2SCristian Marussi 	bool (*init)(struct tdescr *td);
93f96bf434SCristian Marussi 	/* a custom cleanup function called before test exits */
94f96bf434SCristian Marussi 	void (*cleanup)(struct tdescr *td);
95837387a2SCristian Marussi 	/* an optional function to be used as a trigger for starting test */
96f96bf434SCristian Marussi 	int (*trigger)(struct tdescr *td);
97f96bf434SCristian Marussi 	/*
98f96bf434SCristian Marussi 	 * the actual test-core: invoked differently depending on the
99f96bf434SCristian Marussi 	 * presence of the trigger function above; this is mandatory
100f96bf434SCristian Marussi 	 */
101f96bf434SCristian Marussi 	int (*run)(struct tdescr *td, siginfo_t *si, ucontext_t *uc);
102f96bf434SCristian Marussi 	/* an optional function for custom results' processing */
103f96bf434SCristian Marussi 	void (*check_result)(struct tdescr *td);
104f96bf434SCristian Marussi };
105f96bf434SCristian Marussi 
106f96bf434SCristian Marussi extern struct tdescr tde;
107f96bf434SCristian Marussi #endif
108