From 0e6cb1740af22e3c2eeed37a59d0ecde48965778 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 22 Apr 2016 14:14:39 +0000 Subject: [PATCH] tests: extend test coverage of mincore syscall * tests/mincore.c (print_mincore): New function. (test_mincore): Use it. Check mincore with invalid vec address. Check mincore with length argument not a multiple of the page size. (main): Check with DEFAULT_STRLEN pages. --- tests/mincore.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/mincore.c b/tests/mincore.c index d9cbbd4c..ff2922a2 100644 --- a/tests/mincore.c +++ b/tests/mincore.c @@ -32,15 +32,14 @@ #define DEFAULT_STRLEN 32 static void -test_mincore(const unsigned int pages) +print_mincore(const unsigned int pages, void *const addr, + const size_t size, unsigned char *const vec) { - const size_t size = pages * get_page_size(); - char *addr = tail_alloc(size); - unsigned char *vec = tail_alloc(pages); unsigned int i; if (mincore(addr, size, vec)) perror_msg_and_skip("mincore"); + printf("mincore(%p, %zu, [", addr, size); for (i = 0; i < pages; ++i) { if (i >= DEFAULT_STRLEN) { @@ -52,10 +51,28 @@ test_mincore(const unsigned int pages) puts("]) = 0"); } +static void +test_mincore(const unsigned int pages) +{ + const size_t page_size = get_page_size(); + const size_t size = pages * page_size; + void *const addr = tail_alloc(size); + unsigned char *const vec = tail_alloc(pages); + + mincore(addr, size, NULL); + printf("mincore(%p, %zu, NULL) = -1 %s (%m)\n", + addr, size, errno2name()); + + print_mincore(pages, addr, size, vec); + if (size) + print_mincore(pages, addr, size - page_size + 1, vec); +} + int main(void) { test_mincore(1); test_mincore(2); + test_mincore(DEFAULT_STRLEN); test_mincore(DEFAULT_STRLEN + 1); puts("+++ exited with 0 +++"); -- 2.40.0