* [LTP] [PATCH 1/3] mremap02: Convert to new API
@ 2024-02-05 5:12 Yang Xu via ltp
2024-02-05 5:12 ` [LTP] [PATCH] mremap03: " Yang Xu via ltp
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Yang Xu via ltp @ 2024-02-05 5:12 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/mremap/mremap02.c | 186 ++++----------------
1 file changed, 37 insertions(+), 149 deletions(-)
diff --git a/testcases/kernel/syscalls/mremap/mremap02.c b/testcases/kernel/syscalls/mremap/mremap02.c
index 2dabc6847..ff46462d9 100644
--- a/testcases/kernel/syscalls/mremap/mremap02.c
+++ b/testcases/kernel/syscalls/mremap/mremap02.c
@@ -1,162 +1,56 @@
+// 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
+ * Copyright (c) Linux Test Project, 2001-2024
*/
-/*
- * Test Name: mremap02
- *
- * Test Description:
- * Verify that,
- * mremap() fails when used to expand the existing virtual memory mapped
- * region to the requested size, if the virtual memory area previously
- * mapped was not page aligned or invalid argument specified.
- *
- * Expected Result:
- * mremap() should return -1 and set errno to EINVAL.
- *
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed (return=-1)
- * if errno set == expected errno
- * Issue sys call fails with expected return value and errno.
- * Otherwise,
- * Issue sys call fails with unexpected errno.
- * Otherwise,
- * Issue sys call returns unexpected value.
- *
- * Cleanup:
- * Print errno log and/or timing stats if options given
+/*\
+ * [Description]
*
- * Usage: <for command-line>
- * mremap02 [-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.
+ * Test for EINVAL error.
*
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * 11/09/2001 Manoj Iyer (manjo@austin.ibm.com)
- * Modified.
- * - #include <linux/mman.h> should not be included as per man page for
- * mremap, #include <sys/mman.h> alone should do the job. But inorder
- * to include definition of MREMAP_MAYMOVE defined in bits/mman.h
- * (included by sys/mman.h) __USE_GNU needs to be defined.
- * There may be a more elegant way of doing this...
- *
- *
- * RESTRICTIONS:
- * None.
+ * - mremap fail with virtual memory area previously mapped was not page aligned
+ * or invalid argument specified.
*/
+
#define _GNU_SOURCE
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <sys/mman.h>
+#include "tst_test.h"
-#include "test.h"
-
-char *TCID = "mremap02";
-int TST_TOTAL = 1;
-char *addr; /* addr of memory mapped region */
-int memsize; /* memory mapped size */
-int newsize; /* new size of virtual memory block */
+static char *addr; /* addr of memory mapped region */
+static int memsize; /* memory mapped size */
+static int newsize; /* new size of virtual memory block */
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
-
-int main(int ac, char **av)
+static void verify_mremap(void)
{
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
+ errno = 0;
+ addr = mremap(addr, memsize, newsize, MREMAP_MAYMOVE);
+ TST_ERR = errno;
- tst_count = 0;
+ /* Check for the return value of mremap() */
+ if (addr != MAP_FAILED) {
+ tst_res(TFAIL | TTERRNO,
+ "mremap returned invalid value, expected: -1");
- /*
- * Attempt to expand the existing mapped
- * memory region (memsize) by newsize limits using
- * mremap() should fail as old virtual address is not
- * page aligned.
- */
- errno = 0;
- addr = mremap(addr, memsize, newsize, MREMAP_MAYMOVE);
- TEST_ERRNO = errno;
-
- /* Check for the return value of mremap() */
- if (addr != MAP_FAILED) {
- tst_resm(TFAIL,
- "mremap returned invalid value, expected: -1");
-
- /* Unmap the mapped memory region */
- if (munmap(addr, newsize) != 0) {
- tst_brkm(TBROK, cleanup, "munmap fails to "
- "unmap the expanded memory region, "
- "error=%d", errno);
- }
- continue;
- }
-
- if (errno == EINVAL) {
- tst_resm(TPASS, "mremap() Failed, 'invalid argument "
- "specified' - errno %d", TEST_ERRNO);
- } else {
- tst_resm(TFAIL, "mremap() Failed, "
- "'Unexpected errno %d", TEST_ERRNO);
- }
+ /* Unmap the mapped memory region */
+ SAFE_MUNMAP(addr, newsize);
}
- cleanup();
- tst_exit();
-
+ if (errno == EINVAL) {
+ tst_res(TPASS | TTERRNO, "mremap() Failed, 'invalid argument "
+ "specified' - errno %d", TST_ERR);
+ } else {
+ tst_res(TFAIL | TTERRNO, "mremap() Failed, "
+ "'Unexpected errno %d", TST_ERR);
+ }
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- *
- * Get system page size, Set the size of virtual memory area and the
- * new size after resize, Set the virtual memory address such that it
- * is not aligned.
- */
-void setup(void)
-{
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
+static void setup(void)
+{
/* Get the system page size */
if ((memsize = getpagesize()) < 0) {
- tst_brkm(TFAIL, NULL,
- "getpagesize() fails to get system page size");
+ tst_brk(TBROK | TTERRNO, "getpagesize() fails to get system page size");
}
/* Get the New size of virtual memory block after resize */
@@ -166,13 +60,7 @@ void setup(void)
addr = (char *)(addr + (memsize - 1));
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- */
-void cleanup(void)
-{
-
- /* Exit the program */
-
-}
+static struct tst_test test = {
+ .test_all = verify_mremap,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH] mremap03: Convert to new API
2024-02-05 5:12 [LTP] [PATCH 1/3] mremap02: Convert to new API Yang Xu via ltp
@ 2024-02-05 5:12 ` Yang Xu via ltp
2024-02-12 15:43 ` Avinesh Kumar
2024-02-05 5:12 ` [LTP] [PATCH] mremap04: " Yang Xu via ltp
2024-02-12 15:13 ` [LTP] [PATCH 1/3] mremap02: " Avinesh Kumar
2 siblings, 1 reply; 6+ messages in thread
From: Yang Xu via ltp @ 2024-02-05 5:12 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/mremap/mremap03.c | 197 +++++---------------
1 file changed, 44 insertions(+), 153 deletions(-)
diff --git a/testcases/kernel/syscalls/mremap/mremap03.c b/testcases/kernel/syscalls/mremap/mremap03.c
index 02b79bc47..b7497bc01 100644
--- a/testcases/kernel/syscalls/mremap/mremap03.c
+++ b/testcases/kernel/syscalls/mremap/mremap03.c
@@ -1,165 +1,62 @@
+// 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
+ * Copyright (c) Linux Test Project, 2001-2024
*/
-/*
- * Test Name: mremap03
- *
- * Test Description:
- * Verify that,
- * mremap() fails when used to expand the existing virtual memory mapped
- * region to the requested size, if there already exists mappings that
- * cover the whole address space requsted or the old address specified was
- * not mapped.
- *
- * Expected Result:
- * mremap() should return -1 and set errno to EFAULT.
- *
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed (return=-1)
- * if errno set == expected errno
- * Issue sys call fails with expected return value and errno.
- * Otherwise,
- * Issue sys call fails with unexpected errno.
- * Otherwise,
- * Issue sys call returns unexpected value.
+/*\
+ * [Description]
*
- * Cleanup:
- * Print errno log and/or timing stats if options given
+ * Test for EFAULT error.
*
- * Usage: <for command-line>
- * mremap03 [-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.
- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * 11/09/2001 Manoj Iyer (manjo@austin.ibm.com)
- * Modified.
- * - #include <linux/mman.h> should not be included as per man page for
- * mremap, #include <sys/mman.h> alone should do the job. But inorder
- * to include definition of MREMAP_MAYMOVE defined in bits/mman.h
- * (included by sys/mman.h) __USE_GNU needs to be defined.
- * There may be a more elegant way of doing this...
- *
- *
- * RESTRICTIONS:
- * None.
+ * - mremap fail with mapping covering the requested entire address space already exists
+ * or the old address specified was not mapped.
*/
+
#define _GNU_SOURCE
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <sys/mman.h>
+#include "tst_test.h"
-#include "test.h"
-
-char *TCID = "mremap03";
-int TST_TOTAL = 1;
static char *bad_addr;
-static char *addr; /* addr of memory mapped region */
-int memsize; /* memory mapped size */
-int newsize; /* new size of virtual memory block */
+static char *addr; /* addr of memory mapped region */
+static int memsize; /* memory mapped size */
+static int newsize; /* new size of virtual memory block */
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
-
-int main(int ac, char **av)
+static void verify_mremap(void)
{
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
+ errno = 0;
+ addr = mremap(bad_addr, memsize, newsize, MREMAP_MAYMOVE);
+ TST_ERR = errno;
- setup();
+ /* Check for the return value of mremap() */
+ if (addr != MAP_FAILED) {
+ tst_res(TFAIL | TTERRNO,
+ "mremap returned invalid value, expected: -1");
- for (lc = 0; TEST_LOOPING(lc); lc++) {
-
- tst_count = 0;
-
- /*
- * Attempt to expand the existing mapped
- * memory region (memsize) by newsize limits
- * using mremap() should fail as specified old
- * virtual address was not mapped.
- */
- errno = 0;
- addr = mremap(bad_addr, memsize, newsize, MREMAP_MAYMOVE);
- TEST_ERRNO = errno;
-
- /* Check for the return value of mremap() */
- if (addr != MAP_FAILED) {
- tst_resm(TFAIL,
- "mremap returned invalid value, expected: -1");
-
- /* Unmap the mapped memory region */
- if (munmap(addr, newsize) != 0) {
- tst_brkm(TFAIL, cleanup, "munmap fails to "
- "unmap the expanded memory region, "
- " error=%d", errno);
- }
- continue;
- }
-
- /* Check for the expected errno */
- if (errno == EFAULT) {
- tst_resm(TPASS, "mremap() Fails, 'old region not "
- "mapped', errno %d", TEST_ERRNO);
- } else {
- tst_resm(TFAIL, "mremap() Fails, "
- "'Unexpected errno %d", TEST_ERRNO);
- }
+ /* Unmap the mapped memory region */
+ SAFE_MUNMAP(addr, newsize);
}
- cleanup();
- tst_exit();
-
+ /* Check for the expected errno */
+ if (errno == EFAULT) {
+ tst_res(TPASS | TTERRNO, "mremap() Failed, 'old region not "
+ "mapped' - errno %d", TST_ERR);
+ } else {
+ tst_res(TFAIL | TTERRNO, "mremap() Failed, "
+ "'Unexpected errno %d", TST_ERR);
+ }
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- *
- * Get system page size.
- * Set the old address point some high address which is not mapped.
- */
void setup(void)
{
- int page_sz; /* system page size */
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
+ int page_sz; /* system page size */
- TEST_PAUSE;
+ page_sz = getpagesize();
/* Get the system page size */
- if ((page_sz = getpagesize()) < 0) {
- tst_brkm(TFAIL, NULL,
- "getpagesize() fails to get system page size");
+ if (page_sz < 0) {
+ tst_brk(TFAIL | TTERRNO,
+ "getpagesize() fails to get system page size");
}
/* Get the size of virtual memory area to be mapped */
@@ -169,19 +66,13 @@ void setup(void)
newsize = (memsize * 2);
/*
- * Set the old virtual address point to some address
- * which is not mapped.
- */
- bad_addr = tst_get_bad_addr(cleanup);
+ * Set the old virtual address point to some address
+ * which is not mapped.
+ */
+ bad_addr = tst_get_bad_addr(NULL);
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- */
-void cleanup(void)
-{
-
- /* Exit the program */
-
-}
+static struct tst_test test = {
+ .test_all = verify_mremap,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH] mremap04: Convert to new API
2024-02-05 5:12 [LTP] [PATCH 1/3] mremap02: Convert to new API Yang Xu via ltp
2024-02-05 5:12 ` [LTP] [PATCH] mremap03: " Yang Xu via ltp
@ 2024-02-05 5:12 ` Yang Xu via ltp
2024-03-05 12:23 ` Petr Vorel
2024-02-12 15:13 ` [LTP] [PATCH 1/3] mremap02: " Avinesh Kumar
2 siblings, 1 reply; 6+ messages in thread
From: Yang Xu via ltp @ 2024-02-05 5:12 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/mremap/Makefile | 6 +-
testcases/kernel/syscalls/mremap/mremap04.c | 260 ++++----------------
2 files changed, 55 insertions(+), 211 deletions(-)
diff --git a/testcases/kernel/syscalls/mremap/Makefile b/testcases/kernel/syscalls/mremap/Makefile
index 190b7659d..11743f712 100644
--- a/testcases/kernel/syscalls/mremap/Makefile
+++ b/testcases/kernel/syscalls/mremap/Makefile
@@ -1,12 +1,12 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) International Business Machines Corp., 2001
-top_srcdir ?= ../../../..
+top_srcdir ?= ../../../..
-LTPLIBS = ltpipc
+LTPLIBS = ltpnewipc
include $(top_srcdir)/include/mk/testcases.mk
-mremap04: LTPLDLIBS = -lltpipc
+mremap04: LTPLDLIBS = -lltpnewipc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/mremap/mremap04.c b/testcases/kernel/syscalls/mremap/mremap04.c
index 53902df73..ea5a753b1 100644
--- a/testcases/kernel/syscalls/mremap/mremap04.c
+++ b/testcases/kernel/syscalls/mremap/mremap04.c
@@ -1,183 +1,65 @@
+// 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
+ * Copyright (c) Linux Test Project, 2001-2024
*/
-/*
- * Test Name: mremap04
- *
- * Test Description:
- * Verify that,
- * mremap() fails when used to expand the existing virtual memory mapped
- * region to the requested size, if the memory area cannot be expanded at
- * the current virtual address and MREMAP_MAYMOVE flag not set.
- *
- * Expected Result:
- * mremap() should return -1 and set errno to ENOMEM.
- *
- * Algorithm:
- * Setup:
- * Setup signal handling.
- * Create temporary directory.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed (return=-1)
- * if errno set == expected errno
- * Issue sys call failed with expected return value and errno.
- * Otherwise,
- * Issue sys call failed with unexpected errno.
- * Otherwise,
- * Issue sys call returns unexpected value.
- *
- * Cleanup:
- * Print errno log and/or timing stats if options given
- * Delete the temporary directory(s)/file(s) created.
- *
- * Usage: <for command-line>
- * mremap04 [-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.
+/*\
+ * [Description]
*
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
+ * Test for ENOMEM error.
*
- * 11/09/2001 Manoj Iyer (manjo@austin.ibm.com)
- * Modified.
- * - #include <linux/mman.h> should not be included as per man page for
- * mremap, #include <sys/mman.h> alone should do the job. But inorder
- * to include definition of MREMAP_MAYMOVE defined in bits/mman.h
- * (included by sys/mman.h) __USE_GNU needs to be defined.
- * There may be a more elegant way of doing this...
- *
- * 26/02/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
- * - Fix concurrency issue. Use a shm key from getipckey instead of
- * a fixed hard-coded value.
- *
- * RESTRICTIONS:
- * None.
+ * - mremap fail when the memory area cannot be expanded at the current virtual address
+ * and MREMAP_MAYMOVE flag not set
*/
+
#define _GNU_SOURCE
-#include <errno.h>
-#include <unistd.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/shm.h>
+#include "tst_test.h"
+#include "libnewipc.h"
+#include "tst_safe_sysv_ipc.h"
-#include "test.h"
-
-#define SHM_MODE (SHM_R | SHM_W) /* mode permissions of shared memory */
-
-char *TCID = "mremap04";
-int TST_TOTAL = 1;
-char *addr; /* addr of memory mapped region */
-char *shmaddr; /* pointer to shared memory segment */
-int shmid; /* shared memory identifier. */
-int memsize; /* memory mapped size */
-int newsize; /* new size of virtual memory block */
-
-void setup(); /* Main setup function of test */
-void cleanup(); /* cleanup function for the test */
+#define SHM_MODE (SHM_R | SHM_W)
-extern int getipckey();
+static char *addr;
+static char *shmaddr;
+static int shm_id;
+static int memsize;
+static int newsize;
-int main(int ac, char **av)
+static void verify_mremap(void)
{
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
-
- tst_count = 0;
-
- /*
- * Attempt to expand the existing shared
- * memory region of newsize by newsize limits
- * using mremap() should fail as specified
- * memory area already locked and MREMAP_MAYMOVE
- * flag unset.
- */
- errno = 0;
- addr = mremap(shmaddr, memsize, newsize, 0);
- TEST_ERRNO = errno;
+ errno = 0;
+ addr = mremap(shmaddr, memsize, newsize, 0);
+ TST_ERR = errno;
- /* Check for the return value of mremap() */
- if (addr != MAP_FAILED) {
- tst_resm(TFAIL,
- "mremap returned invalid value, expected: -1");
+ /* Check for the return value of mremap() */
+ if (addr != MAP_FAILED) {
+ tst_res(TFAIL | TTERRNO,
+ "mremap returned invalid value, expected: -1");
+ /* Unmap the mapped memory region */
+ SAFE_MUNMAP(addr, newsize);
- /* Unmap the mapped memory region */
- if (munmap(addr, newsize) != 0) {
- tst_brkm(TFAIL, cleanup, "munmap failed to "
- "unmap the expanded memory region, "
- "error=%d", errno);
- }
- continue;
- }
-
- if (TEST_ERRNO == ENOMEM) {
- tst_resm(TPASS, "mremap() failed, "
- "'MREMAP_MAYMOVE flag unset', "
- "errno %d", TEST_ERRNO);
- } else {
- tst_resm(TFAIL, "mremap() failed, "
- "Unexpected errno %d", TEST_ERRNO);
- }
}
- cleanup();
- tst_exit();
-
+ if (TST_ERR == ENOMEM) {
+ tst_res(TPASS | TTERRNO, "mremap() failed, "
+ "'MREMAP_MAYMOVE flag unset', "
+ "errno %d", TST_ERR);
+ } else {
+ tst_res(TFAIL | TTERRNO, "mremap() failed, "
+ "Unexpected errno %d", TST_ERR);
+ }
}
-/*
- * setup() - performs all ONE TIME setup for this test.
- *
- * Get system page size, Set the size of virtual memory area and the
- * newsize after resize,
- * Create a named shared memory segment SHMKEY of newsize and mode SHM_MODE
- * by using shmget() which returns a shared memory identifier associated
- * with the created shared memory segment.
- * Call shmat() to attach the shared memory segment to the data segment of the
- * calling process. The segment is attached at the first available address as
- * selected by the system.
- */
-void setup(void)
+static void setup(void)
{
key_t shmkey;
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- tst_tmpdir();
-
/* Get the system page size */
if ((memsize = getpagesize()) < 0) {
- tst_brkm(TBROK, NULL,
+ tst_brk(TBROK | TTERRNO,
"getpagesize() failed to get system page size");
}
@@ -185,61 +67,23 @@ void setup(void)
newsize = (memsize * 2);
/* get an IPC resource key */
- shmkey = getipckey();
+ shmkey = GETIPCKEY();
- /*
- * Create a shared memory segment represented by SHMKEY of
- * specified size 'newsize' and mode permissions 'SHM_MODE'.
- */
- shmid = shmget(shmkey, newsize, IPC_CREAT | SHM_MODE);
- if (shmid == -1) {
- tst_brkm(TBROK, NULL, "shmget() Failed to create a shared "
- "memory, error:%d", errno);
- }
+ /* Create a shared memory segment represented by SHMKEY */
+ shm_id = SAFE_SHMGET(shmkey, newsize, IPC_CREAT | SHM_MODE);
- /*
- * Attach the shared memory segment associated with the shared
- * memory identifier specified by "shmid" to the data segment of
- * the calling process at the first available address as selected
- * by the system.
- */
- shmaddr = shmat(shmid, NULL, 0);
- if (shmaddr == (void *)-1) {
- tst_brkm(TBROK, cleanup, "shmat() Failed to attach shared "
- "memory, error:%d", errno);
- }
+ shmaddr = SAFE_SHMAT(shm_id, NULL, 0);
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- * Detach the shared memory segment and remove the shared memory
- * identifier associated with the shared memory.
- */
-void cleanup(void)
+static void cleanup(void)
{
-
- /*
- * Detach the shared memory segment attached to
- * the calling process's data segment
- */
- if (shmdt(shmaddr) < 0) {
- tst_brkm(TFAIL, NULL, "shmdt() Failed to detach shared "
- "memory, error:%d", errno);
- }
-
- /*
- * Remove the shared memory identifier associated with
- * the shared memory segment and destroy the shared memory
- * segment.
- */
- if (shmctl(shmid, IPC_RMID, 0) < 0) {
- tst_brkm(TFAIL, NULL, "shmctl() Failed to remove shared "
- "memory, error:%d", errno);
- }
-
- tst_rmdir();
-
- /* Exit the program */
-
+ SAFE_SHMDT(shmaddr);
+ SAFE_SHMCTL(shm_id, IPC_RMID, 0);
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+ .test_all = verify_mremap,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH 1/3] mremap02: Convert to new API
2024-02-05 5:12 [LTP] [PATCH 1/3] mremap02: Convert to new API Yang Xu via ltp
2024-02-05 5:12 ` [LTP] [PATCH] mremap03: " Yang Xu via ltp
2024-02-05 5:12 ` [LTP] [PATCH] mremap04: " Yang Xu via ltp
@ 2024-02-12 15:13 ` Avinesh Kumar
2 siblings, 0 replies; 6+ messages in thread
From: Avinesh Kumar @ 2024-02-12 15:13 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hello Yang,
On Monday, February 5, 2024 6:12:28 AM CET Yang Xu via ltp wrote:
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> testcases/kernel/syscalls/mremap/mremap02.c | 186 ++++----------------
> 1 file changed, 37 insertions(+), 149 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/mremap/mremap02.c
> b/testcases/kernel/syscalls/mremap/mremap02.c index 2dabc6847..ff46462d9
> 100644
> --- a/testcases/kernel/syscalls/mremap/mremap02.c
> +++ b/testcases/kernel/syscalls/mremap/mremap02.c
> @@ -1,162 +1,56 @@
> +// 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
> + * Copyright (c) Linux Test Project, 2001-2024
> */
>
> -/*
> - * Test Name: mremap02
> - *
> - * Test Description:
> - * Verify that,
> - * mremap() fails when used to expand the existing virtual memory mapped
> - * region to the requested size, if the virtual memory area previously
> - * mapped was not page aligned or invalid argument specified.
> - *
> - * Expected Result:
> - * mremap() should return -1 and set errno to EINVAL.
> - *
> - * Algorithm:
> - * Setup:
> - * Setup signal handling.
> - * Pause for SIGUSR1 if option specified.
> - *
> - * Test:
> - * Loop if the proper options are given.
> - * Execute system call
> - * Check return code, if system call failed (return=-1)
> - * if errno set == expected errno
> - * Issue sys call fails with expected return value and errno.
> - * Otherwise,
> - * Issue sys call fails with unexpected errno.
> - * Otherwise,
> - * Issue sys call returns unexpected value.
> - *
> - * Cleanup:
> - * Print errno log and/or timing stats if options given
> +/*\
> + * [Description]
> *
> - * Usage: <for command-line>
> - * mremap02 [-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.
> + * Test for EINVAL error.
> *
> - * HISTORY
> - * 07/2001 Ported by Wayne Boyer
We need to keep the original author details.
> - *
> - * 11/09/2001 Manoj Iyer (manjo@austin.ibm.com)
> - * Modified.
> - * - #include <linux/mman.h> should not be included as per man page
> for - * mremap, #include <sys/mman.h> alone should do the job. But
> inorder - * to include definition of MREMAP_MAYMOVE defined in
> bits/mman.h - * (included by sys/mman.h) __USE_GNU needs to be
> defined. - * There may be a more elegant way of doing this...
> - *
> - *
> - * RESTRICTIONS:
> - * None.
> + * - mremap fail with virtual memory area previously mapped was not page
> aligned + * or invalid argument specified.
this description isn't clear which EINVAL scenario we want to test here.
> */
> +
> #define _GNU_SOURCE
> -#include <errno.h>
> -#include <unistd.h>
> -#include <fcntl.h>
> #include <sys/mman.h>
> +#include "tst_test.h"
>
> -#include "test.h"
> -
> -char *TCID = "mremap02";
> -int TST_TOTAL = 1;
> -char *addr; /* addr of memory mapped region */
> -int memsize; /* memory mapped size */
> -int newsize; /* new size of virtual memory block */
> +static char *addr; /* addr of memory mapped region */
> +static int memsize; /* memory mapped size */
> +static int newsize; /* new size of virtual memory block */
we can get rid of obvious comments from here and everywhere below.
>
> -void setup(); /* Main setup function of test */
> -void cleanup(); /* cleanup function for the test */
> -
> -int main(int ac, char **av)
> +static void verify_mremap(void)
> {
> - int lc;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> - setup();
> -
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> + errno = 0;
> + addr = mremap(addr, memsize, newsize, MREMAP_MAYMOVE);
> + TST_ERR = errno;
>
> - tst_count = 0;
> + /* Check for the return value of mremap() */
> + if (addr != MAP_FAILED) {
> + tst_res(TFAIL | TTERRNO,
> + "mremap returned invalid value, expected: -1");
>
> - /*
> - * Attempt to expand the existing mapped
> - * memory region (memsize) by newsize limits using
> - * mremap() should fail as old virtual address is not
> - * page aligned.
> - */
> - errno = 0;
> - addr = mremap(addr, memsize, newsize, MREMAP_MAYMOVE);
> - TEST_ERRNO = errno;
> -
> - /* Check for the return value of mremap() */
> - if (addr != MAP_FAILED) {
> - tst_resm(TFAIL,
> - "mremap returned invalid value, expected: -1");
> -
> - /* Unmap the mapped memory region */
> - if (munmap(addr, newsize) != 0) {
> - tst_brkm(TBROK, cleanup, "munmap fails to "
> - "unmap the expanded memory region, "
> - "error=%d", errno);
> - }
> - continue;
> - }
> -
> - if (errno == EINVAL) {
> - tst_resm(TPASS, "mremap() Failed, 'invalid argument "
> - "specified' - errno %d", TEST_ERRNO);
> - } else {
> - tst_resm(TFAIL, "mremap() Failed, "
> - "'Unexpected errno %d", TEST_ERRNO);
> - }
> + /* Unmap the mapped memory region */
> + SAFE_MUNMAP(addr, newsize);
> }
>
> - cleanup();
> - tst_exit();
> -
> + if (errno == EINVAL) {
> + tst_res(TPASS | TTERRNO, "mremap() Failed, 'invalid argument "
> + "specified' - errno %d", TST_ERR);
> + } else {
> + tst_res(TFAIL | TTERRNO, "mremap() Failed, "
> + "'Unexpected errno %d", TST_ERR);
> + }
> }
>
> -/*
> - * setup() - performs all ONE TIME setup for this test.
> - *
> - * Get system page size, Set the size of virtual memory area and the
> - * new size after resize, Set the virtual memory address such that it
> - * is not aligned.
> - */
> -void setup(void)
> -{
> -
> - tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> - TEST_PAUSE;
>
> +static void setup(void)
> +{
> /* Get the system page size */
> if ((memsize = getpagesize()) < 0) {
> - tst_brkm(TFAIL, NULL,
> - "getpagesize() fails to get system page size");
> + tst_brk(TBROK | TTERRNO, "getpagesize() fails to get system page size");
> }
maybe we should use -
SAFE_SYSCONF(_SC_PAGESIZE)
>
> /* Get the New size of virtual memory block after resize */
> @@ -166,13 +60,7 @@ void setup(void)
> addr = (char *)(addr + (memsize - 1));
looks like we are trying to have an old_address which is not page aligned,
but first of all, shouldn't old_address have an existing mapping for to be
used in mremap() call.
> }
>
> -/*
> - * cleanup() - performs all ONE TIME cleanup for this test at
> - * completion or premature exit.
> - */
> -void cleanup(void)
> -{
> -
> - /* Exit the program */
> -
> -}
> +static struct tst_test test = {
> + .test_all = verify_mremap,
> + .setup = setup,
> +};
Regards,
Avinesh
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] mremap03: Convert to new API
2024-02-05 5:12 ` [LTP] [PATCH] mremap03: " Yang Xu via ltp
@ 2024-02-12 15:43 ` Avinesh Kumar
0 siblings, 0 replies; 6+ messages in thread
From: Avinesh Kumar @ 2024-02-12 15:43 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi,
most of the comments from mremap02 applies here too.
Also please fix the `make check` complains in all three patches.
Thanks,
Avinesh
On Monday, February 5, 2024 6:12:29 AM CET Yang Xu via ltp wrote:
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> testcases/kernel/syscalls/mremap/mremap03.c | 197 +++++---------------
> 1 file changed, 44 insertions(+), 153 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/mremap/mremap03.c
> b/testcases/kernel/syscalls/mremap/mremap03.c index 02b79bc47..b7497bc01
> 100644
> --- a/testcases/kernel/syscalls/mremap/mremap03.c
> +++ b/testcases/kernel/syscalls/mremap/mremap03.c
> @@ -1,165 +1,62 @@
> +// 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
> + * Copyright (c) Linux Test Project, 2001-2024
> */
>
> -/*
> - * Test Name: mremap03
> - *
> - * Test Description:
> - * Verify that,
> - * mremap() fails when used to expand the existing virtual memory mapped
> - * region to the requested size, if there already exists mappings that
> - * cover the whole address space requsted or the old address specified
> was - * not mapped.
> - *
> - * Expected Result:
> - * mremap() should return -1 and set errno to EFAULT.
> - *
> - * Algorithm:
> - * Setup:
> - * Setup signal handling.
> - * Pause for SIGUSR1 if option specified.
> - *
> - * Test:
> - * Loop if the proper options are given.
> - * Execute system call
> - * Check return code, if system call failed (return=-1)
> - * if errno set == expected errno
> - * Issue sys call fails with expected return value and errno.
> - * Otherwise,
> - * Issue sys call fails with unexpected errno.
> - * Otherwise,
> - * Issue sys call returns unexpected value.
> +/*\
> + * [Description]
> *
> - * Cleanup:
> - * Print errno log and/or timing stats if options given
> + * Test for EFAULT error.
> *
> - * Usage: <for command-line>
> - * mremap03 [-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.
> - *
> - * HISTORY
> - * 07/2001 Ported by Wayne Boyer
> - *
> - * 11/09/2001 Manoj Iyer (manjo@austin.ibm.com)
> - * Modified.
> - * - #include <linux/mman.h> should not be included as per man page
> for - * mremap, #include <sys/mman.h> alone should do the job. But
> inorder - * to include definition of MREMAP_MAYMOVE defined in
> bits/mman.h - * (included by sys/mman.h) __USE_GNU needs to be
> defined. - * There may be a more elegant way of doing this...
> - *
> - *
> - * RESTRICTIONS:
> - * None.
> + * - mremap fail with mapping covering the requested entire address space
> already exists + * or the old address specified was not mapped.
> */
> +
> #define _GNU_SOURCE
> -#include <errno.h>
> -#include <unistd.h>
> -#include <fcntl.h>
> #include <sys/mman.h>
> +#include "tst_test.h"
>
> -#include "test.h"
> -
> -char *TCID = "mremap03";
> -int TST_TOTAL = 1;
> static char *bad_addr;
> -static char *addr; /* addr of memory mapped region */
> -int memsize; /* memory mapped size */
> -int newsize; /* new size of virtual memory block */
> +static char *addr; /* addr of memory mapped region */
> +static int memsize; /* memory mapped size */
> +static int newsize; /* new size of virtual memory block */
>
> -void setup(); /* Main setup function of test */
> -void cleanup(); /* cleanup function for the test */
> -
> -int main(int ac, char **av)
> +static void verify_mremap(void)
> {
> - int lc;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> + errno = 0;
> + addr = mremap(bad_addr, memsize, newsize, MREMAP_MAYMOVE);
> + TST_ERR = errno;
>
> - setup();
> + /* Check for the return value of mremap() */
> + if (addr != MAP_FAILED) {
> + tst_res(TFAIL | TTERRNO,
> + "mremap returned invalid value, expected: -1");
>
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> -
> - tst_count = 0;
> -
> - /*
> - * Attempt to expand the existing mapped
> - * memory region (memsize) by newsize limits
> - * using mremap() should fail as specified old
> - * virtual address was not mapped.
> - */
> - errno = 0;
> - addr = mremap(bad_addr, memsize, newsize, MREMAP_MAYMOVE);
> - TEST_ERRNO = errno;
> -
> - /* Check for the return value of mremap() */
> - if (addr != MAP_FAILED) {
> - tst_resm(TFAIL,
> - "mremap returned invalid value, expected: -1");
> -
> - /* Unmap the mapped memory region */
> - if (munmap(addr, newsize) != 0) {
> - tst_brkm(TFAIL, cleanup, "munmap fails to "
> - "unmap the expanded memory region, "
> - " error=%d", errno);
> - }
> - continue;
> - }
> -
> - /* Check for the expected errno */
> - if (errno == EFAULT) {
> - tst_resm(TPASS, "mremap() Fails, 'old region not "
> - "mapped', errno %d", TEST_ERRNO);
> - } else {
> - tst_resm(TFAIL, "mremap() Fails, "
> - "'Unexpected errno %d", TEST_ERRNO);
> - }
> + /* Unmap the mapped memory region */
> + SAFE_MUNMAP(addr, newsize);
> }
>
> - cleanup();
> - tst_exit();
> -
> + /* Check for the expected errno */
> + if (errno == EFAULT) {
> + tst_res(TPASS | TTERRNO, "mremap() Failed, 'old region not "
> + "mapped' - errno %d", TST_ERR);
> + } else {
> + tst_res(TFAIL | TTERRNO, "mremap() Failed, "
> + "'Unexpected errno %d", TST_ERR);
> + }
> }
>
> -/*
> - * setup() - performs all ONE TIME setup for this test.
> - *
> - * Get system page size.
> - * Set the old address point some high address which is not mapped.
> - */
> void setup(void)
> {
> - int page_sz; /* system page size */
> -
> - tst_sig(FORK, DEF_HANDLER, cleanup);
> + int page_sz; /* system page size */
>
> - TEST_PAUSE;
> + page_sz = getpagesize();
>
> /* Get the system page size */
> - if ((page_sz = getpagesize()) < 0) {
> - tst_brkm(TFAIL, NULL,
> - "getpagesize() fails to get system page size");
> + if (page_sz < 0) {
> + tst_brk(TFAIL | TTERRNO,
> + "getpagesize() fails to get system page size");
> }
>
> /* Get the size of virtual memory area to be mapped */
> @@ -169,19 +66,13 @@ void setup(void)
> newsize = (memsize * 2);
>
> /*
> - * Set the old virtual address point to some address
> - * which is not mapped.
> - */
> - bad_addr = tst_get_bad_addr(cleanup);
> + * Set the old virtual address point to some address
> + * which is not mapped.
> + */
> + bad_addr = tst_get_bad_addr(NULL);
> }
>
> -/*
> - * cleanup() - performs all ONE TIME cleanup for this test at
> - * completion or premature exit.
> - */
> -void cleanup(void)
> -{
> -
> - /* Exit the program */
> -
> -}
> +static struct tst_test test = {
> + .test_all = verify_mremap,
> + .setup = setup,
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] mremap04: Convert to new API
2024-02-05 5:12 ` [LTP] [PATCH] mremap04: " Yang Xu via ltp
@ 2024-03-05 12:23 ` Petr Vorel
0 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2024-03-05 12:23 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi Xu,
I updated status for mremap0[2-4] in patchwork, because you have sent v2.
Please, keep updating patchwork (that saves other's time).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-03-05 12:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-05 5:12 [LTP] [PATCH 1/3] mremap02: Convert to new API Yang Xu via ltp
2024-02-05 5:12 ` [LTP] [PATCH] mremap03: " Yang Xu via ltp
2024-02-12 15:43 ` Avinesh Kumar
2024-02-05 5:12 ` [LTP] [PATCH] mremap04: " Yang Xu via ltp
2024-03-05 12:23 ` Petr Vorel
2024-02-12 15:13 ` [LTP] [PATCH 1/3] mremap02: " Avinesh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox