Skip to content

Commit ee7dad5

Browse files
vireshkmetan-ucw
authored andcommitted
tst_timer: Add support for kernel's 64 bit timespec
The Linux kernel defined a new 64bit timespec some time back and this patch makes necessary changes to tst_timer.h in order to prepare for supporting changes in syscalls testcases. A new enum is introduced to keep a list of all timespec variants we need to support and all the timespec routines are updated to support the listed variants. In order to not do unnecessary changes to other syscall tests, the name of the earlier routines are kept as is. The LTP testsuite is build tested with this patch and nothing fails to compile. Signed-off-by: Viresh Kumar <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent ac334ae commit ee7dad5

File tree

10 files changed

+546
-123
lines changed

10 files changed

+546
-123
lines changed

include/tst_timer.h

Lines changed: 424 additions & 115 deletions
Large diffs are not rendered by default.

lib/newlib_tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test18
2525
test19
2626
test20
2727
tst_expiration_timer
28+
test_timer
2829
test_exec
2930
test_exec_child
3031
test_kconfig

lib/newlib_tests/test_timer.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) 2020 Cyril Hrubis <[email protected]>
4+
*/
5+
6+
/*
7+
* Tests for include/tst_timer.h
8+
*/
9+
10+
#include "tst_test.h"
11+
#include "tst_timer.h"
12+
13+
#define VAL_MS 1001
14+
#define VAL_US 1001000
15+
16+
static void test_diff(enum tst_ts_type type)
17+
{
18+
struct tst_ts ts1, ts2;
19+
long long diff;
20+
21+
ts1 = tst_ts_from_ms(type, VAL_MS);
22+
ts2 = tst_ts_from_us(type, VAL_US);
23+
24+
diff = tst_ts_diff_ns(ts1, ts2);
25+
26+
if (diff == 0)
27+
tst_res(TPASS, "ns_diff = 0");
28+
else
29+
tst_res(TFAIL, "ns_diff = %lli", diff);
30+
31+
diff = tst_ts_diff_ns(ts1, ts2);
32+
33+
if (diff == 0)
34+
tst_res(TPASS, "us_diff = 0");
35+
else
36+
tst_res(TFAIL, "us_diff = %lli", diff);
37+
38+
diff = tst_ts_diff_ms(ts1, ts2);
39+
40+
if (diff == 0)
41+
tst_res(TPASS, "ms_diff = 0");
42+
else
43+
tst_res(TFAIL, "ms_diff = %lli", diff);
44+
}
45+
46+
static void test_lt(enum tst_ts_type type)
47+
{
48+
struct tst_ts ts1, ts2;
49+
50+
ts1 = tst_ts_from_ms(type, VAL_MS);
51+
ts2 = tst_ts_from_us(type, VAL_US + 1);
52+
53+
if (tst_ts_lt(ts1, ts2))
54+
tst_res(TPASS, "ts1 < ts2");
55+
else
56+
tst_res(TFAIL, "ts1 >= ts2");
57+
58+
ts1 = tst_ts_add_us(ts1, 1);
59+
60+
if (tst_ts_lt(ts1, ts2))
61+
tst_res(TFAIL, "ts1 < ts2");
62+
else
63+
tst_res(TPASS, "ts1 >= ts2");
64+
65+
ts1 = tst_ts_add_us(ts1, 1);
66+
67+
if (tst_ts_lt(ts1, ts2))
68+
tst_res(TFAIL, "ts1 < ts2");
69+
else
70+
tst_res(TPASS, "ts1 >= ts2");
71+
}
72+
73+
static void test_add_sub(enum tst_ts_type type)
74+
{
75+
struct tst_ts ts;
76+
77+
ts = tst_ts_from_ns(type, 999999000);
78+
ts = tst_ts_add_us(ts, 1);
79+
80+
long long sec = tst_ts_get_sec(ts);
81+
long long nsec = tst_ts_get_nsec(ts);
82+
83+
/* Check that result was normalized */
84+
if (sec != 1 || nsec != 0)
85+
tst_res(TFAIL, "sec = %lli, nsec = %lli", sec, nsec);
86+
else
87+
tst_res(TPASS, "sec = %lli, nsec = %lli", sec, nsec);
88+
89+
ts = tst_ts_from_ms(type, 1000);
90+
ts = tst_ts_sub_us(ts, 1);
91+
92+
sec = tst_ts_get_sec(ts);
93+
nsec = tst_ts_get_nsec(ts);
94+
95+
/* Check that result was normalized */
96+
if (sec != 0 || nsec != 999999000)
97+
tst_res(TFAIL, "sec = %lli, nsec = %lli", sec, nsec);
98+
else
99+
tst_res(TPASS, "sec = %lli, nsec = %lli", sec, nsec);
100+
}
101+
102+
static void do_test(unsigned int n)
103+
{
104+
tst_res(TINFO, "Testing with type = %i", n);
105+
test_diff(n);
106+
test_lt(n);
107+
test_add_sub(n);
108+
}
109+
110+
static struct tst_test test = {
111+
.test = do_test,
112+
.tcnt = 3,
113+
};

testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep02.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
int sample_fn(int clk_id, long long usec)
1616
{
17-
struct timespec t = tst_us_to_timespec(usec);
17+
struct timespec t = tst_timespec_from_us(usec);
1818

1919
tst_timer_start(clk_id);
2020
TEST(clock_nanosleep(clk_id, 0, &t, NULL));

testcases/kernel/syscalls/futex/futex_cmp_requeue01.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static struct tcase {
4545
static void do_child(void)
4646
{
4747
int slept_for_ms = 0;
48-
struct timespec usec = tst_ms_to_timespec(max_sleep_ms);
48+
struct timespec usec = tst_timespec_from_ms(max_sleep_ms);
4949
int pid = getpid();
5050
int ret = 0;
5151

testcases/kernel/syscalls/futex/futex_wait05.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
int sample_fn(int clk_id, long long usec)
1717
{
18-
struct timespec to = tst_us_to_timespec(usec);
18+
struct timespec to = tst_timespec_from_us(usec);
1919
futex_t futex = FUTEX_INITIALIZER;
2020

2121
tst_timer_start(clk_id);

testcases/kernel/syscalls/nanosleep/nanosleep01.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
int sample_fn(int clk_id, long long usec)
1818
{
19-
struct timespec t = tst_us_to_timespec(usec);
19+
struct timespec t = tst_timespec_from_us(usec);
2020

2121
tst_timer_start(clk_id);
2222
TEST(nanosleep(&t, NULL));

testcases/kernel/syscalls/prctl/prctl09.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
int sample_fn(int clk_id, long long usec)
1818
{
19-
struct timespec t = tst_us_to_timespec(usec);
19+
struct timespec t = tst_timespec_from_us(usec);
2020

2121
tst_timer_start(clk_id);
2222
TEST(nanosleep(&t, NULL));

testcases/kernel/syscalls/pselect/pselect01.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
int sample_fn(int clk_id, long long usec)
1313
{
1414
fd_set readfds;
15-
struct timespec tv = tst_us_to_timespec(usec);
15+
struct timespec tv = tst_timespec_from_us(usec);
1616

1717
FD_ZERO(&readfds);
1818
FD_SET(0, &readfds);

testcases/kernel/syscalls/timerfd/timerfd01.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ static unsigned long long getustime(int clockid)
4444
static void settime(int tfd, struct itimerspec *tmr, int tflags,
4545
unsigned long long tvalue, int tinterval)
4646
{
47-
tmr->it_value = tst_us_to_timespec(tvalue);
48-
tmr->it_interval = tst_us_to_timespec(tinterval);
47+
tmr->it_value = tst_timespec_from_us(tvalue);
48+
tmr->it_interval = tst_timespec_from_us(tinterval);
4949

5050
SAFE_TIMERFD_SETTIME(tfd, tflags, tmr, NULL);
5151
}

0 commit comments

Comments
 (0)