1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4 * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
5 * Copyright (c) 2023 SUSE LLC
6 */
7
8/*\
9 * [Description]
10 *
11 * Basic test for dup(2) of a system pipe descriptor.
12 */
13
14#ifndef _GNU_SOURCE
15#define _GNU_SOURCE
16#endif
17
18#include "tst_test.h"
19
20static int fd[2];
21
22static void run(void)
23{
24	TST_EXP_FD(dup(fd[0]), "dup(%d) read end of the pipe", fd[0]);
25	SAFE_CLOSE(TST_RET);
26
27	TST_EXP_FD(dup(fd[1]), "dup(%d) write end of the pipe", fd[1]);
28	SAFE_CLOSE(TST_RET);
29}
30
31static void setup(void)
32{
33	fd[0] = -1;
34
35	SAFE_PIPE(fd);
36}
37
38static struct tst_test test = {
39	.test_all = run,
40	.setup = setup,
41	.needs_tmpdir = 1,
42};
43