diff options
-rw-r--r-- | regress/sys/dev/kcov/kcov.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/regress/sys/dev/kcov/kcov.c b/regress/sys/dev/kcov/kcov.c index 5e3010a79b4..28d7ee3ed3e 100644 --- a/regress/sys/dev/kcov/kcov.c +++ b/regress/sys/dev/kcov/kcov.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kcov.c,v 1.5 2018/12/27 19:38:01 anton Exp $ */ +/* $OpenBSD: kcov.c,v 1.6 2019/01/03 08:51:31 anton Exp $ */ /* * Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org> @@ -38,8 +38,9 @@ static int test_fork(int, int); static int test_open(int, int); static int test_state(int, int); +static int check_coverage(const unsigned long *, int, unsigned long, int); static void do_syscall(void); -static void dump(const unsigned long *); +static void dump(const unsigned long *, int mode); static void kcov_disable(int); static void kcov_enable(int, int); static int kcov_open(void); @@ -128,14 +129,9 @@ main(int argc, char *argv[]) *cover = 0; error = tests[i].fn(fd, mode); if (verbose) - dump(cover); - if (tests[i].coverage && *cover == 0) { - warnx("coverage empty (count=%lu, fd=%d)\n", *cover, fd); + dump(cover, mode); + if (check_coverage(cover, mode, bufsize, tests[i].coverage)) error = 1; - } else if (!tests[i].coverage && *cover != 0) { - warnx("coverage is not empty (count=%lu, fd=%d)\n", *cover, fd); - error = 1; - } if (munmap(cover, bufsize * sizeof(unsigned long)) == -1) err(1, "munmap"); @@ -157,13 +153,34 @@ do_syscall(void) getpid(); } +static int +check_coverage(const unsigned long *cover, int mode, unsigned long maxsize, + int nonzero) +{ + int error = 0; + + if (nonzero && cover[0] == 0) { + warnx("coverage empty (count=0)\n"); + return 1; + } else if (!nonzero && cover[0] != 0) { + warnx("coverage not empty (count=%lu)\n", *cover); + return 1; + } else if (cover[0] >= maxsize) { + warnx("coverage overflow (count=%lu, max=%lu)\n", *cover, maxsize); + return 1; + } + + return error; +} + static void -dump(const unsigned long *cover) +dump(const unsigned long *cover, int mode) { unsigned long i; + int stride = 1; for (i = 0; i < cover[0]; i++) - printf("%lu/%lu: %p\n", i + 1, cover[0], (void *)cover[i + 1]); + printf("%p\n", (void *)cover[i * stride + 1]); } static int @@ -330,7 +347,7 @@ test_open(int oldfd, int mode) { unsigned long *cover; int fd; - int ret = 0; + int error = 0; fd = kcov_open(); if (ioctl(fd, KIOSETBUFSIZE, &bufsize) == -1) @@ -344,14 +361,13 @@ test_open(int oldfd, int mode) do_syscall(); kcov_disable(fd); - if (*cover == 0) { - warnx("coverage empty (count=0, fd=%d)\n", fd); - ret = 1; - } + error = check_coverage(cover, mode, bufsize, 1); + if (munmap(cover, bufsize * sizeof(unsigned long))) err(1, "munmap"); close(fd); - return ret; + + return error; } /* |