• 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  * [Description]
12  *
13  * Verify that nanosleep() returns -1 and sets errno to EINVAL when failing to suspend the
14  * execution of a process if the specified pause time is invalid.
15  */
16 
17 #include <errno.h>
18 #include <time.h>
19 #include "tst_test.h"
20 
21 static struct timespec tcases[] = {
22 	{.tv_sec = -5, .tv_nsec = 9999},
23 	{.tv_sec = 0, .tv_nsec = 1000000000},
24 	{.tv_sec = 1, .tv_nsec = -100},
25 };
26 
verify_nanosleep(unsigned int n)27 static void verify_nanosleep(unsigned int n)
28 {
29 	TEST(nanosleep(&tcases[n], NULL));
30 
31 	if (TST_RET != -1) {
32 		tst_res(TFAIL,
33 		        "nanosleep() returned %ld, expected -1", TST_RET);
34 		return;
35 	}
36 
37 	if (TST_ERR != EINVAL) {
38 		tst_res(TFAIL | TTERRNO,
39 			"nanosleep() failed,expected EINVAL, got");
40 		return;
41 	}
42 
43 	tst_res(TPASS, "nanosleep() failed with EINVAL");
44 }
45 
46 static struct tst_test test = {
47 	.test = verify_nanosleep,
48 	.tcnt = ARRAY_SIZE(tcases),
49 };
50 
51