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