aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2022-09-28 17:03:54 -0400
committerStefan Hajnoczi <stefanha@redhat.com>2022-09-28 17:03:54 -0400
commit36cd0aeac3337af06875e08683380389df48ccd0 (patch)
treef3f0e2a5ad875b6af4492b4224336f336b270a09 /tests
parentdc6c2342a0c1103bf4b2750dd756609d6ab7ecac (diff)
parent4a877b82f7f99f7366fbb4820687d88dcf97478f (diff)
Merge tag 'linux-user-for-7.2-pull-request' of https://gitlab.com/laurent_vivier/qemu into staging
linux-user pull request 20220928-v2 use 'max' instead of 'qemu32' / 'qemu64' add pidfd_open(), pidfd_send_signal() and pidfd_getfd() Improve madvise(MADV_DONTNEED) futex syscal rework strace improvement HP/PA fixes and improvement Misc fixes # -----BEGIN PGP SIGNATURE----- # # iQJGBAABCAAwFiEEzS913cjjpNwuT1Fz8ww4vT8vvjwFAmM0riISHGxhdXJlbnRA # dml2aWVyLmV1AAoJEPMMOL0/L748gH4P/2wesXJKPMY2zQzP3Rld4iyefoPGG/Yp # mdq59BbjO2jQMR8GBss/nl9l84cIzzkYRQIogaKsjljtZYm/OO5xRefqrzJY6apD # eidxv20dAVjuaXHAIdGhbFlxot1ctExbZs9atB4uj5DWxfYGD6e/stoBy5/pSmr4 # M5EbGHhyrRI7tRbHGtVQVvG6AT6XGE0pT9tzT5JLaApF8UPMkgJwmez16PNWvcMm # v8GEvKm/vEVS8CCpzLV4kfwVeo3f54VAOrEBDi29ph2Yo50IA21k8BvoRZaSp+Kn # G6TMnnly/DkMspAs5EOVfat+kv3TziNNdDH7EnVU1vV1yTDdZgW/1204Uy/JY0Pw # WotwAFuO9FYeHKmjY0CfnIIZZHYZpDYUOZ8M6dESD/O0EjoB8LMf5p9cbYlze4DE # csJZCsVcz19HDv6QZXi5mvvDcJ83B2IDb8/PUAzSc0n62lXL9qjYD0wdb0QsLdAT # I25qLDge1HCmQfCIKcaoHYvE0pDmvkF6ftuQUXLtIwtaV0Z/N5wDf2PEHikjOYHM # gD2izz23/2wQx6KP/9ZNnCJ5QEBkEgm5wpHncsvjzSzi1uIdNlHyzJJwGTAcc5qZ # hOeoJ7dT0D6g0BGnvOdg2W/bDx18KW65mNDxE4d+W0uzn0YmQtArk2YsnhKQNO46 # 12/0ltPFnSV/ # =DIzQ # -----END PGP SIGNATURE----- # gpg: Signature made Wed 28 Sep 2022 16:27:14 EDT # gpg: using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C # gpg: issuer "laurent@vivier.eu" # gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [full] # gpg: aka "Laurent Vivier <laurent@vivier.eu>" [full] # gpg: aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" [full] # Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C * tag 'linux-user-for-7.2-pull-request' of https://gitlab.com/laurent_vivier/qemu: (37 commits) linux-user: Add parameters of getrandom() syscall for strace linux-user: Lock log around strace linux-user: Update print_futex_op linux-user: Implement PI futexes linux-user: Convert signal number for FUTEX_FD linux-user: Implement FUTEX_WAKE_BITSET linux-user: Sink call to do_safe_futex linux-user: Combine do_futex and do_futex_time64 linux-user: Set ELF_BASE_PLATFORM for MIPS linux-user: Introduce stubs for ELF AT_BASE_PLATFORM linux-user/s390x: Save/restore fpc when handling a signal linux-user: Don't assume 0 is not a valid host timer_t value linux-user: fix bug about missing signum convert of sigqueue linux-user/hppa: Fix setup_sigcontext() linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect() linux-user/hppa: Increase guest stack size to 80MB for hppa target linux-user/hppa: Drop stack guard page on hppa target linux-user/hppa: Add signal trampoline for hppa target linux-user: Add proper strace format strings for getdents()/getdents64() linux-user: Fix TARGET_PROT_SEM for XTENSA ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/tcg/multiarch/linux/linux-madvise.c70
1 files changed, 70 insertions, 0 deletions
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;
+}