Skip to content

Commit 0b46b46

Browse files
authored
Setup GNATcov and improve test coverage (#5)
This adds the script coverage.sh to instrument and run the unit tests to generate a coverage HTML report. New tests are added to increase code coverage to 100% (MC/DC).
1 parent 1a13b90 commit 0b46b46

File tree

9 files changed

+329
-34
lines changed

9 files changed

+329
-34
lines changed

.github/workflows/ci.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,27 @@ jobs:
2525
with:
2626
version: 1.2.0
2727

28-
- name: Build
28+
- name: Build library
2929
run: alr build --validation
3030

31-
- name: Unit tests
31+
- name: Build and run unit tests (instrumented)
32+
run: |
33+
cd tests
34+
alr gnatcov instrument --level=stmt+mcdc --dump-trigger=atexit --projects cobs.gpr
35+
alr build -- --src-subdirs=gnatcov-instr --implicit-with=gnatcov_rts_full
36+
alr exec -- bin/unit_tests
37+
alr gnatcov coverage --annotate=xcov --output-dir gnatcov_out --level=stmt+mcdc --projects cobs.gpr *.srctrace
38+
39+
- name: Build and run unit tests (non-instrumented)
3240
run: |
3341
cd tests
3442
alr build --validation
35-
alr run
43+
alr exec -- bin/unit_tests
44+
45+
- uses: alire-project/gnatcov-to-codecovio-action@main
46+
with:
47+
fail_ci_if_error: false # Don't fail the workflow if codecov.io failed
48+
verbose: true
3649

3750
- name: Proof
3851
run: |

README.md

+45-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Consistent Overhead Byte Stuffing (COBS)
22
This repository provides an implementation of a COBS[1] encoder and
3-
decoder using the SPARK programming language.
3+
decoder using the SPARK programming language.
44

55
## License
66
All files are licensed under the MIT license.
@@ -55,11 +55,54 @@ is
5555
5656
type My_COBS is new Generic_COBS (Byte => Unsigned_8,
5757
Index => Positive,
58-
Byte_Count => Positive,
58+
Byte_Count => Natural,
5959
Byte_Array => Byte_Array);
6060
end Example;
6161
```
6262

63+
## Verification
64+
65+
This project takes a "hybrid verification" approach combining formal
66+
verification and testing.
67+
68+
GNATprove is used to prove absence of run-time errors. At the time of writing
69+
there are 139 checks that are automatically proved.
70+
71+
The unit tests are used to check that the encoder and decoder produce the
72+
correct results for a variety of inputs, with 100% MC/DC source coverage.
73+
74+
### Reproducing the results
75+
76+
#### Proof
77+
78+
To run the proofs:
79+
80+
```sh
81+
cd prove
82+
alr exec -- gnatprove -P ../cobs
83+
```
84+
85+
If you want to see only failed checks, then pass `--report=fail` to `gnatprove`.
86+
87+
#### Tests
88+
89+
To run the unit tests:
90+
```sh
91+
alr build --verification
92+
cd tests
93+
alr build --verification
94+
alr run
95+
```
96+
97+
To run the tests and generate a code coverage report:
98+
```sh
99+
alr build --verification
100+
cd tests
101+
./coverage.sh
102+
```
103+
104+
The report will be generated in `tests/gnatcov_out/index.html`.
105+
63106
## References
64107

65108
[1] Consistent Overheady Byte Stuffing

src/generic_cobs.adb

-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ is
6060

6161
Code := B;
6262
Run_Length := Byte_Count (Byte'Pos (B));
63-
64-
exit when B = Frame_Delimiter;
6563
end if;
6664

6765
Run_Length := Run_Length - 1;

tests/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/bin/
33
/alire/
44
/config/
5+
*.srctrace
6+
/gnatcov_out/

tests/alire.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ executables = ["unit_tests"]
1010

1111
[[depends-on]]
1212
aunit = "^22.0.0"
13+
gnatcov = "^22.0.1"
1314
cobs = "*"
1415

1516
[[pins]]
16-
cobs = { path = "../" }
17+
cobs = { path = "../" }

tests/coverage.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
alr gnatcov instrument --level=stmt+mcdc --dump-trigger=atexit --projects cobs.gpr
4+
5+
alr build -- --src-subdirs=gnatcov-instr --implicit-with=gnatcov_rts_full
6+
7+
alr exec -- bin/unit_tests
8+
9+
alr gnatcov coverage \
10+
--annotate=html+ \
11+
--output-dir gnatcov_out \
12+
--level=stmt+mcdc \
13+
--projects cobs.gpr \
14+
*.srctrace

tests/run_tests.sh

-4
This file was deleted.

0 commit comments

Comments
 (0)