Page MenuHomeFreeBSD

bitstring_test: fix bit_nclear/bit_nset tests for last iteration
ClosedPublic

Authored by rlibby on Jul 5 2024, 10:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Oct 12, 11:07 PM
Unknown Object (File)
Sun, Oct 12, 12:43 AM
Unknown Object (File)
Sun, Oct 12, 12:43 AM
Unknown Object (File)
Sun, Oct 12, 12:43 AM
Unknown Object (File)
Sat, Oct 11, 3:12 PM
Unknown Object (File)
Thu, Oct 9, 3:33 PM
Unknown Object (File)
Sun, Oct 5, 3:57 PM
Unknown Object (File)
Sun, Oct 5, 3:28 PM
Subscribers

Details

Summary

Diagnosed by gcc -Wint-in-bool-context.

Test Plan
% kyua test -k /usr/tests/sys/Kyuafile sys/bitstring_test

Diff Detail

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

Event Timeline

rlibby added reviewers: des, markj.

What's the problem? Under what conditions is the current code incorrect?

Apologies, trying to recall. IIRC...

GCC complained because the 2nd arg to the ternary is bool and the 3rd is int. Here it mean that the behavior for j + 1 == nbits wasn't being tested, but we should test that the result is -1.

(j + 1 < nbits) ? found_set_bit == j + 1 : -1,
                  ^^^^^^^^^^^^^^^^^^^^^^   ^^
                            |               |
true or false, depending on result          |
                                            |
always true---------------------------------|

So is -1 being cast to true? Thank you GCC for telling us that. If so, I think we should replace ATF_REQUIRE_MSG with ATF_REQUIRE_EQ_MSG. I think that would be more clear.

So is -1 being cast to true?

Effectively, yes.

Thank you GCC for telling us that. If so, I think we should replace ATF_REQUIRE_MSG with ATF_REQUIRE_EQ_MSG. I think that would be more clear.

Sure, I'll work that up.

asomers feedback: use ATF_REQUIRE_EQ family of tests.

I converted the nearby tests to ATF_REQUIRE_INTEQ_MSG, but I left the 40
other instances in this file alone.

I selected INTEQ instead of EQ as that variant outputs the actual
values on failure.

This revision is now accepted and ready to land.Thu, Oct 2, 8:13 AM