alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 3 | * AUTHOR : Kent Rogers (from Dave Fenner's original) |
| 4 | * CO-PILOT : Rich Logan |
| 5 | * DATE STARTED : 05/01/90 (rewritten 1/96) |
| 6 | * Copyright (c) 2009-2016 Cyril Hrubis <chrubis@suse.cz> |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 7 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 11 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 12 | * This program is distributed in the hope that it would be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 15 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 16 | * Further, this software is distributed without any warranty that it is |
| 17 | * free of the rightful claim of any third person regarding infringement |
| 18 | * or the like. Any license provided herein, whether implied or |
| 19 | * otherwise, applies only to this software file. Patent licenses, if |
| 20 | * any, provided herein do not apply to combinations of this program with |
| 21 | * other software, or any other product whatsoever. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 22 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 23 | * 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] | 24 | * with this program; if not, write the Free Software Foundation, Inc., |
| 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 26 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 27 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 28 | * Mountain View, CA 94043, or: |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 29 | * |
| 30 | * http://www.sgi.com |
| 31 | * |
| 32 | * For further information regarding this notice, see: |
| 33 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 34 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 35 | */ |
| 36 | |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 37 | #define _GNU_SOURCE |
Mike Frysinger | 55d8ae5 | 2014-02-13 04:11:45 -0500 | [diff] [blame] | 38 | |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 39 | #include <pthread.h> |
Garrett Cooper | d3e6e8f | 2010-12-13 02:55:35 -0800 | [diff] [blame] | 40 | #include <assert.h> |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 41 | #include <errno.h> |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 42 | #include <stdio.h> |
| 43 | #include <stdlib.h> |
| 44 | #include <stdarg.h> |
Garrett Cooper | d3e6e8f | 2010-12-13 02:55:35 -0800 | [diff] [blame] | 45 | #include <string.h> |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 46 | #include <unistd.h> |
Xiaoguang Wang | 8c1e0b3 | 2014-07-28 19:51:39 +0800 | [diff] [blame] | 47 | #include <sys/types.h> |
| 48 | #include <sys/wait.h> |
| 49 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 50 | #include "test.h" |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 51 | #include "usctest.h" |
Cyril Hrubis | 06f9fe4 | 2013-06-26 14:55:48 +0200 | [diff] [blame] | 52 | #include "ltp_priv.h" |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 53 | |
Cyril Hrubis | fc41661 | 2013-08-05 14:06:45 +0200 | [diff] [blame] | 54 | long TEST_RETURN; |
| 55 | int TEST_ERRNO; |
Cyril Hrubis | fc41661 | 2013-08-05 14:06:45 +0200 | [diff] [blame] | 56 | |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 57 | #define VERBOSE 1 |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 58 | #define NOPASS 3 |
| 59 | #define DISCARD 4 |
| 60 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 61 | #define MAXMESG 80 /* max length of internal messages */ |
| 62 | #define USERMESG 2048 /* max length of user message */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 63 | #define TRUE 1 |
| 64 | #define FALSE 0 |
| 65 | |
| 66 | /* |
| 67 | * EXPAND_VAR_ARGS - Expand the variable portion (arg_fmt) of a result |
| 68 | * message into the specified string. |
Garrett Cooper | 41176c3 | 2010-12-20 22:59:45 -0800 | [diff] [blame] | 69 | * |
| 70 | * NOTE (garrcoop): arg_fmt _must_ be the last element in each function |
| 71 | * argument list that employs this. |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 72 | */ |
Garrett Cooper | 41176c3 | 2010-12-20 22:59:45 -0800 | [diff] [blame] | 73 | #define EXPAND_VAR_ARGS(buf, arg_fmt, buf_len) do {\ |
| 74 | va_list ap; \ |
| 75 | assert(arg_fmt != NULL); \ |
| 76 | va_start(ap, arg_fmt); \ |
| 77 | vsnprintf(buf, buf_len, arg_fmt, ap); \ |
| 78 | va_end(ap); \ |
| 79 | assert(strlen(buf) > 0); \ |
| 80 | } while (0) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 81 | |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 82 | static pthread_mutex_t tmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; |
| 83 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 84 | static void check_env(void); |
Mike Frysinger | 55d8ae5 | 2014-02-13 04:11:45 -0500 | [diff] [blame] | 85 | static void tst_condense(int tnum, int ttype, const char *tmesg); |
| 86 | static void tst_print(const char *tcid, int tnum, int ttype, const char *tmesg); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 87 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 88 | static int T_exitval = 0; /* exit value used by tst_exit() */ |
| 89 | static int T_mode = VERBOSE; /* flag indicating print mode: VERBOSE, */ |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 90 | /* NOPASS, DISCARD */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 91 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 92 | static char Warn_mesg[MAXMESG]; /* holds warning messages */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * These are used for condensing output when NOT in verbose mode. |
| 96 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 97 | static int Buffered = FALSE; /* TRUE if condensed output is currently */ |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 98 | /* buffered (i.e. not yet printed) */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 99 | static char *Last_tcid; /* previous test case id */ |
| 100 | static int Last_num; /* previous test case number */ |
| 101 | static int Last_type; /* previous test result type */ |
| 102 | static char *Last_mesg; /* previous test result message */ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 103 | |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 104 | int tst_count = 0; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * These globals must be defined in the test. |
| 108 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 109 | extern char *TCID; /* Test case identifier from the test source */ |
| 110 | extern int TST_TOTAL; /* Total number of test cases from the test */ |
Cyril Hrubis | 7b20026 | 2013-11-14 14:38:26 +0100 | [diff] [blame] | 111 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 112 | |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 113 | struct pair { |
| 114 | const char *name; |
| 115 | int val; |
| 116 | }; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 117 | |
Cyril Hrubis | 7b20026 | 2013-11-14 14:38:26 +0100 | [diff] [blame] | 118 | #define PAIR(def) [def] = {.name = #def, .val = def}, |
Xiaoguang Wang | 1a6f68a | 2014-05-13 19:02:59 +0800 | [diff] [blame] | 119 | #define STRPAIR(key, value) [key] = {.name = value, .val = key}, |
Cyril Hrubis | 7b20026 | 2013-11-14 14:38:26 +0100 | [diff] [blame] | 120 | |
Cyril Hrubis | ee75ce3 | 2014-02-05 14:05:06 +0100 | [diff] [blame] | 121 | #define PAIR_LOOKUP(pair_arr, idx) do { \ |
| 122 | if (idx < 0 || (size_t)idx >= ARRAY_SIZE(pair_arr) || \ |
| 123 | pair_arr[idx].name == NULL) \ |
| 124 | return "???"; \ |
| 125 | return pair_arr[idx].name; \ |
Cyril Hrubis | 7b20026 | 2013-11-14 14:38:26 +0100 | [diff] [blame] | 126 | } while (0) |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 127 | |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 128 | const char *strttype(int ttype) |
| 129 | { |
Mike Frysinger | 55d8ae5 | 2014-02-13 04:11:45 -0500 | [diff] [blame] | 130 | static const struct pair ttype_pairs[] = { |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 131 | PAIR(TPASS) |
Cyril Hrubis | 7b20026 | 2013-11-14 14:38:26 +0100 | [diff] [blame] | 132 | PAIR(TFAIL) |
| 133 | PAIR(TBROK) |
Cyril Hrubis | 7b20026 | 2013-11-14 14:38:26 +0100 | [diff] [blame] | 134 | PAIR(TCONF) |
| 135 | PAIR(TWARN) |
| 136 | PAIR(TINFO) |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 137 | }; |
Cyril Hrubis | 7b20026 | 2013-11-14 14:38:26 +0100 | [diff] [blame] | 138 | |
| 139 | PAIR_LOOKUP(ttype_pairs, TTYPE_RESULT(ttype)); |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Cyril Hrubis | 7b20026 | 2013-11-14 14:38:26 +0100 | [diff] [blame] | 142 | #include "errnos.h" |
Xiaoguang Wang | 1a6f68a | 2014-05-13 19:02:59 +0800 | [diff] [blame] | 143 | #include "signame.h" |
| 144 | |
Cyril Hrubis | 6bb766e | 2015-12-16 13:28:47 +0100 | [diff] [blame] | 145 | static void tst_res__(const char *file, const int lineno, int ttype, |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 146 | const char *arg_fmt, ...) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 147 | { |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 148 | pthread_mutex_lock(&tmutex); |
| 149 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 150 | char tmesg[USERMESG]; |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 151 | int len = 0; |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 152 | int ttype_result = TTYPE_RESULT(ttype); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 153 | |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 154 | if (file && (ttype_result != TPASS && ttype_result != TINFO)) |
| 155 | len = sprintf(tmesg, "%s:%d: ", file, lineno); |
| 156 | EXPAND_VAR_ARGS(tmesg + len, arg_fmt, USERMESG - len); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 157 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 158 | /* |
| 159 | * Save the test result type by ORing ttype into the current exit |
| 160 | * value (used by tst_exit()). |
| 161 | */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 162 | T_exitval |= ttype_result; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 163 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 164 | check_env(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 165 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 166 | /* |
| 167 | * Set the test case number and print the results, depending on the |
| 168 | * display type. |
| 169 | */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 170 | if (ttype_result == TWARN || ttype_result == TINFO) { |
Garrett Cooper | 5b87544 | 2010-12-13 20:49:15 -0800 | [diff] [blame] | 171 | tst_print(TCID, 0, ttype, tmesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 172 | } else { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 173 | if (tst_count < 0) |
Garrett Cooper | 5b87544 | 2010-12-13 20:49:15 -0800 | [diff] [blame] | 174 | tst_print(TCID, 0, TWARN, |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 175 | "tst_res(): tst_count < 0 is not valid"); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 176 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 177 | /* |
| 178 | * Process each display type. |
| 179 | */ |
| 180 | switch (T_mode) { |
Garrett Cooper | 8798ebf | 2010-12-13 20:27:37 -0800 | [diff] [blame] | 181 | case DISCARD: |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 182 | break; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 183 | case NOPASS: /* filtered by tst_print() */ |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 184 | tst_condense(tst_count + 1, ttype, tmesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 185 | break; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 186 | default: /* VERBOSE */ |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 187 | tst_print(TCID, tst_count + 1, ttype, tmesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 188 | break; |
| 189 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 190 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 191 | tst_count++; |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 192 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 193 | |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 194 | pthread_mutex_unlock(&tmutex); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 195 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 196 | |
Mike Frysinger | 55d8ae5 | 2014-02-13 04:11:45 -0500 | [diff] [blame] | 197 | static void tst_condense(int tnum, int ttype, const char *tmesg) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 198 | { |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 199 | int ttype_result = TTYPE_RESULT(ttype); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 200 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 201 | /* |
| 202 | * If this result is the same as the previous result, return. |
| 203 | */ |
| 204 | if (Buffered == TRUE) { |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 205 | if (strcmp(Last_tcid, TCID) == 0 && Last_type == ttype_result && |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 206 | strcmp(Last_mesg, tmesg) == 0) |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 207 | return; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 208 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 209 | /* |
| 210 | * This result is different from the previous result. First, |
| 211 | * print the previous result. |
| 212 | */ |
Garrett Cooper | 5b87544 | 2010-12-13 20:49:15 -0800 | [diff] [blame] | 213 | tst_print(Last_tcid, Last_num, Last_type, Last_mesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 214 | free(Last_tcid); |
| 215 | free(Last_mesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 216 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 217 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 218 | /* |
| 219 | * If a file was specified, print the current result since we have no |
| 220 | * way of retaining the file contents for comparing with future |
| 221 | * results. Otherwise, buffer the current result info for next time. |
| 222 | */ |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 223 | Last_tcid = malloc(strlen(TCID) + 1); |
| 224 | strcpy(Last_tcid, TCID); |
| 225 | Last_num = tnum; |
| 226 | Last_type = ttype_result; |
| 227 | Last_mesg = malloc(strlen(tmesg) + 1); |
| 228 | strcpy(Last_mesg, tmesg); |
| 229 | Buffered = TRUE; |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 230 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 231 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 232 | void tst_flush(void) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 233 | { |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 234 | NO_NEWLIB_ASSERT("Unknown", 0); |
| 235 | |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 236 | pthread_mutex_lock(&tmutex); |
| 237 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 238 | /* |
Garrett Cooper | 5b87544 | 2010-12-13 20:49:15 -0800 | [diff] [blame] | 239 | * Print out last line if in NOPASS mode. |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 240 | */ |
Garrett Cooper | 5b87544 | 2010-12-13 20:49:15 -0800 | [diff] [blame] | 241 | if (Buffered == TRUE && T_mode == NOPASS) { |
| 242 | tst_print(Last_tcid, Last_num, Last_type, Last_mesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 243 | Buffered = FALSE; |
| 244 | } |
| 245 | |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 246 | fflush(stdout); |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 247 | |
| 248 | pthread_mutex_unlock(&tmutex); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 249 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 250 | |
Mike Frysinger | 55d8ae5 | 2014-02-13 04:11:45 -0500 | [diff] [blame] | 251 | static void tst_print(const char *tcid, int tnum, int ttype, const char *tmesg) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 252 | { |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 253 | int err = errno; |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 254 | const char *type; |
| 255 | int ttype_result = TTYPE_RESULT(ttype); |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 256 | char message[USERMESG]; |
Cyril Hrubis | ee75ce3 | 2014-02-05 14:05:06 +0100 | [diff] [blame] | 257 | size_t size; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 258 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 259 | /* |
| 260 | * Save the test result type by ORing ttype into the current exit value |
| 261 | * (used by tst_exit()). This is already done in tst_res(), but is |
| 262 | * also done here to catch internal warnings. For internal warnings, |
| 263 | * tst_print() is called directly with a case of TWARN. |
| 264 | */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 265 | T_exitval |= ttype_result; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 266 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 267 | /* |
| 268 | * If output mode is DISCARD, or if the output mode is NOPASS and this |
| 269 | * result is not one of FAIL, BROK, or WARN, just return. This check |
| 270 | * is necessary even though we check for DISCARD mode inside of |
| 271 | * tst_res(), since occasionally we get to this point without going |
| 272 | * through tst_res() (e.g. internal TWARN messages). |
| 273 | */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 274 | if (T_mode == DISCARD || (T_mode == NOPASS && ttype_result != TFAIL && |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 275 | ttype_result != TBROK |
| 276 | && ttype_result != TWARN)) |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 277 | return; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 278 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 279 | /* |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 280 | * Build the result line and print it. |
| 281 | */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 282 | type = strttype(ttype); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 283 | if (T_mode == VERBOSE) { |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 284 | size = snprintf(message, sizeof(message), |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 285 | "%-8s %4d %s : %s", tcid, tnum, type, tmesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 286 | } else { |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 287 | size = snprintf(message, sizeof(message), |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 288 | "%-8s %4d %s : %s", |
| 289 | tcid, tnum, type, tmesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 290 | } |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 291 | |
| 292 | if (size >= sizeof(message)) { |
| 293 | printf("%s: %i: line too long\n", __func__, __LINE__); |
| 294 | abort(); |
| 295 | } |
| 296 | |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 297 | if (ttype & TERRNO) { |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 298 | size += snprintf(message + size, sizeof(message) - size, |
Xiaoguang Wang | 1a6f68a | 2014-05-13 19:02:59 +0800 | [diff] [blame] | 299 | ": errno=%s(%i): %s", tst_strerrno(err), |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 300 | err, strerror(err)); |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 301 | } |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 302 | |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 303 | if (size >= sizeof(message)) { |
| 304 | printf("%s: %i: line too long\n", __func__, __LINE__); |
| 305 | abort(); |
| 306 | } |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 307 | |
yaberauneya | 7113a0c | 2009-12-01 08:57:20 +0000 | [diff] [blame] | 308 | if (ttype & TTERRNO) { |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 309 | size += snprintf(message + size, sizeof(message) - size, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 310 | ": TEST_ERRNO=%s(%i): %s", |
Xiaoguang Wang | 1a6f68a | 2014-05-13 19:02:59 +0800 | [diff] [blame] | 311 | tst_strerrno(TEST_ERRNO), (int)TEST_ERRNO, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 312 | strerror(TEST_ERRNO)); |
yaberauneya | 7113a0c | 2009-12-01 08:57:20 +0000 | [diff] [blame] | 313 | } |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 314 | |
Jan Stancek | 927a15c | 2014-09-11 11:11:45 +0200 | [diff] [blame] | 315 | if (size >= sizeof(message)) { |
| 316 | printf("%s: %i: line too long\n", __func__, __LINE__); |
| 317 | abort(); |
| 318 | } |
| 319 | |
| 320 | if (ttype & TRERRNO) { |
| 321 | size += snprintf(message + size, sizeof(message) - size, |
| 322 | ": TEST_RETURN=%s(%i): %s", |
| 323 | tst_strerrno(TEST_RETURN), (int)TEST_RETURN, |
| 324 | strerror(TEST_RETURN)); |
| 325 | } |
| 326 | |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 327 | if (size + 1 >= sizeof(message)) { |
| 328 | printf("%s: %i: line too long\n", __func__, __LINE__); |
| 329 | abort(); |
| 330 | } |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 331 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 332 | message[size] = '\n'; |
| 333 | message[size + 1] = '\0'; |
Cyril Hrubis | d2e9f84 | 2012-01-19 17:47:35 +0100 | [diff] [blame] | 334 | |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 335 | fputs(message, stdout); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 336 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 337 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 338 | static void check_env(void) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 339 | { |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 340 | static int first_time = 1; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 341 | char *value; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 342 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 343 | if (!first_time) |
| 344 | return; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 345 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 346 | first_time = 0; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 347 | |
Garrett Cooper | 60cd167 | 2010-11-23 21:06:05 -0800 | [diff] [blame] | 348 | /* BTOUTPUT not defined, use default */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 349 | if ((value = getenv(TOUTPUT)) == NULL) { |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 350 | T_mode = VERBOSE; |
| 351 | return; |
| 352 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 353 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 354 | if (strcmp(value, TOUT_NOPASS_S) == 0) { |
| 355 | T_mode = NOPASS; |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | if (strcmp(value, TOUT_DISCARD_S) == 0) { |
| 360 | T_mode = DISCARD; |
| 361 | return; |
| 362 | } |
| 363 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 364 | T_mode = VERBOSE; |
| 365 | return; |
| 366 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 367 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 368 | void tst_exit(void) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 369 | { |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 370 | NO_NEWLIB_ASSERT("Unknown", 0); |
| 371 | |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 372 | pthread_mutex_lock(&tmutex); |
| 373 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 374 | tst_flush(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 375 | |
Xiaoguang Wang | cdfe337 | 2014-07-21 17:00:03 +0800 | [diff] [blame] | 376 | exit(T_exitval & ~TINFO); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 377 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 378 | |
Cyril Hrubis | ddd3b85 | 2014-02-03 17:10:04 +0100 | [diff] [blame] | 379 | pid_t tst_fork(void) |
| 380 | { |
Xiaoguang Wang | 8c1e0b3 | 2014-07-28 19:51:39 +0800 | [diff] [blame] | 381 | pid_t child; |
| 382 | |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 383 | NO_NEWLIB_ASSERT("Unknown", 0); |
| 384 | |
Cyril Hrubis | ddd3b85 | 2014-02-03 17:10:04 +0100 | [diff] [blame] | 385 | tst_flush(); |
Xiaoguang Wang | 8c1e0b3 | 2014-07-28 19:51:39 +0800 | [diff] [blame] | 386 | |
| 387 | child = fork(); |
| 388 | if (child == 0) |
| 389 | T_exitval = 0; |
| 390 | |
| 391 | return child; |
| 392 | } |
| 393 | |
| 394 | void tst_record_childstatus(void (*cleanup)(void), pid_t child) |
| 395 | { |
| 396 | int status, ttype_result; |
| 397 | |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 398 | NO_NEWLIB_ASSERT("Unknown", 0); |
| 399 | |
Xiaoguang Wang | 8c1e0b3 | 2014-07-28 19:51:39 +0800 | [diff] [blame] | 400 | if (waitpid(child, &status, 0) < 0) |
| 401 | tst_brkm(TBROK | TERRNO, cleanup, "waitpid(%d) failed", child); |
| 402 | |
| 403 | if (WIFEXITED(status)) { |
| 404 | ttype_result = WEXITSTATUS(status); |
| 405 | ttype_result = TTYPE_RESULT(ttype_result); |
| 406 | T_exitval |= ttype_result; |
| 407 | |
| 408 | if (ttype_result == TPASS) |
| 409 | tst_resm(TINFO, "Child process returned TPASS"); |
| 410 | |
| 411 | if (ttype_result & TFAIL) |
| 412 | tst_resm(TINFO, "Child process returned TFAIL"); |
| 413 | |
| 414 | if (ttype_result & TBROK) |
| 415 | tst_resm(TINFO, "Child process returned TBROK"); |
| 416 | |
| 417 | if (ttype_result & TCONF) |
| 418 | tst_resm(TINFO, "Child process returned TCONF"); |
| 419 | |
| 420 | } else { |
| 421 | tst_brkm(TBROK, cleanup, "child process(%d) killed by " |
| 422 | "unexpected signal %s(%d)", child, |
| 423 | tst_strsig(WTERMSIG(status)), WTERMSIG(status)); |
| 424 | } |
Cyril Hrubis | ddd3b85 | 2014-02-03 17:10:04 +0100 | [diff] [blame] | 425 | } |
| 426 | |
Cyril Hrubis | 3f0510c | 2014-02-06 13:50:14 +0100 | [diff] [blame] | 427 | pid_t tst_vfork(void) |
| 428 | { |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 429 | NO_NEWLIB_ASSERT("Unknown", 0); |
| 430 | |
Cyril Hrubis | 3f0510c | 2014-02-06 13:50:14 +0100 | [diff] [blame] | 431 | tst_flush(); |
| 432 | return vfork(); |
| 433 | } |
| 434 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 435 | /* |
Garrett Cooper | 68d76e0 | 2010-12-20 05:49:48 -0800 | [diff] [blame] | 436 | * Make tst_brk reentrant so that one can call the SAFE_* macros from within |
| 437 | * user-defined cleanup functions. |
| 438 | */ |
Garrett Cooper | 43891b7 | 2010-12-20 06:37:22 -0800 | [diff] [blame] | 439 | static int tst_brk_entered = 0; |
Garrett Cooper | 68d76e0 | 2010-12-20 05:49:48 -0800 | [diff] [blame] | 440 | |
Cyril Hrubis | ec2765c | 2016-01-07 12:12:34 +0100 | [diff] [blame] | 441 | static void tst_brk__(const char *file, const int lineno, int ttype, |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 442 | void (*func)(void), const char *arg_fmt, ...) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 443 | { |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 444 | pthread_mutex_lock(&tmutex); |
| 445 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 446 | char tmesg[USERMESG]; |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 447 | int ttype_result = TTYPE_RESULT(ttype); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 448 | |
subrata_modak | 3311a25 | 2009-10-13 13:59:29 +0000 | [diff] [blame] | 449 | EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 450 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 451 | /* |
| 452 | * Only FAIL, BROK, CONF, and RETR are supported by tst_brk(). |
| 453 | */ |
vapier | 9799ea1 | 2009-07-20 02:42:32 +0000 | [diff] [blame] | 454 | if (ttype_result != TFAIL && ttype_result != TBROK && |
Xiaoguang Wang | cdfe337 | 2014-07-21 17:00:03 +0800 | [diff] [blame] | 455 | ttype_result != TCONF) { |
Garrett Cooper | eacf2a3 | 2010-12-16 16:04:04 -0800 | [diff] [blame] | 456 | sprintf(Warn_mesg, "%s: Invalid Type: %d. Using TBROK", |
| 457 | __func__, ttype_result); |
Garrett Cooper | 5b87544 | 2010-12-13 20:49:15 -0800 | [diff] [blame] | 458 | tst_print(TCID, 0, TWARN, Warn_mesg); |
Garrett Cooper | eacf2a3 | 2010-12-16 16:04:04 -0800 | [diff] [blame] | 459 | /* Keep TERRNO, TTERRNO, etc. */ |
| 460 | ttype = (ttype & ~ttype_result) | TBROK; |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 461 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 462 | |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 463 | tst_res__(file, lineno, ttype, "%s", tmesg); |
Garrett Cooper | 68d76e0 | 2010-12-20 05:49:48 -0800 | [diff] [blame] | 464 | if (tst_brk_entered == 0) { |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 465 | if (ttype_result == TCONF) { |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 466 | tst_res__(file, lineno, ttype, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 467 | "Remaining cases not appropriate for " |
| 468 | "configuration"); |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 469 | } else if (ttype_result == TBROK) { |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 470 | tst_res__(file, lineno, TBROK, |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 471 | "Remaining cases broken"); |
| 472 | } |
Garrett Cooper | 68d76e0 | 2010-12-20 05:49:48 -0800 | [diff] [blame] | 473 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 474 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 475 | /* |
| 476 | * If no cleanup function was specified, just return to the caller. |
Garrett Cooper | 9f2555e | 2010-12-13 23:55:22 -0800 | [diff] [blame] | 477 | * Otherwise call the specified function. |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 478 | */ |
Garrett Cooper | 43891b7 | 2010-12-20 06:37:22 -0800 | [diff] [blame] | 479 | if (func != NULL) { |
| 480 | tst_brk_entered++; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 481 | (*func) (); |
Garrett Cooper | 43891b7 | 2010-12-20 06:37:22 -0800 | [diff] [blame] | 482 | tst_brk_entered--; |
Garrett Cooper | 6bfb01e | 2010-11-22 10:16:28 -0800 | [diff] [blame] | 483 | } |
Garrett Cooper | 43891b7 | 2010-12-20 06:37:22 -0800 | [diff] [blame] | 484 | if (tst_brk_entered == 0) |
| 485 | tst_exit(); |
| 486 | |
Alexey Kodanev | 89293b2 | 2014-02-18 17:53:36 +0400 | [diff] [blame] | 487 | pthread_mutex_unlock(&tmutex); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 488 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 489 | |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 490 | void tst_resm_(const char *file, const int lineno, int ttype, |
| 491 | const char *arg_fmt, ...) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 492 | { |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 493 | char tmesg[USERMESG]; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 494 | |
subrata_modak | 3311a25 | 2009-10-13 13:59:29 +0000 | [diff] [blame] | 495 | EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 496 | |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 497 | if (tst_test) |
| 498 | tst_res_(file, lineno, ttype, "%s", tmesg); |
| 499 | else |
| 500 | tst_res__(file, lineno, ttype, "%s", tmesg); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 501 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 502 | |
Jan Stancek | f72ca5b | 2016-10-06 13:34:39 +0200 | [diff] [blame] | 503 | typedef void (*tst_res_func_t)(const char *file, const int lineno, |
| 504 | int ttype, const char *fmt, ...); |
| 505 | |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 506 | void tst_resm_hexd_(const char *file, const int lineno, int ttype, |
| 507 | const void *buf, size_t size, const char *arg_fmt, ...) |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 508 | { |
| 509 | char tmesg[USERMESG]; |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 510 | static const size_t symb_num = 2; /* xx */ |
| 511 | static const size_t size_max = 16; |
| 512 | size_t offset = strlen(tmesg); |
Jan Stancek | f72ca5b | 2016-10-06 13:34:39 +0200 | [diff] [blame] | 513 | size_t i; |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 514 | char *pmesg = tmesg; |
Jan Stancek | f72ca5b | 2016-10-06 13:34:39 +0200 | [diff] [blame] | 515 | tst_res_func_t res_func; |
| 516 | |
| 517 | if (tst_test) |
| 518 | res_func = tst_res_; |
| 519 | else |
| 520 | res_func = tst_res__; |
| 521 | |
| 522 | EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG); |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 523 | |
| 524 | if (size > size_max || size == 0 || |
| 525 | (offset + size * (symb_num + 1)) >= USERMESG) |
Jan Stancek | f72ca5b | 2016-10-06 13:34:39 +0200 | [diff] [blame] | 526 | res_func(file, lineno, ttype, "%s", tmesg); |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 527 | else |
| 528 | pmesg += offset; |
| 529 | |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 530 | for (i = 0; i < size; ++i) { |
| 531 | /* add space before byte except first one */ |
| 532 | if (pmesg != tmesg) |
| 533 | *(pmesg++) = ' '; |
| 534 | |
| 535 | sprintf(pmesg, "%02x", ((unsigned char *)buf)[i]); |
| 536 | pmesg += symb_num; |
| 537 | if ((i + 1) % size_max == 0 || i + 1 == size) { |
Jan Stancek | f72ca5b | 2016-10-06 13:34:39 +0200 | [diff] [blame] | 538 | res_func(file, lineno, ttype, "%s", tmesg); |
Alexey Kodanev | 04a34ba | 2013-05-23 11:03:18 +0400 | [diff] [blame] | 539 | pmesg = tmesg; |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
Xiaoguang Wang | a161c6f | 2014-07-21 17:00:04 +0800 | [diff] [blame] | 544 | void tst_brkm_(const char *file, const int lineno, int ttype, |
| 545 | void (*func)(void), const char *arg_fmt, ...) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 546 | { |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 547 | char tmesg[USERMESG]; |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 548 | |
subrata_modak | 3311a25 | 2009-10-13 13:59:29 +0000 | [diff] [blame] | 549 | EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 550 | |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 551 | if (tst_test) { |
| 552 | if (func) { |
| 553 | tst_brk_(file, lineno, TBROK, |
| 554 | "Non-NULL cleanup in newlib!"); |
| 555 | } |
| 556 | |
| 557 | tst_brk_(file, lineno, ttype, "%s", tmesg); |
| 558 | } else { |
| 559 | tst_brk__(file, lineno, ttype, func, "%s", tmesg); |
| 560 | } |
| 561 | |
Cyril Hrubis | 3e60f62 | 2016-02-03 18:25:11 +0100 | [diff] [blame] | 562 | /* Shouldn't be reached, but fixes build time warnings about noreturn. */ |
Mike Frysinger | 9f42be1 | 2014-01-13 18:09:23 -0500 | [diff] [blame] | 563 | abort(); |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 564 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 565 | |
Cyril Hrubis | d1e794d | 2015-07-30 23:52:51 +0200 | [diff] [blame] | 566 | void tst_require_root(void) |
vapier | 640adf4 | 2008-05-06 15:47:54 +0000 | [diff] [blame] | 567 | { |
Cyril Hrubis | bbdb9f7 | 2016-03-16 15:53:57 +0100 | [diff] [blame] | 568 | NO_NEWLIB_ASSERT("Unknown", 0); |
| 569 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 570 | if (geteuid() != 0) |
Cyril Hrubis | d1e794d | 2015-07-30 23:52:51 +0200 | [diff] [blame] | 571 | tst_brkm(TCONF, NULL, "Test needs to be run as root"); |
vapier | 640adf4 | 2008-05-06 15:47:54 +0000 | [diff] [blame] | 572 | } |