1*49cdfc7eSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0-or-later */
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2015-2016 Cyril Hrubis <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) Linux Test Project, 2016-2024
5*49cdfc7eSAndroid Build Coastguard Worker */
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_TEST_H__
8*49cdfc7eSAndroid Build Coastguard Worker #define TST_TEST_H__
9*49cdfc7eSAndroid Build Coastguard Worker
10*49cdfc7eSAndroid Build Coastguard Worker #ifdef __TEST_H__
11*49cdfc7eSAndroid Build Coastguard Worker # error Oldlib test.h already included
12*49cdfc7eSAndroid Build Coastguard Worker #endif /* __TEST_H__ */
13*49cdfc7eSAndroid Build Coastguard Worker
14*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <limits.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
18*49cdfc7eSAndroid Build Coastguard Worker #include <sys/resource.h>
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker #include "tst_common.h"
21*49cdfc7eSAndroid Build Coastguard Worker #include "tst_res_flags.h"
22*49cdfc7eSAndroid Build Coastguard Worker #include "tst_parse.h"
23*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test_macros.h"
24*49cdfc7eSAndroid Build Coastguard Worker #include "tst_checkpoint.h"
25*49cdfc7eSAndroid Build Coastguard Worker #include "tst_device.h"
26*49cdfc7eSAndroid Build Coastguard Worker #include "tst_mkfs.h"
27*49cdfc7eSAndroid Build Coastguard Worker #include "tst_fs.h"
28*49cdfc7eSAndroid Build Coastguard Worker #include "tst_pid.h"
29*49cdfc7eSAndroid Build Coastguard Worker #include "tst_cmd.h"
30*49cdfc7eSAndroid Build Coastguard Worker #include "tst_cpu.h"
31*49cdfc7eSAndroid Build Coastguard Worker #include "tst_process_state.h"
32*49cdfc7eSAndroid Build Coastguard Worker #include "tst_atomic.h"
33*49cdfc7eSAndroid Build Coastguard Worker #include "tst_kvercmp.h"
34*49cdfc7eSAndroid Build Coastguard Worker #include "tst_kernel.h"
35*49cdfc7eSAndroid Build Coastguard Worker #include "tst_minmax.h"
36*49cdfc7eSAndroid Build Coastguard Worker #include "tst_get_bad_addr.h"
37*49cdfc7eSAndroid Build Coastguard Worker #include "tst_path_has_mnt_flags.h"
38*49cdfc7eSAndroid Build Coastguard Worker #include "tst_sys_conf.h"
39*49cdfc7eSAndroid Build Coastguard Worker #include "tst_coredump.h"
40*49cdfc7eSAndroid Build Coastguard Worker #include "tst_buffers.h"
41*49cdfc7eSAndroid Build Coastguard Worker #include "tst_capability.h"
42*49cdfc7eSAndroid Build Coastguard Worker #include "tst_hugepage.h"
43*49cdfc7eSAndroid Build Coastguard Worker #include "tst_assert.h"
44*49cdfc7eSAndroid Build Coastguard Worker #include "tst_security.h"
45*49cdfc7eSAndroid Build Coastguard Worker #include "tst_taint.h"
46*49cdfc7eSAndroid Build Coastguard Worker #include "tst_memutils.h"
47*49cdfc7eSAndroid Build Coastguard Worker #include "tst_arch.h"
48*49cdfc7eSAndroid Build Coastguard Worker #include "tst_fd.h"
49*49cdfc7eSAndroid Build Coastguard Worker
50*49cdfc7eSAndroid Build Coastguard Worker void tst_res_(const char *file, const int lineno, int ttype,
51*49cdfc7eSAndroid Build Coastguard Worker const char *fmt, ...)
52*49cdfc7eSAndroid Build Coastguard Worker __attribute__ ((format (printf, 4, 5)));
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker /**
55*49cdfc7eSAndroid Build Coastguard Worker * tst_res() - Reports a test result.
56*49cdfc7eSAndroid Build Coastguard Worker *
57*49cdfc7eSAndroid Build Coastguard Worker * @ttype: An enum tst_res_type.
58*49cdfc7eSAndroid Build Coastguard Worker * @arg_fmt: A printf-like format.
59*49cdfc7eSAndroid Build Coastguard Worker * @...: A printf-like parameters.
60*49cdfc7eSAndroid Build Coastguard Worker *
61*49cdfc7eSAndroid Build Coastguard Worker * This is the main test reporting function. Each time this function is called
62*49cdfc7eSAndroid Build Coastguard Worker * with one of TPASS, TFAIL, TCONF, TBROK or TWARN a counter in page of shared
63*49cdfc7eSAndroid Build Coastguard Worker * memory is incremented. This means that there is no need to propagate test
64*49cdfc7eSAndroid Build Coastguard Worker * results from children and that results are accounted for once this function
65*49cdfc7eSAndroid Build Coastguard Worker * returns. The counters are incremented atomically which makes this function
66*49cdfc7eSAndroid Build Coastguard Worker * thread-safe.
67*49cdfc7eSAndroid Build Coastguard Worker */
68*49cdfc7eSAndroid Build Coastguard Worker #define tst_res(ttype, arg_fmt, ...) \
69*49cdfc7eSAndroid Build Coastguard Worker ({ \
70*49cdfc7eSAndroid Build Coastguard Worker TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN(\
71*49cdfc7eSAndroid Build Coastguard Worker !((TTYPE_RESULT(ttype) ?: TCONF) & \
72*49cdfc7eSAndroid Build Coastguard Worker (TCONF | TDEBUG | TFAIL | TINFO | TPASS | TWARN))); \
73*49cdfc7eSAndroid Build Coastguard Worker tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
74*49cdfc7eSAndroid Build Coastguard Worker })
75*49cdfc7eSAndroid Build Coastguard Worker
76*49cdfc7eSAndroid Build Coastguard Worker void tst_resm_hexd_(const char *file, const int lineno, int ttype,
77*49cdfc7eSAndroid Build Coastguard Worker const void *buf, size_t size, const char *arg_fmt, ...)
78*49cdfc7eSAndroid Build Coastguard Worker __attribute__ ((format (printf, 6, 7)));
79*49cdfc7eSAndroid Build Coastguard Worker /**
80*49cdfc7eSAndroid Build Coastguard Worker * tst_res_hexd() - Reports a test result along with hex dump of a buffer.
81*49cdfc7eSAndroid Build Coastguard Worker *
82*49cdfc7eSAndroid Build Coastguard Worker * This call is the same as tst_res() but includes a pointer and size of the
83*49cdfc7eSAndroid Build Coastguard Worker * buffer that is going to be printed in the output in a hexadecimal format.
84*49cdfc7eSAndroid Build Coastguard Worker *
85*49cdfc7eSAndroid Build Coastguard Worker * @ttype: An enum tst_res_type.
86*49cdfc7eSAndroid Build Coastguard Worker * @buf: A pointer to a buffer to print in hexadecimal format.
87*49cdfc7eSAndroid Build Coastguard Worker * @size: A size of the buffer.
88*49cdfc7eSAndroid Build Coastguard Worker * @arg_fmt: A printf-like format.
89*49cdfc7eSAndroid Build Coastguard Worker * @...: A printf-like parameters.
90*49cdfc7eSAndroid Build Coastguard Worker */
91*49cdfc7eSAndroid Build Coastguard Worker #define tst_res_hexd(ttype, buf, size, arg_fmt, ...) \
92*49cdfc7eSAndroid Build Coastguard Worker tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \
93*49cdfc7eSAndroid Build Coastguard Worker (arg_fmt), ##__VA_ARGS__)
94*49cdfc7eSAndroid Build Coastguard Worker
95*49cdfc7eSAndroid Build Coastguard Worker void tst_brk_(const char *file, const int lineno, int ttype,
96*49cdfc7eSAndroid Build Coastguard Worker const char *fmt, ...)
97*49cdfc7eSAndroid Build Coastguard Worker __attribute__ ((format (printf, 4, 5)));
98*49cdfc7eSAndroid Build Coastguard Worker
99*49cdfc7eSAndroid Build Coastguard Worker /**
100*49cdfc7eSAndroid Build Coastguard Worker * tst_brk() - Reports a breakage and exits the test.
101*49cdfc7eSAndroid Build Coastguard Worker *
102*49cdfc7eSAndroid Build Coastguard Worker * @ttype: An enum tst_res_type.
103*49cdfc7eSAndroid Build Coastguard Worker * @arg_fmt: A printf-like format.
104*49cdfc7eSAndroid Build Coastguard Worker * @...: A printf-like parameters.
105*49cdfc7eSAndroid Build Coastguard Worker *
106*49cdfc7eSAndroid Build Coastguard Worker * Reports either TBROK or TCONF and exits the test immediately. When called
107*49cdfc7eSAndroid Build Coastguard Worker * all children in the same process group as the main test library process are
108*49cdfc7eSAndroid Build Coastguard Worker * killed. This function, unless in a test cleanup, calls _exit() and does not
109*49cdfc7eSAndroid Build Coastguard Worker * return.
110*49cdfc7eSAndroid Build Coastguard Worker *
111*49cdfc7eSAndroid Build Coastguard Worker * When test is in cleanup() function TBROK is converted into TWARN by the test
112*49cdfc7eSAndroid Build Coastguard Worker * library and we attempt to carry on with a cleanup even when tst_brk() was
113*49cdfc7eSAndroid Build Coastguard Worker * called. This makes it possible to use SAFE_FOO() macros in the test cleanup
114*49cdfc7eSAndroid Build Coastguard Worker * without interrupting the cleanup process on a failure.
115*49cdfc7eSAndroid Build Coastguard Worker */
116*49cdfc7eSAndroid Build Coastguard Worker #define tst_brk(ttype, arg_fmt, ...) \
117*49cdfc7eSAndroid Build Coastguard Worker ({ \
118*49cdfc7eSAndroid Build Coastguard Worker TST_BRK_SUPPORTS_ONLY_TCONF_TBROK(!((ttype) & \
119*49cdfc7eSAndroid Build Coastguard Worker (TBROK | TCONF | TFAIL))); \
120*49cdfc7eSAndroid Build Coastguard Worker tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
121*49cdfc7eSAndroid Build Coastguard Worker })
122*49cdfc7eSAndroid Build Coastguard Worker
123*49cdfc7eSAndroid Build Coastguard Worker void tst_printf(const char *const fmt, ...)
124*49cdfc7eSAndroid Build Coastguard Worker __attribute__((nonnull(1), format (printf, 1, 2)));
125*49cdfc7eSAndroid Build Coastguard Worker
126*49cdfc7eSAndroid Build Coastguard Worker /**
127*49cdfc7eSAndroid Build Coastguard Worker * tst_flush() - Flushes the output file streams.
128*49cdfc7eSAndroid Build Coastguard Worker *
129*49cdfc7eSAndroid Build Coastguard Worker * There are rare cases when we want to flush the output file streams
130*49cdfc7eSAndroid Build Coastguard Worker * explicitly, e.g. before we do an action that may crash the test to ensure
131*49cdfc7eSAndroid Build Coastguard Worker * that the messages have been written out.
132*49cdfc7eSAndroid Build Coastguard Worker *
133*49cdfc7eSAndroid Build Coastguard Worker * This is also called by the SAFE_FORK() because otherwise each child would
134*49cdfc7eSAndroid Build Coastguard Worker * end up with the same copy of the file in it's memory and any messages in
135*49cdfc7eSAndroid Build Coastguard Worker * buffers would be multiplied.
136*49cdfc7eSAndroid Build Coastguard Worker */
137*49cdfc7eSAndroid Build Coastguard Worker void tst_flush(void);
138*49cdfc7eSAndroid Build Coastguard Worker
139*49cdfc7eSAndroid Build Coastguard Worker pid_t safe_fork(const char *filename, unsigned int lineno);
140*49cdfc7eSAndroid Build Coastguard Worker /**
141*49cdfc7eSAndroid Build Coastguard Worker * SAFE_FORK() - Forks a test child.
142*49cdfc7eSAndroid Build Coastguard Worker *
143*49cdfc7eSAndroid Build Coastguard Worker * This call makes sure that output file streams are flushed and also handles
144*49cdfc7eSAndroid Build Coastguard Worker * errors from fork(). Use this instead of fork() whenever possible!
145*49cdfc7eSAndroid Build Coastguard Worker */
146*49cdfc7eSAndroid Build Coastguard Worker #define SAFE_FORK() \
147*49cdfc7eSAndroid Build Coastguard Worker safe_fork(__FILE__, __LINE__)
148*49cdfc7eSAndroid Build Coastguard Worker
149*49cdfc7eSAndroid Build Coastguard Worker #define TST_TRACE(expr) \
150*49cdfc7eSAndroid Build Coastguard Worker ({int ret = expr; \
151*49cdfc7eSAndroid Build Coastguard Worker ret != 0 ? tst_res(TINFO, #expr " failed"), ret : ret; }) \
152*49cdfc7eSAndroid Build Coastguard Worker
153*49cdfc7eSAndroid Build Coastguard Worker /**
154*49cdfc7eSAndroid Build Coastguard Worker * tst_strerrno() - Converts an errno number into a name.
155*49cdfc7eSAndroid Build Coastguard Worker *
156*49cdfc7eSAndroid Build Coastguard Worker * @err: An errno number.
157*49cdfc7eSAndroid Build Coastguard Worker * return: An errno name e.g. "EINVAL".
158*49cdfc7eSAndroid Build Coastguard Worker */
159*49cdfc7eSAndroid Build Coastguard Worker const char *tst_strerrno(int err);
160*49cdfc7eSAndroid Build Coastguard Worker
161*49cdfc7eSAndroid Build Coastguard Worker /**
162*49cdfc7eSAndroid Build Coastguard Worker * tst_strsig() - Converts a signal number into a name.
163*49cdfc7eSAndroid Build Coastguard Worker *
164*49cdfc7eSAndroid Build Coastguard Worker * @sig: A signal number.
165*49cdfc7eSAndroid Build Coastguard Worker * return: A signal name e.g. "SIGINT".
166*49cdfc7eSAndroid Build Coastguard Worker */
167*49cdfc7eSAndroid Build Coastguard Worker const char *tst_strsig(int sig);
168*49cdfc7eSAndroid Build Coastguard Worker
169*49cdfc7eSAndroid Build Coastguard Worker
170*49cdfc7eSAndroid Build Coastguard Worker /**
171*49cdfc7eSAndroid Build Coastguard Worker * tst_strstatus() - Returns string describing status as returned by wait().
172*49cdfc7eSAndroid Build Coastguard Worker *
173*49cdfc7eSAndroid Build Coastguard Worker * WARNING: Not thread safe.
174*49cdfc7eSAndroid Build Coastguard Worker *
175*49cdfc7eSAndroid Build Coastguard Worker * @status: A status as returned by wait()
176*49cdfc7eSAndroid Build Coastguard Worker * return: A string description for the status e.g. "killed by SIGKILL".
177*49cdfc7eSAndroid Build Coastguard Worker */
178*49cdfc7eSAndroid Build Coastguard Worker const char *tst_strstatus(int status);
179*49cdfc7eSAndroid Build Coastguard Worker
180*49cdfc7eSAndroid Build Coastguard Worker #include "tst_safe_macros.h"
181*49cdfc7eSAndroid Build Coastguard Worker #include "tst_safe_file_ops.h"
182*49cdfc7eSAndroid Build Coastguard Worker #include "tst_safe_net.h"
183*49cdfc7eSAndroid Build Coastguard Worker #include "tst_clone.h"
184*49cdfc7eSAndroid Build Coastguard Worker #include "tst_cgroup.h"
185*49cdfc7eSAndroid Build Coastguard Worker
186*49cdfc7eSAndroid Build Coastguard Worker /**
187*49cdfc7eSAndroid Build Coastguard Worker * tst_reap_children() - Waits for all child processes to exit.
188*49cdfc7eSAndroid Build Coastguard Worker *
189*49cdfc7eSAndroid Build Coastguard Worker * Wait for all children and exit with TBROK if any of them returned a non-zero
190*49cdfc7eSAndroid Build Coastguard Worker * exit status.
191*49cdfc7eSAndroid Build Coastguard Worker */
192*49cdfc7eSAndroid Build Coastguard Worker void tst_reap_children(void);
193*49cdfc7eSAndroid Build Coastguard Worker
194*49cdfc7eSAndroid Build Coastguard Worker /**
195*49cdfc7eSAndroid Build Coastguard Worker * struct tst_option - Test command line option.
196*49cdfc7eSAndroid Build Coastguard Worker *
197*49cdfc7eSAndroid Build Coastguard Worker * @optstr: A short command line option, e.g. "a" or "a:".
198*49cdfc7eSAndroid Build Coastguard Worker * @arg: A pointer to store the option value to.
199*49cdfc7eSAndroid Build Coastguard Worker * @help: A help string for the option displayed when test is passed '-h' on
200*49cdfc7eSAndroid Build Coastguard Worker * the command-line.
201*49cdfc7eSAndroid Build Coastguard Worker */
202*49cdfc7eSAndroid Build Coastguard Worker struct tst_option {
203*49cdfc7eSAndroid Build Coastguard Worker char *optstr;
204*49cdfc7eSAndroid Build Coastguard Worker char **arg;
205*49cdfc7eSAndroid Build Coastguard Worker char *help;
206*49cdfc7eSAndroid Build Coastguard Worker };
207*49cdfc7eSAndroid Build Coastguard Worker
208*49cdfc7eSAndroid Build Coastguard Worker /**
209*49cdfc7eSAndroid Build Coastguard Worker * struct tst_tag - A test tag.
210*49cdfc7eSAndroid Build Coastguard Worker *
211*49cdfc7eSAndroid Build Coastguard Worker * @name: A tag name.
212*49cdfc7eSAndroid Build Coastguard Worker * @value: A tag value.
213*49cdfc7eSAndroid Build Coastguard Worker *
214*49cdfc7eSAndroid Build Coastguard Worker * This structure is used to encode pointers to upstream commits in regression
215*49cdfc7eSAndroid Build Coastguard Worker * tests as well as CVE numbers or any additional useful hints.
216*49cdfc7eSAndroid Build Coastguard Worker *
217*49cdfc7eSAndroid Build Coastguard Worker * The content of these tags is printed by the test on a failure to help the
218*49cdfc7eSAndroid Build Coastguard Worker * testers with debugging.
219*49cdfc7eSAndroid Build Coastguard Worker *
220*49cdfc7eSAndroid Build Coastguard Worker * The supported tags are:
221*49cdfc7eSAndroid Build Coastguard Worker *
222*49cdfc7eSAndroid Build Coastguard Worker * - "linux-git" with first 12 numbers from an upstream kernel git hash.
223*49cdfc7eSAndroid Build Coastguard Worker * - "CVE" with a CVE number e.g. "2000-1234".
224*49cdfc7eSAndroid Build Coastguard Worker * - "glibc-git" with first 12 numbers from an upstream glibc git hash.
225*49cdfc7eSAndroid Build Coastguard Worker * - "musl-git" with first 12 numbers from an upstream musl git hash.
226*49cdfc7eSAndroid Build Coastguard Worker * - "known-fail" a message describing something that is supposed to work but
227*49cdfc7eSAndroid Build Coastguard Worker * rather than that produces a longstanding failures.
228*49cdfc7eSAndroid Build Coastguard Worker */
229*49cdfc7eSAndroid Build Coastguard Worker struct tst_tag {
230*49cdfc7eSAndroid Build Coastguard Worker const char *name;
231*49cdfc7eSAndroid Build Coastguard Worker const char *value;
232*49cdfc7eSAndroid Build Coastguard Worker };
233*49cdfc7eSAndroid Build Coastguard Worker
234*49cdfc7eSAndroid Build Coastguard Worker extern unsigned int tst_variant;
235*49cdfc7eSAndroid Build Coastguard Worker
236*49cdfc7eSAndroid Build Coastguard Worker #define TST_UNLIMITED_RUNTIME (-1)
237*49cdfc7eSAndroid Build Coastguard Worker
238*49cdfc7eSAndroid Build Coastguard Worker /**
239*49cdfc7eSAndroid Build Coastguard Worker * struct tst_ulimit_val - An ulimit resource and value.
240*49cdfc7eSAndroid Build Coastguard Worker *
241*49cdfc7eSAndroid Build Coastguard Worker * @resource: Which resource limits should be adjusted. See setrlimit(2) for
242*49cdfc7eSAndroid Build Coastguard Worker * the list of the RLIMIT_* constants.
243*49cdfc7eSAndroid Build Coastguard Worker * @rlim_cur: A limit value.
244*49cdfc7eSAndroid Build Coastguard Worker */
245*49cdfc7eSAndroid Build Coastguard Worker struct tst_ulimit_val {
246*49cdfc7eSAndroid Build Coastguard Worker int resource;
247*49cdfc7eSAndroid Build Coastguard Worker rlim_t rlim_cur;
248*49cdfc7eSAndroid Build Coastguard Worker };
249*49cdfc7eSAndroid Build Coastguard Worker
250*49cdfc7eSAndroid Build Coastguard Worker /**
251*49cdfc7eSAndroid Build Coastguard Worker * struct tst_test - A test description.
252*49cdfc7eSAndroid Build Coastguard Worker *
253*49cdfc7eSAndroid Build Coastguard Worker * @tcnt: A number of tests. If set the test() callback is called tcnt times
254*49cdfc7eSAndroid Build Coastguard Worker * and each time passed an increasing counter value.
255*49cdfc7eSAndroid Build Coastguard Worker * @options: An NULL optstr terminated array of struct tst_option.
256*49cdfc7eSAndroid Build Coastguard Worker *
257*49cdfc7eSAndroid Build Coastguard Worker * @min_kver: A minimal kernel version the test can run on. e.g. "3.10".
258*49cdfc7eSAndroid Build Coastguard Worker *
259*49cdfc7eSAndroid Build Coastguard Worker * @supported_archs: A NULL terminated array of architectures the test runs on
260*49cdfc7eSAndroid Build Coastguard Worker * e.g. {"x86_64, "x86", NULL}. Calls tst_is_on_arch() to
261*49cdfc7eSAndroid Build Coastguard Worker * check if current CPU architecture is supported and exits
262*49cdfc7eSAndroid Build Coastguard Worker * the test with TCONF if it's not.
263*49cdfc7eSAndroid Build Coastguard Worker *
264*49cdfc7eSAndroid Build Coastguard Worker * @tconf_msg: If set the test exits with TCONF right after entering the test
265*49cdfc7eSAndroid Build Coastguard Worker * library. This is used by the TST_TEST_TCONF() macro to disable
266*49cdfc7eSAndroid Build Coastguard Worker * tests at compile time.
267*49cdfc7eSAndroid Build Coastguard Worker *
268*49cdfc7eSAndroid Build Coastguard Worker * @needs_tmpdir: If set a temporary directory is prepared for the test inside
269*49cdfc7eSAndroid Build Coastguard Worker * $TMPDIR and the test $CWD is set to point to it. The content
270*49cdfc7eSAndroid Build Coastguard Worker * of the temporary directory is removed automatically after
271*49cdfc7eSAndroid Build Coastguard Worker * the test is finished.
272*49cdfc7eSAndroid Build Coastguard Worker *
273*49cdfc7eSAndroid Build Coastguard Worker * @needs_root: If set the test exit with TCONF unless it's executed under root
274*49cdfc7eSAndroid Build Coastguard Worker * user.
275*49cdfc7eSAndroid Build Coastguard Worker *
276*49cdfc7eSAndroid Build Coastguard Worker * @forks_child: Has to be set if the test intends to fork children.
277*49cdfc7eSAndroid Build Coastguard Worker *
278*49cdfc7eSAndroid Build Coastguard Worker * @needs_device: If set a block device is prepared for the test, the device
279*49cdfc7eSAndroid Build Coastguard Worker * path and size are set in the struct tst_device variable
280*49cdfc7eSAndroid Build Coastguard Worker * called tst_device. If $LTP_DEV variable exists in the test
281*49cdfc7eSAndroid Build Coastguard Worker * environment the test attempts to use that device first and
282*49cdfc7eSAndroid Build Coastguard Worker * only if that fails the test falls back to use loop devices.
283*49cdfc7eSAndroid Build Coastguard Worker * This flag implies needs_tmpdir flag because loop device
284*49cdfc7eSAndroid Build Coastguard Worker * backing files are created in the test temporary directory.
285*49cdfc7eSAndroid Build Coastguard Worker *
286*49cdfc7eSAndroid Build Coastguard Worker * @needs_checkpoints: Has to be set if the test wants to use checkpoint
287*49cdfc7eSAndroid Build Coastguard Worker * synchronization primitives.
288*49cdfc7eSAndroid Build Coastguard Worker *
289*49cdfc7eSAndroid Build Coastguard Worker * @needs_overlay: If set overlay file system is mounted on the top of the
290*49cdfc7eSAndroid Build Coastguard Worker * file system at tst_test.mntpoint.
291*49cdfc7eSAndroid Build Coastguard Worker *
292*49cdfc7eSAndroid Build Coastguard Worker * @format_device: Does all tst_test.needs_device would do and also formats
293*49cdfc7eSAndroid Build Coastguard Worker * the device with tst_test.dev_fs_type file system as well.
294*49cdfc7eSAndroid Build Coastguard Worker *
295*49cdfc7eSAndroid Build Coastguard Worker * @mount_device: Does all tst_test.format_device would do and also mounts the
296*49cdfc7eSAndroid Build Coastguard Worker * device at tst_test.mntpoint.
297*49cdfc7eSAndroid Build Coastguard Worker *
298*49cdfc7eSAndroid Build Coastguard Worker * @needs_rofs: If set a read-only file system is mounted at tst_test.mntpoint.
299*49cdfc7eSAndroid Build Coastguard Worker *
300*49cdfc7eSAndroid Build Coastguard Worker * @child_needs_reinit: Has to be set if the test needs to call tst_reinit()
301*49cdfc7eSAndroid Build Coastguard Worker * from a process started by exec().
302*49cdfc7eSAndroid Build Coastguard Worker *
303*49cdfc7eSAndroid Build Coastguard Worker * @needs_devfs: If set the devfs is mounted at tst_test.mntpoint. This is
304*49cdfc7eSAndroid Build Coastguard Worker * needed for tests that need to create device files since tmpfs
305*49cdfc7eSAndroid Build Coastguard Worker * at /tmp is usually mounted with 'nodev' option.
306*49cdfc7eSAndroid Build Coastguard Worker *
307*49cdfc7eSAndroid Build Coastguard Worker * @restore_wallclock: Saves wall clock at the start of the test and restores
308*49cdfc7eSAndroid Build Coastguard Worker * it at the end with the help of monotonic timers.
309*49cdfc7eSAndroid Build Coastguard Worker * Testcases that modify system wallclock use this to
310*49cdfc7eSAndroid Build Coastguard Worker * restore the system to the previous state.
311*49cdfc7eSAndroid Build Coastguard Worker *
312*49cdfc7eSAndroid Build Coastguard Worker * @all_filesystems: If set the test is executed for all supported filesytems,
313*49cdfc7eSAndroid Build Coastguard Worker * i.e. file system that is supported by the kernel and has
314*49cdfc7eSAndroid Build Coastguard Worker * mkfs installed on the system.The file system is mounted at
315*49cdfc7eSAndroid Build Coastguard Worker * tst_test.mntpoint and file system details, e.g. type are set
316*49cdfc7eSAndroid Build Coastguard Worker * in the struct tst_device. Each execution is independent,
317*49cdfc7eSAndroid Build Coastguard Worker * that means that for each iteration tst_test.setup() is
318*49cdfc7eSAndroid Build Coastguard Worker * called at the test start and tst_test.cleanup() is called
319*49cdfc7eSAndroid Build Coastguard Worker * at the end and tst_brk() only exits test for a single
320*49cdfc7eSAndroid Build Coastguard Worker * file system. That especially means that calling
321*49cdfc7eSAndroid Build Coastguard Worker * tst_brk(TCONF, ...) in the test setup will skip the
322*49cdfc7eSAndroid Build Coastguard Worker * current file system.
323*49cdfc7eSAndroid Build Coastguard Worker *
324*49cdfc7eSAndroid Build Coastguard Worker * @skip_in_lockdown: Skip the test if kernel lockdown is enabled.
325*49cdfc7eSAndroid Build Coastguard Worker *
326*49cdfc7eSAndroid Build Coastguard Worker * @skip_in_secureboot: Skip the test if secureboot is enabled.
327*49cdfc7eSAndroid Build Coastguard Worker *
328*49cdfc7eSAndroid Build Coastguard Worker * @skip_in_compat: Skip the test if we are executing 32bit binary on a 64bit
329*49cdfc7eSAndroid Build Coastguard Worker * kernel, i.e. we are testing the kernel compat layer.
330*49cdfc7eSAndroid Build Coastguard Worker *
331*49cdfc7eSAndroid Build Coastguard Worker * @needs_abi_bits: Skip the test if runs on a different kernel ABI than
332*49cdfc7eSAndroid Build Coastguard Worker * requested (on 32bit instead of 64bit or vice versa).
333*49cdfc7eSAndroid Build Coastguard Worker * Possible values: 32, 64.
334*49cdfc7eSAndroid Build Coastguard Worker *
335*49cdfc7eSAndroid Build Coastguard Worker * @needs_hugetlbfs: If set hugetlbfs is mounted at tst_test.mntpoint.
336*49cdfc7eSAndroid Build Coastguard Worker *
337*49cdfc7eSAndroid Build Coastguard Worker * @skip_filesystems: A NULL terminated array of unsupported file systems. The
338*49cdfc7eSAndroid Build Coastguard Worker * test reports TCONF if the file system to be tested is
339*49cdfc7eSAndroid Build Coastguard Worker * present in the array. This is especially useful to filter
340*49cdfc7eSAndroid Build Coastguard Worker * out unsupported file system when tst_test.all_filesystems
341*49cdfc7eSAndroid Build Coastguard Worker * is enabled.
342*49cdfc7eSAndroid Build Coastguard Worker *
343*49cdfc7eSAndroid Build Coastguard Worker * @min_cpus: Minimal number of online CPUs the test needs to run.
344*49cdfc7eSAndroid Build Coastguard Worker *
345*49cdfc7eSAndroid Build Coastguard Worker * @min_mem_avail: Minimal amount of available RAM memory in megabytes required
346*49cdfc7eSAndroid Build Coastguard Worker * for the test to run.
347*49cdfc7eSAndroid Build Coastguard Worker *
348*49cdfc7eSAndroid Build Coastguard Worker * @min_swap_avail: Minimal amount of available swap memory in megabytes
349*49cdfc7eSAndroid Build Coastguard Worker * required for the test to run.
350*49cdfc7eSAndroid Build Coastguard Worker *
351*49cdfc7eSAndroid Build Coastguard Worker * @hugepages: An interface to reserve hugepages prior running the test.
352*49cdfc7eSAndroid Build Coastguard Worker * Request how many hugepages should be reserved in the global
353*49cdfc7eSAndroid Build Coastguard Worker * pool and also if having hugepages is required for the test run
354*49cdfc7eSAndroid Build Coastguard Worker * or not, i.e. if test should exit with TCONF if the requested
355*49cdfc7eSAndroid Build Coastguard Worker * amount of hugepages cannot be reserved. If TST_REQUEST is set
356*49cdfc7eSAndroid Build Coastguard Worker * the library will try it's best to reserve the hugepages and
357*49cdfc7eSAndroid Build Coastguard Worker * return the number of available hugepages in tst_hugepages, which
358*49cdfc7eSAndroid Build Coastguard Worker * may be 0 if there is no free memory or hugepages are not
359*49cdfc7eSAndroid Build Coastguard Worker * supported at all. If TST_NEEDS the requested hugepages are
360*49cdfc7eSAndroid Build Coastguard Worker * required for the test and the test exits if it couldn't be
361*49cdfc7eSAndroid Build Coastguard Worker * required. It can also be used to disable hugepages by setting
362*49cdfc7eSAndroid Build Coastguard Worker * .hugepages = {TST_NO_HUGEPAGES}. The test library restores the
363*49cdfc7eSAndroid Build Coastguard Worker * original poll allocations after the test has finished.
364*49cdfc7eSAndroid Build Coastguard Worker *
365*49cdfc7eSAndroid Build Coastguard Worker * @taint_check: If set the test fails if kernel is tainted during the test run.
366*49cdfc7eSAndroid Build Coastguard Worker * That means tst_taint_init() is called during the test setup
367*49cdfc7eSAndroid Build Coastguard Worker * and tst_taint_check() at the end of the test. If all_filesystems
368*49cdfc7eSAndroid Build Coastguard Worker * is set taint check will be performed after each iteration and
369*49cdfc7eSAndroid Build Coastguard Worker * testing will be terminated by TBROK if taint is detected.
370*49cdfc7eSAndroid Build Coastguard Worker *
371*49cdfc7eSAndroid Build Coastguard Worker * @test_variants: If set denotes number of test variant, the test is executed
372*49cdfc7eSAndroid Build Coastguard Worker * variants times each time with tst_variant set to different
373*49cdfc7eSAndroid Build Coastguard Worker * number. This allows us to run the same test for different
374*49cdfc7eSAndroid Build Coastguard Worker * settings. The intended use is to test different syscall
375*49cdfc7eSAndroid Build Coastguard Worker * wrappers/variants but the API is generic and does not limit
376*49cdfc7eSAndroid Build Coastguard Worker * usage in any way.
377*49cdfc7eSAndroid Build Coastguard Worker *
378*49cdfc7eSAndroid Build Coastguard Worker * @dev_min_size: A minimal device size in megabytes.
379*49cdfc7eSAndroid Build Coastguard Worker *
380*49cdfc7eSAndroid Build Coastguard Worker * @dev_fs_type: If set overrides the default file system type for the device and
381*49cdfc7eSAndroid Build Coastguard Worker * sets the tst_device.fs_type.
382*49cdfc7eSAndroid Build Coastguard Worker *
383*49cdfc7eSAndroid Build Coastguard Worker * @dev_fs_opts: A NULL terminated array of options passed to mkfs in the case
384*49cdfc7eSAndroid Build Coastguard Worker * of 'tst_test.format_device'. These options are passed to mkfs
385*49cdfc7eSAndroid Build Coastguard Worker * before the device path.
386*49cdfc7eSAndroid Build Coastguard Worker *
387*49cdfc7eSAndroid Build Coastguard Worker * @dev_extra_opts: A NULL terminated array of extra options passed to mkfs in
388*49cdfc7eSAndroid Build Coastguard Worker * the case of 'tst_test.format_device'. Extra options are
389*49cdfc7eSAndroid Build Coastguard Worker * passed to mkfs after the device path. Commonly the option
390*49cdfc7eSAndroid Build Coastguard Worker * after mkfs is the number of blocks and can be used to limit
391*49cdfc7eSAndroid Build Coastguard Worker * the file system not to use the whole block device.
392*49cdfc7eSAndroid Build Coastguard Worker *
393*49cdfc7eSAndroid Build Coastguard Worker * @mntpoint: A mount point where the test library mounts requested file system.
394*49cdfc7eSAndroid Build Coastguard Worker * The directory is created by the library, the test must not create
395*49cdfc7eSAndroid Build Coastguard Worker * it itself.
396*49cdfc7eSAndroid Build Coastguard Worker *
397*49cdfc7eSAndroid Build Coastguard Worker * @mnt_flags: MS_* flags passed to mount(2) when the test library mounts a
398*49cdfc7eSAndroid Build Coastguard Worker * device in the case of 'tst_test.mount_device'.
399*49cdfc7eSAndroid Build Coastguard Worker *
400*49cdfc7eSAndroid Build Coastguard Worker * @mnt_data: The data passed to mount(2) when the test library mounts a device
401*49cdfc7eSAndroid Build Coastguard Worker * in the case of 'tst_test.mount_device'.
402*49cdfc7eSAndroid Build Coastguard Worker *
403*49cdfc7eSAndroid Build Coastguard Worker * @max_runtime: Maximal test runtime in seconds. Any test that runs for more
404*49cdfc7eSAndroid Build Coastguard Worker * than a second or two should set this and also use
405*49cdfc7eSAndroid Build Coastguard Worker * tst_remaining_runtime() to exit when runtime was used up.
406*49cdfc7eSAndroid Build Coastguard Worker * Tests may finish sooner, for example if requested number of
407*49cdfc7eSAndroid Build Coastguard Worker * iterations was reached before the runtime runs out. If test
408*49cdfc7eSAndroid Build Coastguard Worker * runtime cannot be know in advance it should be set to
409*49cdfc7eSAndroid Build Coastguard Worker * TST_UNLIMITED_RUNTIME.
410*49cdfc7eSAndroid Build Coastguard Worker *
411*49cdfc7eSAndroid Build Coastguard Worker * @setup: Setup callback is called once at the start of the test in order to
412*49cdfc7eSAndroid Build Coastguard Worker * prepare the test environment.
413*49cdfc7eSAndroid Build Coastguard Worker *
414*49cdfc7eSAndroid Build Coastguard Worker * @cleanup: Cleanup callback is either called at the end of the test, or in a
415*49cdfc7eSAndroid Build Coastguard Worker * case that tst_brk() was called. That means that cleanup must be
416*49cdfc7eSAndroid Build Coastguard Worker * able to handle all possible states the test can be in. This
417*49cdfc7eSAndroid Build Coastguard Worker * usually means that we have to check if file descriptor was opened
418*49cdfc7eSAndroid Build Coastguard Worker * before we attempt to close it, etc.
419*49cdfc7eSAndroid Build Coastguard Worker *
420*49cdfc7eSAndroid Build Coastguard Worker *
421*49cdfc7eSAndroid Build Coastguard Worker * @test: A main test function, only one of the tst_test.test and test_all can
422*49cdfc7eSAndroid Build Coastguard Worker * be set. When this function is set the tst_test.tcnt must be set to a
423*49cdfc7eSAndroid Build Coastguard Worker * positive integer and this function will be executed tcnt times
424*49cdfc7eSAndroid Build Coastguard Worker * during a single test iteration. May be executed several times if test
425*49cdfc7eSAndroid Build Coastguard Worker * was passed '-i' or '-d' command line parameters.
426*49cdfc7eSAndroid Build Coastguard Worker *
427*49cdfc7eSAndroid Build Coastguard Worker * @test_all: A main test function, only one of the tst_test.test and test_all
428*49cdfc7eSAndroid Build Coastguard Worker * can be set. May be executed several times if test was passed '-i'
429*49cdfc7eSAndroid Build Coastguard Worker * or '-d' command line parameters.
430*49cdfc7eSAndroid Build Coastguard Worker *
431*49cdfc7eSAndroid Build Coastguard Worker * @resource_files: A NULL terminated array of filenames that will be copied
432*49cdfc7eSAndroid Build Coastguard Worker * to the test temporary directory from the LTP datafiles
433*49cdfc7eSAndroid Build Coastguard Worker * directory.
434*49cdfc7eSAndroid Build Coastguard Worker *
435*49cdfc7eSAndroid Build Coastguard Worker * @needs_drivers: A NULL terminated array of kernel modules required to run
436*49cdfc7eSAndroid Build Coastguard Worker * the test. The module has to be build in or present in order
437*49cdfc7eSAndroid Build Coastguard Worker * for the test to run.
438*49cdfc7eSAndroid Build Coastguard Worker *
439*49cdfc7eSAndroid Build Coastguard Worker * @save_restore: A {} terminated array of /proc or /sys files that should
440*49cdfc7eSAndroid Build Coastguard Worker * saved at the start of the test and restored at the end. See
441*49cdfc7eSAndroid Build Coastguard Worker * tst_sys_conf_save() and struct tst_path_val for details.
442*49cdfc7eSAndroid Build Coastguard Worker *
443*49cdfc7eSAndroid Build Coastguard Worker * @ulimit: A {} terminated array of process limits RLIMIT_* to be adjusted for
444*49cdfc7eSAndroid Build Coastguard Worker * the test.
445*49cdfc7eSAndroid Build Coastguard Worker *
446*49cdfc7eSAndroid Build Coastguard Worker * @needs_kconfigs: A NULL terminated array of kernel config options that are
447*49cdfc7eSAndroid Build Coastguard Worker * required for the test. All strings in the array have to be
448*49cdfc7eSAndroid Build Coastguard Worker * evaluated to true for the test to run. Boolean operators
449*49cdfc7eSAndroid Build Coastguard Worker * and parenthesis are supported, e.g.
450*49cdfc7eSAndroid Build Coastguard Worker * "CONFIG_X86_INTEL_UMIP=y | CONFIG_X86_UIMP=y" is evaluated
451*49cdfc7eSAndroid Build Coastguard Worker * to true if at least one of the options is present.
452*49cdfc7eSAndroid Build Coastguard Worker *
453*49cdfc7eSAndroid Build Coastguard Worker * @bufs: A description of guarded buffers to be allocated for the test. Guarded
454*49cdfc7eSAndroid Build Coastguard Worker * buffers are buffers with poisoned page allocated right before the start
455*49cdfc7eSAndroid Build Coastguard Worker * of the buffer and canary right after the end of the buffer. See
456*49cdfc7eSAndroid Build Coastguard Worker * struct tst_buffers and tst_buffer_alloc() for details.
457*49cdfc7eSAndroid Build Coastguard Worker *
458*49cdfc7eSAndroid Build Coastguard Worker * @caps: A {} terminated array of capabilities to change before the start of
459*49cdfc7eSAndroid Build Coastguard Worker * the test. See struct tst_cap and tst_cap_setup() for details.
460*49cdfc7eSAndroid Build Coastguard Worker *
461*49cdfc7eSAndroid Build Coastguard Worker * @tags: A {} terminated array of test tags. See struct tst_tag for details.
462*49cdfc7eSAndroid Build Coastguard Worker *
463*49cdfc7eSAndroid Build Coastguard Worker * @needs_cmds: A NULL terminated array of commands required for the test to run.
464*49cdfc7eSAndroid Build Coastguard Worker *
465*49cdfc7eSAndroid Build Coastguard Worker * @needs_cgroup_ver: If set the test will run only if the specified cgroup
466*49cdfc7eSAndroid Build Coastguard Worker * version is present on the system.
467*49cdfc7eSAndroid Build Coastguard Worker *
468*49cdfc7eSAndroid Build Coastguard Worker * @needs_cgroup_ctrls: A {} terminated array of cgroup controllers the test
469*49cdfc7eSAndroid Build Coastguard Worker * needs to run.
470*49cdfc7eSAndroid Build Coastguard Worker *
471*49cdfc7eSAndroid Build Coastguard Worker * @needs_cgroup_nsdelegate: If set test the will run only if cgroup2 is mounted
472*49cdfc7eSAndroid Build Coastguard Worker * with nsdelegate option.
473*49cdfc7eSAndroid Build Coastguard Worker */
474*49cdfc7eSAndroid Build Coastguard Worker
475*49cdfc7eSAndroid Build Coastguard Worker struct tst_test {
476*49cdfc7eSAndroid Build Coastguard Worker unsigned int tcnt;
477*49cdfc7eSAndroid Build Coastguard Worker
478*49cdfc7eSAndroid Build Coastguard Worker struct tst_option *options;
479*49cdfc7eSAndroid Build Coastguard Worker
480*49cdfc7eSAndroid Build Coastguard Worker const char *min_kver;
481*49cdfc7eSAndroid Build Coastguard Worker
482*49cdfc7eSAndroid Build Coastguard Worker const char *const *supported_archs;
483*49cdfc7eSAndroid Build Coastguard Worker
484*49cdfc7eSAndroid Build Coastguard Worker const char *tconf_msg;
485*49cdfc7eSAndroid Build Coastguard Worker
486*49cdfc7eSAndroid Build Coastguard Worker unsigned int needs_tmpdir:1;
487*49cdfc7eSAndroid Build Coastguard Worker unsigned int needs_root:1;
488*49cdfc7eSAndroid Build Coastguard Worker unsigned int forks_child:1;
489*49cdfc7eSAndroid Build Coastguard Worker unsigned int needs_device:1;
490*49cdfc7eSAndroid Build Coastguard Worker unsigned int needs_checkpoints:1;
491*49cdfc7eSAndroid Build Coastguard Worker unsigned int needs_overlay:1;
492*49cdfc7eSAndroid Build Coastguard Worker unsigned int format_device:1;
493*49cdfc7eSAndroid Build Coastguard Worker unsigned int mount_device:1;
494*49cdfc7eSAndroid Build Coastguard Worker unsigned int needs_rofs:1;
495*49cdfc7eSAndroid Build Coastguard Worker unsigned int child_needs_reinit:1;
496*49cdfc7eSAndroid Build Coastguard Worker unsigned int needs_devfs:1;
497*49cdfc7eSAndroid Build Coastguard Worker unsigned int restore_wallclock:1;
498*49cdfc7eSAndroid Build Coastguard Worker
499*49cdfc7eSAndroid Build Coastguard Worker unsigned int all_filesystems:1;
500*49cdfc7eSAndroid Build Coastguard Worker
501*49cdfc7eSAndroid Build Coastguard Worker unsigned int skip_in_lockdown:1;
502*49cdfc7eSAndroid Build Coastguard Worker unsigned int skip_in_secureboot:1;
503*49cdfc7eSAndroid Build Coastguard Worker unsigned int skip_in_compat:1;
504*49cdfc7eSAndroid Build Coastguard Worker int needs_abi_bits;
505*49cdfc7eSAndroid Build Coastguard Worker
506*49cdfc7eSAndroid Build Coastguard Worker unsigned int needs_hugetlbfs:1;
507*49cdfc7eSAndroid Build Coastguard Worker
508*49cdfc7eSAndroid Build Coastguard Worker const char *const *skip_filesystems;
509*49cdfc7eSAndroid Build Coastguard Worker
510*49cdfc7eSAndroid Build Coastguard Worker unsigned long min_cpus;
511*49cdfc7eSAndroid Build Coastguard Worker unsigned long min_mem_avail;
512*49cdfc7eSAndroid Build Coastguard Worker unsigned long min_swap_avail;
513*49cdfc7eSAndroid Build Coastguard Worker
514*49cdfc7eSAndroid Build Coastguard Worker struct tst_hugepage hugepages;
515*49cdfc7eSAndroid Build Coastguard Worker
516*49cdfc7eSAndroid Build Coastguard Worker unsigned int taint_check;
517*49cdfc7eSAndroid Build Coastguard Worker
518*49cdfc7eSAndroid Build Coastguard Worker unsigned int test_variants;
519*49cdfc7eSAndroid Build Coastguard Worker
520*49cdfc7eSAndroid Build Coastguard Worker unsigned int dev_min_size;
521*49cdfc7eSAndroid Build Coastguard Worker
522*49cdfc7eSAndroid Build Coastguard Worker const char *dev_fs_type;
523*49cdfc7eSAndroid Build Coastguard Worker
524*49cdfc7eSAndroid Build Coastguard Worker const char *const *dev_fs_opts;
525*49cdfc7eSAndroid Build Coastguard Worker const char *const *dev_extra_opts;
526*49cdfc7eSAndroid Build Coastguard Worker
527*49cdfc7eSAndroid Build Coastguard Worker const char *mntpoint;
528*49cdfc7eSAndroid Build Coastguard Worker unsigned int mnt_flags;
529*49cdfc7eSAndroid Build Coastguard Worker void *mnt_data;
530*49cdfc7eSAndroid Build Coastguard Worker
531*49cdfc7eSAndroid Build Coastguard Worker int max_runtime;
532*49cdfc7eSAndroid Build Coastguard Worker
533*49cdfc7eSAndroid Build Coastguard Worker void (*setup)(void);
534*49cdfc7eSAndroid Build Coastguard Worker void (*cleanup)(void);
535*49cdfc7eSAndroid Build Coastguard Worker void (*test)(unsigned int test_nr);
536*49cdfc7eSAndroid Build Coastguard Worker void (*test_all)(void);
537*49cdfc7eSAndroid Build Coastguard Worker
538*49cdfc7eSAndroid Build Coastguard Worker const char *scall;
539*49cdfc7eSAndroid Build Coastguard Worker int (*sample)(int clk_id, long long usec);
540*49cdfc7eSAndroid Build Coastguard Worker
541*49cdfc7eSAndroid Build Coastguard Worker const char *const *resource_files;
542*49cdfc7eSAndroid Build Coastguard Worker const char * const *needs_drivers;
543*49cdfc7eSAndroid Build Coastguard Worker
544*49cdfc7eSAndroid Build Coastguard Worker const struct tst_path_val *save_restore;
545*49cdfc7eSAndroid Build Coastguard Worker
546*49cdfc7eSAndroid Build Coastguard Worker const struct tst_ulimit_val *ulimit;
547*49cdfc7eSAndroid Build Coastguard Worker
548*49cdfc7eSAndroid Build Coastguard Worker const char *const *needs_kconfigs;
549*49cdfc7eSAndroid Build Coastguard Worker
550*49cdfc7eSAndroid Build Coastguard Worker struct tst_buffers *bufs;
551*49cdfc7eSAndroid Build Coastguard Worker
552*49cdfc7eSAndroid Build Coastguard Worker struct tst_cap *caps;
553*49cdfc7eSAndroid Build Coastguard Worker
554*49cdfc7eSAndroid Build Coastguard Worker const struct tst_tag *tags;
555*49cdfc7eSAndroid Build Coastguard Worker
556*49cdfc7eSAndroid Build Coastguard Worker const char *const *needs_cmds;
557*49cdfc7eSAndroid Build Coastguard Worker
558*49cdfc7eSAndroid Build Coastguard Worker const enum tst_cg_ver needs_cgroup_ver;
559*49cdfc7eSAndroid Build Coastguard Worker
560*49cdfc7eSAndroid Build Coastguard Worker const char *const *needs_cgroup_ctrls;
561*49cdfc7eSAndroid Build Coastguard Worker
562*49cdfc7eSAndroid Build Coastguard Worker int needs_cgroup_nsdelegate:1;
563*49cdfc7eSAndroid Build Coastguard Worker };
564*49cdfc7eSAndroid Build Coastguard Worker
565*49cdfc7eSAndroid Build Coastguard Worker /**
566*49cdfc7eSAndroid Build Coastguard Worker * tst_run_tcases() - Entry point to the test library.
567*49cdfc7eSAndroid Build Coastguard Worker *
568*49cdfc7eSAndroid Build Coastguard Worker * @argc: An argc that was passed to the main().
569*49cdfc7eSAndroid Build Coastguard Worker * @argv: An argv that was passed to the main().
570*49cdfc7eSAndroid Build Coastguard Worker * @self: The test description and callbacks packed in the struct tst_test
571*49cdfc7eSAndroid Build Coastguard Worker * structure.
572*49cdfc7eSAndroid Build Coastguard Worker *
573*49cdfc7eSAndroid Build Coastguard Worker * A main() function which calls this function is added to each test
574*49cdfc7eSAndroid Build Coastguard Worker * automatically by including the tst_test.h header. The test has to define the
575*49cdfc7eSAndroid Build Coastguard Worker * struct tst_test called test.
576*49cdfc7eSAndroid Build Coastguard Worker *
577*49cdfc7eSAndroid Build Coastguard Worker * This function does not return, i.e. calls exit() after the test has finished.
578*49cdfc7eSAndroid Build Coastguard Worker */
579*49cdfc7eSAndroid Build Coastguard Worker void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
580*49cdfc7eSAndroid Build Coastguard Worker __attribute__ ((noreturn));
581*49cdfc7eSAndroid Build Coastguard Worker
582*49cdfc7eSAndroid Build Coastguard Worker #define IPC_ENV_VAR "LTP_IPC_PATH"
583*49cdfc7eSAndroid Build Coastguard Worker
584*49cdfc7eSAndroid Build Coastguard Worker /**
585*49cdfc7eSAndroid Build Coastguard Worker * tst_reinit() - Reinitialize the test library.
586*49cdfc7eSAndroid Build Coastguard Worker *
587*49cdfc7eSAndroid Build Coastguard Worker * In a cases where a test child process calls exec() it no longer can access
588*49cdfc7eSAndroid Build Coastguard Worker * the test library shared memory and therefore use the test reporting
589*49cdfc7eSAndroid Build Coastguard Worker * functions, checkpoint library, etc. This function re-initializes the test
590*49cdfc7eSAndroid Build Coastguard Worker * library so that it can be used again.
591*49cdfc7eSAndroid Build Coastguard Worker *
592*49cdfc7eSAndroid Build Coastguard Worker * @important The LTP_IPC_PATH variable must be passed to the program environment.
593*49cdfc7eSAndroid Build Coastguard Worker */
594*49cdfc7eSAndroid Build Coastguard Worker void tst_reinit(void);
595*49cdfc7eSAndroid Build Coastguard Worker
596*49cdfc7eSAndroid Build Coastguard Worker unsigned int tst_multiply_timeout(unsigned int timeout);
597*49cdfc7eSAndroid Build Coastguard Worker
598*49cdfc7eSAndroid Build Coastguard Worker /*
599*49cdfc7eSAndroid Build Coastguard Worker * Returns remaining test runtime. Test that runs for more than a few seconds
600*49cdfc7eSAndroid Build Coastguard Worker * should check if they should exit by calling this function regularly.
601*49cdfc7eSAndroid Build Coastguard Worker *
602*49cdfc7eSAndroid Build Coastguard Worker * The function returns remaining runtime in seconds. If runtime was used up
603*49cdfc7eSAndroid Build Coastguard Worker * zero is returned.
604*49cdfc7eSAndroid Build Coastguard Worker */
605*49cdfc7eSAndroid Build Coastguard Worker unsigned int tst_remaining_runtime(void);
606*49cdfc7eSAndroid Build Coastguard Worker
607*49cdfc7eSAndroid Build Coastguard Worker /*
608*49cdfc7eSAndroid Build Coastguard Worker * Sets maximal test runtime in seconds.
609*49cdfc7eSAndroid Build Coastguard Worker */
610*49cdfc7eSAndroid Build Coastguard Worker void tst_set_max_runtime(int max_runtime);
611*49cdfc7eSAndroid Build Coastguard Worker
612*49cdfc7eSAndroid Build Coastguard Worker /*
613*49cdfc7eSAndroid Build Coastguard Worker * Create and open a random file inside the given dir path.
614*49cdfc7eSAndroid Build Coastguard Worker * It unlinks the file after opening and return file descriptor.
615*49cdfc7eSAndroid Build Coastguard Worker */
616*49cdfc7eSAndroid Build Coastguard Worker int tst_creat_unlinked(const char *path, int flags);
617*49cdfc7eSAndroid Build Coastguard Worker
618*49cdfc7eSAndroid Build Coastguard Worker /*
619*49cdfc7eSAndroid Build Coastguard Worker * Returns path to the test temporary directory in a newly allocated buffer.
620*49cdfc7eSAndroid Build Coastguard Worker */
621*49cdfc7eSAndroid Build Coastguard Worker char *tst_get_tmpdir(void);
622*49cdfc7eSAndroid Build Coastguard Worker
623*49cdfc7eSAndroid Build Coastguard Worker /*
624*49cdfc7eSAndroid Build Coastguard Worker * Returns path to the test temporary directory root (TMPDIR).
625*49cdfc7eSAndroid Build Coastguard Worker */
626*49cdfc7eSAndroid Build Coastguard Worker const char *tst_get_tmpdir_root(void);
627*49cdfc7eSAndroid Build Coastguard Worker
628*49cdfc7eSAndroid Build Coastguard Worker /*
629*49cdfc7eSAndroid Build Coastguard Worker * Validates exit status of child processes
630*49cdfc7eSAndroid Build Coastguard Worker */
631*49cdfc7eSAndroid Build Coastguard Worker int tst_validate_children_(const char *file, const int lineno,
632*49cdfc7eSAndroid Build Coastguard Worker unsigned int count);
633*49cdfc7eSAndroid Build Coastguard Worker #define tst_validate_children(child_count) \
634*49cdfc7eSAndroid Build Coastguard Worker tst_validate_children_(__FILE__, __LINE__, (child_count))
635*49cdfc7eSAndroid Build Coastguard Worker
636*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_NO_DEFAULT_MAIN
637*49cdfc7eSAndroid Build Coastguard Worker
638*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test;
639*49cdfc7eSAndroid Build Coastguard Worker
main(int argc,char * argv[])640*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
641*49cdfc7eSAndroid Build Coastguard Worker {
642*49cdfc7eSAndroid Build Coastguard Worker tst_run_tcases(argc, argv, &test);
643*49cdfc7eSAndroid Build Coastguard Worker }
644*49cdfc7eSAndroid Build Coastguard Worker
645*49cdfc7eSAndroid Build Coastguard Worker #endif /* TST_NO_DEFAULT_MAIN */
646*49cdfc7eSAndroid Build Coastguard Worker
647*49cdfc7eSAndroid Build Coastguard Worker /**
648*49cdfc7eSAndroid Build Coastguard Worker * TST_TEST_TCONF() - Exit tests with a TCONF message.
649*49cdfc7eSAndroid Build Coastguard Worker *
650*49cdfc7eSAndroid Build Coastguard Worker * This macro is used in test that couldn't be compiled either because current
651*49cdfc7eSAndroid Build Coastguard Worker * CPU architecture is unsupported or because of missing development libraries.
652*49cdfc7eSAndroid Build Coastguard Worker */
653*49cdfc7eSAndroid Build Coastguard Worker #define TST_TEST_TCONF(message) \
654*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = { .tconf_msg = message } \
655*49cdfc7eSAndroid Build Coastguard Worker
656*49cdfc7eSAndroid Build Coastguard Worker #endif /* TST_TEST_H__ */
657