Skip to content

Commit

Permalink
Added coverage.py, and optional coverage info to test.py
Browse files Browse the repository at this point in the history
Now coverage information can be collected if you provide the --coverage
to test.py. Internally this uses GCC's gcov instrumentation along with a
new script, coverage.py, to parse *.gcov files.

The main use for this is finding coverage info during CI runs. There's a
risk that the instrumentation may make it more difficult to debug, so I
decided to not make coverage collection enabled by default.
  • Loading branch information
geky committed Jan 10, 2021
1 parent b2235e9 commit eeeceb9
Show file tree
Hide file tree
Showing 4 changed files with 551 additions and 22 deletions.
31 changes: 28 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push, pull_request]
env:
CFLAGS: -Werror
MAKEFLAGS: -j
COVERAGE: 1

jobs:
# run tests
Expand Down Expand Up @@ -70,9 +71,10 @@ jobs:
-Duser_provided_block_device_erase=NULL \
-Duser_provided_block_device_sync=NULL \
-include stdio.h"
# # normal+reentrant tests
# - name: test-default
# run: make test SCRIPTFLAGS+="-nrk"
# normal+reentrant tests
- name: test-default
continue-on-error: true
run: make test SCRIPTFLAGS+="-nrk"
# # NOR flash: read/prog = 1 block = 4KiB
# - name: test-nor
# run: make test SCRIPTFLAGS+="-nrk
Expand Down Expand Up @@ -102,6 +104,29 @@ jobs:
# run: make test SCRIPTFLAGS+="-nrk
# -DLFS_READ_SIZE=11 -DLFS_BLOCK_SIZE=704"

- name: test-default-what
run: |
echo "version"
gcov --version
echo "tests"
ls tests
echo "hmm"
cat tests/*.gcov
echo "woah"
# collect coverage
- name: collect-coverage
continue-on-error: true
run: |
mkdir -p coverage
mv results/coverage.gcov coverage/${{github.job}}.gcov
- name: upload-coverage
continue-on-error: true
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage

# update results
- uses: actions/checkout@v2
if: github.ref != 'refs/heads/master'
Expand Down
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CC ?= gcc
AR ?= ar
SIZE ?= size
NM ?= nm
GCOV ?= gcov

SRC += $(wildcard *.c bd/*.c)
OBJ := $(SRC:.c=.o)
Expand All @@ -31,6 +32,12 @@ override CFLAGS += -Wextra -Wshadow -Wjump-misses-init -Wundef
ifdef VERBOSE
override SCRIPTFLAGS += -v
endif
ifdef EXEC
override TESTFLAGS += $(patsubst %,--exec=%,$(EXEC))
endif
ifdef COVERAGE
override TESTFLAGS += --coverage
endif


all: $(TARGET)
Expand All @@ -43,11 +50,14 @@ size: $(OBJ)
code:
./scripts/code.py $(SCRIPTFLAGS)

coverage:
./scripts/coverage.py $(SCRIPTFLAGS)

test:
./scripts/test.py $(EXEC:%=--exec=%) $(SCRIPTFLAGS)
./scripts/test.py $(TESTFLAGS) $(SCRIPTFLAGS)
.SECONDEXPANSION:
test%: tests/test$$(firstword $$(subst \#, ,%)).toml
./scripts/test.py $@ $(EXEC:%=--exec=%) $(SCRIPTFLAGS)
./scripts/test.py $@ $(TESTFLAGS) $(SCRIPTFLAGS)

-include $(DEP)

Expand All @@ -63,10 +73,14 @@ lfs: $(OBJ)
%.s: %.c
$(CC) -S $(CFLAGS) $< -o $@

%.gcda.gcov: %.gcda
( cd $(dir $@) ; $(GCOV) -ri $(notdir $<) )

clean:
rm -f $(TARGET)
rm -f $(OBJ)
rm -f $(DEP)
rm -f $(ASM)
rm -f tests/*.toml.*
rm -f sizes/*
rm -f results/*
Loading

0 comments on commit eeeceb9

Please sign in to comment.