• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  * Copyright (c) 2017 Fujitsu Ltd.
5  */
6 
7 #include <errno.h>
8 #include "tst_test.h"
9 
10 #define SIZE 512
11 
12 static int fd;
13 static char buf[SIZE];
14 
verify_read(void)15 static void verify_read(void)
16 {
17 	SAFE_LSEEK(fd, 0, SEEK_SET);
18 
19 	TEST(read(fd, buf, SIZE));
20 
21 	if (TST_RET == -1)
22 		tst_res(TFAIL | TTERRNO, "read(2) failed");
23 	else
24 		tst_res(TPASS, "read(2) returned %ld", TST_RET);
25 }
26 
setup(void)27 static void setup(void)
28 {
29 	memset(buf, '*', SIZE);
30 	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700);
31 	SAFE_WRITE(1, fd, buf, SIZE);
32 }
33 
cleanup(void)34 static void cleanup(void)
35 {
36 	if (fd > 0)
37 		SAFE_CLOSE(fd);
38 }
39 
40 static struct tst_test test = {
41 	.test_all = verify_read,
42 	.setup = setup,
43 	.cleanup = cleanup,
44 	.needs_tmpdir = 1,
45 };
46