1 /* 2 * Copyright (c) 2015-2016 Cyril Hrubis <chrubis (at) suse.cz> 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef TST_TEST_H__ 19 #define TST_TEST_H__ 20 21 #include <unistd.h> 22 23 #include "tst_common.h" 24 #include "tst_res_flags.h" 25 #include "tst_checkpoint.h" 26 #include "tst_device.h" 27 #include "tst_mkfs.h" 28 #include "tst_fs.h" 29 #include "tst_pid.h" 30 #include "tst_cmd.h" 31 #include "tst_cpu.h" 32 #include "tst_process_state.h" 33 #include "tst_atomic.h" 34 #include "tst_kvercmp.h" 35 36 /* 37 * Reports testcase result. 38 */ 39 void tst_res_(const char *file, const int lineno, int ttype, 40 const char *fmt, ...) 41 __attribute__ ((format (printf, 4, 5))); 42 43 #define tst_res(ttype, arg_fmt, ...) \ 44 tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) 45 46 /* 47 * Reports result and exits a test. 48 */ 49 void tst_brk_(const char *file, const int lineno, int ttype, 50 const char *fmt, ...) 51 __attribute__ ((format (printf, 4, 5))) 52 __attribute__ ((noreturn)); 53 54 #define tst_brk(ttype, arg_fmt, ...) \ 55 tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) 56 57 pid_t safe_fork(const char *filename, unsigned int lineno); 58 #define SAFE_FORK() \ 59 safe_fork(__FILE__, __LINE__) 60 61 #include "tst_safe_macros.h" 62 #include "tst_safe_file_ops.h" 63 #include "tst_safe_net.h" 64 #include "tst_safe_pthread.h" 65 66 struct tst_option { 67 char *optstr; 68 char **arg; 69 char *help; 70 }; 71 72 struct tst_test { 73 /* test id usually the same as test filename without file suffix */ 74 const char *tid; 75 /* number of tests available in test() function */ 76 unsigned int tcnt; 77 78 struct tst_option *options; 79 80 const char *min_kver; 81 82 int needs_tmpdir:1; 83 int needs_root:1; 84 int forks_child:1; 85 int needs_device:1; 86 int needs_checkpoints:1; 87 88 /* override default timeout per test run */ 89 unsigned int timeout; 90 91 void (*setup)(void); 92 void (*cleanup)(void); 93 94 void (*test)(unsigned int test_nr); 95 void (*test_all)(void); 96 97 /* NULL terminated array of resource file names */ 98 const char *const *resource_files; 99 }; 100 101 /* 102 * Runs tests. 103 */ 104 void tst_run_tcases(int argc, char *argv[], struct tst_test *self) 105 __attribute__ ((noreturn)); 106 107 /* 108 * Does library initialization for child processes started by exec() 109 * 110 * The LTP_IPC_PATH variable must be passed to the program environment. 111 */ 112 void tst_reinit(void); 113 114 //TODO Clean? 115 #define TEST(SCALL) \ 116 do { \ 117 errno = 0; \ 118 TEST_RETURN = SCALL; \ 119 TEST_ERRNO = errno; \ 120 } while (0) 121 122 extern long TEST_RETURN; 123 extern int TEST_ERRNO; 124 125 /* 126 * Functions to convert ERRNO to its name and SIGNAL to its name. 127 */ 128 const char *tst_strerrno(int err); 129 const char *tst_strsig(int sig); 130 131 #ifndef TST_NO_DEFAULT_MAIN 132 133 static struct tst_test test; 134 135 int main(int argc, char *argv[]) 136 { 137 tst_run_tcases(argc, argv, &test); 138 } 139 140 #endif /* TST_NO_DEFAULT_MAIN */ 141 142 #define TST_TEST_TCONF(message) \ 143 static void tst_do_test(void) { tst_brk(TCONF, "%s", message); }; \ 144 static struct tst_test test = { .test_all = tst_do_test } \ 145 146 /* 147 * This is a hack to make the testcases link without defining TCID 148 */ 149 const char *TCID; 150 151 #endif /* TST_TEST_H__ */ 152