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> |
Xiaoguang Wang | 4694167 | 2014-04-25 10:02:07 +0800 | [diff] [blame] | 42 | #include <stdint.h> |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 43 | |
vapier | 2751f26 | 2008-02-11 16:39:54 +0000 | [diff] [blame] | 44 | #include "compiler.h" |
| 45 | |
Cyril Hrubis | aabb834 | 2015-02-04 14:37:03 +0100 | [diff] [blame^] | 46 | #include "usctest.h" |
| 47 | |
Cyril Hrubis | 4274895 | 2012-11-27 19:26:45 +0100 | [diff] [blame] | 48 | #include "safe_file_ops.h" |
Cyril Hrubis | ab8388c | 2012-11-28 15:42:17 +0100 | [diff] [blame] | 49 | #include "tst_checkpoint.h" |
Cyril Hrubis | 1924061 | 2012-12-11 18:51:54 +0100 | [diff] [blame] | 50 | #include "tst_process_state.h" |
Cyril Hrubis | 69c2ab0 | 2012-12-12 17:22:29 +0100 | [diff] [blame] | 51 | #include "tst_resource.h" |
Xiaoguang Wang | 6f6878f | 2014-06-24 15:11:39 +0800 | [diff] [blame] | 52 | #include "tst_res_flags.h" |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 53 | |
Jan Stancek | 11a84a6 | 2013-10-17 12:44:49 +0200 | [diff] [blame] | 54 | /* virt types for tst_is_virt() */ |
| 55 | #define VIRT_XEN 1 /* xen dom0/domU */ |
| 56 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 57 | /* |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 58 | * Ensure that NUMSIGS is defined. |
| 59 | * It should be defined in signal.h or sys/signal.h on |
| 60 | * UNICOS/mk and IRIX systems. On UNICOS systems, |
| 61 | * it is not defined, thus it is being set to UNICOS's NSIG. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 62 | * Note: IRIX's NSIG (signals are 1-(NSIG-1)) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 63 | * is not same meaning as UNICOS/UMK's NSIG (signals 1-NSIG) |
| 64 | */ |
| 65 | #ifndef NUMSIGS |
| 66 | #define NUMSIGS NSIG |
| 67 | #endif |
| 68 | |
| 69 | |
| 70 | /* defines for unexpected signal setup routine (set_usig.c) */ |
| 71 | #define FORK 1 /* SIGCLD is to be ignored */ |
| 72 | #define NOFORK 0 /* SIGCLD is to be caught */ |
subrata_modak | 40bc6aa | 2009-09-27 17:46:05 +0000 | [diff] [blame] | 73 | #define DEF_HANDLER SIG_ERR /* tells set_usig() to use default signal handler */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * The following defines are used to control tst_res and t_result reporting. |
| 77 | */ |
| 78 | |
| 79 | #define TOUTPUT "TOUTPUT" /* The name of the environment variable */ |
| 80 | /* that can be set to one of the following */ |
| 81 | /* strings to control tst_res output */ |
| 82 | /* If not set, TOUT_VERBOSE_S is assumed */ |
| 83 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 84 | /* |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 85 | * fork() can't be used on uClinux systems, so use FORK_OR_VFORK instead, |
| 86 | * which will run vfork() on uClinux. |
| 87 | * mmap() doesn't support MAP_PRIVATE on uClinux systems, so use |
| 88 | * MAP_PRIVATE_EXCEPT_UCLINUX instead, which will skip the option on uClinux. |
| 89 | * If MAP_PRIVATE really is required, the test can not be run on uClinux. |
| 90 | */ |
| 91 | #ifdef UCLINUX |
Cyril Hrubis | 3f0510c | 2014-02-06 13:50:14 +0100 | [diff] [blame] | 92 | # define FORK_OR_VFORK tst_vfork |
| 93 | # define MAP_PRIVATE_EXCEPT_UCLINUX 0 |
| 94 | /* tst_flush() + vfork() */ |
| 95 | pid_t tst_vfork(void); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 96 | #else |
Cyril Hrubis | 3f0510c | 2014-02-06 13:50:14 +0100 | [diff] [blame] | 97 | # define FORK_OR_VFORK tst_fork |
| 98 | # define MAP_PRIVATE_EXCEPT_UCLINUX MAP_PRIVATE |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 99 | #endif |
| 100 | |
| 101 | /* |
Alexey Kodanev | bf17abf | 2014-02-18 18:08:30 +0400 | [diff] [blame] | 102 | * Macro to use for making functions called only once in |
| 103 | * multi-threaded tests such as init or cleanup function. |
| 104 | * The first call to @name_fn function by any thread shall |
| 105 | * call the @exec_fn. Subsequent calls shall not call @exec_fn. |
| 106 | * *_fn functions must not take any arguments. |
| 107 | */ |
| 108 | #define TST_DECLARE_ONCE_FN(name_fn, exec_fn) \ |
| 109 | void name_fn(void) \ |
| 110 | { \ |
| 111 | static pthread_once_t ltp_once = PTHREAD_ONCE_INIT; \ |
| 112 | pthread_once(<p_once, exec_fn); \ |
| 113 | } |
| 114 | |
| 115 | /* |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 116 | * lib/forker.c |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 117 | */ |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 118 | extern int Forker_pids[]; |
| 119 | extern int Forker_npids; |
| 120 | |
| 121 | /* lib/tst_res.c */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 122 | const char *strttype(int ttype); |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 123 | void tst_res_(const char *file, const int lineno, int ttype, |
| 124 | const char *fname, const char *arg_fmt, ...) |
| 125 | __attribute__ ((format (printf, 5, 6))); |
| 126 | |
| 127 | #define tst_res(ttype, fname, arg_fmt, ...) \ |
| 128 | tst_res_(__FILE__, __LINE__, (ttype), (fname), \ |
| 129 | (arg_fmt), ##__VA_ARGS__) |
| 130 | |
| 131 | void tst_resm_(const char *file, const int lineno, int ttype, |
| 132 | const char *arg_fmt, ...) |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 133 | __attribute__ ((format (printf, 4, 5))); |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 134 | #define tst_resm(ttype, arg_fmt, ...) \ |
| 135 | tst_resm_(__FILE__, __LINE__, (ttype), \ |
| 136 | (arg_fmt), ##__VA_ARGS__) |
| 137 | |
| 138 | void tst_resm_hexd_(const char *file, const int lineno, int ttype, |
| 139 | const void *buf, size_t size, const char *arg_fmt, ...) |
| 140 | __attribute__ ((format (printf, 6, 7))); |
| 141 | #define tst_resm_hexd(ttype, buf, size, arg_fmt, ...) \ |
| 142 | tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \ |
| 143 | (arg_fmt), ##__VA_ARGS__) |
| 144 | |
| 145 | void tst_brk_(const char *file, const int lineno, int ttype, |
| 146 | const char *fname, void (*func)(void), const char *arg_fmt, ...) |
| 147 | __attribute__ ((format (printf, 6, 7))); |
| 148 | #define tst_brk(ttype, fname, func, arg_fmt, ...) \ |
| 149 | tst_brk_(__FILE__, __LINE__, (ttype), (fname), (func), \ |
| 150 | (arg_fmt), ##__VA_ARGS__) |
| 151 | |
| 152 | void tst_brkm_(const char *file, const int lineno, int ttype, |
| 153 | void (*func)(void), const char *arg_fmt, ...) |
| 154 | __attribute__ ((format (printf, 5, 6))) LTP_ATTRIBUTE_NORETURN; |
| 155 | #define tst_brkm(ttype, func, arg_fmt, ...) \ |
| 156 | tst_brkm_(__FILE__, __LINE__, (ttype), (func), \ |
| 157 | (arg_fmt), ##__VA_ARGS__) |
| 158 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 159 | void tst_require_root(void (*func)(void)); |
| 160 | int tst_environ(void); |
| 161 | void tst_exit(void) LTP_ATTRIBUTE_NORETURN; |
| 162 | void tst_flush(void); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 163 | |
Cyril Hrubis | ddd3b85 | 2014-02-03 17:10:04 +0100 | [diff] [blame] | 164 | /* |
| 165 | * tst_flush() + fork |
Xiaoguang Wang | 8c1e0b3 | 2014-07-28 19:51:39 +0800 | [diff] [blame] | 166 | * NOTE: tst_fork() will reset T_exitval to 0 for child process. |
Cyril Hrubis | ddd3b85 | 2014-02-03 17:10:04 +0100 | [diff] [blame] | 167 | */ |
| 168 | pid_t tst_fork(void); |
| 169 | |
Xiaoguang Wang | 8c1e0b3 | 2014-07-28 19:51:39 +0800 | [diff] [blame] | 170 | /* lib/tst_res.c */ |
| 171 | /* |
| 172 | * In case we need do real test work in child process parent process can use |
| 173 | * tst_record_childstatus() to make child process's test results propagated to |
| 174 | * parent process correctly. |
| 175 | * |
| 176 | * The child can use tst_resm(), tst_brkm() followed by the tst_exit() or |
| 177 | * plain old exit() (with TPASS, TFAIL and TBROK). |
| 178 | * |
| 179 | * WARNING: Be wary that the child cleanup function passed to tst_brkm() |
| 180 | * must clean only resources the child has allocated. E.g. the |
| 181 | * child cleanup is different function from the parent cleanup. |
| 182 | */ |
| 183 | void tst_record_childstatus(void (*cleanup)(void), pid_t child); |
| 184 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 185 | extern int tst_count; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 186 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 187 | /* lib/tst_sig.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 188 | void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)()); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 189 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 190 | /* lib/tst_tmpdir.c */ |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 191 | |
| 192 | /* tst_tmpdir() |
| 193 | * |
| 194 | * Create a unique temporary directory and chdir() to it. It expects the caller |
| 195 | * to have defined/initialized the TCID/TST_TOTAL global variables. |
| 196 | * The TESTDIR global variable will be set to the directory that gets used |
| 197 | * as the testing directory. |
| 198 | * |
| 199 | * NOTE: This function must be called BEFORE any activity that would require |
| 200 | * CLEANUP. If tst_tmpdir() fails, it cleans up afer itself and calls |
| 201 | * tst_exit() (i.e. does not return). |
| 202 | */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 203 | void tst_tmpdir(void); |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 204 | /* tst_rmdir() |
| 205 | * |
| 206 | * Recursively remove the temporary directory created by tst_tmpdir(). |
| 207 | * This function is intended ONLY as a companion to tst_tmpdir(). |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 208 | */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 209 | void tst_rmdir(void); |
Cyril Hrubis | 9c31ad2 | 2014-05-14 17:15:39 +0200 | [diff] [blame] | 210 | /* tst_get_tmpdir() |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 211 | * |
| 212 | * Return a copy of the test temp directory as seen by LTP. This is for |
| 213 | * path-oriented tests like chroot, etc, that may munge the path a bit. |
| 214 | * |
| 215 | * FREE VARIABLE AFTER USE IF IT IS REUSED! |
| 216 | */ |
Cyril Hrubis | 9c31ad2 | 2014-05-14 17:15:39 +0200 | [diff] [blame] | 217 | char *tst_get_tmpdir(void); |
Cyril Hrubis | ab8388c | 2012-11-28 15:42:17 +0100 | [diff] [blame] | 218 | /* |
| 219 | * Returns 1 if temp directory was created. |
| 220 | */ |
| 221 | int tst_tmpdir_created(void); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 222 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 223 | /* lib/get_high_address.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 224 | char *get_high_address(void); |
robbiew | f3a83d5 | 2002-05-28 16:26:16 +0000 | [diff] [blame] | 225 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 226 | /* lib/tst_kvercmp.c */ |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 227 | void tst_getkver(int *k1, int *k2, int *k3); |
| 228 | int tst_kvercmp(int r1, int r2, int r3); |
robbiew | 143090a | 2005-01-17 22:10:09 +0000 | [diff] [blame] | 229 | |
Wanlong Gao | ef73cc9 | 2013-07-09 15:54:51 +0800 | [diff] [blame] | 230 | struct tst_kern_exv { |
| 231 | char *dist_name; |
| 232 | char *extra_ver; |
| 233 | }; |
| 234 | |
| 235 | int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers); |
| 236 | |
Xiaoguang Wang | 4694167 | 2014-04-25 10:02:07 +0800 | [diff] [blame] | 237 | enum { |
| 238 | TST_BYTES = 1, |
| 239 | TST_KB = 1024, |
| 240 | TST_MB = 1048576, |
| 241 | TST_GB = 1073741824, |
| 242 | }; |
| 243 | |
| 244 | /* lib/tst_fs_has_free.c |
| 245 | * |
| 246 | * @path: path is the pathname of any file within the mounted file system |
| 247 | * @mult: mult should be TST_KB, TST_MB or TST_GB |
| 248 | * the required free space is calculated by @size * @mult |
| 249 | */ |
| 250 | int tst_fs_has_free(void (*cleanup)(void), const char *path, |
| 251 | unsigned int size, unsigned int mult); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 252 | |
Jan Stancek | 11a84a6 | 2013-10-17 12:44:49 +0200 | [diff] [blame] | 253 | int tst_is_virt(int virt_type); |
| 254 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 255 | /* lib/self_exec.c */ |
Mike Frysinger | 55d8ae5 | 2014-02-13 04:11:45 -0500 | [diff] [blame] | 256 | void maybe_run_child(void (*child)(), const char *fmt, ...); |
| 257 | int self_exec(const char *argv0, const char *fmt, ...); |
subrata_modak | 744305e | 2008-08-19 07:00:49 +0000 | [diff] [blame] | 258 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 259 | /* Functions from lib/cloner.c */ |
Zeng Linggang | 1db6266 | 2014-01-09 20:10:11 +0800 | [diff] [blame] | 260 | int ltp_clone(unsigned long flags, int (*fn)(void *arg), void *arg, |
| 261 | size_t stack_size, void *stack); |
| 262 | int ltp_clone7(unsigned long flags, int (*fn)(void *arg), void *arg, |
zenglg.jy | 5f5cb63 | 2013-12-18 17:29:51 +0800 | [diff] [blame] | 263 | size_t stack_size, void *stack, ...); |
vapier | f6d7f09 | 2009-11-03 20:07:35 +0000 | [diff] [blame] | 264 | int ltp_clone_malloc(unsigned long clone_flags, int (*fn)(void *arg), |
| 265 | void *arg, size_t stacksize); |
| 266 | int ltp_clone_quick(unsigned long clone_flags, int (*fn)(void *arg), |
| 267 | void *arg); |
| 268 | #define clone(...) use_the_ltp_clone_functions,do_not_use_clone |
| 269 | |
Garrett Cooper | aec33cd | 2010-12-17 04:14:16 -0800 | [diff] [blame] | 270 | /* Function from lib/get_path.c */ |
Subrata Modak | ca758b7 | 2010-05-18 01:28:14 +0530 | [diff] [blame] | 271 | int tst_get_path(const char *prog_name, char *buf, size_t buf_len); |
| 272 | |
Wanlong Gao | 3b535a8 | 2012-10-18 16:35:14 +0800 | [diff] [blame] | 273 | /* lib/tst_cpu.c */ |
| 274 | long tst_ncpus(void); |
Zeng Linggang | da642ba | 2014-09-10 13:25:57 +0800 | [diff] [blame] | 275 | long tst_ncpus_conf(void); |
Wanlong Gao | 3b535a8 | 2012-10-18 16:35:14 +0800 | [diff] [blame] | 276 | long tst_ncpus_max(void); |
| 277 | |
Alexey Kodanev | 4bc55ec | 2013-06-27 18:52:22 +0400 | [diff] [blame] | 278 | /* lib/tst_run_cmd.c |
| 279 | * |
| 280 | * vfork() + execvp() specified program. |
| 281 | * @argv: a list of two (at least program name + NULL) or more pointers that |
| 282 | * represent the argument list to the new program. The array of pointers |
| 283 | * must be terminated by a NULL pointer. |
Stanislav kholmanskikh | bee0a94 | 2013-08-06 16:54:37 +0400 | [diff] [blame] | 284 | * @stdout_fd: file descriptor where to redirect stdout. Set -1 if |
| 285 | * redirection is not needed. |
| 286 | * @stderr_fd: file descriptor where to redirect stderr. Set -1 if |
| 287 | * redirection is not needed. |
Stanislav Kholmanskikh | a648a4d | 2015-01-26 13:15:32 +0300 | [diff] [blame] | 288 | * @pass_exit_val: if it's non-zero, this function will return the program |
| 289 | * exit code, otherwise it will call cleanup_fn() if the program |
| 290 | * exit code is not zero. |
Alexey Kodanev | 4bc55ec | 2013-06-27 18:52:22 +0400 | [diff] [blame] | 291 | */ |
Stanislav Kholmanskikh | a648a4d | 2015-01-26 13:15:32 +0300 | [diff] [blame] | 292 | int tst_run_cmd_fds(void (cleanup_fn)(void), |
Stanislav Kholmanskikh | e63337a | 2013-08-08 11:18:06 +0400 | [diff] [blame] | 293 | const char *const argv[], |
Stanislav kholmanskikh | bee0a94 | 2013-08-06 16:54:37 +0400 | [diff] [blame] | 294 | int stdout_fd, |
Stanislav Kholmanskikh | a648a4d | 2015-01-26 13:15:32 +0300 | [diff] [blame] | 295 | int stderr_fd, |
| 296 | int pass_exit_val); |
Stanislav kholmanskikh | bee0a94 | 2013-08-06 16:54:37 +0400 | [diff] [blame] | 297 | |
| 298 | /* Executes tst_run_cmd_fds() and redirects its output to a file |
| 299 | * @stdout_path: path where to redirect stdout. Set NULL if redirection is |
| 300 | * not needed. |
| 301 | * @stderr_path: path where to redirect stderr. Set NULL if redirection is |
| 302 | * not needed. |
Stanislav Kholmanskikh | a648a4d | 2015-01-26 13:15:32 +0300 | [diff] [blame] | 303 | * @pass_exit_val: if it's non-zero, this function will return the program |
| 304 | * exit code, otherwise it will call cleanup_fn() if the program |
| 305 | * exit code is not zero. |
Stanislav kholmanskikh | bee0a94 | 2013-08-06 16:54:37 +0400 | [diff] [blame] | 306 | */ |
Stanislav Kholmanskikh | a648a4d | 2015-01-26 13:15:32 +0300 | [diff] [blame] | 307 | int tst_run_cmd(void (cleanup_fn)(void), |
Stanislav Kholmanskikh | e63337a | 2013-08-08 11:18:06 +0400 | [diff] [blame] | 308 | const char *const argv[], |
Stanislav kholmanskikh | bee0a94 | 2013-08-06 16:54:37 +0400 | [diff] [blame] | 309 | const char *stdout_path, |
Stanislav Kholmanskikh | a648a4d | 2015-01-26 13:15:32 +0300 | [diff] [blame] | 310 | const char *stderr_path, |
| 311 | int pass_exit_val); |
Alexey Kodanev | 4bc55ec | 2013-06-27 18:52:22 +0400 | [diff] [blame] | 312 | |
George Wang | a83cbb8 | 2014-12-18 22:02:14 +0800 | [diff] [blame] | 313 | /* Wrapper function for system(3), ignorcing SIGCLD signal. |
| 314 | * @command: the command to be run. |
| 315 | */ |
| 316 | int tst_system(const char *command); |
| 317 | |
Cyril Hrubis | 2492ce2 | 2013-08-08 14:24:38 +0200 | [diff] [blame] | 318 | /* lib/tst_mkfs.c |
| 319 | * |
| 320 | * @dev: path to a device |
| 321 | * @fs_type: filesystem type |
Xiaoguang Wang | 3526685 | 2014-03-26 17:23:45 +0800 | [diff] [blame] | 322 | * @fs_opts: NULL or NULL terminated array of extra mkfs options |
Cyril Hrubis | 2492ce2 | 2013-08-08 14:24:38 +0200 | [diff] [blame] | 323 | */ |
| 324 | void tst_mkfs(void (cleanup_fn)(void), const char *dev, |
Xiaoguang Wang | 3526685 | 2014-03-26 17:23:45 +0800 | [diff] [blame] | 325 | const char *fs_type, const char *const fs_opts[]); |
Cyril Hrubis | 2492ce2 | 2013-08-08 14:24:38 +0200 | [diff] [blame] | 326 | |
Cyril Hrubis | e6c24c1 | 2014-06-19 12:46:45 +0200 | [diff] [blame] | 327 | /* |
| 328 | * Returns filesystem type to be used for the testing. Unless your test is |
| 329 | * designed for specific filesystem you should use this function to the tested |
| 330 | * filesytem. |
| 331 | * |
| 332 | * If TST_DEV_FS_TYPE is set the function returns it's content, |
| 333 | * otherwise default fs type hardcoded in the library is returned. |
| 334 | */ |
| 335 | const char *tst_dev_fs_type(void); |
| 336 | |
Cyril Hrubis | 85e787e | 2014-06-18 17:09:21 +0200 | [diff] [blame] | 337 | /* lib/tst_device.c |
| 338 | * |
| 339 | * Acquires test device. |
| 340 | * |
| 341 | * Can be used only once, i.e. you cannot get two different devices. |
| 342 | * |
| 343 | * Looks for LTP_DEV env variable first (which may be passed by the test |
| 344 | * driver or by a user) and returns just it's value if found. |
| 345 | * |
| 346 | * Otherwise creates a temp file and loop device. |
| 347 | * |
| 348 | * Note that you have to call tst_tmpdir() beforehand. |
| 349 | * |
| 350 | * Returns path to the device or NULL if it cannot be created. |
| 351 | */ |
| 352 | const char *tst_acquire_device(void (cleanup_fn)(void)); |
| 353 | |
| 354 | /* lib/tst_device.c |
| 355 | * @dev: device path returned by the tst_acquire_device() |
| 356 | */ |
| 357 | void tst_release_device(void (cleanup_fn)(void), const char *dev); |
| 358 | |
Cyril Hrubis | 420add2 | 2015-01-29 16:00:10 +0100 | [diff] [blame] | 359 | /* lib/tst_device.c |
| 360 | * |
| 361 | * Just like umount() but retries several times on failure. |
| 362 | * @path: Path to umount |
| 363 | */ |
| 364 | int tst_umount(const char *path); |
| 365 | |
Stanislav Kholmanskikh | 1d5d484 | 2013-08-14 10:01:46 +0400 | [diff] [blame] | 366 | /* lib/tst_fill_file.c |
| 367 | * |
| 368 | * Creates/ovewrites a file with specified pattern |
| 369 | * @path: path to file |
| 370 | * @pattern: pattern |
| 371 | * @bs: block size |
| 372 | * @bcount: blocks amount |
| 373 | */ |
| 374 | int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount); |
| 375 | |
Jan Stancek | e77bf55 | 2014-03-07 10:08:30 +0100 | [diff] [blame] | 376 | /* lib/tst_net.c |
| 377 | * |
| 378 | * Return unused port |
| 379 | */ |
| 380 | unsigned short tst_get_unused_port(void (cleanup_fn)(void), |
| 381 | unsigned short family, int type); |
| 382 | |
Xiaoguang Wang | 1a6f68a | 2014-05-13 19:02:59 +0800 | [diff] [blame] | 383 | /* lib/tst_res.c |
| 384 | * tst_strsig converts signal's value to corresponding string. |
| 385 | * tst_strerrno converts errno to corresponding string. |
| 386 | */ |
| 387 | const char *tst_strsig(int sig); |
| 388 | const char *tst_strerrno(int err); |
| 389 | |
gux.fnst@cn.fujitsu.com | 2db5739 | 2014-05-08 17:50:51 +0800 | [diff] [blame] | 390 | /* lib/tst_path_has_mnt_flags.c |
| 391 | * |
| 392 | * Check whether a path is on a filesystem that is mounted with |
| 393 | * specified flags |
Cyril Hrubis | 78fe642 | 2014-05-14 16:53:04 +0200 | [diff] [blame] | 394 | * @path: path to file, if path is NULL tst_tmpdir is used. |
gux.fnst@cn.fujitsu.com | 2db5739 | 2014-05-08 17:50:51 +0800 | [diff] [blame] | 395 | * @flags: NULL or NULL terminated array of mount flags |
| 396 | * |
| 397 | * Return: 0..n - number of flags matched |
| 398 | */ |
| 399 | int tst_path_has_mnt_flags(void (cleanup_fn)(void), |
| 400 | const char *path, const char *flags[]); |
| 401 | |
Xiaoguang Wang | 3db2082 | 2014-06-09 15:37:10 +0800 | [diff] [blame] | 402 | /* |
| 403 | * lib/tst_fs_link_count.c |
| 404 | * |
| 405 | * Try to get maximum number of hard links to a regular file inside the @dir. |
| 406 | * |
| 407 | * Note: This number depends on the filesystem @dir is on. |
| 408 | * |
| 409 | * The code uses link(2) to create hard links to a single file until it gets |
| 410 | * EMLINK or creates 65535 links. |
| 411 | * |
| 412 | * If limit is hit maximal number of hardlinks is returned and the the @dir is |
| 413 | * filled with hardlinks in format "testfile%i" where i belongs to [0, limit) |
| 414 | * interval. |
| 415 | * |
| 416 | * If no limit is hit (succed to create 65535 without error) or if link() |
| 417 | * failed with ENOSPC or EDQUOT zero is returned previously created files are |
| 418 | * removed. |
| 419 | */ |
| 420 | int tst_fs_fill_hardlinks(void (*cleanup) (void), const char *dir); |
| 421 | |
| 422 | /* |
| 423 | * lib/tst_fs_link_count.c |
| 424 | * |
| 425 | * Try to get maximum number of subdirectories in directory. |
| 426 | * |
| 427 | * Note: This number depends on the filesystem @dir is on. |
| 428 | * |
| 429 | * The code uses mkdir(2) to create directories in @dir until it gets EMLINK |
| 430 | * or creates 65535 directories. |
| 431 | * |
| 432 | * If limit is hit the maximal number of subdirectories is returned and the |
| 433 | * @dir is filled with subdirectories in format "testdir%i" where i belongs to |
| 434 | * [0, limit - 2) interval (because each newly created dir has two links |
| 435 | * allready the '.' and link from parent dir). |
| 436 | * |
| 437 | * If no limit is hit or mkdir() failed with ENOSPC or EDQUOT zero is returned |
| 438 | * previously created directories are removed. |
| 439 | * |
| 440 | */ |
| 441 | int tst_fs_fill_subdirs(void (*cleanup) (void), const char *dir); |
| 442 | |
Stanislav Kholmanskikh | 07a1033 | 2014-06-30 14:48:22 +0400 | [diff] [blame] | 443 | /* |
| 444 | * lib/tst_pid.c |
| 445 | * |
Stanislav Kholmanskikh | 502e42f | 2014-06-30 14:48:23 +0400 | [diff] [blame] | 446 | * Get a pid value not used by the OS |
Stanislav Kholmanskikh | 07a1033 | 2014-06-30 14:48:22 +0400 | [diff] [blame] | 447 | */ |
Stanislav Kholmanskikh | 502e42f | 2014-06-30 14:48:23 +0400 | [diff] [blame] | 448 | pid_t tst_get_unused_pid(void (*cleanup_fn) (void)); |
Stanislav Kholmanskikh | 07a1033 | 2014-06-30 14:48:22 +0400 | [diff] [blame] | 449 | |
| 450 | /* |
| 451 | * lib/tst_pid.c |
| 452 | * |
Stanislav Kholmanskikh | 502e42f | 2014-06-30 14:48:23 +0400 | [diff] [blame] | 453 | * Returns number of free pids by substarction of the number of pids |
Stanislav Kholmanskikh | 07a1033 | 2014-06-30 14:48:22 +0400 | [diff] [blame] | 454 | * currently used ('ps -eT') from max_pids |
| 455 | */ |
Stanislav Kholmanskikh | 502e42f | 2014-06-30 14:48:23 +0400 | [diff] [blame] | 456 | int tst_get_free_pids(void (*cleanup_fn) (void)); |
Stanislav Kholmanskikh | 07a1033 | 2014-06-30 14:48:22 +0400 | [diff] [blame] | 457 | |
subrata_modak | 744305e | 2008-08-19 07:00:49 +0000 | [diff] [blame] | 458 | #ifdef TST_USE_COMPAT16_SYSCALL |
| 459 | #define TCID_BIT_SUFFIX "_16" |
| 460 | #elif TST_USE_NEWER64_SYSCALL |
| 461 | #define TCID_BIT_SUFFIX "_64" |
| 462 | #else |
| 463 | #define TCID_BIT_SUFFIX "" |
| 464 | #endif |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 465 | #define TCID_DEFINE(ID) char *TCID = (#ID TCID_BIT_SUFFIX) |
subrata_modak | 744305e | 2008-08-19 07:00:49 +0000 | [diff] [blame] | 466 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 467 | #endif /* __TEST_H__ */ |