Skip to content

Commit

Permalink
Setup GNATcov and improve test coverage (#5)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
damaki authored Jun 11, 2022
1 parent 1a13b90 commit 0b46b46
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 34 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ jobs:
with:
version: 1.2.0

- name: Build
- name: Build library
run: alr build --validation

- name: Unit tests
- name: Build and run unit tests (instrumented)
run: |
cd tests
alr gnatcov instrument --level=stmt+mcdc --dump-trigger=atexit --projects cobs.gpr
alr build -- --src-subdirs=gnatcov-instr --implicit-with=gnatcov_rts_full
alr exec -- bin/unit_tests
alr gnatcov coverage --annotate=xcov --output-dir gnatcov_out --level=stmt+mcdc --projects cobs.gpr *.srctrace
- name: Build and run unit tests (non-instrumented)
run: |
cd tests
alr build --validation
alr run
alr exec -- bin/unit_tests
- uses: alire-project/gnatcov-to-codecovio-action@main
with:
fail_ci_if_error: false # Don't fail the workflow if codecov.io failed
verbose: true

- name: Proof
run: |
Expand Down
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Consistent Overhead Byte Stuffing (COBS)
This repository provides an implementation of a COBS[1] encoder and
decoder using the SPARK programming language.
decoder using the SPARK programming language.

## License
All files are licensed under the MIT license.
Expand Down Expand Up @@ -55,11 +55,54 @@ is
type My_COBS is new Generic_COBS (Byte => Unsigned_8,
Index => Positive,
Byte_Count => Positive,
Byte_Count => Natural,
Byte_Array => Byte_Array);
end Example;
```

## Verification

This project takes a "hybrid verification" approach combining formal
verification and testing.

GNATprove is used to prove absence of run-time errors. At the time of writing
there are 139 checks that are automatically proved.

The unit tests are used to check that the encoder and decoder produce the
correct results for a variety of inputs, with 100% MC/DC source coverage.

### Reproducing the results

#### Proof

To run the proofs:

```sh
cd prove
alr exec -- gnatprove -P ../cobs
```

If you want to see only failed checks, then pass `--report=fail` to `gnatprove`.

#### Tests

To run the unit tests:
```sh
alr build --verification
cd tests
alr build --verification
alr run
```

To run the tests and generate a code coverage report:
```sh
alr build --verification
cd tests
./coverage.sh
```

The report will be generated in `tests/gnatcov_out/index.html`.

## References

[1] Consistent Overheady Byte Stuffing
Expand Down
2 changes: 0 additions & 2 deletions src/generic_cobs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ is

Code := B;
Run_Length := Byte_Count (Byte'Pos (B));

exit when B = Frame_Delimiter;
end if;

Run_Length := Run_Length - 1;
Expand Down
2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/bin/
/alire/
/config/
*.srctrace
/gnatcov_out/
3 changes: 2 additions & 1 deletion tests/alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ executables = ["unit_tests"]

[[depends-on]]
aunit = "^22.0.0"
gnatcov = "^22.0.1"
cobs = "*"

[[pins]]
cobs = { path = "../" }
cobs = { path = "../" }
14 changes: 14 additions & 0 deletions tests/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

alr gnatcov instrument --level=stmt+mcdc --dump-trigger=atexit --projects cobs.gpr

alr build -- --src-subdirs=gnatcov-instr --implicit-with=gnatcov_rts_full

alr exec -- bin/unit_tests

alr gnatcov coverage \
--annotate=html+ \
--output-dir gnatcov_out \
--level=stmt+mcdc \
--projects cobs.gpr \
*.srctrace
4 changes: 0 additions & 4 deletions tests/run_tests.sh

This file was deleted.

Loading

0 comments on commit 0b46b46

Please sign in to comment.