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 */
18 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
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
47 #include "test.h"
48 #include "linux_syscall_numbers.h"
49
50 char *TCID = "clock_nanosleep2_01";
51 int testno;
52 int TST_TOTAL = 1;
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 /******************************************************************************/
cleanup(void)72 void cleanup(void)
73 {
74
75 tst_rmdir();
76
77 tst_exit();
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 /******************************************************************************/
setup(void)98 void setup(void)
99 {
100 /* Capture signals if any */
101 /* Create temporary directories */
102 TEST_PAUSE;
103 tst_tmpdir();
104 }
105
106 const clockid_t CLOCK_TO_USE = CLOCK_MONOTONIC;
clock_nanosleep2(clockid_t clock_id,int flags,const struct timespec * req,struct timespec * rem)107 static int clock_nanosleep2(clockid_t clock_id, int flags,
108 const struct timespec *req, struct timespec *rem)
109 {
110 return ltp_syscall(__NR_clock_nanosleep, clock_id, flags, req, rem);
111 }
112
main(int ac,char ** av)113 int main(int ac, char **av)
114 {
115 int i;
116 int lc;
117 struct timespec ts;
118
119 tst_parse_opts(ac, av, NULL, NULL);
120
121 setup();
122
123 for (lc = 0; TEST_LOOPING(lc); ++lc) {
124 tst_count = 0;
125 for (testno = 0; testno < TST_TOTAL; ++testno) {
126 TEST(clock_gettime(CLOCK_TO_USE, &ts));
127 for (i = 0; i <= 50; i++) {
128 ts.tv_sec++;
129 TEST(clock_nanosleep2
130 (CLOCK_TO_USE, TIMER_ABSTIME, &ts, NULL));
131 if (TEST_ERRNO) {
132 tst_brkm(TFAIL,
133 cleanup, "%s failed - errno = %d : %s",
134 TCID, TEST_ERRNO,
135 strerror(TEST_ERRNO));
136 }
137 tst_resm(TINFO, "Iteration = %i", i);
138 }
139 tst_resm(TPASS, "clock_nanosleep2() passed");
140 }
141 }
142 tst_exit();
143 }
144