Page MenuHomeFreeBSD

Make sys headers includable in kernel unit tests
Needs ReviewPublic

Authored by rstone on Feb 10 2022, 8:51 PM.
Tags
None
Referenced Files
Unknown Object (File)
May 8 2024, 1:46 AM
Unknown Object (File)
May 8 2024, 1:46 AM
Unknown Object (File)
May 7 2024, 9:17 PM
Unknown Object (File)
Apr 29 2024, 12:54 AM
Unknown Object (File)
Apr 28 2024, 8:29 AM
Unknown Object (File)
Jan 11 2024, 5:14 AM
Unknown Object (File)
Dec 20 2023, 7:28 AM
Unknown Object (File)
Dec 19 2023, 5:55 PM
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

When compiling code for a kernel unit test, we have to define
_KERNEL so that kernel types and API declarations are exposed.
Rework how userland symbols like syscalls are declared in our
headers. Rather than excluding them if _KERNEL is set, add
a new _KERNEL_UT macro that can be defined when compiling the
test. When this macro is defined, kernel declarations will
still be made available, but syscalls and other userland symbols
will also be declared.

However, when compiling a kernel source file for linking into
the unit test, we don't want any userland symbols to be exposed.
Also add a _KERNEL_UT_KSRC macro that can be defined to inhibit
the visibility of userland declarations. It is not sufficient
to only set _KERNEL and not _KERNEL_UT in this case because there
will be rare cases where kernel sources compiled for the kernel and
kernel sources compiled for a unit test need a different set of
declarations.

Diff Detail

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

Event Timeline

This is the approach to exposing kernel declarations to userland that glebius@ requested I investigate. It has the advantage of being less invasive in kernel headers than the last attempt, and the meaning of the _KERNEL/_KERNEL_UT/_KERNEL_UT_KSRC macros is a lot clearer than in the last version. However I'm not thrilled with how this requires changes to how every header exposes syscalls. At the very least, this would require an exp-run before committing.

Also there are a few headers that couldn't be switched over to this new mechanism, as they are included in the bootstrap-tools phase and need to remain compatible with the hosts older cdefs.h, which doesn't have the __EXPOSE_USERLAND_SYMS() macro defined. Examples include sys/cnv.h and sys/md5.h.

I figured that I'd put this up for review and we can compare this approach to the previous one and see which one we all prefer.