Module Name: src Committed By: rillig Date: Sat Jan 18 22:31:23 UTC 2025
Modified Files: src/distrib/sets/lists/tests: mi src/etc/mtree: NetBSD.dist.tests src/tests/usr.bin: Makefile Added Files: src/tests/usr.bin/gcov: Makefile t_gcov.sh Log Message: tests/gcov: demonstrate wrong coverage report after vfork/exec Discovered in usr.bin/make, function Cmd_Exec. The coverage test I ran on 2024-07-13 was still good. I don't remember the exact version of NetBSD-current I was running back then. With NetBSD-current from 2025-01-17, gcov does not report full coverage data after a vfork/exec call. Running the test program inside ktrace shows that after a vfork call, the child process writes its coverage data back, probably right before the exec call, but the parent process doesn't. Running a child process through system(3) is not affected; there, posix_spawn is used instead of vfork/exec. To generate a diff of this commit: cvs rdiff -u -r1.1356 -r1.1357 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.209 -r1.210 src/etc/mtree/NetBSD.dist.tests cvs rdiff -u -r1.42 -r1.43 src/tests/usr.bin/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/gcov/Makefile \ src/tests/usr.bin/gcov/t_gcov.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1356 src/distrib/sets/lists/tests/mi:1.1357 --- src/distrib/sets/lists/tests/mi:1.1356 Fri Jan 10 23:00:37 2025 +++ src/distrib/sets/lists/tests/mi Sat Jan 18 22:31:22 2025 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1356 2025/01/10 23:00:37 rillig Exp $ +# $NetBSD: mi,v 1.1357 2025/01/18 22:31:22 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -4942,6 +4942,10 @@ ./usr/tests/usr.bin/ftp/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua ./usr/tests/usr.bin/ftp/custom_headers.sh tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/ftp/t_custom_headers tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/gcov tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/gcov/Atffile tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/gcov/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua +./usr/tests/usr.bin/gcov/t_gcov tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/gdb tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/gdb/Atffile tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/gdb/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua Index: src/etc/mtree/NetBSD.dist.tests diff -u src/etc/mtree/NetBSD.dist.tests:1.209 src/etc/mtree/NetBSD.dist.tests:1.210 --- src/etc/mtree/NetBSD.dist.tests:1.209 Fri Oct 18 23:23:40 2024 +++ src/etc/mtree/NetBSD.dist.tests Sat Jan 18 22:31:22 2025 @@ -1,4 +1,4 @@ -# $NetBSD: NetBSD.dist.tests,v 1.209 2024/10/18 23:23:40 christos Exp $ +# $NetBSD: NetBSD.dist.tests,v 1.210 2025/01/18 22:31:22 rillig Exp $ ./usr/libdata/debug/usr/tests ./usr/libdata/debug/usr/tests/atf @@ -453,6 +453,7 @@ ./usr/tests/usr.bin/find ./usr/tests/usr.bin/fstat ./usr/tests/usr.bin/ftp +./usr/tests/usr.bin/gcov ./usr/tests/usr.bin/gdb ./usr/tests/usr.bin/grep ./usr/tests/usr.bin/gzip Index: src/tests/usr.bin/Makefile diff -u src/tests/usr.bin/Makefile:1.42 src/tests/usr.bin/Makefile:1.43 --- src/tests/usr.bin/Makefile:1.42 Sat Oct 12 22:19:37 2024 +++ src/tests/usr.bin/Makefile Sat Jan 18 22:31:22 2025 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.42 2024/10/12 22:19:37 riastradh Exp $ +# $NetBSD: Makefile,v 1.43 2025/01/18 22:31:22 rillig Exp $ # .include <bsd.own.mk> @@ -6,7 +6,7 @@ TESTSDIR= ${TESTSBASE}/usr.bin TESTS_SUBDIRS= awk basename bzip2 cc cmp compress config cpio col cut \ - diff dirname error find fstat ftp gdb grep gzip id indent \ + diff dirname error find fstat ftp gcov gdb grep gzip id indent \ infocmp jot ld locale m4 make mixerctl mkdep mtree nbperf \ netpgpverify patch pkill pr printf pwhash realpath rump_server \ shmif_dumpbus shmif_pcapin sdiff sed sort stat tar tmux tr \ Added files: Index: src/tests/usr.bin/gcov/Makefile diff -u /dev/null src/tests/usr.bin/gcov/Makefile:1.1 --- /dev/null Sat Jan 18 22:31:23 2025 +++ src/tests/usr.bin/gcov/Makefile Sat Jan 18 22:31:22 2025 @@ -0,0 +1,7 @@ +# $NetBSD: Makefile,v 1.1 2025/01/18 22:31:22 rillig Exp $ + +TESTSDIR= ${TESTSBASE}/usr.bin/gcov + +TESTS_SH= t_gcov + +.include <bsd.test.mk> Index: src/tests/usr.bin/gcov/t_gcov.sh diff -u /dev/null src/tests/usr.bin/gcov/t_gcov.sh:1.1 --- /dev/null Sat Jan 18 22:31:23 2025 +++ src/tests/usr.bin/gcov/t_gcov.sh Sat Jan 18 22:31:22 2025 @@ -0,0 +1,104 @@ +# $NetBSD: t_gcov.sh,v 1.1 2025/01/18 22:31:22 rillig Exp $ +# +# Copyright (c) 2025 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +after_exec_head() +{ +} +after_exec_body() +{ + atf_require_prog cat + atf_require_prog gcc + atf_require_prog gcov + atf_require_prog grep + + cat <<EOF >prog.c +#include <unistd.h> + +int +main(void) +{ + pid_t pid = vfork(); + switch (pid) { + case 0: + execl("/bin/sh", "sh", "-c", ":", (const char *)0); + /* FALLTHROUGH */ + case -1: + write(2, "error\n", 6); + _exit(1); + } + + write(1, "reached\n", 8); + return 0; +} +EOF + + cat <<EOF >prog.c.gcov.expected + -: 0:Source:prog.c + -: 0:Graph:prog.gcno + -: 0:Data:prog.gcda + -: 0:Runs:1 + -: 1:#include <unistd.h> + -: 2: + -: 3:int + 1: 4:main(void) + -: 5:{ + 1: 6: pid_t pid = vfork(); + 1: 7: switch (pid) { + 1: 8: case 0: + 1: 9: execl("/bin/sh", "sh", "-c", ":", (const char *)0); + -: 10: /* FALLTHROUGH */ + #####: 11: case -1: + #####: 12: write(2, "error\n", 6); + #####: 13: _exit(1); + -: 14: } + -: 15: + #####: 16: write(1, "reached\n", 8); + #####: 17: return 0; + -: 18:} +EOF + + atf_check \ + gcc --coverage -c prog.c + atf_check \ + gcc --coverage -o prog prog.o + atf_check -o inline:'reached\n' \ + ./prog + atf_check -o ignore \ + gcov prog.c + + atf_check -o file:prog.c.gcov.expected \ + cat prog.c.gcov + + # FIXME: The code was reached once but is reported as unreached. + atf_check -o ignore \ + grep "#####.*reached" prog.c.gcov +} + +atf_init_test_cases() +{ + atf_add_test_case after_exec +}