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
F104035510: D34244.diff
Mon, Dec 2, 5:16 PM
Unknown Object (File)
Fri, Nov 29, 5:03 PM
Unknown Object (File)
Sat, Nov 23, 12:23 AM
Unknown Object (File)
Fri, Nov 15, 7:28 AM
Unknown Object (File)
Oct 20 2024, 7:23 AM
Unknown Object (File)
Oct 20 2024, 6:12 AM
Unknown Object (File)
Sep 24 2024, 10:05 AM
Unknown Object (File)
Sep 24 2024, 9:09 AM
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.