alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
Cyril Hrubis | 06f9fe4 | 2013-06-26 14:55:48 +0200 | [diff] [blame] | 3 | * Copyright (c) 2009-2013 Cyril Hrubis chrubis@suse.cz |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 4 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 5 | * 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. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 8 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 9 | * 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. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 12 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 13 | * 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. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 19 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 20 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 21 | * with this program; if not, write the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 23 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 24 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 25 | * Mountain View, CA 94043, or: |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 26 | * |
| 27 | * http://www.sgi.com |
| 28 | * |
| 29 | * For further information regarding this notice, see: |
| 30 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 31 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 32 | */ |
| 33 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 34 | #ifndef __TEST_H__ |
| 35 | #define __TEST_H__ |
| 36 | |
| 37 | #include <stdio.h> |
| 38 | #include <signal.h> |
| 39 | #include <unistd.h> |
plars | 2888451 | 2002-05-21 13:01:00 +0000 | [diff] [blame] | 40 | #include <string.h> |
| 41 | #include <stdlib.h> |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 42 | |
vapier | 2751f26 | 2008-02-11 16:39:54 +0000 | [diff] [blame] | 43 | #include "compiler.h" |
| 44 | |
Cyril Hrubis | 4274895 | 2012-11-27 19:26:45 +0100 | [diff] [blame] | 45 | #include "safe_file_ops.h" |
Cyril Hrubis | ab8388c | 2012-11-28 15:42:17 +0100 | [diff] [blame] | 46 | #include "tst_checkpoint.h" |
Cyril Hrubis | 1924061 | 2012-12-11 18:51:54 +0100 | [diff] [blame] | 47 | #include "tst_process_state.h" |
Cyril Hrubis | 69c2ab0 | 2012-12-12 17:22:29 +0100 | [diff] [blame] | 48 | #include "tst_resource.h" |
Cyril Hrubis | 4274895 | 2012-11-27 19:26:45 +0100 | [diff] [blame] | 49 | |
subrata_modak | 7f71cfb | 2009-08-04 11:47:10 +0000 | [diff] [blame] | 50 | /* Use low 6 bits to encode test type */ |
| 51 | #define TTYPE_MASK 0x3f |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 52 | #define TPASS 0 /* Test passed flag */ |
| 53 | #define TFAIL 1 /* Test failed flag */ |
| 54 | #define TBROK 2 /* Test broken flag */ |
subrata_modak | 7f71cfb | 2009-08-04 11:47:10 +0000 | [diff] [blame] | 55 | #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 */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 59 | #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 Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 63 | #define TRERRNO 0x300 /* Capture errno information from TEST_RETURN to |
| 64 | output; useful for pthread-like APIs :). */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 65 | |
| 66 | /* |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 67 | * 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. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 71 | * Note: IRIX's NSIG (signals are 1-(NSIG-1)) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 72 | * 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_modak | 40bc6aa | 2009-09-27 17:46:05 +0000 | [diff] [blame] | 82 | #define DEF_HANDLER SIG_ERR /* tells set_usig() to use default signal handler */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 83 | |
| 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 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 93 | /* |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 94 | * 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 |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 102 | #define MAP_PRIVATE_EXCEPT_UCLINUX 0 |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 103 | #else |
| 104 | #define FORK_OR_VFORK fork |
| 105 | #define MAP_PRIVATE_EXCEPT_UCLINUX MAP_PRIVATE |
| 106 | #endif |
| 107 | |
| 108 | /* |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 109 | * lib/forker.c |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 110 | */ |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 111 | extern int Forker_pids[]; |
| 112 | extern int Forker_npids; |
| 113 | |
| 114 | /* lib/tst_res.c */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 115 | const char *strttype(int ttype); |
subrata_modak | 0d719e5 | 2009-08-30 17:18:18 +0000 | [diff] [blame] | 116 | void tst_res(int ttype, char *fname, char *arg_fmt, ...) |
| 117 | __attribute__ ((format (printf, 3, 4))); |
| 118 | void tst_resm(int ttype, char *arg_fmt, ...) |
| 119 | __attribute__ ((format (printf, 2, 3))); |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 120 | void tst_resm_hexd(int ttype, const void *buf, size_t size, char *arg_fmt, ...) |
| 121 | __attribute__ ((format (printf, 4, 5))); |
subrata_modak | 0d719e5 | 2009-08-30 17:18:18 +0000 | [diff] [blame] | 122 | void tst_brk(int ttype, char *fname, void (*func)(void), char *arg_fmt, ...) |
Garrett Cooper | 68d76e0 | 2010-12-20 05:49:48 -0800 | [diff] [blame] | 123 | __attribute__ ((format (printf, 4, 5))); |
subrata_modak | 0d719e5 | 2009-08-30 17:18:18 +0000 | [diff] [blame] | 124 | void tst_brkm(int ttype, void (*func)(void), char *arg_fmt, ...) |
Cyril Hrubis | 9ef186f | 2011-05-11 13:13:12 +0200 | [diff] [blame] | 125 | __attribute__ ((format (printf, 3, 4))) LTP_ATTRIBUTE_NORETURN; |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 126 | void tst_require_root(void (*func)(void)); |
| 127 | int tst_environ(void); |
| 128 | void tst_exit(void) LTP_ATTRIBUTE_NORETURN; |
| 129 | void tst_flush(void); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 130 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 131 | extern int tst_count; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 132 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 133 | /* lib/tst_sig.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 134 | void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)()); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 135 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 136 | /* lib/tst_tmpdir.c */ |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 137 | |
| 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_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 149 | void tst_tmpdir(void); |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 150 | /* 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 Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 154 | */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 155 | void tst_rmdir(void); |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 156 | /* 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 Cooper | db97680 | 2010-12-16 15:56:25 -0800 | [diff] [blame] | 163 | char *get_tst_tmpdir(void); |
Cyril Hrubis | ab8388c | 2012-11-28 15:42:17 +0100 | [diff] [blame] | 164 | /* |
| 165 | * Returns 1 if temp directory was created. |
| 166 | */ |
| 167 | int tst_tmpdir_created(void); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 168 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 169 | /* lib/get_high_address.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 170 | char *get_high_address(void); |
robbiew | f3a83d5 | 2002-05-28 16:26:16 +0000 | [diff] [blame] | 171 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 172 | /* lib/tst_kvercmp.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 173 | void tst_getkver(int *k1, int *k2, int *k3); |
| 174 | int tst_kvercmp(int r1, int r2, int r3); |
robbiew | 143090a | 2005-01-17 22:10:09 +0000 | [diff] [blame] | 175 | |
Wanlong Gao | ef73cc9 | 2013-07-09 15:54:51 +0800 | [diff] [blame^] | 176 | struct tst_kern_exv { |
| 177 | char *dist_name; |
| 178 | char *extra_ver; |
| 179 | }; |
| 180 | |
| 181 | int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers); |
| 182 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 183 | /* lib/tst_is_cwd.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 184 | int tst_is_cwd_nfs(void); |
Cyril Hrubis | bc5da68 | 2011-02-24 20:04:44 +0100 | [diff] [blame] | 185 | int tst_is_cwd_v9fs(void); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 186 | int tst_is_cwd_tmpfs(void); |
vapier | 019fc96 | 2009-08-28 12:43:06 +0000 | [diff] [blame] | 187 | int tst_is_cwd_ramfs(void); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 188 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 189 | /* lib/tst_cwd_has_free.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 190 | int tst_cwd_has_free(int required_kib); |
| 191 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 192 | /* lib/self_exec.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 193 | void maybe_run_child(void (*child)(), char *fmt, ...); |
| 194 | int self_exec(char *argv0, char *fmt, ...); |
subrata_modak | 744305e | 2008-08-19 07:00:49 +0000 | [diff] [blame] | 195 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 196 | /* Functions from lib/cloner.c */ |
vapier | f6d7f09 | 2009-11-03 20:07:35 +0000 | [diff] [blame] | 197 | int ltp_clone(unsigned long clone_flags, int (*fn)(void *arg), void *arg, |
| 198 | size_t stack_size, void *stack); |
| 199 | int ltp_clone_malloc(unsigned long clone_flags, int (*fn)(void *arg), |
| 200 | void *arg, size_t stacksize); |
| 201 | int 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 Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 205 | /* Functions from lib/mount_utils.c */ |
yaberauneya | cfb7063 | 2010-01-10 08:01:15 +0000 | [diff] [blame] | 206 | char *get_block_device(const char *path); |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 207 | char *get_mountpoint(const char *path); |
yaberauneya | cfb7063 | 2010-01-10 08:01:15 +0000 | [diff] [blame] | 208 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 209 | /* Function from lib/get_path.c */ |
Subrata Modak | ca758b7 | 2010-05-18 01:28:14 +0530 | [diff] [blame] | 210 | int tst_get_path(const char *prog_name, char *buf, size_t buf_len); |
| 211 | |
Wanlong Gao | 3b535a8 | 2012-10-18 16:35:14 +0800 | [diff] [blame] | 212 | /* lib/tst_cpu.c */ |
| 213 | long tst_ncpus(void); |
| 214 | long tst_ncpus_max(void); |
| 215 | |
Alexey Kodanev | 4bc55ec | 2013-06-27 18:52:22 +0400 | [diff] [blame] | 216 | /* 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 | */ |
| 223 | void tst_run_cmd(void (cleanup_fn)(void), char *const argv[]); |
| 224 | |
subrata_modak | 744305e | 2008-08-19 07:00:49 +0000 | [diff] [blame] | 225 | #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_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 232 | #define TCID_DEFINE(ID) char *TCID = (#ID TCID_BIT_SUFFIX) |
subrata_modak | 744305e | 2008-08-19 07:00:49 +0000 | [diff] [blame] | 233 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 234 | #endif /* __TEST_H__ */ |