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)
Wed, May 8, 1:46 AM
Unknown Object (File)
Wed, May 8, 1:46 AM
Unknown Object (File)
Tue, May 7, 9:16 PM
Unknown Object (File)
Sat, May 4, 4:39 PM
Unknown Object (File)
Dec 20 2023, 4:47 AM
Unknown Object (File)
Aug 11 2023, 1:28 AM
Unknown Object (File)
Jun 25 2023, 6:46 PM
Unknown Object (File)
Mar 3 2023, 4:02 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.