Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Make sure to use the values calculated in...



details:   https://anonhg.NetBSD.org/src/rev/d1165ca58ad4
branches:  trunk
changeset: 806549:d1165ca58ad4
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Feb 28 13:57:08 2015 +0000

description:
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:

 tests/lib/libc/sys/t_mmap.c |  12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diffs (42 lines):

diff -r 91b6956e745f -r d1165ca58ad4 tests/lib/libc/sys/t_mmap.c
--- a/tests/lib/libc/sys/t_mmap.c       Sat Feb 28 13:08:00 2015 +0000
+++ b/tests/lib/libc/sys/t_mmap.c       Sat Feb 28 13:57:08 2015 +0000
@@ -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 @@
 
        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);



Home | Main Index | Thread Index | Old Index