Page MenuHomeFreeBSD

Expose <sys/pcpu.h> kernel decls to sysunit tests
AbandonedPublic

Authored by rstone on Jan 25 2022, 9:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sep 28 2024, 3:35 PM
Unknown Object (File)
Sep 27 2024, 2:09 PM
Unknown Object (File)
Sep 13 2024, 2:12 AM
Unknown Object (File)
Sep 4 2024, 11:44 AM
Unknown Object (File)
Aug 8 2024, 3:25 PM
Unknown Object (File)
Jul 29 2024, 1:39 AM
Unknown Object (File)
Jul 26 2024, 4:09 PM
Unknown Object (File)
Jun 5 2024, 1:07 PM
Subscribers

Details

Reviewers
vangyzen
Summary

This requires inventing some KPIs that the low-level PCPU code
will call in the _KERNEL_UT case. I've built a kernel with and
without this change and confirmed that the kernel is bit-for-bit
identical.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 44091
Build 40979: arc lint + arc unit

Event Timeline

A preference for positive logic here where the primary thing (_KERNEL) is also switched on makes it easier to understand, imho.

sys/amd64/include/pcpu.h
126

In this case, I'd prefer #ifdef _KERNEL here

sys/amd64/include/pcpu_aux.h
50

same

sys/sys/pcpu.h
60–61

same, etc

In D34034#769620, @imp wrote:

A preference for positive logic here where the primary thing (_KERNEL) is also switched on makes it easier to understand, imho.

I should have explained this a bit more clearly in the first review. _KERNEL and _KERNEL_UT aren't mutually exclusive. When compiling kernel sources for linking into a unit test, I set both _KERNEL and _KERNEL_UT. This way the kernel code gets access to KPIs that can't be exposed to userland due to symbol conflicts (e.g. log(9) or malloc(9)). When compiling the unit test itself (or userland libraries that support the unit test by, for example, implementing a KPI), I set only _KERNEL_UT.

So ifndef _KERNEL_UT is correct thing to test as I want both the kernel code under test and the test itself to see the same symbol declarations.

In the __curthread case I could do #ifdef _KERNEL_UT ... #else ... but I thought it might be clearer to have the real kernel definition first and the unit test hook second.

@rstone wrote:

I thought it might be clearer to have the real kernel definition first and the unit test hook second.

Like @imp, I prefer avoiding negative logic, for the sake of readability. However, your rationale of keeping the "real" definition first is a good reason to break that rule.

sys/amd64/include/pcpu.h
255

Indentation looks different on this line versus line 250.

This revision is now accepted and ready to land.Jan 27 2022, 1:36 AM

glebius@ has requested a different approach where unit tests define _KERNEL and opt out of the KPI symbols that they don't want, rather than opting into the symbols that they do want.