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