subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007-2008 ,Hitachi, Ltd */ |
| 3 | /* Author(s): Takahiro Yasui <takahiro.yasui.mp@hitachi.com>, */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 4 | /* Yumiko Sugita <yumiko.sugita.yf@hitachi.com>, */ |
| 5 | /* Satoshi Fujiwara <sa-fuji@sdl.hitachi.co.jp> */ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 6 | /* */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 7 | /* This program is free software; you can redistribute it and/or modify */ |
| 8 | /* it under the terms of the GNU General Public License as published by */ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 9 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 10 | /* (at your option) any later version. */ |
| 11 | /* */ |
| 12 | /* This program is distributed in the hope that it will be useful, */ |
| 13 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 14 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 15 | /* the GNU General Public License for more details. */ |
| 16 | /* */ |
| 17 | /* You should have received a copy of the GNU General Public License */ |
| 18 | /* along with this program; if not, write to the Free Software */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 19 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 20 | /* */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 21 | /******************************************************************************/ |
| 22 | /******************************************************************************/ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 23 | /* */ |
| 24 | /* File: clock_nanosleep01.c */ |
| 25 | /* */ |
| 26 | /* Description: This tests the clock_nanosleep() syscall */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 27 | /* */ |
| 28 | /* */ |
| 29 | /* */ |
| 30 | /* */ |
| 31 | /* */ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 32 | /* */ |
| 33 | /* Usage: <for command-line> */ |
| 34 | /* clock_nanosleep01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 35 | /* where, -c n : Run n copies concurrently. */ |
| 36 | /* -e : Turn on errno logging. */ |
| 37 | /* -i n : Execute test n times. */ |
| 38 | /* -I x : Execute test for x seconds. */ |
| 39 | /* -P x : Pause for x seconds between iterations. */ |
| 40 | /* -t : Turn on syscall timing. */ |
| 41 | /* */ |
| 42 | /* Total Tests: 1 */ |
| 43 | /* */ |
| 44 | /* Test Name: clock_nanosleep01 */ |
| 45 | /* History: Porting from Crackerjack to LTP is done by */ |
| 46 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 47 | /******************************************************************************/ |
| 48 | #include <sys/syscall.h> |
| 49 | #include <sys/types.h> |
| 50 | #include <getopt.h> |
| 51 | #include <string.h> |
| 52 | #include <stdlib.h> |
| 53 | #include <errno.h> |
| 54 | #include <stdio.h> |
| 55 | #include <time.h> |
| 56 | #include <signal.h> |
| 57 | #include "../utils/common_j_h.c" |
| 58 | #include "../utils/include_j_h.h" |
| 59 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 60 | #include "test.h" |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 61 | #include "linux_syscall_numbers.h" |
| 62 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 63 | char *TCID = "clock_nanosleep01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 64 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 65 | int TST_TOTAL = 1; |
subrata_modak | 266ec97 | 2009-10-18 17:56:53 +0000 | [diff] [blame] | 66 | struct sigaction act; |
| 67 | |
| 68 | /* |
| 69 | * sighandler() |
| 70 | */ |
| 71 | void sighandler(int sig) |
| 72 | { |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 73 | if (sig == SIGINT) |
| 74 | return; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 75 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 76 | return; |
subrata_modak | 266ec97 | 2009-10-18 17:56:53 +0000 | [diff] [blame] | 77 | } |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 78 | |
| 79 | /* Extern Global Functions */ |
| 80 | /******************************************************************************/ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 81 | /* */ |
| 82 | /* Function: cleanup */ |
| 83 | /* */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 84 | /* Description: Performs all one time clean up for this test on successful */ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 85 | /* completion, premature exit or failure. Closes all temporary */ |
| 86 | /* files, removes all temporary directories exits the test with */ |
| 87 | /* appropriate return code by calling tst_exit() function. */ |
| 88 | /* */ |
| 89 | /* Input: None. */ |
| 90 | /* */ |
| 91 | /* Output: None. */ |
| 92 | /* */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 93 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 94 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 95 | /* */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 96 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 97 | void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 98 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 99 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 100 | tst_rmdir(); |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 101 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /* Local Functions */ |
| 105 | /******************************************************************************/ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 106 | /* */ |
| 107 | /* Function: setup */ |
| 108 | /* */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 109 | /* Description: Performs all one time setup for this test. This function is */ |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 110 | /* typically used to capture signals, create temporary dirs */ |
| 111 | /* and temporary files that may be used in the course of this */ |
| 112 | /* test. */ |
| 113 | /* */ |
| 114 | /* Input: None. */ |
| 115 | /* */ |
| 116 | /* Output: None. */ |
| 117 | /* */ |
| 118 | /* Return: On failure - Exits by calling cleanup(). */ |
| 119 | /* On success - returns 0. */ |
| 120 | /* */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 121 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 122 | void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | { |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 124 | /* Capture signals if any */ |
subrata_modak | 266ec97 | 2009-10-18 17:56:53 +0000 | [diff] [blame] | 125 | act.sa_handler = sighandler; |
| 126 | sigfillset(&act.sa_mask); |
| 127 | sigaction(SIGINT, &act, NULL); |
| 128 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 129 | /* Create temporary directories */ |
| 130 | TEST_PAUSE; |
| 131 | tst_tmpdir(); |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 132 | } |
| 133 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 134 | /* |
| 135 | * Macros |
| 136 | */ |
| 137 | #define SYSCALL_NAME "clock_nanosleep" |
| 138 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 139 | enum test_type { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 140 | NORMAL, |
| 141 | NULL_POINTER, |
| 142 | SEND_SIGINT, |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 145 | /* |
| 146 | * Data Structure |
| 147 | */ |
| 148 | struct test_case { |
| 149 | clockid_t clk_id; |
| 150 | int ttype; |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 151 | int flags; |
| 152 | time_t sec; |
| 153 | long nsec; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 154 | int ret; |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 155 | int err; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 158 | /* Test cases |
| 159 | * |
| 160 | * test status of errors on man page |
| 161 | * |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 162 | * EINTR v (function was interrupted by a signal) |
| 163 | * EINVAL v (invalid tv_nsec, etc.) |
| 164 | * ENOTSUP can't check because not supported clk_id generates |
| 165 | * EINVAL |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 166 | */ |
| 167 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 168 | static struct test_case tcase[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 169 | { // case00 |
| 170 | .clk_id = CLOCK_REALTIME, |
| 171 | .ttype = NORMAL, |
| 172 | .flags = 0, |
| 173 | .sec = 0, |
| 174 | .nsec = 500000000, // 500msec |
| 175 | .ret = 0, |
| 176 | .err = 0, |
| 177 | }, |
| 178 | { // case01 |
| 179 | .clk_id = CLOCK_MONOTONIC, |
| 180 | .ttype = NORMAL, |
| 181 | .flags = 0, |
| 182 | .sec = 0, |
| 183 | .nsec = 500000000, // 500msec |
| 184 | .ret = 0, |
| 185 | .err = 0, |
| 186 | }, |
| 187 | { // case02 |
| 188 | .ttype = NORMAL, |
| 189 | .clk_id = CLOCK_REALTIME, |
| 190 | .flags = 0, |
| 191 | .sec = 0, |
| 192 | .nsec = -1, // invalid |
| 193 | .ret = EINVAL, |
| 194 | .err = 0, |
| 195 | }, |
| 196 | { // case03 |
| 197 | .ttype = NORMAL, |
| 198 | .clk_id = CLOCK_REALTIME, |
| 199 | .flags = 0, |
| 200 | .sec = 0, |
| 201 | .nsec = 1000000000, // invalid |
| 202 | .ret = EINVAL, |
| 203 | .err = 0, |
| 204 | }, |
| 205 | { // case04 |
| 206 | .ttype = NORMAL, |
| 207 | .clk_id = CLOCK_THREAD_CPUTIME_ID, // not supported |
| 208 | .flags = 0, |
| 209 | .sec = 0, |
| 210 | .nsec = 500000000, // 500msec |
| 211 | .ret = EINVAL, // RHEL4U1 + 2.6.18 returns EINVAL |
| 212 | .err = 0, |
| 213 | }, |
| 214 | { // case05 |
| 215 | .ttype = SEND_SIGINT, |
| 216 | .clk_id = CLOCK_REALTIME, |
| 217 | .flags = 0, |
| 218 | .sec = 10, |
| 219 | .nsec = 0, |
| 220 | .ret = EINTR, |
| 221 | .err = 0, |
| 222 | }, |
| 223 | #if 0 // glibc generates SEGV error (RHEL4U1 + 2.6.18) |
| 224 | { // caseXX |
| 225 | .ttype = NULL_POINTER, |
| 226 | .clk_id = CLOCK_REALTIME, |
| 227 | .flags = 0, |
| 228 | .sec = 0, |
| 229 | .nsec = 500000000, // 500msec |
| 230 | .ret = EFAULT, |
| 231 | .err = 0, |
| 232 | }, |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 233 | #endif |
| 234 | }; |
| 235 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 236 | /* |
| 237 | * chk_difftime() |
| 238 | * Return : OK(0), NG(-1) |
| 239 | */ |
| 240 | #define MAX_MSEC_DIFF 20 |
| 241 | |
| 242 | static int chk_difftime(struct timespec *bef, struct timespec *aft, |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 243 | time_t sec, long nsec) |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 244 | { |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 245 | struct timespec t; |
| 246 | time_t expect; |
| 247 | time_t result; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 248 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 249 | t.tv_sec = aft->tv_sec - bef->tv_sec; |
| 250 | t.tv_nsec = aft->tv_nsec - bef->tv_nsec; |
| 251 | if (t.tv_nsec < 0) { |
| 252 | t.tv_sec -= 1; |
| 253 | t.tv_nsec += 1000000000; |
| 254 | } |
| 255 | expect = (sec * 1000) + (nsec / 1000000); |
| 256 | result = (t.tv_sec * 1000) + (t.tv_nsec / 1000000); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 257 | tst_resm(TINFO, "check sleep time: (min:%ld) < %ld < (max:%ld) (msec)", |
| 258 | expect - MAX_MSEC_DIFF, result, expect + MAX_MSEC_DIFF); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 259 | if (result < expect - MAX_MSEC_DIFF || result > expect + MAX_MSEC_DIFF) |
| 260 | return -1; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 264 | /* |
| 265 | * do_test() |
| 266 | * |
| 267 | * Input : TestCase Data |
| 268 | * Return : RESULT_OK(0), RESULT_NG(1) |
| 269 | * |
| 270 | */ |
| 271 | static int do_test(struct test_case *tc) |
| 272 | { |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 273 | int sys_ret; |
| 274 | int sys_errno; |
| 275 | int result = RESULT_OK; |
| 276 | struct timespec beftp, afttp, rq, rm; |
| 277 | int rc, range_ok = 1, remain_ok = 1; |
| 278 | pid_t pid = 0; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 279 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 280 | /* |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 281 | * Check before sleep time |
| 282 | */ |
| 283 | if (tc->ttype == SEND_SIGINT) { |
| 284 | pid = create_sig_proc(500000, SIGINT, UINT_MAX); |
| 285 | if (pid < 0) |
| 286 | return 1; |
| 287 | } |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 288 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 289 | /* |
| 290 | * Check before sleep time |
| 291 | */ |
| 292 | TEST(rc = clock_gettime(tc->clk_id, &beftp)); |
| 293 | if (rc < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 294 | tst_resm(TFAIL | TTERRNO, "iclock_gettime failed"); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 295 | result = 1; |
| 296 | goto EXIT; |
| 297 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 298 | /* |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 299 | * Execute system call |
| 300 | */ |
| 301 | rq.tv_sec = tc->sec; |
| 302 | rq.tv_nsec = tc->nsec; |
| 303 | // !!!CAUTION: 'clock_gettime' returns errno itself |
| 304 | errno = 0; |
| 305 | if (tc->ttype == NULL_POINTER) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 306 | TEST(sys_ret = |
| 307 | clock_nanosleep(tc->clk_id, tc->flags, NULL, &rm)); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 308 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 309 | TEST(sys_ret = |
| 310 | clock_nanosleep(tc->clk_id, tc->flags, &rq, &rm)); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 311 | sys_errno = errno; |
| 312 | if (sys_ret != 0) |
| 313 | goto TEST_END; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 314 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 315 | /* |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 316 | * Check after sleep time |
| 317 | */ |
| 318 | TEST(rc = clock_gettime(tc->clk_id, &afttp)); |
| 319 | if (TEST_RETURN < 0) { |
| 320 | EPRINTF("clock_gettime failed.\n"); |
| 321 | result = 1; |
| 322 | goto EXIT; |
| 323 | } |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 324 | range_ok = chk_difftime(&beftp, &afttp, tc->sec, tc->nsec) == 0; |
| 325 | /* |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 326 | * Check remaining time |
| 327 | */ |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 328 | TEST_END: |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 329 | if (tc->ttype == NORMAL || tc->ttype == SEND_SIGINT) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 330 | tst_resm(TINFO, "remain time: %ld %ld", rm.tv_sec, rm.tv_nsec); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 331 | if (tc->ttype == NORMAL) |
| 332 | remain_ok = 1; |
| 333 | else |
| 334 | remain_ok = rm.tv_sec != 0 || rm.tv_nsec != 0; |
| 335 | } |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 336 | |
| 337 | /* |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 338 | * Check results |
| 339 | */ |
| 340 | result |= (sys_ret != tc->ret) || !range_ok || !remain_ok; |
| 341 | if (!range_ok) |
| 342 | PRINT_RESULT_EXTRA(0, tc->ret, tc->err, sys_ret, sys_errno, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 343 | "time range check", range_ok); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 344 | else |
| 345 | PRINT_RESULT_EXTRA(0, tc->ret, tc->err, sys_ret, sys_errno, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 346 | "remain time check", remain_ok); |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 347 | EXIT: |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 348 | if (pid > 0) { |
| 349 | int st; |
| 350 | TEST(kill(pid, SIGTERM)); |
| 351 | TEST(wait(&st)); |
| 352 | } |
| 353 | return result; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 354 | } |
| 355 | |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 356 | /* |
| 357 | * main() |
| 358 | */ |
| 359 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 360 | int main(int ac, char **av) |
| 361 | { |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 362 | int result = RESULT_OK; |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 363 | int i; |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 364 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 365 | const char *msg; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 366 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 367 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
| 368 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 369 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 370 | setup(); |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 371 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 372 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 373 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 374 | tst_count = 0; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 375 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 376 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 377 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 378 | for (i = 0; i < (int)(sizeof(tcase) / sizeof(tcase[0])); |
| 379 | i++) { |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 380 | int ret; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 381 | tst_resm(TINFO, "(case%02d) START", i); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 382 | ret = do_test(&tcase[i]); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 383 | tst_resm(TINFO, "(case%02d) END => %s", |
| 384 | i, (ret == 0) ? "OK" : "NG"); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 385 | result |= ret; |
| 386 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 387 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 388 | switch (result) { |
| 389 | case RESULT_OK: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 390 | tst_resm(TPASS, |
| 391 | "clock_nanosleep call succeeded"); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 392 | break; |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 393 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 394 | default: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 395 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 396 | "clock_nanosleep failed"); |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 397 | break; |
| 398 | } |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 399 | |
Garrett Cooper | d74fde6 | 2010-11-22 15:21:28 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | } |
| 403 | |
| 404 | cleanup(); |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 405 | tst_exit(); |
subrata_modak | 2f3f956 | 2009-05-29 10:35:39 +0000 | [diff] [blame] | 406 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 407 | } |