summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authoranton <anton@cvs.openbsd.org>2018-12-25 22:57:59 +0000
committeranton <anton@cvs.openbsd.org>2018-12-25 22:57:59 +0000
commit022f3181c38d24686768379807a6d93b25055573 (patch)
treeb89fc5c76d0442e312f00c12cd387361b6aee2f0 /regress
parentbc68b927c0665bd027dc00cc49d916162f3c339f (diff)
test dying kcov descriptor logic
Diffstat (limited to 'regress')
-rw-r--r--regress/sys/dev/kcov/Makefile6
-rw-r--r--regress/sys/dev/kcov/kcov.c41
2 files changed, 45 insertions, 2 deletions
diff --git a/regress/sys/dev/kcov/Makefile b/regress/sys/dev/kcov/Makefile
index dabc14a03d7..61b8e781d13 100644
--- a/regress/sys/dev/kcov/Makefile
+++ b/regress/sys/dev/kcov/Makefile
@@ -1,14 +1,18 @@
-# $OpenBSD: Makefile,v 1.3 2018/12/17 22:11:37 anton Exp $
+# $OpenBSD: Makefile,v 1.4 2018/12/25 22:57:58 anton Exp $
PROG= kcov
WARNINGS= yes
+LDADD+= -lpthread
+DPADD+= ${LIBPTHREAD}
+
TESTS+= coverage
TESTS+= fork
TESTS+= exec
TESTS+= mode
TESTS+= open
TESTS+= close
+TESTS+= dying
REGRESS_SETUP_ONCE= setup
setup: ${PROG}
diff --git a/regress/sys/dev/kcov/kcov.c b/regress/sys/dev/kcov/kcov.c
index dd8a2c360a6..b04fe64f27f 100644
--- a/regress/sys/dev/kcov/kcov.c
+++ b/regress/sys/dev/kcov/kcov.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kcov.c,v 1.2 2018/12/16 15:56:03 anton Exp $ */
+/* $OpenBSD: kcov.c,v 1.3 2018/12/25 22:57:58 anton Exp $ */
/*
* Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org>
@@ -24,6 +24,7 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -31,6 +32,7 @@
static int test_close(int);
static int test_coverage(int);
+static int test_dying(int);
static int test_exec(int);
static int test_fork(int);
static int test_mode(int);
@@ -60,6 +62,7 @@ main(int argc, char *argv[])
{ "mode", test_mode, 1 },
{ "open", test_open, 0 },
{ "close", test_close, 0 },
+ { "dying", test_dying, 1 },
{ NULL, NULL, 0 },
};
unsigned long *cover;
@@ -206,6 +209,42 @@ test_coverage(int fd)
return 0;
}
+static void *
+closer(void *arg)
+{
+ int fd = *((int *)arg);
+
+ close(fd);
+ return NULL;
+}
+
+/*
+ * Close kcov descriptor in another thread during tracing.
+ */
+static int
+test_dying(int fd)
+{
+ pthread_t th;
+ int error;
+
+ kcov_enable(fd);
+
+ if ((error = pthread_create(&th, NULL, closer, &fd)))
+ errc(1, error, "pthread_create");
+ if ((error = pthread_join(th, NULL)))
+ errc(1, error, "pthread_join");
+
+ if (close(fd) == -1) {
+ if (errno != EBADF)
+ err(1, "close");
+ } else {
+ warnx("expected kcov descriptor to be closed");
+ return 1;
+ }
+
+ return 0;
+}
+
/*
* Coverage of thread after exec.
*/