[Toybox] generating toybox test coverage data

enh enh at google.com
Tue Jun 16 15:41:23 PDT 2020


TL;DR: the current state of test coverage looks like:

function:  59.85% (468/782)
line:  56.17% (12111/21560)
region:  53.61% (11280/21039)

but in case anyone's interested in actually reproducing my results:

cd /tmp
git clone https://github.com/landley/toybox.git toybox-coverage
cd toybox-coverage
export CC=clang
export CFLAGS="-fprofile-instr-generate -fcoverage-mapping"
export LDFLAGS="-fprofile-instr-generate -fcoverage-mapping"

apply this patch because atexit() doesn't work in toybox:

diff --git a/lib/xwrap.c b/lib/xwrap.c
index c09923ba..3ee3ca89 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -39,6 +39,7 @@ void _xexit(void)
 {
   if (toys.rebound) siglongjmp(*toys.rebound, 1);

+  __llvm_profile_write_file();
   _exit(toys.exitval);
 }



make defconfig
make
export LLVM_PROFILE_FILE="/tmp/coverage/%p"
TEST_ALL=1 make tests
llvm-profdata-9 merge -sparse /tmp/coverage/* -o toybox.profdata
llvm-cov-9 show ./toybox -instr-profile=toybox.profdata
-show-instantiations=false -format html -output-dir=html-coverage
google-chrome ./html-coverage/index.html



More information about the Toybox mailing list