Page MenuHomeFreeBSD

lib/libc/tests/string/memcmp_test.c: extend test to support custom memcmp function
ClosedPublic

Authored by fuz on Aug 21 2023, 7:22 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Oct 22, 1:00 PM
Unknown Object (File)
Fri, Oct 18, 7:40 PM
Unknown Object (File)
Fri, Oct 18, 12:34 AM
Unknown Object (File)
Wed, Oct 16, 4:12 PM
Unknown Object (File)
Wed, Oct 16, 4:12 PM
Unknown Object (File)
Wed, Oct 16, 4:12 PM
Unknown Object (File)
Oct 1 2024, 1:50 PM
Unknown Object (File)
Sep 30 2024, 2:41 AM
Subscribers

Details

Summary

Extend the tests to permit loading an external memcmp function
and testing it over using the libc version. This was added by the
example of other tests in the test suite doing the same thing and
helped tremendously in development.

This change was originally part of D41442 but was taken out to
permit separate review as extrapolated from @ngie's request in
D41349.

Sponsored by: FreeBSD Foundation

Test Plan

n/a

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

fuz requested review of this revision.Aug 21 2023, 7:22 PM

lib/libc/tests/string: expand memcmp test to bcmp, timingsafe_{b,mem}cmp

The four functions more or less perform the same operation.
Reuse the same unit test with slight changes so we can cover
them all. Constant-time operation is not verified for the
timingsafe_* functions.

This addition prepares the test suite for an upcoming changeset
the vectorise timingsafe_{b,mem}cmp.

No ship-blocking comments.
Thank you 🙂!!

lib/libc/tests/string/memcmp_test.c
121

Is this needed? I don’t see a library named test_bcmp, etc, being created via the Makefile, but I might be overlooking something by accident…

lib/libc/tests/string/timingsafe_bcmp_test.c
1 ↗(On Diff #126703)

(Nonblocking comment) This is a fair bit of license boilerplate for adding a file that specifies a few #defines. I wonder if you can use the SPDX shortened form instead.

kevans added inline comments.
lib/libc/tests/string/timingsafe_bcmp_test.c
1 ↗(On Diff #126703)

I suspect the foundation's contract verbiage hasn't been updated to account for that possibility; we've only semi-recently started allowing dropping the license copy in favor of just an SPDX tag (which does need to be added whether the rest of the copy can be dropped or not, to this and other new files).

fuz marked 3 inline comments as done.Sep 29 2023, 3:51 PM

Please remember to accept the revision if you are ok with it so I can commit it!

lib/libc/tests/string/memcmp_test.c
121

Hi ngie,

The objective of this code is to allow the programmer of a custom bcmp/memcmp/... function to test his/her function without it being used by other code that calls bcmp/memcmp/... This is done by naming your custom function test_{b,mem}cmp, linking it into a shared object and loading it into the unit test via LD_PRELOAD.

This is extremely useful as if the function is defective, it is possible that test program doesn't even get as far as running the first unit test. The same design pattern is used in other unit tests (e.g. some of the NetBSD lib/libc/string unit tests).

lib/libc/tests/string/timingsafe_bcmp_test.c
1 ↗(On Diff #126703)

Yes, correct. The foundation contract states that this is the copyright header I am supposed to use.

This revision is now accepted and ready to land.Oct 2 2023, 4:15 PM