Skip to content

Commit

Permalink
Merge pull request #2 from dwRchyngqxs/Coverage
Browse files Browse the repository at this point in the history
Added coverage
  • Loading branch information
johnwickerson authored Jan 24, 2024
2 parents 616a63f + acb62b3 commit 0002f30
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y --fix-missing \
dos2unix \
gdb \
gcc \
lcov \
make \
flex \
build-essential \
Expand Down
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@ bin/c_compiler : src/cli.cpp src/compiler.cpp
@mkdir -p bin
g++ $(CPPFLAGS) -o bin/c_compiler $^

with_coverage : CPPFLAGS += --coverage
with_coverage : bin/c_compiler

coverage : coverage/index.html

coverage/index.html :
@mkdir -p coverage
# somehow lexer and parser coverage info are available but not accurate. To exclude them use:
# lcov -c --no-external --exclude "`pwd`/src/lexer.*" --exclude "`pwd`/src/parser.*" -d . -o coverage/cov.info
lcov -c --no-external -d . -o coverage/cov.info
genhtml coverage/cov.info -o coverage
@find . -name "*.gcda" -delete

clean :
rm -rf bin/*
@rm -rf coverage
@find . -name "*.o" -delete
@rm -rf bin/*
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ All submissions will be tested functionally -- there is no expectation for your
Changelog
=========

* New for 2023/2024:

* Provided guidance to generate coverage information.

* New for 2022/2023:

* Target architecture is now RISC-V rather than MIPS, in order to align with the modernised Instruction Architectures half of the module.
Expand Down
11 changes: 11 additions & 0 deletions c_compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ By default, the first `_example/example.c` test should be passing.

This basic framework ignores the source input file and always produces the same assembly, which loads the value `5` into `a0`.

Coverage information
--------------------

If you want to know which part of your code is executed when running your compiler on a file you can build your compiler with `make with_coverage`, run your compiler on the file, then run `make coverage`.

This will generate a webpage `coverage/index.html` with a listing of all the source files and for each source file a listing of the number of times each line has been executed.

![Index.html screenshot](coverage_example.png)

It can also be used automatically on all test files by running `./test.sh coverage`.

Program build and execution
---------------------------

Expand Down
Binary file added coverage_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
set -uo pipefail
shopt -s globstar

make bin/c_compiler
make clean

with_coverage=1
if [ $# -eq 1 ]; then
test $1 = "coverage"
with_coverage=$?
fi
if [ $with_coverage -eq 0 ]; then
rm -rf coverage
make with_coverage
else
make bin/c_compiler
fi

mkdir -p bin
mkdir -p bin/output
Expand Down Expand Up @@ -67,5 +79,9 @@ for DRIVER in compiler_tests/**/*_driver.c; do
fi
done

if [ $with_coverage -eq 0 ]; then
make coverage
fi

printf "\nPassing %d/%d tests\n" "${PASSING}" "${TOTAL}"
printf '%s\n' '</testsuite>' >> "${J_UNIT_OUTPUT_FILE}"

0 comments on commit 0002f30

Please sign in to comment.