Skip to content

Commit de36948

Browse files
bozutafmetan-ucw
authored andcommitted
syscalls/clock_nanosleep: add a test case for bad timespec address
This patch introduces test cases for already existing test for syscall 'clock_nanosleep()' (clock_nanosleep01). These test cases are for situations when bad timespec addresses are passed for arguments 'request' and 'remain' in which case errno EFAULT ('Bad address') is expected to be set. Signed-off-by: Filip Bozuta <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent df69346 commit de36948

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
* Satoshi Fujiwara <[email protected]>
77
* Copyright (c) 2016 Linux Test Project
88
*/
9+
/*
10+
* test status of errors on man page
11+
* EINTR v (function was interrupted by a signal)
12+
* EINVAL v (invalid tv_nsec, etc.)
13+
* ENOTSUP v (sleep not supported against the specified clock_id)
14+
* EFAULT v (Invalid request pointer)
15+
* EFAULT V (Invalid remain pointer when interrupted by a signal)
16+
*/
917

1018
#include <limits.h>
1119

@@ -20,10 +28,14 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
2028
enum test_type {
2129
NORMAL,
2230
SEND_SIGINT,
31+
BAD_TS_ADDR_REQ,
32+
BAD_TS_ADDR_REM,
2333
};
2434

2535
#define TYPE_NAME(x) .ttype = x, .desc = #x
2636

37+
static void *bad_addr;
38+
2739
struct test_case {
2840
clockid_t clk_id; /* clock_* clock type parameter */
2941
int ttype; /* test type (enum) */
@@ -35,12 +47,6 @@ struct test_case {
3547
int exp_err;
3648
};
3749

38-
/*
39-
* test status of errors on man page
40-
* EINTR v (function was interrupted by a signal)
41-
* EINVAL v (invalid tv_nsec, etc.)
42-
*/
43-
4450
static struct test_case tcase[] = {
4551
{
4652
TYPE_NAME(NORMAL),
@@ -78,6 +84,22 @@ static struct test_case tcase[] = {
7884
.exp_ret = -1,
7985
.exp_err = EINTR,
8086
},
87+
{
88+
TYPE_NAME(BAD_TS_ADDR_REQ),
89+
.clk_id = CLOCK_REALTIME,
90+
.flags = 0,
91+
.exp_ret = -1,
92+
.exp_err = EFAULT,
93+
},
94+
{
95+
TYPE_NAME(BAD_TS_ADDR_REM),
96+
.clk_id = CLOCK_REALTIME,
97+
.flags = 0,
98+
.tv_sec = 10,
99+
.tv_nsec = 0,
100+
.exp_ret = -1,
101+
.exp_err = EFAULT,
102+
},
81103
};
82104

83105
static struct tst_ts *rq;
@@ -104,26 +126,38 @@ void setup(void)
104126
rq->type = variants[tst_variant].type;
105127
tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
106128
SAFE_SIGNAL(SIGINT, sighandler);
129+
bad_addr = tst_get_bad_addr(NULL);
107130
}
108131

109132
static void do_test(unsigned int i)
110133
{
111134
struct test_variants *tv = &variants[tst_variant];
112135
struct test_case *tc = &tcase[i];
113136
pid_t pid = 0;
137+
void *request, *remain;
114138

115139
memset(rm, 0, sizeof(*rm));
116140
rm->type = rq->type;
117141

118142
tst_res(TINFO, "case %s", tc->desc);
119143

120-
if (tc->ttype == SEND_SIGINT)
144+
if (tc->ttype == SEND_SIGINT || tc->ttype == BAD_TS_ADDR_REM)
121145
pid = create_sig_proc(SIGINT, 40, 500000);
122146

123147
tst_ts_set_sec(rq, tc->tv_sec);
124148
tst_ts_set_nsec(rq, tc->tv_nsec);
125149

126-
TEST(tv->func(tc->clk_id, tc->flags, tst_ts_get(rq), tst_ts_get(rm)));
150+
if (tc->ttype == BAD_TS_ADDR_REQ)
151+
request = bad_addr;
152+
else
153+
request = tst_ts_get(rq);
154+
155+
if (tc->ttype == BAD_TS_ADDR_REM)
156+
remain = bad_addr;
157+
else
158+
remain = tst_ts_get(rm);
159+
160+
TEST(tv->func(tc->clk_id, tc->flags, request, remain));
127161

128162
if (tv->func == libc_clock_nanosleep) {
129163
/*

0 commit comments

Comments
 (0)