All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roi Klevansky <roiklevansky@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Helge Deller" <deller@gmx.de>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Roi Klevansky" <roiklevansky@gmail.com>
Subject: [PATCH 2/2] tests/tcg: add linux-user test for madvise returning ENOMEM
Date: Tue,  1 Sep 2026 00:20:40 +0300	[thread overview]
Message-ID: <20260831212040.1833650-3-roiklevansky@gmail.com> (raw)
In-Reply-To: <20260831212040.1833650-1-roiklevansky@gmail.com>

Add tests for madvise() under linux-user with partially and fully
unmapped address ranges, making sure it returns ENOMEM, just like
the kernel does.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4382
Signed-off-by: Roi Klevansky <roiklevansky@gmail.com>
---
 tests/tcg/multiarch/linux/linux-madvise.c | 43 +++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/tests/tcg/multiarch/linux/linux-madvise.c b/tests/tcg/multiarch/linux/linux-madvise.c
index 539fb3b772..b7a52abb6c 100644
--- a/tests/tcg/multiarch/linux/linux-madvise.c
+++ b/tests/tcg/multiarch/linux/linux-madvise.c
@@ -1,4 +1,5 @@
 #include <assert.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <unistd.h>
@@ -63,10 +64,52 @@ static void test_file(void)
     assert(ret == 0);
 }
 
+static void test_mapped_and_unmapped(void)
+{
+    int pagesize = getpagesize();
+    void *page;
+    int ret;
+
+    page = mmap(NULL, pagesize, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+    assert(page != MAP_FAILED);
+
+    ret = madvise(page, pagesize, MADV_NORMAL);
+    assert(ret == 0);
+
+    ret = munmap(page, pagesize);
+    assert(ret == 0);
+
+    ret = madvise(page, pagesize, MADV_NORMAL);
+    assert(ret == -1);
+    assert(errno == ENOMEM);
+}
+
+static void test_partially_unmapped_enomem(void)
+{
+    int pagesize = getpagesize();
+    void *page;
+    int ret;
+
+    page = mmap(NULL, 3 * pagesize, PROT_READ,
+                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+    assert(page != MAP_FAILED);
+    ret = munmap((char *)page + pagesize, pagesize);
+    assert(ret == 0);
+
+    ret = madvise(page, 3 * pagesize, MADV_NORMAL);
+    assert(ret == -1);
+    assert(errno == ENOMEM);
+
+    ret = munmap(page, 3 * pagesize);
+    assert(ret == 0);
+}
+
 int main(void)
 {
     test_anonymous();
     test_file();
+    test_mapped_and_unmapped();
+    test_partially_unmapped_enomem();
 
     return EXIT_SUCCESS;
 }
-- 
2.55.0



      parent reply	other threads:[~2026-08-31 23:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 21:20 [PATCH 0/2] linux-user: return ENOMEM from madvise on unmapped ranges Roi Klevansky
2026-08-31 21:20 ` [PATCH 1/2] " Roi Klevansky
2026-08-31 21:20 ` Roi Klevansky [this message]

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=20260831212040.1833650-3-roiklevansky@gmail.com \
    --to=roiklevansky@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=deller@gmx.de \
    --cc=laurent@vivier.eu \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    /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.