1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) 2016 Linux Test Project
4f08c3bdfSopenharmony_ci */
5f08c3bdfSopenharmony_ci#include <errno.h>
6f08c3bdfSopenharmony_ci#include <signal.h>
7f08c3bdfSopenharmony_ci#include <stdlib.h>
8f08c3bdfSopenharmony_ci#include "tst_test.h"
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_cistatic void sig_handler(int sig LTP_ATTRIBUTE_UNUSED)
11f08c3bdfSopenharmony_ci{
12f08c3bdfSopenharmony_ci}
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_cistatic void do_child(void)
15f08c3bdfSopenharmony_ci{
16f08c3bdfSopenharmony_ci	SAFE_SIGNAL(SIGINT, sig_handler);
17f08c3bdfSopenharmony_ci
18f08c3bdfSopenharmony_ci	TST_CHECKPOINT_WAKE(0);
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci	TEST(pause());
21f08c3bdfSopenharmony_ci	if (TST_RET != -1)
22f08c3bdfSopenharmony_ci		tst_res(TFAIL, "pause() succeeded unexpectedly");
23f08c3bdfSopenharmony_ci	else if (TST_ERR == EINTR)
24f08c3bdfSopenharmony_ci		tst_res(TPASS, "pause() interrupted with EINTR");
25f08c3bdfSopenharmony_ci	else
26f08c3bdfSopenharmony_ci		tst_res(TFAIL | TTERRNO, "pause() unexpected errno");
27f08c3bdfSopenharmony_ci
28f08c3bdfSopenharmony_ci	TST_CHECKPOINT_WAKE(0);
29f08c3bdfSopenharmony_ci	exit(0);
30f08c3bdfSopenharmony_ci}
31f08c3bdfSopenharmony_ci
32f08c3bdfSopenharmony_cistatic void do_test(void)
33f08c3bdfSopenharmony_ci{
34f08c3bdfSopenharmony_ci	int pid, status;
35f08c3bdfSopenharmony_ci
36f08c3bdfSopenharmony_ci	pid = SAFE_FORK();
37f08c3bdfSopenharmony_ci	if (pid == 0)
38f08c3bdfSopenharmony_ci		do_child();
39f08c3bdfSopenharmony_ci
40f08c3bdfSopenharmony_ci	TST_CHECKPOINT_WAIT(0);
41f08c3bdfSopenharmony_ci	TST_PROCESS_STATE_WAIT(pid, 'S', 0);
42f08c3bdfSopenharmony_ci	kill(pid, SIGINT);
43f08c3bdfSopenharmony_ci
44f08c3bdfSopenharmony_ci	/*
45f08c3bdfSopenharmony_ci	 * TST_CHECKPOINT_WAIT has built-in timeout, if pause() doesn't return,
46f08c3bdfSopenharmony_ci	 * this checkpoint call will reliably end the test.
47f08c3bdfSopenharmony_ci	 */
48f08c3bdfSopenharmony_ci	TST_CHECKPOINT_WAIT(0);
49f08c3bdfSopenharmony_ci	SAFE_WAIT(&status);
50f08c3bdfSopenharmony_ci}
51f08c3bdfSopenharmony_ci
52f08c3bdfSopenharmony_cistatic struct tst_test test = {
53f08c3bdfSopenharmony_ci	.forks_child = 1,
54f08c3bdfSopenharmony_ci	.needs_checkpoints = 1,
55f08c3bdfSopenharmony_ci	.test_all = do_test,
56f08c3bdfSopenharmony_ci};
57