[LTP] [PATCH] syscalls/read05: Test read with zero count

Liao Huangjie liaohj.jy@fujitsu.com
Mon Jul 25 09:02:44 CEST 2022


From: Huangjie Liao <liaohj.jy@fujitsu.com>

Signed-off-by: Huangjie Liao <liaohj.jy@fujitsu.com>
---
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/read/.gitignore |  1 +
 testcases/kernel/syscalls/read/read05.c   | 44 +++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
 create mode 100644 testcases/kernel/syscalls/read/read05.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 3847e8a..0bd47fc 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1094,6 +1094,7 @@ read01 read01
 read02 read02
 read03 read03
 read04 read04
+read05 read05
 
 readahead01 readahead01
 readahead02 readahead02
diff --git a/testcases/kernel/syscalls/read/.gitignore b/testcases/kernel/syscalls/read/.gitignore
index e89c008..69d97b3 100644
--- a/testcases/kernel/syscalls/read/.gitignore
+++ b/testcases/kernel/syscalls/read/.gitignore
@@ -2,3 +2,4 @@
 /read02
 /read03
 /read04
+/read05
diff --git a/testcases/kernel/syscalls/read/read05.c b/testcases/kernel/syscalls/read/read05.c
new file mode 100644
index 0000000..83ac763
--- /dev/null
+++ b/testcases/kernel/syscalls/read/read05.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All Rights Reserved.
+ * Author: Huangjie Liao <liaohj.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * In the absence of any errors, a read() with a count of 0 returns zero.
+ */
+
+#include <errno.h>
+#include "tst_test.h"
+
+#define SIZE 512
+
+static int fd;
+static char buf[SIZE];
+
+static void verify_read(void)
+{
+	TST_EXP_VAL(read(fd, buf, 0), 0);
+}
+
+static void setup(void)
+{
+	memset(buf, '*', SIZE);
+	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700);
+	SAFE_WRITE(1, fd, buf, SIZE);
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = verify_read,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
-- 
1.8.3.1



More information about the ltp mailing list