The crashing_child_sparse() helper touches the first page of the
mapping. That forces everything behind it to be a trailing hole. This is
easy to handle. Make the test more difficult meaningful by also touchin
the last page. This causes the hole to sit between two populated pages.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 tools/testing/selftests/coredump/coredump_test_helpers.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/coredump/coredump_test_helpers.c 
b/tools/testing/selftests/coredump/coredump_test_helpers.c
index 45d76fa0f469..89f3954c5607 100644
--- a/tools/testing/selftests/coredump/coredump_test_helpers.c
+++ b/tools/testing/selftests/coredump/coredump_test_helpers.c
@@ -58,14 +58,16 @@ void crashing_child_sparse(size_t size)
        char *p;
 
        /*
-        * Touch the first page only. The whole mapping is dumped because
-        * it has been written to, but all of it save that one page is a
-        * hole.
+        * Touch the first and the last page. This will cause the whole mapping
+        * to be dumped because it has been written to. Everything between
+        * those two pages is a hole though.
         */
        p = mmap(NULL, size, PROT_READ | PROT_WRITE,
                 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
-       if (p != MAP_FAILED)
+       if (p != MAP_FAILED) {
                p[0] = 'x';
+               p[size - 1] = 'x';
+       }
 
        /* crash on purpose */
        *(volatile int *)NULL = 0;

-- 
2.53.0


Reply via email to