Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] syscalls/sendfile: Convert sendfile04 to the new API
Date: Fri, 23 Apr 2021 15:03:25 +0200	[thread overview]
Message-ID: <YILFnTZv5k23bM/Q@yuki> (raw)
In-Reply-To: <20210423095944.118255-2-xieziyao@huawei.com>

Hi!
I've simplified the code even a bit more and pushed, thanks.

I've did a minor adjustenment such as:

- there is no need to reopen the in_fd since we do not actually read
  from it

- no need to define OFF_T to off_t

- no need for the SOCKETPAIR, the in_fd and out_fd can be any fds as
  long as in is opened for reading and out opened for writing

full diff:

diff --git a/testcases/kernel/syscalls/sendfile/sendfile04.c b/testcases/kernel/syscalls/sendfile/sendfile04.c
index 42600a8ac..4cbc48edc 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile04.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile04.c
@@ -9,7 +9,7 @@
  * [Description]
  *
  * Testcase to test that sendfile(2) system call returns EFAULT when passing
- * wrong buffer.
+ * wrong offset pointer.
  *
  * [Algorithm]
  *
@@ -31,16 +31,8 @@
 
 #include "tst_test.h"
 
-#ifndef OFF_T
-#define OFF_T off_t
-#endif
-
-#define IN_FILE "sendfile04_infile"
-
-int in_fd;
-int out_fd;
-int out[2];
-static char buf[] = "abcdefghijklmnopqrstuvwxyz";
+static int in_fd;
+static int out_fd;
 
 struct test_case_t {
 	int protection;
@@ -56,40 +48,33 @@ struct test_case_t {
 
 static void setup(void)
 {
-	in_fd = SAFE_CREAT(IN_FILE, 00700);
-	SAFE_WRITE(1, in_fd, buf, strlen(buf));
-	SAFE_CLOSE(in_fd);
-
-	SAFE_SOCKETPAIR(AF_UNIX, SOCK_DGRAM, 0, out);
-	out_fd = out[0];
+	in_fd = SAFE_CREAT("in_file", O_RDONLY);
+	out_fd = SAFE_CREAT("out_file", O_WRONLY);
+	SAFE_WRITE(1, in_fd, "a", 1);
 }
 
 static void cleanup(void)
 {
-	SAFE_CLOSE(out[0]);
-	SAFE_CLOSE(out[1]);
+	SAFE_CLOSE(in_fd);
+	SAFE_CLOSE(out_fd);
 }
 
 static void run(unsigned int i)
 {
-	OFF_T *protected_buffer;
+	off_t *protected_buffer;
 	protected_buffer = SAFE_MMAP(NULL, sizeof(*protected_buffer),
 			             tc[i].protection,
-				     MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+				     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+
 	if (tc[i].pass_unmapped_buffer)
 		SAFE_MUNMAP(protected_buffer, sizeof(*protected_buffer));
 
-	struct stat sb;
-	SAFE_STAT(IN_FILE, &sb);
-	in_fd = SAFE_OPEN(IN_FILE, O_RDONLY);
-
-	TST_EXP_FAIL(sendfile(out_fd, in_fd, protected_buffer, sb.st_size),
+	TST_EXP_FAIL(sendfile(out_fd, in_fd, protected_buffer, 1),
 		     EFAULT, "sendfile(..) with %s, protection=%d",
 		     tc[i].desc, tc[i].protection);
 
 	if (!tc[i].pass_unmapped_buffer)
 		SAFE_MUNMAP(protected_buffer, sizeof(*protected_buffer));
-	SAFE_CLOSE(in_fd);
 }
 
 static struct tst_test test = {

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2021-04-23 13:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23  9:59 [LTP] [PATCH 0/2] syscalls/sendfile: Convert sendfile{04, 05} to the new API Xie Ziyao
2021-04-23  9:59 ` [LTP] [PATCH 1/2] syscalls/sendfile: Convert sendfile04 " Xie Ziyao
2021-04-23 13:03   ` Cyril Hrubis [this message]
2021-04-23 13:28   ` Cyril Hrubis
2021-04-23  9:59 ` [LTP] [PATCH 2/2] syscalls/sendfile: Convert sendfile05 " Xie Ziyao
2021-04-23 13:27   ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YILFnTZv5k23bM/Q@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox