Page MenuHomeFreeBSD

libc tests: add tests for link_addr(3) and link_ntoa(3)
ClosedPublic

Authored by ivy on Apr 29 2025, 2:02 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Aug 20, 1:30 PM
Unknown Object (File)
Wed, Aug 20, 8:08 AM
Unknown Object (File)
Tue, Aug 19, 1:49 AM
Unknown Object (File)
Fri, Aug 1, 3:45 PM
Unknown Object (File)
Wed, Jul 30, 3:49 PM
Unknown Object (File)
Mon, Jul 28, 8:40 PM
Unknown Object (File)
Mon, Jul 28, 6:28 PM
Unknown Object (File)
Sun, Jul 27, 9:20 PM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 63768
Build 60652: arc lint + arc unit

Event Timeline

ivy requested review of this revision.Apr 29 2025, 2:02 AM
  • consistently use the style(9) const placement rather than C++ style

some fixes for the test utility functions

  • more useful check for sdl_len in make_linkaddr, > 0 rather than >= 0
  • initialise some ether_addrs
  • use correct buffer length in data()

I like it; have you thought of any negative tests? ie, testing that parsing invalid addresses (like feeding link_ntoa -> link_addr as you mentioned) fails?

I like it; have you thought of any negative tests? ie, testing that parsing invalid addresses (like feeding link_ntoa -> link_addr as you mentioned) fails?

so a fun thing about link_addr is it has no way to indicate an error, it will just return garbage. D49936 will fix that, but i wanted to get the tests in first so i can change the other diff a bit and make sure i don’t break it. i’ll add some negative tests there at the same time.

In D50062#1141980, @ivy wrote:

I like it; have you thought of any negative tests? ie, testing that parsing invalid addresses (like feeding link_ntoa -> link_addr as you mentioned) fails?

so a fun thing about link_addr is it has no way to indicate an error, it will just return garbage. D49936 will fix that, but i wanted to get the tests in first so i can change the other diff a bit and make sure i don’t break it. i’ll add some negative tests there at the same time.

aaahahahahahahahah :p

This revision is now accepted and ready to land.Apr 29 2025, 1:58 PM
ngie added a subscriber: ngie.
ngie added inline comments.
lib/libc/tests/net/link_addr_test.cc
44

The following code seems like it’s a logical item to add to a common C/C++ library. I highly doubt that this logic hasn’t been written somewhere or relied upon in the past.

169

Some other potential testcases:

positive:

  • all caps addresses (dash, colon, and period delimited).

negative:

  • mixed delimiters
  • input too short
  • input too long
  • NULL address (is crashing acceptable behavior?)
  • invalid, e.g., non-hex, character set (zz:yy…).
  • valid IPv6 addresses that seem like valid link addresses (shortened)
  • IPv4 addresses

add some additional tests

  • address with mixed case hex digits
  • short address
  • long address
  • very long address (SA-16:37.libc)
This revision now requires review to proceed.May 4 2025, 5:51 AM
lib/libc/tests/net/link_addr_test.cc
169

i've added a test for a mixed-case address; i wasn't sure if it was worth duplicating the other tests with different case.

i've also added tests for short and long addresses, but they aren't negative tests since link_addr is supposed to accept them.

This revision is now accepted and ready to land.May 5 2025, 11:36 AM