blob: a76fafc5b6acd2e1bdfea7cf23757389f3162a0c [file] [log] [blame]
alaffincc2e5552000-07-27 17:13:18 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
Cyril Hrubis06f9fe42013-06-26 14:55:48 +02003 * Copyright (c) 2009-2013 Cyril Hrubis chrubis@suse.cz
subrata_modak88c166c2009-06-09 16:01:20 +00004 *
alaffincc2e5552000-07-27 17:13:18 +00005 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
vapier45a8ba02009-07-20 10:59:32 +00008 *
alaffincc2e5552000-07-27 17:13:18 +00009 * This program is distributed in the hope that it would be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
vapier45a8ba02009-07-20 10:59:32 +000012 *
alaffincc2e5552000-07-27 17:13:18 +000013 * Further, this software is distributed without any warranty that it is
14 * free of the rightful claim of any third person regarding infringement
15 * or the like. Any license provided herein, whether implied or
16 * otherwise, applies only to this software file. Patent licenses, if
17 * any, provided herein do not apply to combinations of this program with
18 * other software, or any other product whatsoever.
vapier45a8ba02009-07-20 10:59:32 +000019 *
alaffincc2e5552000-07-27 17:13:18 +000020 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080021 * with this program; if not, write the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapier45a8ba02009-07-20 10:59:32 +000023 *
alaffincc2e5552000-07-27 17:13:18 +000024 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 * Mountain View, CA 94043, or:
vapier45a8ba02009-07-20 10:59:32 +000026 *
27 * http://www.sgi.com
28 *
29 * For further information regarding this notice, see:
30 *
alaffincc2e5552000-07-27 17:13:18 +000031 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
32 */
33
alaffincc2e5552000-07-27 17:13:18 +000034#ifndef __TEST_H__
35#define __TEST_H__
36
37#include <stdio.h>
38#include <signal.h>
39#include <unistd.h>
plars28884512002-05-21 13:01:00 +000040#include <string.h>
41#include <stdlib.h>
alaffincc2e5552000-07-27 17:13:18 +000042
vapier2751f262008-02-11 16:39:54 +000043#include "compiler.h"
44
Cyril Hrubis42748952012-11-27 19:26:45 +010045#include "safe_file_ops.h"
Cyril Hrubisab8388c2012-11-28 15:42:17 +010046#include "tst_checkpoint.h"
Cyril Hrubis19240612012-12-11 18:51:54 +010047#include "tst_process_state.h"
Cyril Hrubis69c2ab02012-12-12 17:22:29 +010048#include "tst_resource.h"
Cyril Hrubis42748952012-11-27 19:26:45 +010049
subrata_modak7f71cfb2009-08-04 11:47:10 +000050/* Use low 6 bits to encode test type */
51#define TTYPE_MASK 0x3f
vapier9799ea12009-07-20 02:42:32 +000052#define TPASS 0 /* Test passed flag */
53#define TFAIL 1 /* Test failed flag */
54#define TBROK 2 /* Test broken flag */
subrata_modak7f71cfb2009-08-04 11:47:10 +000055#define TWARN 4 /* Test warning flag */
56#define TRETR 8 /* Test retire flag */
57#define TINFO 16 /* Test information flag */
58#define TCONF 32 /* Test not appropriate for configuration flag */
vapier9799ea12009-07-20 02:42:32 +000059#define TTYPE_RESULT(ttype) ((ttype) & TTYPE_MASK)
60
61#define TERRNO 0x100 /* Append errno information to output */
62#define TTERRNO 0x200 /* Append TEST_ERRNO information to output */
Garrett Coopera9e49f12010-12-16 10:54:03 -080063#define TRERRNO 0x300 /* Capture errno information from TEST_RETURN to
64 output; useful for pthread-like APIs :). */
alaffincc2e5552000-07-27 17:13:18 +000065
66/*
alaffincc2e5552000-07-27 17:13:18 +000067 * Ensure that NUMSIGS is defined.
68 * It should be defined in signal.h or sys/signal.h on
69 * UNICOS/mk and IRIX systems. On UNICOS systems,
70 * it is not defined, thus it is being set to UNICOS's NSIG.
vapier45a8ba02009-07-20 10:59:32 +000071 * Note: IRIX's NSIG (signals are 1-(NSIG-1))
alaffincc2e5552000-07-27 17:13:18 +000072 * is not same meaning as UNICOS/UMK's NSIG (signals 1-NSIG)
73 */
74#ifndef NUMSIGS
75#define NUMSIGS NSIG
76#endif
77
78
79/* defines for unexpected signal setup routine (set_usig.c) */
80#define FORK 1 /* SIGCLD is to be ignored */
81#define NOFORK 0 /* SIGCLD is to be caught */
subrata_modak40bc6aa2009-09-27 17:46:05 +000082#define DEF_HANDLER SIG_ERR /* tells set_usig() to use default signal handler */
alaffincc2e5552000-07-27 17:13:18 +000083
84/*
85 * The following defines are used to control tst_res and t_result reporting.
86 */
87
88#define TOUTPUT "TOUTPUT" /* The name of the environment variable */
89 /* that can be set to one of the following */
90 /* strings to control tst_res output */
91 /* If not set, TOUT_VERBOSE_S is assumed */
92
alaffincc2e5552000-07-27 17:13:18 +000093/*
robbiewd34d5812005-07-11 22:28:09 +000094 * fork() can't be used on uClinux systems, so use FORK_OR_VFORK instead,
95 * which will run vfork() on uClinux.
96 * mmap() doesn't support MAP_PRIVATE on uClinux systems, so use
97 * MAP_PRIVATE_EXCEPT_UCLINUX instead, which will skip the option on uClinux.
98 * If MAP_PRIVATE really is required, the test can not be run on uClinux.
99 */
100#ifdef UCLINUX
101#define FORK_OR_VFORK vfork
vapier45a8ba02009-07-20 10:59:32 +0000102#define MAP_PRIVATE_EXCEPT_UCLINUX 0
robbiewd34d5812005-07-11 22:28:09 +0000103#else
104#define FORK_OR_VFORK fork
105#define MAP_PRIVATE_EXCEPT_UCLINUX MAP_PRIVATE
106#endif
107
108/*
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800109 * lib/forker.c
alaffincc2e5552000-07-27 17:13:18 +0000110 */
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800111extern int Forker_pids[];
112extern int Forker_npids;
113
114/* lib/tst_res.c */
vapier9799ea12009-07-20 02:42:32 +0000115const char *strttype(int ttype);
subrata_modak0d719e52009-08-30 17:18:18 +0000116void tst_res(int ttype, char *fname, char *arg_fmt, ...)
117 __attribute__ ((format (printf, 3, 4)));
118void tst_resm(int ttype, char *arg_fmt, ...)
119 __attribute__ ((format (printf, 2, 3)));
Alexey Kodanev04a34ba2013-05-23 11:03:18 +0400120void tst_resm_hexd(int ttype, const void *buf, size_t size, char *arg_fmt, ...)
121 __attribute__ ((format (printf, 4, 5)));
subrata_modak0d719e52009-08-30 17:18:18 +0000122void tst_brk(int ttype, char *fname, void (*func)(void), char *arg_fmt, ...)
Garrett Cooper68d76e02010-12-20 05:49:48 -0800123 __attribute__ ((format (printf, 4, 5)));
subrata_modak0d719e52009-08-30 17:18:18 +0000124void tst_brkm(int ttype, void (*func)(void), char *arg_fmt, ...)
Cyril Hrubis9ef186f2011-05-11 13:13:12 +0200125 __attribute__ ((format (printf, 3, 4))) LTP_ATTRIBUTE_NORETURN;
subrata_modak88c166c2009-06-09 16:01:20 +0000126void tst_require_root(void (*func)(void));
127int tst_environ(void);
128void tst_exit(void) LTP_ATTRIBUTE_NORETURN;
129void tst_flush(void);
alaffincc2e5552000-07-27 17:13:18 +0000130
Caspar Zhangd59a6592013-03-07 14:59:12 +0800131extern int tst_count;
alaffincc2e5552000-07-27 17:13:18 +0000132
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800133/* lib/tst_sig.c */
subrata_modak88c166c2009-06-09 16:01:20 +0000134void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)());
alaffincc2e5552000-07-27 17:13:18 +0000135
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800136/* lib/tst_tmpdir.c */
Marios Makris60b1baa2012-08-09 20:36:46 +0300137
138/* tst_tmpdir()
139 *
140 * Create a unique temporary directory and chdir() to it. It expects the caller
141 * to have defined/initialized the TCID/TST_TOTAL global variables.
142 * The TESTDIR global variable will be set to the directory that gets used
143 * as the testing directory.
144 *
145 * NOTE: This function must be called BEFORE any activity that would require
146 * CLEANUP. If tst_tmpdir() fails, it cleans up afer itself and calls
147 * tst_exit() (i.e. does not return).
148 */
subrata_modak88c166c2009-06-09 16:01:20 +0000149void tst_tmpdir(void);
Marios Makris60b1baa2012-08-09 20:36:46 +0300150/* tst_rmdir()
151 *
152 * Recursively remove the temporary directory created by tst_tmpdir().
153 * This function is intended ONLY as a companion to tst_tmpdir().
Marios Makris60b1baa2012-08-09 20:36:46 +0300154 */
subrata_modak88c166c2009-06-09 16:01:20 +0000155void tst_rmdir(void);
Marios Makris60b1baa2012-08-09 20:36:46 +0300156/* get_tst_tmpdir()
157 *
158 * Return a copy of the test temp directory as seen by LTP. This is for
159 * path-oriented tests like chroot, etc, that may munge the path a bit.
160 *
161 * FREE VARIABLE AFTER USE IF IT IS REUSED!
162 */
Garrett Cooperdb976802010-12-16 15:56:25 -0800163char *get_tst_tmpdir(void);
Cyril Hrubisab8388c2012-11-28 15:42:17 +0100164/*
165 * Returns 1 if temp directory was created.
166 */
167int tst_tmpdir_created(void);
alaffincc2e5552000-07-27 17:13:18 +0000168
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800169/* lib/get_high_address.c */
subrata_modak88c166c2009-06-09 16:01:20 +0000170char *get_high_address(void);
robbiewf3a83d52002-05-28 16:26:16 +0000171
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800172/* lib/tst_kvercmp.c */
subrata_modak88c166c2009-06-09 16:01:20 +0000173void tst_getkver(int *k1, int *k2, int *k3);
174int tst_kvercmp(int r1, int r2, int r3);
robbiew143090a2005-01-17 22:10:09 +0000175
Wanlong Gaoef73cc92013-07-09 15:54:51 +0800176struct tst_kern_exv {
177 char *dist_name;
178 char *extra_ver;
179};
180
181int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers);
182
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800183/* lib/tst_is_cwd.c */
subrata_modak88c166c2009-06-09 16:01:20 +0000184int tst_is_cwd_nfs(void);
Cyril Hrubisbc5da682011-02-24 20:04:44 +0100185int tst_is_cwd_v9fs(void);
subrata_modak88c166c2009-06-09 16:01:20 +0000186int tst_is_cwd_tmpfs(void);
vapier019fc962009-08-28 12:43:06 +0000187int tst_is_cwd_ramfs(void);
subrata_modak88c166c2009-06-09 16:01:20 +0000188
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800189/* lib/tst_cwd_has_free.c */
subrata_modak88c166c2009-06-09 16:01:20 +0000190int tst_cwd_has_free(int required_kib);
191
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800192/* lib/self_exec.c */
subrata_modak88c166c2009-06-09 16:01:20 +0000193void maybe_run_child(void (*child)(), char *fmt, ...);
194int self_exec(char *argv0, char *fmt, ...);
subrata_modak744305e2008-08-19 07:00:49 +0000195
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800196/* Functions from lib/cloner.c */
vapierf6d7f092009-11-03 20:07:35 +0000197int ltp_clone(unsigned long clone_flags, int (*fn)(void *arg), void *arg,
198 size_t stack_size, void *stack);
199int ltp_clone_malloc(unsigned long clone_flags, int (*fn)(void *arg),
200 void *arg, size_t stacksize);
201int ltp_clone_quick(unsigned long clone_flags, int (*fn)(void *arg),
202 void *arg);
203#define clone(...) use_the_ltp_clone_functions,do_not_use_clone
204
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800205/* Functions from lib/mount_utils.c */
yaberauneyacfb70632010-01-10 08:01:15 +0000206char *get_block_device(const char *path);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000207char *get_mountpoint(const char *path);
yaberauneyacfb70632010-01-10 08:01:15 +0000208
Garrett Cooperaec33cd2010-12-17 04:14:16 -0800209/* Function from lib/get_path.c */
Subrata Modakca758b72010-05-18 01:28:14 +0530210int tst_get_path(const char *prog_name, char *buf, size_t buf_len);
211
Wanlong Gao3b535a82012-10-18 16:35:14 +0800212/* lib/tst_cpu.c */
213long tst_ncpus(void);
214long tst_ncpus_max(void);
215
Alexey Kodanev4bc55ec2013-06-27 18:52:22 +0400216/* lib/tst_run_cmd.c
217 *
218 * vfork() + execvp() specified program.
219 * @argv: a list of two (at least program name + NULL) or more pointers that
220 * represent the argument list to the new program. The array of pointers
221 * must be terminated by a NULL pointer.
222 */
223void tst_run_cmd(void (cleanup_fn)(void), char *const argv[]);
224
subrata_modak744305e2008-08-19 07:00:49 +0000225#ifdef TST_USE_COMPAT16_SYSCALL
226#define TCID_BIT_SUFFIX "_16"
227#elif TST_USE_NEWER64_SYSCALL
228#define TCID_BIT_SUFFIX "_64"
229#else
230#define TCID_BIT_SUFFIX ""
231#endif
subrata_modak88c166c2009-06-09 16:01:20 +0000232#define TCID_DEFINE(ID) char *TCID = (#ID TCID_BIT_SUFFIX)
subrata_modak744305e2008-08-19 07:00:49 +0000233
subrata_modak88c166c2009-06-09 16:01:20 +0000234#endif /* __TEST_H__ */