1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 Ported by Wayne Boyer
5*49cdfc7eSAndroid Build Coastguard Worker *
6*49cdfc7eSAndroid Build Coastguard Worker * Ported to new library:
7*49cdfc7eSAndroid Build Coastguard Worker * 07/2019 Yang Xu <[email protected]>
8*49cdfc7eSAndroid Build Coastguard Worker */
9*49cdfc7eSAndroid Build Coastguard Worker
10*49cdfc7eSAndroid Build Coastguard Worker /*
11*49cdfc7eSAndroid Build Coastguard Worker * Test Description:
12*49cdfc7eSAndroid Build Coastguard Worker * Verify that nanosleep() will fail to suspend the execution
13*49cdfc7eSAndroid Build Coastguard Worker * of a process if the specified pause time is invalid.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * Expected Result:
16*49cdfc7eSAndroid Build Coastguard Worker * nanosleep() should return with -1 value and sets errno to EINVAL.
17*49cdfc7eSAndroid Build Coastguard Worker */
18*49cdfc7eSAndroid Build Coastguard Worker
19*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
20*49cdfc7eSAndroid Build Coastguard Worker #include <time.h>
21*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker static struct timespec tcases[] = {
24*49cdfc7eSAndroid Build Coastguard Worker {.tv_sec = -5, .tv_nsec = 9999},
25*49cdfc7eSAndroid Build Coastguard Worker {.tv_sec = 0, .tv_nsec = 1000000000},
26*49cdfc7eSAndroid Build Coastguard Worker {.tv_sec = 1, .tv_nsec = -100},
27*49cdfc7eSAndroid Build Coastguard Worker };
28*49cdfc7eSAndroid Build Coastguard Worker
verify_nanosleep(unsigned int n)29*49cdfc7eSAndroid Build Coastguard Worker static void verify_nanosleep(unsigned int n)
30*49cdfc7eSAndroid Build Coastguard Worker {
31*49cdfc7eSAndroid Build Coastguard Worker TEST(nanosleep(&tcases[n], NULL));
32*49cdfc7eSAndroid Build Coastguard Worker
33*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET != -1) {
34*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL,
35*49cdfc7eSAndroid Build Coastguard Worker "nanosleep() returned %ld, expected -1", TST_RET);
36*49cdfc7eSAndroid Build Coastguard Worker return;
37*49cdfc7eSAndroid Build Coastguard Worker }
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard Worker if (TST_ERR != EINVAL) {
40*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO,
41*49cdfc7eSAndroid Build Coastguard Worker "nanosleep() failed,expected EINVAL, got");
42*49cdfc7eSAndroid Build Coastguard Worker return;
43*49cdfc7eSAndroid Build Coastguard Worker }
44*49cdfc7eSAndroid Build Coastguard Worker
45*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "nanosleep() failed with EINVAL");
46*49cdfc7eSAndroid Build Coastguard Worker }
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
49*49cdfc7eSAndroid Build Coastguard Worker .test = verify_nanosleep,
50*49cdfc7eSAndroid Build Coastguard Worker .tcnt = ARRAY_SIZE(tcases),
51*49cdfc7eSAndroid Build Coastguard Worker };
52*49cdfc7eSAndroid Build Coastguard Worker
53