subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 2 | /* Copyright (c) M. Koehrer <mathias_koehrer@arcor.de>, 2009 */ |
| 3 | /* */ |
| 4 | /* LKML Reference: http://lkml.org/lkml/2009/4/9/89 */ |
| 5 | /* */ |
| 6 | /* This program is free software; you can redistribute it and/or modify */ |
| 7 | /* it under the terms of the GNU General Public License as published by */ |
| 8 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 9 | /* (at your option) any later version. */ |
| 10 | /* */ |
| 11 | /* This program is distributed in the hope that it will be useful, */ |
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 14 | /* the GNU General Public License for more details. */ |
| 15 | /* */ |
| 16 | /* You should have received a copy of the GNU General Public License */ |
| 17 | /* along with this program; if not, write to the Free Software */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 19 | /* */ |
| 20 | /******************************************************************************/ |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
| 23 | /* File: clock_nanosleep2_01.c */ |
| 24 | /* */ |
| 25 | /* Description: This tests the clock_nanosleep2-out() syscall */ |
| 26 | /* */ |
| 27 | /* Usage: <for command-line> */ |
| 28 | /* clock_nanosleep2_01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 29 | /* where, -c n : Run n copies concurrently. */ |
| 30 | /* -e : Turn on errno logging. */ |
| 31 | /* -i n : Execute test n times. */ |
| 32 | /* -I x : Execute test for x seconds. */ |
| 33 | /* -P x : Pause for x seconds between iterations. */ |
| 34 | /* -t : Turn on syscall timing. */ |
| 35 | /* */ |
| 36 | /* Total Tests: 1 */ |
| 37 | /* */ |
| 38 | /* Test Name: clock_nanosleep2_01 */ |
| 39 | /******************************************************************************/ |
| 40 | #define _GNU_SOURCE |
| 41 | #include <stdio.h> |
| 42 | #include <time.h> |
| 43 | #include <unistd.h> |
| 44 | #include <sys/syscall.h> |
| 45 | #include <linux/unistd.h> |
| 46 | |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 47 | #include "test.h" |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 48 | #include "linux_syscall_numbers.h" |
| 49 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 50 | char *TCID = "clock_nanosleep2_01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 51 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 52 | int TST_TOTAL = 1; |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 53 | |
| 54 | /* Extern Global Functions */ |
| 55 | /******************************************************************************/ |
| 56 | /* */ |
| 57 | /* Function: cleanup */ |
| 58 | /* */ |
| 59 | /* Description: Performs all one time clean up for this test on successful */ |
| 60 | /* completion, premature exit or failure. Closes all temporary */ |
| 61 | /* files, removes all temporary directories exits the test with */ |
| 62 | /* appropriate return code by calling tst_exit() function. */ |
| 63 | /* */ |
| 64 | /* Input: None. */ |
| 65 | /* */ |
| 66 | /* Output: None. */ |
| 67 | /* */ |
| 68 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 69 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 70 | /* */ |
| 71 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 72 | void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 73 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 74 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 75 | tst_rmdir(); |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 76 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | tst_exit(); |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /* Local Functions */ |
| 81 | /******************************************************************************/ |
| 82 | /* */ |
| 83 | /* Function: setup */ |
| 84 | /* */ |
| 85 | /* Description: Performs all one time setup for this test. This function is */ |
| 86 | /* typically used to capture signals, create temporary dirs */ |
| 87 | /* and temporary files that may be used in the course of this */ |
| 88 | /* test. */ |
| 89 | /* */ |
| 90 | /* Input: None. */ |
| 91 | /* */ |
| 92 | /* Output: None. */ |
| 93 | /* */ |
| 94 | /* Return: On failure - Exits by calling cleanup(). */ |
| 95 | /* On success - returns 0. */ |
| 96 | /* */ |
| 97 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 98 | void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 99 | { |
| 100 | /* Capture signals if any */ |
| 101 | /* Create temporary directories */ |
| 102 | TEST_PAUSE; |
| 103 | tst_tmpdir(); |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 106 | const clockid_t CLOCK_TO_USE = CLOCK_MONOTONIC; |
| 107 | static int clock_nanosleep2(clockid_t clock_id, int flags, |
| 108 | const struct timespec *req, struct timespec *rem) |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 109 | { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 110 | return ltp_syscall(__NR_clock_nanosleep, clock_id, flags, req, rem); |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 113 | int main(int ac, char **av) |
| 114 | { |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 115 | int i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 116 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 117 | const char *msg; |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 118 | struct timespec ts; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 119 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 120 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
| 121 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 122 | } |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 123 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 124 | setup(); |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 125 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 126 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 127 | tst_count = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 128 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 129 | TEST(clock_gettime(CLOCK_TO_USE, &ts)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 130 | for (i = 0; i <= 50; i++) { |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 131 | ts.tv_sec++; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 132 | TEST(clock_nanosleep2 |
| 133 | (CLOCK_TO_USE, TIMER_ABSTIME, &ts, NULL)); |
| 134 | if (TEST_ERRNO) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame] | 135 | tst_brkm(TFAIL, |
| 136 | cleanup, "%s failed - errno = %d : %s", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 137 | TCID, TEST_ERRNO, |
| 138 | strerror(TEST_ERRNO)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 139 | } |
| 140 | tst_resm(TINFO, "Iteration = %i", i); |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 141 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 142 | tst_resm(TPASS, "clock_nanosleep2() passed"); |
subrata_modak | 6155aed | 2009-04-15 06:29:16 +0000 | [diff] [blame] | 143 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 144 | } |
| 145 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 146 | } |