All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Xu <xuyang2018.jy@fujitsu.com>
To: <ltp@lists.linux.it>
Subject: [LTP] [PATCH 2/2] syscalls/shmdt02: Convert into new api
Date: Wed, 27 Apr 2022 12:39:22 +0800	[thread overview]
Message-ID: <1651034362-18672-2-git-send-email-xuyang2018.jy@fujitsu.com> (raw)
In-Reply-To: <1651034362-18672-1-git-send-email-xuyang2018.jy@fujitsu.com>

Signed-off-by: Liao Huangjie <liaohj.jy@fujitsu.com>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/ipc/shmdt/Makefile  |   7 +-
 testcases/kernel/syscalls/ipc/shmdt/shmdt02.c | 134 +++++-------------
 2 files changed, 34 insertions(+), 107 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/shmdt/Makefile b/testcases/kernel/syscalls/ipc/shmdt/Makefile
index a48dbf48f..6b2b26d05 100644
--- a/testcases/kernel/syscalls/ipc/shmdt/Makefile
+++ b/testcases/kernel/syscalls/ipc/shmdt/Makefile
@@ -3,13 +3,10 @@
 
 top_srcdir              ?= ../../../../..
 
-LTPLIBS = ltpipc ltpnewipc
+LTPLIBS = ltpnewipc
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-shmdt01: LTPLDLIBS = -lltpnewipc
-shmdt02: LTPLDLIBS = -lltpipc
-
-LTPLDLIBS  = -lltpipc ltpnewipc
+LTPLDLIBS  = -lltpnewipc
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c b/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c
index 5cab2596b..782c6f488 100644
--- a/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c
+++ b/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c
@@ -1,118 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * NAME
- *	shmdt02.c
- *
- * DESCRIPTION
- *	shmdt02 - check for EINVAL error
- *
- * ALGORITHM
- *	loop if that option was specified
- *	  call shmdt() using an invalid shared memory address
- *	  check the errno value
- *	    issue a PASS message if we get EINVAL
- *	  otherwise, the tests fails
- *	    issue a FAIL message
- *	call cleanup
+/*\
+ * [Description]
  *
- * USAGE:  <for command-line>
- *  shmdt02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
+ * Tests basic error handing of the shmdt syscall.
  *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
+ * -EINVAL there is no shared memory segment attached at shmaddr.
+ * -EINVAL shmaddr is not aligned on a page boundary.
  */
 
-#include "ipcshm.h"
-
-char *TCID = "shmdt02";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
-{
-	int lc;
-	int unshared;		/* a local variable to use to produce *//* the error in the shmdt() call */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
+#include <sys/types.h>
+#include <sys/shm.h>
+#include "tst_test.h"
+#include "libnewipc.h"
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
+static void *non_attched_addr;
+static void *unaligned_addr;
 
-		/*
-		 * make the call using the TEST() macro - attempt to
-		 * remove an invalid shared memory address
-		 */
+struct tcase {
+	void **addr;
+	char *des;
+} tcases[] = {
+	{&non_attched_addr, "shmdt(non_attched_addr)"},
+	{&unaligned_addr, "shmdt(unaligned_addr)"}
+};
 
-		TEST(shmdt(&unshared));
-
-		if (TEST_RETURN != -1) {
-			tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly");
-		}
-
-		switch (TEST_ERRNO) {
-		case EINVAL:
-			tst_resm(TPASS, "expected failure - errno = %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an unexpected error "
-				 "- %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
-
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void verify_shmdt(unsigned int n)
 {
+	struct tcase *tc = &tcases[n];
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL(shmdt(*tc->addr), EINVAL, "%s", tc->des);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void setup(void)
 {
-
+	non_attched_addr = PROBE_FREE_ADDR();
+	unaligned_addr = non_attched_addr + SHMLBA - 1;
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_shmdt,
+	.tcnt = ARRAY_SIZE(tcases),
+};
-- 
2.23.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2022-04-27  3:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27  4:39 [LTP] [PATCH 1/2] syscalls/shmdt01: Convert into new api Yang Xu
2022-04-27  4:39 ` Yang Xu [this message]
2022-06-01 14:19   ` [LTP] [PATCH 2/2] syscalls/shmdt02: " Cyril Hrubis
2022-04-27 15:14 ` [LTP] [PATCH 1/2] syscalls/shmdt01: " Cyril Hrubis
2022-04-28  2:59   ` [LTP] [PATCH v2] " Yang Xu
2022-06-01 13:14     ` 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=1651034362-18672-2-git-send-email-xuyang2018.jy@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.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.