From: Ilya Leoshkevich <iii@linux.ibm.com>
To: "Richard Henderson" <richard.henderson@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Laurent Vivier" <laurent@vivier.eu>,
"Taylor Simpson" <tsimpson@quicinc.com>,
"Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH v3 5/5] tests/tcg/linux-test: Add linux-madvise test
Date: Tue, 6 Sep 2022 02:08:39 +0200 [thread overview]
Message-ID: <20220906000839.1672934-6-iii@linux.ibm.com> (raw)
In-Reply-To: <20220906000839.1672934-1-iii@linux.ibm.com>
Add a test that checks madvise(MADV_DONTNEED) behavior with anonymous
and file mappings in order to prevent regressions.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tests/tcg/multiarch/linux/linux-madvise.c | 70 +++++++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 tests/tcg/multiarch/linux/linux-madvise.c
diff --git a/tests/tcg/multiarch/linux/linux-madvise.c b/tests/tcg/multiarch/linux/linux-madvise.c
new file mode 100644
index 0000000000..29d0997e68
--- /dev/null
+++ b/tests/tcg/multiarch/linux/linux-madvise.c
@@ -0,0 +1,70 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+static void test_anonymous(void)
+{
+ int pagesize = getpagesize();
+ char *page;
+ int ret;
+
+ page = mmap(NULL, pagesize, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ assert(page != MAP_FAILED);
+
+ /* Check that mprotect() does not interfere with MADV_DONTNEED. */
+ ret = mprotect(page, pagesize, PROT_READ | PROT_WRITE);
+ assert(ret == 0);
+
+ /* Check that MADV_DONTNEED clears the page. */
+ *page = 42;
+ ret = madvise(page, pagesize, MADV_DONTNEED);
+ assert(ret == 0);
+ assert(*page == 0);
+
+ ret = munmap(page, pagesize);
+ assert(ret == 0);
+}
+
+static void test_file(void)
+{
+ char tempname[] = "/tmp/.cmadviseXXXXXX";
+ int pagesize = getpagesize();
+ ssize_t written;
+ char c = 42;
+ char *page;
+ int ret;
+ int fd;
+
+ fd = mkstemp(tempname);
+ assert(fd != -1);
+ ret = unlink(tempname);
+ assert(ret == 0);
+ written = write(fd, &c, sizeof(c));
+ assert(written == sizeof(c));
+ page = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE, fd, 0);
+ assert(page != MAP_FAILED);
+
+ /* Check that mprotect() does not interfere with MADV_DONTNEED. */
+ ret = mprotect(page, pagesize, PROT_READ | PROT_WRITE);
+ assert(ret == 0);
+
+ /* Check that MADV_DONTNEED resets the page. */
+ *page = 0;
+ ret = madvise(page, pagesize, MADV_DONTNEED);
+ assert(ret == 0);
+ assert(*page == c);
+
+ ret = munmap(page, pagesize);
+ assert(ret == 0);
+ ret = close(fd);
+ assert(ret == 0);
+}
+
+int main(void)
+{
+ test_anonymous();
+ test_file();
+
+ return EXIT_SUCCESS;
+}
--
2.37.2
next prev parent reply other threads:[~2022-09-06 0:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-06 0:08 [PATCH v3 0/5] linux-user: Passthrough MADV_DONTNEED for certain file mappings Ilya Leoshkevich
2022-09-06 0:08 ` [PATCH v3 1/5] linux-user: Provide MADV_* definitions Ilya Leoshkevich
2022-09-23 21:51 ` Laurent Vivier
2022-09-06 0:08 ` [PATCH v3 2/5] linux-user: Fix madvise(MADV_DONTNEED) on alpha Ilya Leoshkevich
2022-09-23 21:51 ` Laurent Vivier
2022-09-06 0:08 ` [PATCH v3 3/5] linux-user: Implement stracing madvise() Ilya Leoshkevich
2022-09-23 21:51 ` Laurent Vivier
2022-09-06 0:08 ` [PATCH v3 4/5] linux-user: Passthrough MADV_DONTNEED for certain file mappings Ilya Leoshkevich
2022-09-23 21:51 ` Laurent Vivier
2022-09-06 0:08 ` Ilya Leoshkevich [this message]
2022-09-23 21:52 ` [PATCH v3 5/5] tests/tcg/linux-test: Add linux-madvise test Laurent Vivier
2022-09-06 7:35 ` [PATCH v3 0/5] linux-user: Passthrough MADV_DONTNEED for certain file mappings Richard Henderson
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=20220906000839.1672934-6-iii@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=alex.bennee@linaro.org \
--cc=laurent@vivier.eu \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=tsimpson@quicinc.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;
as well as URLs for NNTP newsgroup(s).