Page MenuHomeFreeBSD

tests: Add Linuxulator regression test infrastructure
Needs ReviewPublic

Authored by vova_fbsd.ru on Tue, Oct 13, 2:57 PM.
Tags
None
Referenced Files
F175981960: D60702.diff
Thu, Oct 15, 12:24 AM
F175976997: D60702.diff
Wed, Oct 14, 11:23 PM
F175976921: D60702.id189806.diff
Wed, Oct 14, 11:22 PM
F175957553: D60702.id189806.diff
Wed, Oct 14, 6:59 PM
F175912340: D60702.id189806.diff
Wed, Oct 14, 10:34 AM
F175901866: D60702.id189730.diff
Wed, Oct 14, 8:33 AM
F175880774: D60702.id189730.diff
Wed, Oct 14, 3:58 AM
F175880512: D60702.id189806.diff
Wed, Oct 14, 3:55 AM
Subscribers

Details

Reviewers
glebius
ngie
igoro
olivier
dchagin
kib
Group Reviewers
tests
Summary

Add infrastructure for running regression tests whose test subjects must
execute under the Linux ABI.

Keep the test sources and the reusable Linux-side runtime under
sys/tests/linux. Add tests/sys/linux as the build-system integration
point and register it in the system test hierarchy, installing the tests
under /usr/tests/sys/linux.

Linux test programs are built as static, freestanding ELF binaries. They
do not depend on a Linux base system, libc, an ELF interpreter, or any
files below compat.linux.emul_path. This allows the tests to run on
minimal test systems and in buildworld test sandboxes.

Provide a small reusable runtime for Linux-side test helpers:

  • linux_crt0 supplies the ELF entry point, invokes a conventional main(), and terminates the process with the Linux exit_group system call.
  • linux_syscalls provides the architecture-specific raw system call interface and a minimal set of syscall wrappers.
  • amd64 and arm64 are supported, producing x86-64 and AArch64 Linux ELF executables respectively.

Linux kernel modules required by individual tests are declared through
the ATF require.kmods metadata. Kyua can therefore load linux64.ko before
executing a test, without requiring each test to implement module
management.

Add the first regression test for Linux controlling-terminal semantics.
The native ATF test creates a pseudo-terminal, establishes it as the
controlling terminal of a new session, and executes a static Linux
helper. The helper closes the last descriptors referencing the slave
and then attempts to reopen /dev/tty.

Linux keeps the session's controlling-terminal reference across the last
slave close, so reopening /dev/tty must succeed. This exercises the
devfs behavior fixed by D60701 ("devfs: Keep a Linux controlling
tty across the last slave close").

Also register /usr/tests/sys/linux in BSD.tests.dist so that make check
creates the directory in its temporary installation hierarchy.

Test Plan
# make -C tests/sys/linux check
...
devfs_pty:ctty_last_close  ->  passed  [0.003s]

Results file id is usr_obj_usr_src_arm64.aarch64_tests_sys_linux_checkdir_usr_tests_sys_linux.20261013-152246-721666
Results saved to /root/.kyua/store/results.usr_obj_usr_src_arm64.aarch64_tests_sys_linux_checkdir_usr_tests_sys_linux.20261013-152246-721666.db

1/1 passed (0 broken, 0 failed, 0 skipped)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 78231
Build 75114: arc lint + arc unit

Event Timeline

vova_fbsd.ru edited the test plan for this revision. (Show Details)
vova_fbsd.ru edited the test plan for this revision. (Show Details)

Thanks a lot for this project! It is definitely very valuable. Adding more reviewers.

sys/tests/linux/Makefile
20–24 ↗(On Diff #189730)

As more tests are added you definitely don't want to copy over all these CFLAGS. I don't know what is better, to append CFLAGS or to fully override them.

vova_fbsd.ru edited the test plan for this revision. (Show Details)

tests: Consolidate Linux helper build flags and brand binaries

Define the compiler and linker flags used for static Linux test
helpers in one place and use a common rule to build all helpers.

Explicitly brand the resulting binaries as Linux. Clang and lld
otherwise produce static ELF binaries with the System V OSABI and no
ABI note, which only worked when kern.elf64.fallback_brand was set to
Linux.

This makes the tests independent of the host's fallback ELF brand
configuration and simplifies adding more Linux helpers.

Thank you for this, but I'm wondering if the functional testing for Linux syscalls are better suited for LTP. I'm not as active with that project as I used to be, but I'm still able to contribute there. There is some support missing from FreeBSD that would need to be added in order to make those tests work (/dev/loop), and some of the tests assume explicit Linux support which FreeBSD lacks (SCHED_EXT, etc), but there might be some items that can be gleaned from that project that allows us to avoid reinventing the wheel too much.
Treating this as a simple smoke test though for Linuxulator would be ok, but I want to make sure the tests are constrained to smoke tests and we don't go reinventing the wheel too much.

sys/tests/linux/devfs_pty_linux.c
14–16 ↗(On Diff #189806)

Please use linux_close_range instead.

sys/tests/linux/linux_crt0.c
17 ↗(On Diff #189806)

Who is expected to define __x86_64__? FreeBSD has typically used __amd64__, not __x86_64__ (this is a Linux-ism).

% rg -c __x86_64__ | awk -F: 'NF == 2 { s += $2 } END { print s }'
2050
% rg -c __amd64__ | awk -F: 'NF == 2 { s += $2 } END { print s }'
2389
%

Most of the __x86_64__ uses are in contrib.

18–33 ↗(On Diff #189806)

Where did the assembly here come from? FreeBSD source? GNU/Linux source?

sys/tests/linux/linux_crt0.h
1–12 ↗(On Diff #189806)

Is this header necessary?

sys/tests/linux/linux_syscalls.c
9 ↗(On Diff #189806)
22–47 ↗(On Diff #189806)

These are architecture specific syscall numbers. Is there a way that a symbolic constant like __NR_open (the Linux-documented symbol), etc, could be used instead? Per syscall(2), they should be available in sys/syscall.h

54 ↗(On Diff #189806)

What about syscalls that accept more or less than 4 arguments?

sys/tests/linux/linux_syscalls.h
10 ↗(On Diff #189806)

This should be defined in the non-test linux_syscalls.h header.

12–15 ↗(On Diff #189806)

These should use the Linux(-ish) types so the syscalls compile properly on 32-bit and 64-bit.

tests/sys/linux/Makefile
2–4
  • Why the indirection?
  • How can a user specify that they don't want to try and build and install the tests?
  • What about unsupported architectures, e.g., powerpc64?

Who is expected to define x86_64? FreeBSD has typically used amd64, not x86_64 (this is a Linux-ism).

I assume, it is defined by --target=x86_64-linux-gnu but I agree, FreeBSD-style will be better

I'm wondering if the functional testing for Linux syscalls are better suited for LTP

I would assime that LTP tests - are good for extended set of tests that require to setup additional software packages (linux base in that case).
As far I understand we have no such beast yet in freebsd-src, so all tests should be buildable/runnable with just base.
Intent was to cover with tests linxlator fixes. I would assume that running whole LTP would be a little challenging, but good to have.

Where did the assembly here come from? FreeBSD source? GNU/Linux source?

This assembly was written specifically for these freestanding test helpers; it was not copied from FreeBSD or GNU/Linux sources. It provides only the minimum ABI entry point needed to align/initialize the call frame and invoke linux_start(). The helpers do not currently consume argc, argv, envp, or the auxiliary vector.

sys/tests/linux/Makefile
17 ↗(On Diff #189806)

I think you need something like -ffreestanding otherwise compiler is allowed to assume presence of some STD C runtime.

sys/tests/linux/devfs_pty_linux.c
12 ↗(On Diff #189806)

I think the type should be int.

tests: Refine Linuxulator test infrastructure

Move the Linuxulator userland tests from sys/tests/linux to
tests/sys/linux. sys/tests is intended for kernel-side test modules,
while ATF tests and their helper programs belong under tests/sys.

Use the generated architecture-specific Linux syscall numbers instead
of embedding raw syscall numbers in the test support code. Extend the
low-level syscall primitive to pass all six Linux ABI arguments on
amd64 and arm64.

Use close_range(2) to close the standard descriptors in the devfs PTY
helper, remove the unnecessary crt0 header, and use the FreeBSD
amd64 spelling for the architecture check.

Only descend into tests/sys/linux on architectures for which the
freestanding Linux helpers can currently be built.

Suggested by: ngie
Differential Revision: https://reviews.freebsd.org/D60702