xref: /aosp_15_r20/external/ltp/include/old/test.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-only
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2009-2013 Cyril Hrubis [email protected]
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker #ifndef __TEST_H__
8*49cdfc7eSAndroid Build Coastguard Worker #define __TEST_H__
9*49cdfc7eSAndroid Build Coastguard Worker 
10*49cdfc7eSAndroid Build Coastguard Worker #ifdef TST_TEST_H__
11*49cdfc7eSAndroid Build Coastguard Worker # error Newlib tst_test.h already included
12*49cdfc7eSAndroid Build Coastguard Worker #endif /* TST_TEST_H__ */
13*49cdfc7eSAndroid Build Coastguard Worker 
14*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
18*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
19*49cdfc7eSAndroid Build Coastguard Worker #include <stdint.h>
20*49cdfc7eSAndroid Build Coastguard Worker 
21*49cdfc7eSAndroid Build Coastguard Worker #include "usctest.h"
22*49cdfc7eSAndroid Build Coastguard Worker 
23*49cdfc7eSAndroid Build Coastguard Worker #include "tst_common.h"
24*49cdfc7eSAndroid Build Coastguard Worker #include "old_safe_file_ops.h"
25*49cdfc7eSAndroid Build Coastguard Worker #include "old_checkpoint.h"
26*49cdfc7eSAndroid Build Coastguard Worker #include "tst_process_state.h"
27*49cdfc7eSAndroid Build Coastguard Worker #include "old_resource.h"
28*49cdfc7eSAndroid Build Coastguard Worker #include "tst_res_flags.h"
29*49cdfc7eSAndroid Build Coastguard Worker #include "tst_kvercmp.h"
30*49cdfc7eSAndroid Build Coastguard Worker #include "tst_fs.h"
31*49cdfc7eSAndroid Build Coastguard Worker #include "tst_pid.h"
32*49cdfc7eSAndroid Build Coastguard Worker #include "tst_cmd.h"
33*49cdfc7eSAndroid Build Coastguard Worker #include "tst_cpu.h"
34*49cdfc7eSAndroid Build Coastguard Worker #include "tst_clone.h"
35*49cdfc7eSAndroid Build Coastguard Worker #include "old_device.h"
36*49cdfc7eSAndroid Build Coastguard Worker #include "old_tmpdir.h"
37*49cdfc7eSAndroid Build Coastguard Worker #include "tst_minmax.h"
38*49cdfc7eSAndroid Build Coastguard Worker #include "tst_get_bad_addr.h"
39*49cdfc7eSAndroid Build Coastguard Worker #include "tst_path_has_mnt_flags.h"
40*49cdfc7eSAndroid Build Coastguard Worker 
41*49cdfc7eSAndroid Build Coastguard Worker /*
42*49cdfc7eSAndroid Build Coastguard Worker  * Ensure that NUMSIGS is defined.
43*49cdfc7eSAndroid Build Coastguard Worker  * It should be defined in signal.h or sys/signal.h on
44*49cdfc7eSAndroid Build Coastguard Worker  * UNICOS/mk and IRIX systems.   On UNICOS systems,
45*49cdfc7eSAndroid Build Coastguard Worker  * it is not defined, thus it is being set to UNICOS's NSIG.
46*49cdfc7eSAndroid Build Coastguard Worker  * Note:  IRIX's NSIG (signals are 1-(NSIG-1))
47*49cdfc7eSAndroid Build Coastguard Worker  *      is not same meaning as UNICOS/UMK's NSIG  (signals 1-NSIG)
48*49cdfc7eSAndroid Build Coastguard Worker  */
49*49cdfc7eSAndroid Build Coastguard Worker #ifndef NUMSIGS
50*49cdfc7eSAndroid Build Coastguard Worker #define NUMSIGS NSIG
51*49cdfc7eSAndroid Build Coastguard Worker #endif
52*49cdfc7eSAndroid Build Coastguard Worker 
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker /* defines for unexpected signal setup routine (set_usig.c) */
55*49cdfc7eSAndroid Build Coastguard Worker #define FORK    1		/* SIGCHLD is to be ignored */
56*49cdfc7eSAndroid Build Coastguard Worker #define NOFORK  0		/* SIGCHLD is to be caught */
57*49cdfc7eSAndroid Build Coastguard Worker #define DEF_HANDLER SIG_ERR	/* tells set_usig() to use default signal handler */
58*49cdfc7eSAndroid Build Coastguard Worker 
59*49cdfc7eSAndroid Build Coastguard Worker /*
60*49cdfc7eSAndroid Build Coastguard Worker  * The following defines are used to control tst_res and t_result reporting.
61*49cdfc7eSAndroid Build Coastguard Worker  */
62*49cdfc7eSAndroid Build Coastguard Worker 
63*49cdfc7eSAndroid Build Coastguard Worker #define TOUTPUT	   "TOUTPUT"		/* The name of the environment variable */
64*49cdfc7eSAndroid Build Coastguard Worker 					/* that can be set to one of the following */
65*49cdfc7eSAndroid Build Coastguard Worker 					/* strings to control tst_res output */
66*49cdfc7eSAndroid Build Coastguard Worker 					/* If not set, TOUT_VERBOSE_S is assumed */
67*49cdfc7eSAndroid Build Coastguard Worker 
68*49cdfc7eSAndroid Build Coastguard Worker /*
69*49cdfc7eSAndroid Build Coastguard Worker  * Macro to use for making functions called only once in
70*49cdfc7eSAndroid Build Coastguard Worker  * multi-threaded tests such as init or cleanup function.
71*49cdfc7eSAndroid Build Coastguard Worker  * The first call to @name_fn function by any thread shall
72*49cdfc7eSAndroid Build Coastguard Worker  * call the @exec_fn. Subsequent calls shall not call @exec_fn.
73*49cdfc7eSAndroid Build Coastguard Worker  * *_fn functions must not take any arguments.
74*49cdfc7eSAndroid Build Coastguard Worker  */
75*49cdfc7eSAndroid Build Coastguard Worker #define TST_DECLARE_ONCE_FN(name_fn, exec_fn)				\
76*49cdfc7eSAndroid Build Coastguard Worker 	void name_fn(void)						\
77*49cdfc7eSAndroid Build Coastguard Worker 	{								\
78*49cdfc7eSAndroid Build Coastguard Worker 		static pthread_once_t ltp_once = PTHREAD_ONCE_INIT;	\
79*49cdfc7eSAndroid Build Coastguard Worker 		pthread_once(&ltp_once, exec_fn);			\
80*49cdfc7eSAndroid Build Coastguard Worker 	}
81*49cdfc7eSAndroid Build Coastguard Worker 
82*49cdfc7eSAndroid Build Coastguard Worker /*
83*49cdfc7eSAndroid Build Coastguard Worker  * lib/forker.c
84*49cdfc7eSAndroid Build Coastguard Worker  */
85*49cdfc7eSAndroid Build Coastguard Worker extern int Forker_pids[];
86*49cdfc7eSAndroid Build Coastguard Worker extern int Forker_npids;
87*49cdfc7eSAndroid Build Coastguard Worker 
88*49cdfc7eSAndroid Build Coastguard Worker typedef struct {
89*49cdfc7eSAndroid Build Coastguard Worker 	char *option;	/* Valid option string (one option only) like "a:"  */
90*49cdfc7eSAndroid Build Coastguard Worker 	int  *flag;	/* Pointer to location to set true if option given  */
91*49cdfc7eSAndroid Build Coastguard Worker 	char **arg;	/* Pointer to location to place argument, if needed */
92*49cdfc7eSAndroid Build Coastguard Worker } option_t;
93*49cdfc7eSAndroid Build Coastguard Worker 
94*49cdfc7eSAndroid Build Coastguard Worker /* lib/tst_parse_opts.c */
95*49cdfc7eSAndroid Build Coastguard Worker void tst_parse_opts(int argc, char *argv[], const option_t *user_optarg,
96*49cdfc7eSAndroid Build Coastguard Worker                     void (*user_help)(void));
97*49cdfc7eSAndroid Build Coastguard Worker 
98*49cdfc7eSAndroid Build Coastguard Worker /* lib/tst_res.c */
99*49cdfc7eSAndroid Build Coastguard Worker const char *strttype(int ttype);
100*49cdfc7eSAndroid Build Coastguard Worker 
101*49cdfc7eSAndroid Build Coastguard Worker void tst_resm_(const char *file, const int lineno, int ttype,
102*49cdfc7eSAndroid Build Coastguard Worker 	const char *arg_fmt, ...)
103*49cdfc7eSAndroid Build Coastguard Worker 	__attribute__ ((format (printf, 4, 5)));
104*49cdfc7eSAndroid Build Coastguard Worker #define tst_resm(ttype, arg_fmt, ...) \
105*49cdfc7eSAndroid Build Coastguard Worker 	tst_resm_(__FILE__, __LINE__, (ttype), \
106*49cdfc7eSAndroid Build Coastguard Worker 		  (arg_fmt), ##__VA_ARGS__)
107*49cdfc7eSAndroid Build Coastguard Worker 
108*49cdfc7eSAndroid Build Coastguard Worker void tst_resm_hexd_(const char *file, const int lineno, int ttype,
109*49cdfc7eSAndroid Build Coastguard Worker 	const void *buf, size_t size, const char *arg_fmt, ...)
110*49cdfc7eSAndroid Build Coastguard Worker 	__attribute__ ((format (printf, 6, 7)));
111*49cdfc7eSAndroid Build Coastguard Worker #define tst_resm_hexd(ttype, buf, size, arg_fmt, ...) \
112*49cdfc7eSAndroid Build Coastguard Worker 	tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \
113*49cdfc7eSAndroid Build Coastguard Worker 		       (arg_fmt), ##__VA_ARGS__)
114*49cdfc7eSAndroid Build Coastguard Worker 
115*49cdfc7eSAndroid Build Coastguard Worker void tst_brkm__(const char *file, const int lineno, int ttype,
116*49cdfc7eSAndroid Build Coastguard Worker 	void (*func)(void), const char *arg_fmt, ...)
117*49cdfc7eSAndroid Build Coastguard Worker 	__attribute__ ((format (printf, 5, 6))) LTP_ATTRIBUTE_NORETURN;
118*49cdfc7eSAndroid Build Coastguard Worker 
119*49cdfc7eSAndroid Build Coastguard Worker #ifdef LTPLIB
120*49cdfc7eSAndroid Build Coastguard Worker # include "ltp_priv.h"
121*49cdfc7eSAndroid Build Coastguard Worker # define tst_brkm(flags, cleanup, fmt, ...) do { \
122*49cdfc7eSAndroid Build Coastguard Worker 	if (tst_test) \
123*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk_(__FILE__, __LINE__, flags, fmt, ##__VA_ARGS__); \
124*49cdfc7eSAndroid Build Coastguard Worker 	else \
125*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm__(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \
126*49cdfc7eSAndroid Build Coastguard Worker 	} while (0)
127*49cdfc7eSAndroid Build Coastguard Worker 
128*49cdfc7eSAndroid Build Coastguard Worker #define tst_brkm_(file, lineno, flags, cleanup, fmt, ...) do { \
129*49cdfc7eSAndroid Build Coastguard Worker 	if (tst_test) \
130*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk_(file, lineno, flags, fmt, ##__VA_ARGS__); \
131*49cdfc7eSAndroid Build Coastguard Worker 	else \
132*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm__(file, lineno, flags, cleanup, fmt, ##__VA_ARGS__); \
133*49cdfc7eSAndroid Build Coastguard Worker 	} while (0)
134*49cdfc7eSAndroid Build Coastguard Worker #else
135*49cdfc7eSAndroid Build Coastguard Worker # define tst_brkm(flags, cleanup, fmt, ...) do { \
136*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm__(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \
137*49cdfc7eSAndroid Build Coastguard Worker 	} while (0)
138*49cdfc7eSAndroid Build Coastguard Worker #endif
139*49cdfc7eSAndroid Build Coastguard Worker 
140*49cdfc7eSAndroid Build Coastguard Worker void tst_require_root(void);
141*49cdfc7eSAndroid Build Coastguard Worker void tst_exit(void) LTP_ATTRIBUTE_NORETURN;
142*49cdfc7eSAndroid Build Coastguard Worker void tst_old_flush(void);
143*49cdfc7eSAndroid Build Coastguard Worker 
144*49cdfc7eSAndroid Build Coastguard Worker /*
145*49cdfc7eSAndroid Build Coastguard Worker  * tst_old_flush() + fork
146*49cdfc7eSAndroid Build Coastguard Worker  * NOTE: tst_fork() will reset T_exitval to 0 for child process.
147*49cdfc7eSAndroid Build Coastguard Worker  */
148*49cdfc7eSAndroid Build Coastguard Worker pid_t tst_fork(void);
149*49cdfc7eSAndroid Build Coastguard Worker 
150*49cdfc7eSAndroid Build Coastguard Worker /* lib/tst_res.c */
151*49cdfc7eSAndroid Build Coastguard Worker /*
152*49cdfc7eSAndroid Build Coastguard Worker  * In case we need do real test work in child process parent process can use
153*49cdfc7eSAndroid Build Coastguard Worker  * tst_record_childstatus() to make child process's test results propagated to
154*49cdfc7eSAndroid Build Coastguard Worker  * parent process correctly.
155*49cdfc7eSAndroid Build Coastguard Worker  *
156*49cdfc7eSAndroid Build Coastguard Worker  * The child can use tst_resm(), tst_brkm() followed by the tst_exit() or
157*49cdfc7eSAndroid Build Coastguard Worker  * plain old exit() (with TPASS, TFAIL and TBROK).
158*49cdfc7eSAndroid Build Coastguard Worker  *
159*49cdfc7eSAndroid Build Coastguard Worker  * WARNING: Be wary that the child cleanup function passed to tst_brkm()
160*49cdfc7eSAndroid Build Coastguard Worker  *          must clean only resources the child has allocated. E.g. the
161*49cdfc7eSAndroid Build Coastguard Worker  *          child cleanup is different function from the parent cleanup.
162*49cdfc7eSAndroid Build Coastguard Worker  */
163*49cdfc7eSAndroid Build Coastguard Worker void tst_record_childstatus(void (*cleanup)(void), pid_t child);
164*49cdfc7eSAndroid Build Coastguard Worker 
165*49cdfc7eSAndroid Build Coastguard Worker extern int tst_count;
166*49cdfc7eSAndroid Build Coastguard Worker 
167*49cdfc7eSAndroid Build Coastguard Worker /* lib/tst_sig.c */
168*49cdfc7eSAndroid Build Coastguard Worker void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)());
169*49cdfc7eSAndroid Build Coastguard Worker 
170*49cdfc7eSAndroid Build Coastguard Worker /* lib/tst_mkfs.c
171*49cdfc7eSAndroid Build Coastguard Worker  *
172*49cdfc7eSAndroid Build Coastguard Worker  * @dev: path to a device
173*49cdfc7eSAndroid Build Coastguard Worker  * @fs_type: filesystem type
174*49cdfc7eSAndroid Build Coastguard Worker  * @fs_opts: NULL or NULL terminated array of mkfs options
175*49cdfc7eSAndroid Build Coastguard Worker  * @extra_opts: NULL or NULL terminated array of extra mkfs options which are
176*49cdfc7eSAndroid Build Coastguard Worker  * passed after the device name.
177*49cdfc7eSAndroid Build Coastguard Worker  */
178*49cdfc7eSAndroid Build Coastguard Worker #define tst_mkfs(cleanup, dev, fs_type, fs_opts, extra_opts) \
179*49cdfc7eSAndroid Build Coastguard Worker 	tst_mkfs_(__FILE__, __LINE__, cleanup, dev, fs_type, \
180*49cdfc7eSAndroid Build Coastguard Worker 		  fs_opts, extra_opts)
181*49cdfc7eSAndroid Build Coastguard Worker void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
182*49cdfc7eSAndroid Build Coastguard Worker 	       const char *dev, const char *fs_type,
183*49cdfc7eSAndroid Build Coastguard Worker 	       const char *const fs_opts[], const char *const extra_opts[]);
184*49cdfc7eSAndroid Build Coastguard Worker 
185*49cdfc7eSAndroid Build Coastguard Worker /* lib/tst_res.c
186*49cdfc7eSAndroid Build Coastguard Worker  * tst_strsig converts signal's value to corresponding string.
187*49cdfc7eSAndroid Build Coastguard Worker  * tst_strerrno converts errno to corresponding string.
188*49cdfc7eSAndroid Build Coastguard Worker  */
189*49cdfc7eSAndroid Build Coastguard Worker const char *tst_strsig(int sig);
190*49cdfc7eSAndroid Build Coastguard Worker const char *tst_strerrno(int err);
191*49cdfc7eSAndroid Build Coastguard Worker 
192*49cdfc7eSAndroid Build Coastguard Worker #ifdef TST_USE_COMPAT16_SYSCALL
193*49cdfc7eSAndroid Build Coastguard Worker #define TCID_BIT_SUFFIX "_16"
194*49cdfc7eSAndroid Build Coastguard Worker #elif  TST_USE_NEWER64_SYSCALL
195*49cdfc7eSAndroid Build Coastguard Worker #define TCID_BIT_SUFFIX "_64"
196*49cdfc7eSAndroid Build Coastguard Worker #else
197*49cdfc7eSAndroid Build Coastguard Worker #define TCID_BIT_SUFFIX ""
198*49cdfc7eSAndroid Build Coastguard Worker #endif
199*49cdfc7eSAndroid Build Coastguard Worker #define TCID_DEFINE(ID) char *TCID = (#ID TCID_BIT_SUFFIX)
200*49cdfc7eSAndroid Build Coastguard Worker 
201*49cdfc7eSAndroid Build Coastguard Worker #endif	/* __TEST_H__ */
202