• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  *
5  * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
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 
20 int fd[2];
21 
run(void)22 static void run(void)
23 {
24 	TEST(dup(fd[0]));
25 
26 	if (TST_RET == -1)
27 		tst_res(TFAIL | TTERRNO,
28 			 "dup of read side of pipe failed");
29 	else {
30 		tst_res(TPASS,
31 			 "dup(%d) read side of syspipe returned %ld",
32 			 fd[0], TST_RET);
33 
34 		SAFE_CLOSE(TST_RET);
35 	}
36 
37 	TEST(dup(fd[1]));
38 
39 	if (TST_RET == -1) {
40 		tst_res(TFAIL | TTERRNO,
41 			 "dup of write side of pipe failed");
42 	} else {
43 		tst_res(TPASS,
44 			 "dup(%d) write side of syspipe returned %ld",
45 			 fd[1], TST_RET);
46 
47 		SAFE_CLOSE(TST_RET);
48 	}
49 }
50 
setup(void)51 void setup(void)
52 {
53 	fd[0] = -1;
54 
55 	SAFE_PIPE(fd);
56 }
57 
58 static struct tst_test test = {
59         .test_all = run,
60         .setup = setup,
61         .needs_tmpdir = 1,
62 };
63