All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Xing <kerneljasonxing@linux.alibaba.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/cma: test case should return TCONF if syscall doesn't exist
Date: Mon,  3 Dec 2018 17:43:47 +0800	[thread overview]
Message-ID: <1543830227-15605-1-git-send-email-kerneljasonxing@linux.alibaba.com> (raw)

The original code returns TFAIL when process_vm_readv/_writev syscalls
do not exist, while we are expecting a TCONF. During investigation, we
find it is due to '#if defined(__NR_process_vm_readv/_writev)' fails to
work as expected.  We fix this issue by using ltp_syscall() function in
setup function. BTW, we don't use new tst_syscall() interface due to
compatibility issue exists between old apis and new ones.

Signed-off-by: jasonxing <kerneljasonxing@linux.alibaba.com>
Signed-off-by: Caspar Zhang <caspar@linux.alibaba.com>
---
 testcases/kernel/syscalls/cma/process_vm.h         | 62 ----------------------
 testcases/kernel/syscalls/cma/process_vm01.c       | 30 ++++-------
 testcases/kernel/syscalls/cma/process_vm_readv02.c | 12 ++---
 testcases/kernel/syscalls/cma/process_vm_readv03.c | 14 ++---
 .../kernel/syscalls/cma/process_vm_writev02.c      | 12 ++---
 5 files changed, 30 insertions(+), 100 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/cma/process_vm.h

diff --git a/testcases/kernel/syscalls/cma/process_vm.h b/testcases/kernel/syscalls/cma/process_vm.h
deleted file mode 100644
index 1ecf325..0000000
--- a/testcases/kernel/syscalls/cma/process_vm.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2012 Linux Test Project, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-#ifndef _PROCESS_VM_H_
-#define _PROCESS_VM_H_
-
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/sem.h>
-#include <sys/syscall.h>
-#include <sys/uio.h>
-#include <unistd.h>
-#include "lapi/semun.h"
-
-static inline ssize_t test_process_vm_readv(pid_t pid,
-		const struct iovec *lvec, unsigned long liovcnt,
-		const struct iovec *rvec, unsigned long riovcnt,
-		unsigned long flags)
-{
-#if defined(__NR_process_vm_readv)
-	return syscall(__NR_process_vm_readv, pid, lvec, liovcnt,
-			rvec, riovcnt, flags);
-#else
-	return syscall(-1);
-#endif
-}
-
-static inline ssize_t test_process_vm_writev(pid_t pid,
-		const struct iovec *lvec, unsigned long liovcnt,
-		const struct iovec *rvec, unsigned long riovcnt,
-		unsigned long flags)
-{
-#if defined(__NR_process_vm_writev)
-	return syscall(__NR_process_vm_writev, pid, lvec, liovcnt,
-			rvec, riovcnt, flags);
-#else
-	return syscall(-1);
-#endif
-}
-
-#endif /* _PROCESS_VM_H_ */
diff --git a/testcases/kernel/syscalls/cma/process_vm01.c b/testcases/kernel/syscalls/cma/process_vm01.c
index bc6b04f..f9bd865 100644
--- a/testcases/kernel/syscalls/cma/process_vm01.c
+++ b/testcases/kernel/syscalls/cma/process_vm01.c
@@ -42,7 +42,7 @@
 #include "config.h"
 #include "test.h"
 #include "safe_macros.h"
-#include "process_vm.h"
+#include "lapi/syscalls.h"
 
 struct process_vm_params {
 	int len;
@@ -103,20 +103,10 @@ static void setup(char *argv[])
 			 " at the same time.");
 	else if (rflag) {
 		TCID = TCID_readv;
-#if defined(__NR_process_vm_readv)
 		cma_test_params = cma_test_params_read;
-#else
-		tst_brkm(TCONF, NULL, "process_vm_readv does not"
-			 " exist on your system.");
-#endif
 	} else if (wflag) {
 		TCID = TCID_writev;
-#if defined(__NR_process_vm_writev)
 		cma_test_params = cma_test_params_write;
-#else
-		tst_brkm(TCONF, NULL, "process_vm_writev does not"
-			 " exist on your system.");
-#endif
 	} else
 		tst_brkm(TBROK, NULL, "Parameter missing, required -r or -w.");
 	TEST_PAUSE;
@@ -134,18 +124,20 @@ static void help(void)
 
 static void cma_test_params_read(struct process_vm_params *params)
 {
-	TEST(test_process_vm_readv(params->pid,
-				   params->lvec, params->liovcnt,
-				   params->rvec, params->riovcnt,
-				   params->flags));
+	TEST(ltp_syscall(__NR_process_vm_readv,
+			 params->pid,
+			 params->lvec, params->liovcnt,
+			 params->rvec, params->riovcnt,
+			 params->flags));
 }
 
 static void cma_test_params_write(struct process_vm_params *params)
 {
-	TEST(test_process_vm_writev(params->pid,
-				    params->lvec, params->liovcnt,
-				    params->rvec, params->riovcnt,
-				    params->flags));
+	TEST(ltp_syscall(__NR_process_vm_writev,
+			 params->pid,
+			 params->lvec, params->liovcnt,
+			 params->rvec, params->riovcnt,
+			 params->flags));
 }
 
 static int cma_check_ret(long expected_ret, long act_ret)
diff --git a/testcases/kernel/syscalls/cma/process_vm_readv02.c b/testcases/kernel/syscalls/cma/process_vm_readv02.c
index ef9b7e1..e1fc32a 100644
--- a/testcases/kernel/syscalls/cma/process_vm_readv02.c
+++ b/testcases/kernel/syscalls/cma/process_vm_readv02.c
@@ -29,7 +29,7 @@
 
 #include "test.h"
 #include "safe_macros.h"
-#include "process_vm.h"
+#include "lapi/syscalls.h"
 
 char *TCID = "process_vm_readv02";
 int TST_TOTAL = 1;
@@ -134,7 +134,8 @@ static void child_invoke(void)
 	remote.iov_len = len;
 
 	tst_resm(TINFO, "child 1: reading string from same memory location.");
-	TEST(test_process_vm_readv(pids[0], &local, 1, &remote, 1, 0));
+	TEST(ltp_syscall(__NR_process_vm_readv, pids[0],
+			 &local, 1, &remote, 1, 0));
 	if (TEST_RETURN != len)
 		tst_brkm(TFAIL | TERRNO, tst_exit, "process_vm_readv");
 	if (strncmp(lp, tst_string, len) != 0)
@@ -148,10 +149,9 @@ static void setup(void)
 {
 	tst_require_root();
 
-#if !defined(__NR_process_vm_readv)
-	tst_brkm(TCONF, NULL, "process_vm_readv does not exist "
-		 "on your system");
-#endif
+	/* Just a sanity check of the existence of syscall */
+	ltp_syscall(__NR_process_vm_readv, getpid(), NULL, 0, NULL, 0, 0);
+
 	tst_tmpdir();
 	TST_CHECKPOINT_INIT(cleanup);
 
diff --git a/testcases/kernel/syscalls/cma/process_vm_readv03.c b/testcases/kernel/syscalls/cma/process_vm_readv03.c
index 8b8dfc3..45f7c92 100644
--- a/testcases/kernel/syscalls/cma/process_vm_readv03.c
+++ b/testcases/kernel/syscalls/cma/process_vm_readv03.c
@@ -32,7 +32,7 @@
 
 #include "test.h"
 #include "safe_macros.h"
-#include "process_vm.h"
+#include "lapi/syscalls.h"
 
 char *TCID = "process_vm_readv03";
 int TST_TOTAL = 1;
@@ -180,7 +180,8 @@ static long *fetch_remote_addrs(void)
 	remote.iov_base = foo;
 	remote.iov_len = len;
 
-	TEST(test_process_vm_readv(pids[0], &local, 1, &remote, 1, 0));
+	TEST(ltp_syscall(__NR_process_vm_readv, pids[0], &local,
+			 1, &remote, 1, 0));
 	if (TEST_RETURN != len)
 		tst_brkm(TFAIL | TERRNO, tst_exit, "process_vm_readv");
 
@@ -212,7 +213,7 @@ static void child_invoke(int *bufsz_arr)
 	tst_resm(TINFO, "child 1: %d local iovecs initialized.",
 		 NUM_LOCAL_VECS);
 
-	TEST(test_process_vm_readv(pids[0], local, NUM_LOCAL_VECS,
+	TEST(ltp_syscall(__NR_process_vm_readv, pids[0], local, NUM_LOCAL_VECS,
 				   remote, nr_iovecs, 0));
 	if (TEST_RETURN != bufsz)
 		tst_brkm(TBROK | TERRNO, tst_exit, "process_vm_readv");
@@ -246,14 +247,13 @@ static void setup(void)
 {
 	tst_require_root();
 
+	/* Just a sanity check of the existence of syscall */
+	ltp_syscall(__NR_process_vm_readv, getpid(), NULL, 0, NULL, 0, 0);
+
 	nr_iovecs = nflag ? SAFE_STRTOL(NULL, nr_opt, 1, IOV_MAX) : 10;
 	bufsz = sflag ? SAFE_STRTOL(NULL, sz_opt, NUM_LOCAL_VECS, LONG_MAX)
 	    : 100000;
 
-#if !defined(__NR_process_vm_readv)
-	tst_brkm(TCONF, NULL, "process_vm_readv does not exist "
-		 "on your system");
-#endif
 	tst_tmpdir();
 	TST_CHECKPOINT_INIT(cleanup);
 	srand(time(NULL));
diff --git a/testcases/kernel/syscalls/cma/process_vm_writev02.c b/testcases/kernel/syscalls/cma/process_vm_writev02.c
index b707760..b1edba5 100644
--- a/testcases/kernel/syscalls/cma/process_vm_writev02.c
+++ b/testcases/kernel/syscalls/cma/process_vm_writev02.c
@@ -30,7 +30,7 @@
 
 #include "test.h"
 #include "safe_macros.h"
-#include "process_vm.h"
+#include "lapi/syscalls.h"
 
 char *TCID = "process_vm_writev02";
 int TST_TOTAL = 1;
@@ -171,7 +171,8 @@ static void child_write(void)
 	remote.iov_len = bufsz;
 
 	tst_resm(TINFO, "child 2: write to the same memory location.");
-	TEST(test_process_vm_writev(pids[0], &local, 1, &remote, 1, 0));
+	TEST(ltp_syscall(__NR_process_vm_writev, pids[0], &local,
+			 1, &remote, 1, 0));
 	if (TEST_RETURN != bufsz)
 		tst_brkm(TFAIL | TERRNO, tst_exit, "process_vm_readv");
 }
@@ -180,14 +181,13 @@ static void setup(void)
 {
 	tst_require_root();
 
+	/* Just a sanity check of the existence of syscall */
+	ltp_syscall(__NR_process_vm_writev, getpid(), NULL, 0, NULL, 0, 0);
+
 	bufsz =
 	    sflag ? SAFE_STRTOL(NULL, sz_opt, 1, LONG_MAX - PADDING_SIZE * 2)
 	    : 100000;
 
-#if !defined(__NR_process_vm_readv)
-	tst_brkm(TCONF, NULL, "process_vm_writev does not exist "
-		 "on your system");
-#endif
 	tst_tmpdir();
 	TST_CHECKPOINT_INIT(cleanup);
 
-- 
1.8.3.1


             reply	other threads:[~2018-12-03  9:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-03  9:43 Jason Xing [this message]
2018-12-03  9:58 ` [LTP] [PATCH] syscalls/cma: test case should return TCONF if syscall doesn't exist Jan Stancek
2018-12-04  2:49   ` Jason Xing
2018-12-04  8:54     ` Jan Stancek
2018-12-05 13:43       ` [LTP] [PATCH v2 1/2] " Jason Xing
2018-12-05 13:43         ` [LTP] [PATCH v2 2/2] lapi/syscalls: Add syscall numbers for process_vm_readv/_writev Jason Xing
2018-12-05 22:07           ` Petr Vorel
2018-12-06  3:37             ` Jason Xing
2019-02-15 10:50         ` [LTP] [PATCH v2 1/2] syscalls/cma: test case should return TCONF if syscall doesn't exist Li Wang
2019-02-15 13:53           ` Jan Stancek
2019-02-16  7:18             ` Li Wang
2019-02-16 10:28               ` Jan Stancek
2019-02-22 18:29                 ` Jan Stancek
2019-02-23  6:21                   ` Caspar Zhang
2019-02-25  8:22                     ` [LTP] [PATCH] syscalls/cma: fix the failure of compiling with O2 option Jason Xing
2019-02-25 10:34                       ` Li Wang
2019-02-25 10:47                       ` Jan Stancek
2019-02-25 13:16                         ` Caspar Zhang
2019-02-26  1:42                           ` [LTP] [PATCH v2] " Jason Xing
2019-02-26  2:22                             ` [LTP] [PATCH v3] " Jason Xing
2019-02-26  3:17                               ` Li Wang
2019-02-26 16:03                               ` Jan Stancek
2019-02-26  2:00                         ` [LTP] [PATCH] " Jason Xing

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=1543830227-15605-1-git-send-email-kerneljasonxing@linux.alibaba.com \
    --to=kerneljasonxing@linux.alibaba.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.