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

Increase test coverage of C code [AP-949] #1377

Merged
merged 7 commits into from
Nov 22, 2023

Conversation

woodfell
Copy link
Contributor

@woodfell woodfell commented Nov 15, 2023

Description

@swift-nav/devinfra

Increase the test coverage of C code by rewriting the template for the V4 C++ tests

This is a complete rewrite of the existing template which covers the following test cases:

  • Behaviour of *_encoded_len()
  • Encoding payload directly to a user-provided buffer
    • Underflow errors and alternative uses
  • Decoding payload from a user provided buffer
    • Underflow errors and alternative uses
  • Sending and receiving complete frame through C API (sbp_state_t)
  • Sending and receiving complete frame through C++ API (sbp::State and sbp::MessageHandler<>)
  • Encoding/decoding payload through C++ API
  • Comparison functions and operators with all potential mismatches covered automatically
  • C++ type traits
  • All string functions generated as part of the API for each message which contains string fields

This comprehensive template covers 100% of generated V4 code. No attempt was made to increase coverage of the legacy API, although there is little code to test anyway.

This rewrite by itself increases code coverage from ~20% to ~55% just based on the existing test cases.

Coverage can be further increased by introducing new test cases for the 120 or so messages which are currently uncovered. This is done on a separate PR #1382 and brings coverage up to ~99% (generated locally with lcov, sonar cloud seems to have a different way of calculating it)

To keep things a little smaller this PR will not introduce the new test cases, they will be kept separate and merged in to this branch before going to master

To aid with reviewing the commits are broken up to logical steps. The first couple deal with some supporting changes such as altering the generate to pass through some extra meta information (the generated companion fields for variable length arrays were already present to some extent in the previous template, but the information provided was not sufficient to get complete test coverage)

Next there are some minor alterations to some existing test cases. These all follow the same pattern of only affecting messages which have variable length arrays or string. For variable length arrays the existing specification for the companion "count" fields is extended out with 2 extra bits of information, for encoded strings there is one new fields. Both of these are required in order to get 100% coverage in the new template.

Finally, all code is regenerated. The final commit makes up the vast majority of changes in this PR. I suggest concentrating on just a single test case along with the code template itself, once these are understood all the other generated files can be treated with confidence.

Sonar cloud is not reporting any code coverage for this PR because there are no changes to actual code in libsbp, only the test case source code which isn't included in the calculation. You can see the effect of this PR by following the sonar cloud link an noting the "estimated after merge" number.

For Reviewers
Suggested places to concentrate on:

  • generator/sbpg/targets/resources/c/test/v4/sbp_cpp_test.cc.j2 - The main template which was rewritten for this PR
  • spec/tests/yaml/swiftnav/sbp/logging/test_MsgFwd.yaml - for an example of how the meta information for variable length arrays has changed
    • c/test/cpp/auto_check_sbp_logging_MsgFwd.cc - generated output of above test case
  • spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexResp.yaml - for an example of how the meta information for encoded strings has changed
    • c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexDone.cc - generated output of above test case

API compatibility

Does this change introduce a API compatibility risk?

No

API compatibility plan

If the above is "Yes", please detail the compatibility (or migration) plan:

N/A

JIRA Reference

https://swift-nav.atlassian.net/browse/AP-949

@woodfell woodfell changed the title Woodfell/try to increase code coverage Increase test coverage of C code [AP-949] Nov 21, 2023
@woodfell woodfell force-pushed the woodfell/try_to_increase_code_coverage branch 2 times, most recently from f4eda7e to a975a84 Compare November 21, 2023 06:12
@woodfell woodfell marked this pull request as ready for review November 21, 2023 06:31
@woodfell woodfell requested review from jungleraptor and a team as code owners November 21, 2023 06:31
Copy link
Contributor

@RReichert RReichert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a glance through (since these are test cases update and have no production impact), looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the python sonarcloud checks need tweaking (out of scope for PR). its assuming this file is production code and needs test cases.

@woodfell woodfell force-pushed the woodfell/try_to_increase_code_coverage branch from a975a84 to 9861721 Compare November 22, 2023 00:00
# Description

@swift-nav/devinfra

Companion PR for #1377 which
introduces new test cases. Once merged this PR will increase test
coverage of the C binding to near 100%

# API compatibility

Does this change introduce a API compatibility risk?

<!-- Provide a short explanation why or why not -->

## API compatibility plan

If the above is "Yes", please detail the compatibility (or migration)
plan:

<!-- Provide a short explanation plan here -->

# JIRA Reference

https://swift-nav.atlassian.net/browse/BOARD-XXXX
Copy link

[libsbp-c] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@woodfell woodfell merged commit a067434 into master Nov 22, 2023
21 of 22 checks passed
@woodfell woodfell deleted the woodfell/try_to_increase_code_coverage branch November 22, 2023 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants