• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2023 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
4  */
5 
6 /*\
7  * [Description]
8  *
9  * Verify that, if the write end of a pipe is closed, then a process reading
10  * from the pipe will see end-of-file (i.e., read() returns 0) once it has
11  * read all remaining data in the pipe.
12  */
13 
14 #include "tst_test.h"
15 
16 static int fds[2];
17 
run(void)18 static void run(void)
19 {
20 	char wrbuf[] = "abcdefghijklmnopqrstuvwxyz";
21 	char rdbuf[30];
22 
23 	memset(rdbuf, 0, sizeof(rdbuf));
24 	SAFE_PIPE(fds);
25 
26 	SAFE_WRITE(SAFE_WRITE_ALL, fds[1], wrbuf, sizeof(wrbuf));
27 	SAFE_CLOSE(fds[1]);
28 
29 	SAFE_READ(0, fds[0], rdbuf, sizeof(wrbuf));
30 
31 	TST_EXP_VAL(SAFE_READ(0, fds[0], rdbuf, 1), 0);
32 	SAFE_CLOSE(fds[0]);
33 }
34 
cleanup(void)35 static void cleanup(void)
36 {
37 	if (fds[0] > 0)
38 		SAFE_CLOSE(fds[0]);
39 	if (fds[1] > 0)
40 		SAFE_CLOSE(fds[1]);
41 }
42 
43 static struct tst_test test = {
44 	.test_all = run,
45 	.cleanup = cleanup
46 };
47