diff options
| author | martin <martin@NetBSD.org> | 2015-02-28 13:57:08 +0000 |
|---|---|---|
| committer | martin <martin@NetBSD.org> | 2015-02-28 13:57:08 +0000 |
| commit | 494fbebba5d8c133dff6de677faf993fbc5cd9b2 (patch) | |
| tree | af6ffebb14519ca5a52e53b7d6c47b8ff60e71f5 /tests/lib/libc/sys | |
| parent | 96899f4c90846120c49f2e85b08b213ce79529e8 (diff) | |
Make sure to use the values calculated in the loop that is supposed to crash
the client process - so the compiler does not optimize it all away.
Also improve diagnostic in case of common bug: SIGSEGV instead of SIGBUS.
Diffstat (limited to 'tests/lib/libc/sys')
| -rw-r--r-- | tests/lib/libc/sys/t_mmap.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/lib/libc/sys/t_mmap.c b/tests/lib/libc/sys/t_mmap.c index 7917f415082..8576403fdea 100644 --- a/tests/lib/libc/sys/t_mmap.c +++ b/tests/lib/libc/sys/t_mmap.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mmap.c,v 1.8 2015/02/27 16:09:19 christos Exp $ */ +/* $NetBSD: t_mmap.c,v 1.9 2015/02/28 13:57:08 martin Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ * SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_mmap.c,v 1.8 2015/02/27 16:09:19 christos Exp $"); +__RCSID("$NetBSD: t_mmap.c,v 1.9 2015/02/28 13:57:08 martin Exp $"); #include <sys/param.h> #include <sys/mman.h> @@ -486,15 +486,23 @@ ATF_TC_BODY(mmap_truncate_signal, tc) if (pid == 0) { ATF_REQUIRE(signal(SIGBUS, map_sighandler) != SIG_ERR); + ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); sta = 0; for (i = 0; i < page; i++) sta += map[i]; + /* child never will get this far, but the compiler will + not know, so better use the values calculated to + prevent the access to be optimized out */ ATF_REQUIRE(i == 0); + ATF_REQUIRE(sta == 0); + return; } (void)wait(&sta); ATF_REQUIRE(WIFEXITED(sta) != 0); + if (WEXITSTATUS(sta) == SIGSEGV) + atf_tc_fail("child process got SIGSEGV instead of SIGBUS"); ATF_REQUIRE(WEXITSTATUS(sta) == SIGBUS); ATF_REQUIRE(munmap(map, page) == 0); ATF_REQUIRE(close(fd) == 0); |
