]> granicus.if.org Git - strace/commitdiff
tests: extend test coverage of mincore syscall
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 22 Apr 2016 14:14:39 +0000 (14:14 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 22 Apr 2016 14:14:39 +0000 (14:14 +0000)
* 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

index d9cbbd4cc480b629cc26276ad9de7011ab157143..ff2922a2400d5590a0da8623d6e278c32a35d4d7 100644 (file)
 #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 +++");