From b42da810c8298576ece578b336a1ab2bff11e885 Mon Sep 17 00:00:00 2001 From: ngie Date: Wed, 4 Jan 2017 08:35:46 +0000 Subject: [PATCH] swapcontext1: test for getcontext(3) and swapcontext(3) success properly The beforementioned libcalls both succeed if the return codes aren't -1 MFC after: 3 days Reported by: Coverity CID: 976790, 976791 --- contrib/netbsd-tests/lib/libpthread/t_swapcontext.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c b/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c index dc1897c68d02..8536846eb1ba 100644 --- a/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c +++ b/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c @@ -30,6 +30,8 @@ __RCSID("$NetBSD"); #ifdef __FreeBSD__ #include +#include +#include #endif #include #include @@ -80,7 +82,12 @@ threadfunc(void *arg) oself = (void *)pthread_self(); printf("before swapcontext self = %p\n", oself); +#ifdef __FreeBSD__ + ATF_REQUIRE_MSG(swapcontext(&octx, &nctx) != -1, "swapcontext failed: %s", + strerror(errno)); +#else PTHREAD_REQUIRE(swapcontext(&octx, &nctx)); +#endif /* NOTREACHED */ return NULL; @@ -111,7 +118,12 @@ ATF_TC_BODY(swapcontext1, tc) printf("Testing if swapcontext() alters pthread_self()\n"); +#ifdef __FreeBSD__ + ATF_REQUIRE_MSG(getcontext(&nctx) != -1, "getcontext failed: %s", + strerror(errno)); +#else PTHREAD_REQUIRE(getcontext(&nctx)); +#endif PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL)); PTHREAD_REQUIRE(pthread_join(thread, NULL)); }