smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.64k stars 404 forks source link

Improve tests using `rstest` #796

Closed thvdveld closed 1 year ago

thvdveld commented 1 year ago

rstest provides useful macros for making tests more generic. A place where this is useful is in the interface. Here, we need to test for different mediums: IP, Ethernet and IEEE802.15.4. Previously, we had a variable MEDIUM which was the medium that was used by the interface, and depending on the feature flags that were set at compile time a different medium was used. This was not ideal. I think rstest is a better fit for achieving the same goal. I think this is a first step into making the writing of tests simpler, such that we can increase the coverage by adding more tests.

codecov[bot] commented 1 year ago

Codecov Report

Merging #796 (6239609) into master (a4cee91) will decrease coverage by 0.71%. The diff coverage is 25.39%.

@@            Coverage Diff             @@
##           master     #796      +/-   ##
==========================================
- Coverage   80.27%   79.57%   -0.71%     
==========================================
  Files          72       71       -1     
  Lines       29280    27653    -1627     
==========================================
- Hits        23505    22005    -1500     
+ Misses       5775     5648     -127     
Impacted Files Coverage Δ
src/iface/interface/mod.rs 49.49% <7.31%> (-0.55%) :arrow_down:
src/iface/interface/igmp.rs 50.57% <22.22%> (+14.48%) :arrow_up:
src/iface/interface/sixlowpan.rs 74.93% <60.00%> (+4.08%) :arrow_up:
src/iface/interface/ieee802154.rs 88.75% <100.00%> (+27.99%) :arrow_up:
src/socket/udp.rs 84.88% <100.00%> (ø)

... and 8 files with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

thvdveld commented 1 year ago

~For some reason, the test directory does not count anymore for coverage. This file had a coverage of 100%. This is now gone. Overall, coverage increased.~

https://github.com/taiki-e/cargo-llvm-cov/pull/251 does not count test files for the coverage.

Overall, the coverage has increased for IPv6/IPv4/IEEE8021.5.4/6LoWPAN.