Skip to content

tests: raise libpilot coverage from 0.4% to 5.1%#1

Merged
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage
May 27, 2026
Merged

tests: raise libpilot coverage from 0.4% to 5.1%#1
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

Adds 18 internal tests covering every code path in this package that is reachable from go test:

  • Handle table (storeHandle / loadHandle / deleteHandle): identity round-trip, monotonic IDs, zero-id reservation, idempotent delete, unknown-id no-op, distinct IDs for identical values, two parallel stress tests for -race.
  • embeddedConfig.defaults(): blank-field fill, explicit-value preservation, negative + zero KeepaliveSec clamping, DataDir/SocketPath left untouched, registry/beacon host:port shape check.

Coverage delta: 0.4% → 5.1% (per-function: every targeted helper at 100%).

Why coverage didn't reach the 30% target

The 45 //export wrappers plus errJSON / okJSON / driverFromHandle / unmarshalCString all carry C.* types in their signatures. Go's test toolchain refuses to compile _test.go files that import "C" when the package already declares //export symbols:

use of cgo in test zz_internal_test.go not supported

That rules out calling them from Go test code, so their branches can only be reached from C-side integration tests linked against the compiled .so. Tracked as future work; would need either a separate cgo bridge file (production code change, out of scope here) or a C-language test driver.

Test plan

  • go test -race -count=1 -timeout 120s ./... passes (18 new tests + existing smoke)
  • go vet ./... clean
  • go tool cover -func shows 100% on every targeted helper
  • No production code (bindings.go, embedded.go) modified

Add 18 internal tests for the only code paths reachable from a
go test binary in this c-shared/main package:

- handle table (storeHandle/loadHandle/deleteHandle): identity,
  uniqueness, idempotent delete, concurrent stress for -race
- embeddedConfig.defaults(): blank fill, explicit preserve,
  negative/zero keepalive clamping, registry/beacon format

The 45 //export wrappers plus errJSON/okJSON/driverFromHandle/
unmarshalCString carry C.* types in their signatures. Go's test
toolchain rejects 'import "C"' in _test.go files for packages
that already use //export (use of cgo in test … not supported),
so those branches are only reachable from C-side integration
tests against the compiled .so.
@TeoSlayer TeoSlayer merged commit d760ab7 into main May 27, 2026
1 check passed
@TeoSlayer TeoSlayer deleted the add-test-coverage branch May 27, 2026 22:45
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

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.

2 participants