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