public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: Zhao Gongyi <zhaogongyi@huawei.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE)
Date: Mon, 24 Oct 2022 11:47:42 +0100	[thread overview]
Message-ID: <87r0yxze6a.fsf@suse.de> (raw)
In-Reply-To: <20221013134728.49609-5-zhaogongyi@huawei.com>

Hello,

Zhao Gongyi via ltp <ltp@lists.linux.it> writes:

> Check that after a successful madvise(2) MADV_REMOVE operation, subsequent
> accesses in the specified address range will see bytes containing zero.
>
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>  runtest/syscalls                              |  1 +
>  testcases/kernel/syscalls/madvise/.gitignore  |  1 +
>  testcases/kernel/syscalls/madvise/madvise12.c | 85 +++++++++++++++++++
>  3 files changed, 87 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/madvise/madvise12.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 296af9f9d..0697b31ab 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -949,6 +949,7 @@ madvise08 madvise08
>  madvise09 madvise09
>  madvise10 madvise10
>  madvise11 madvise11
> +madvise12 madvise12
>
>  newuname01 newuname01
>
> diff --git a/testcases/kernel/syscalls/madvise/.gitignore b/testcases/kernel/syscalls/madvise/.gitignore
> index ffd8823d1..dc82c82bd 100644
> --- a/testcases/kernel/syscalls/madvise/.gitignore
> +++ b/testcases/kernel/syscalls/madvise/.gitignore
> @@ -9,3 +9,4 @@
>  /madvise09
>  /madvise10
>  /madvise11
> +/madvise12
> diff --git a/testcases/kernel/syscalls/madvise/madvise12.c b/testcases/kernel/syscalls/madvise/madvise12.c
> new file mode 100644
> index 000000000..7c22e464d
> --- /dev/null
> +++ b/testcases/kernel/syscalls/madvise/madvise12.c
> @@ -0,0 +1,85 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
> + * Author: Zhao Gongyi <zhaogongyi@huawei.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Check that after a successful madvise(2) MADV_REMOVE operation, subsequent
> + * accesses in the specified address range will see bytes containing zero.
> + */
> +
> +#define _GNU_SOURCE
> +#include <fcntl.h>
> +#include "tst_test.h"
> +
> +#define MAP_SIZE (8 * 1024)
> +#define FNAME "madvise_remove"
> +#define MOUNT_POINT "mntpoint"
> +
> +static char *addr;
> +static int fd;
> +
> +static void run(void)
> +{

Same as the other test, memset is required here

> +	TEST(madvise(addr, MAP_SIZE, MADV_REMOVE));
> +	if (TST_RET == -1) {
> +		if (TST_ERR == EOPNOTSUPP)
> +			tst_brk(TCONF, "'MADV_REMOVE' not supported?");
> +		else {
> +			tst_res(TFAIL | TTERRNO, "madvise(%p, %d, 0x%x) failed",
> +				addr, MAP_SIZE, MADV_REMOVE);
> +			return;
> +		}
> +	}

Also same as other test, this could be put in SAFE_MADVISE.

> +
> +	for (int i = 0; i < MAP_SIZE; i++) {
> +		if (addr[0]) {
> +			tst_res(TFAIL,
> +				"The content of mapping memory is not
> removed");

This could be replaced with memcmp. Unless you print the location of
where the bytes are non-zero.

> +			return;
> +		}
> +	}
> +
> +	tst_res(TPASS, "The content of mapping memory is removed");
> +}
> +
> +static void setup(void)
> +{
> +	fd = SAFE_OPEN(FNAME, O_CREAT | O_RDWR, 0777);
> +	TEST(fallocate(fd, 0, 0, MAP_SIZE));
> +	if (TST_RET) {
> +		if (TST_ERR == ENOSYS || TST_ERR == EOPNOTSUPP)
> +			tst_brk(TCONF, "fallocate not support");
> +		else
> +			tst_brk(TBROK | TERRNO, "fallocate failed");
> +	}
> +
> +	addr = SAFE_MMAP(NULL, MAP_SIZE,
> +			PROT_READ | PROT_WRITE,
> +			MAP_SHARED,
> +			fd, 0);
> +	memset(addr, 1, MAP_SIZE);
> +}
> +
> +static void cleanup(void)
> +{
> +	SAFE_CLOSE(fd);
> +	SAFE_UNLINK(FNAME);
> +	if (addr)
> +		SAFE_MUNMAP(addr, MAP_SIZE);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.needs_root = 1,
> +	.min_kver = "2.6.16",
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.all_filesystems = 1,
> +	.mount_device = 1,
> +	.mntpoint = MOUNT_POINT,
> +};
> +
> --
> 2.17.1


-- 
Thank you,
Richard.

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

  reply	other threads:[~2022-10-24 10:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-13 13:47 [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-13 13:47 ` [LTP] [PATCH v4 0/4] new test for madvise(MADV_DONTNEED/MADV_REMOVE) Zhao Gongyi via ltp
2022-10-13 13:47 ` [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-24  7:58   ` Richard Palethorpe
2022-10-13 13:47 ` [LTP] [PATCH v4 2/4] syscalls/madvise11: " Zhao Gongyi via ltp
2022-10-24  9:48   ` Richard Palethorpe
2022-10-13 13:47 ` [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE) Zhao Gongyi via ltp
2022-10-24 10:47   ` Richard Palethorpe [this message]
2022-10-13 13:47 ` [LTP] [PATCH v4 4/4] syscalls/madvise13: " Zhao Gongyi via ltp
2022-10-24 11:01   ` Richard Palethorpe

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=87r0yxze6a.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=ltp@lists.linux.it \
    --cc=zhaogongyi@huawei.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