public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Avinesh Kumar <akumar@suse.de>
To: Yang Xu <xuyang2018.jy@fujitsu.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] mremap03: Convert to new API
Date: Mon, 12 Feb 2024 16:43:06 +0100	[thread overview]
Message-ID: <6989698.9J7NaK4W3v@localhost> (raw)
In-Reply-To: <20240205051230.6272-2-xuyang2018.jy@fujitsu.com>

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

  reply	other threads:[~2024-02-12 15:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=6989698.9J7NaK4W3v@localhost \
    --to=akumar@suse.de \
    --cc=ltp@lists.linux.it \
    --cc=xuyang2018.jy@fujitsu.com \
    /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