Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage support #65

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ riscof_work
*.signature

*.cf

sail-riscv/

#coverage simulation
sim/*.gcno
sim/*.gcda
sim/*.o
sim/neorv32_riscof_tb
sim/coverage
html
neorv32_riscof.info
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ takes care of installing all the required packages.
* [RISC-V GCC toolchain](https://github.com/stnolting/riscv-gcc-prebuilt) - for compiling native `rv32` code
* [Sail RISC-V](https://github.com/riscv/sail-riscv) - the reference model (pre-built binary in the[`bin`](https://github.com/stnolting/neorv32-riscof/tree/main/bin) folder)
* [RISCOF](https://github.com/riscv-software-src/riscof) - the architecture test framework
* [GHDL](https://github.com/ghdl/ghdl) - the _awesome_ VHDL simulator for simulating the DUT
* [GHDL with coverage support](https://github.com/ghdl/ghdl) - the _awesome_ VHDL simulator for simulating the DUT


The framework (running all tests) is invoked via a single shell script
[`run.sh`](https://github.com/stnolting/neorv32-riscof/blob/main/run.sh) that returns 0 if all tests were executed
Expand Down Expand Up @@ -104,3 +105,39 @@ specific Python script in the DUT's plugin folder
This Python script makes extensive use of shell commands to move and execute files and scripts.

[[back to top](#NEORV32-Core-Verification-using-RISCOF)]


# coverage
## GHDL coverage support
GHDL can support coverage with the help of GCC backend with gcov.
To enable this feature you have to recompile GHDL with the official [procedure](https://ghdl.github.io/ghdl/development/building/GCC.html#build-gcc) or applie the one below if you are running Ubuntu 22.04.1 LTS (change gcc version to yours if not). The new `ghdl` application will be installed in `/opt/ghdl`. Do not forget to add it to the path with command `export PATH=/opt/ghdl/bin:$PATH` to replace your previous `ghdl version` by this one for the test.

```bash
$ sudo apt-get install gnat build-essential libmpc-dev flex bison libz-dev lcov gcc-11-source texinfo gcovr
$ git clone https://github.com/ghdl/ghdl.git
$ cd /usr/src/gcc-11
$ sudo tar xvf gcc-11.3.0.tar.xz
$ cd gcc-11.3.0
$ ./contrib/download_prerequisites
$ cd ghdl
$ mdir build
$ cd build
$ ../configure --with-gcc=/usr/src/gcc-11/gcc-11.3.0 --prefix=/opt/ghdl
$ make copy-sources
$ mkdir gcc-objs; cd gcc-objs
$ /usr/src/gcc-11/gcc-11.3.0/configure --prefix=/opt/ghdl --enable-languages=c,vhdl --disable-bootstrap --disable-lto --disable-multilib --disable-libssp --disable-libgomp --disable-libquadmath --enable-default-pie
$ make -j4 && make install MAKEINFO=true
$ cd ..
$ make ghdllib
$ make install
```

## collecting coverage report for riscof
The following files have been changed:
- `ghdl_run.sh` and `ghdl_setup.sh` to include coverage support during ghdl call.
- `riscof_neorv32.py` to backcup coverage result in a dedicated `coverage` folder.

Execute `run.sh`

## acknowledgment
This test was adapted thanks to https://github.com/huettern/ghdl-coverage repository. You can use it to check your ghdl with coverage installation works.
2 changes: 2 additions & 0 deletions coverage.xml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions plugin-neorv32/riscof_neorv32.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def runTests(self, testList):

# we will iterate over each entry in the testList. Each entry node will be referred to by the
# variable testname.
testID=0
for testname in testList:

logger.debug('Running Test: {0} on DUT'.format(testname))
Expand Down Expand Up @@ -196,6 +197,23 @@ def runTests(self, testList):
logger.debug('DUT executing ' + execute)
utils.shellCommand(execute).run()

# save coverage files
## create test result folder
execute = 'mkdir -p {0}'.format(os.path.join('./sim/coverage',str(testID)))
logger.debug('DUT executing ' + execute)
utils.shellCommand(execute).run()

## save coverage result
execute = 'cp -f ./sim/*.gcda {0}'.format(os.path.join('./sim/coverage/',str(testID)))
logger.debug('DUT executing ' + execute)
utils.shellCommand(execute).run()

## save coverage source object
execute = 'cp -f ./sim/*.gcno {0}'.format(os.path.join('./sim/coverage/',str(testID)))
logger.debug('DUT executing ' + execute)
utils.shellCommand(execute).run()
testID=testID+1


# if target runs are not required then we simply exit as this point after running all
# the makefile targets.
Expand Down
13 changes: 12 additions & 1 deletion run.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ riscof run --config=config.ini \
--env=riscv-arch-test/riscv-test-suite/env \
--no-browser

#merge coverage
lcov -c -d ./sim -o neorv32_riscof.info
#compile coverage output
genhtml -o html neorv32_riscof.info


##create sonarqube coverage
gcovr -r . --sonarqube coverage.xml



# check report - run successful?
if grep -rniq riscof_work/report.html -e '>0failed<'
then
Expand All @@ -24,4 +35,4 @@ then
else
echo "Test FAILED!"
exit 1
fi
fi
3 changes: 2 additions & 1 deletion sim/ghdl_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ chmod 777 neorv32.uart0.sim_mode.text.out

GHDL="${GHDL:-ghdl}"

$GHDL -m --std=08 --work=neorv32 neorv32_riscof_tb
#comment this line has it block coverage and doen't seem to add any value for simulation
#$GHDL -m --std=08 --work=neorv32 neorv32_riscof_tb

# timeout as fall-back; simulation should be terminated by the testbench using "finish;"
GHDL_TIMEOUT="--stop-time=2ms"
Expand Down
52 changes: 48 additions & 4 deletions sim/ghdl_setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,51 @@ cd $(dirname "$0")
NEORV32_RTL=${NEORV32_RTL:-../neorv32/rtl}
SRC_FOLDER=${SRC_FOLDER:-.}

ghdl -i --work=neorv32 --std=08 \
"$NEORV32_RTL"/core/*.vhd \
"$NEORV32_RTL"/core/mem/*.vhd \
"$SRC_FOLDER"/neorv32_riscof_tb.vhd
# # build library manually as automatic ghdl -i command doestn't handle coverage parameters
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_package.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_application_image.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_bootloader_image.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_boot_rom.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_bus_keeper.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_busswitch.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cfs.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_alu.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_bus.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_control.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_cp_bitmanip.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_cp_cfu.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_cp_fpu.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_cp_muldiv.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_cp_shifter.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_decompressor.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu_regfile.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_cpu.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_debug_dm.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_debug_dtm.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_dmem.entity.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_fifo.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_gpio.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_gptmr.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_icache.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_imem.entity.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_mtime.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_neoled.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_onewire.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_pwm.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_slink.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_spi.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_sysinfo.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_top.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_trng.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_twi.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_uart.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_wdt.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_wishbone.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_xip.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/neorv32_xirq.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/mem/neorv32_dmem.default.vhd
ghdl -a -Wc,-fprofile-arcs -Wc,-ftest-coverage --work=neorv32 --std=08 "$NEORV32_RTL"/core/mem/neorv32_imem.default.vhd
ghdl -a --work=neorv32 --std=08 "$SRC_FOLDER"/neorv32_riscof_tb.vhd

# #elaborate with coverage support
ghdl -e -Wl,-lgcov --std=08 --work=neorv32 neorv32_riscof_tb