Skip to content

Commit

Permalink
cheribsd: Default to building alternate kernel ABIs
Browse files Browse the repository at this point in the history
We want it to be easy to get started with purecap kernels, so make sure
people get them by default.

As part of this, reformat the various kernel ABI tests to be exceedingly
uniform and easy to scan through as the changes in line wrapping make
them hard to trawl through and update.
  • Loading branch information
jrtc27 committed Oct 14, 2021
1 parent 344dbe3 commit 03418a8
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 45 deletions.
29 changes: 19 additions & 10 deletions pycheribuild/projects/cross/cheribsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,12 @@ class BuildCHERIBSD(BuildFreeBSD):
use_llvm_binutils = True
has_installsysroot_target = True

# NB: Full CHERI-MIPS purecap kernel support was never merged
purecap_kernel_targets = [CompilationTargets.CHERIBSD_RISCV_HYBRID,
CompilationTargets.CHERIBSD_RISCV_PURECAP,
CompilationTargets.CHERIBSD_MORELLO_HYBRID,
CompilationTargets.CHERIBSD_MORELLO_PURECAP]

@classmethod
def setup_config_options(cls, kernel_only_target=False, install_directory_help=None, **kwargs):
if install_directory_help is None:
Expand All @@ -1626,15 +1632,9 @@ def setup_config_options(cls, kernel_only_target=False, install_directory_help=N
cls.mfs_root_image = cls.add_path_option(
"mfs-root-image", help="Path to an MFS root image to be embedded in the kernel for booting")

# NB: Full CHERI-MIPS purecap kernel support was never merged
purecap_kernel_targets = [CompilationTargets.CHERIBSD_RISCV_HYBRID,
CompilationTargets.CHERIBSD_RISCV_PURECAP,
CompilationTargets.CHERIBSD_MORELLO_HYBRID,
CompilationTargets.CHERIBSD_MORELLO_PURECAP]

cls.default_kernel_abi = cls.add_config_option(
"default-kernel-abi", show_help=True, _allow_unknown_targets=True,
only_add_for_targets=purecap_kernel_targets,
only_add_for_targets=cls.purecap_kernel_targets,
kind=KernelABI, default=KernelABI.HYBRID,
enum_choices=[KernelABI.HYBRID, KernelABI.PURECAP],
help="Select default kernel to build")
Expand All @@ -1643,7 +1643,8 @@ def setup_config_options(cls, kernel_only_target=False, install_directory_help=N
cls.build_alternate_abi_kernels = cls.add_bool_option(
"build-alternate-abi-kernels", show_help=True,
_allow_unknown_targets=True,
only_add_for_targets=purecap_kernel_targets,
only_add_for_targets=cls.purecap_kernel_targets,
default=True,
help="Also build kernels with non-default ABI (purecap or hybrid)")

cls.build_bench_kernels = cls.add_bool_option("build-bench-kernels", show_help=True,
Expand Down Expand Up @@ -1672,8 +1673,13 @@ def __init__(self, config: CheriConfig):
self.extra_kernels_with_mfs += [c.kernconf for c in configs if c.mfsroot]

def get_default_kernel_abi(self):
if self.crosscompile_target.is_hybrid_or_purecap_cheri():
# XXX: Because the config option has _allow_unknown_targets it exists

This comment has been minimized.

Copy link
@jrtc27

jrtc27 Oct 14, 2021

Author Member

These should really have been in the previous commit, but didn't notice until the default flipped and tests were failing in stupid ways...

# in the base class and thus still inherited by non-purecap-kernel
# targets
if self.crosscompile_target in self.purecap_kernel_targets:
kernABI = self.default_kernel_abi
elif self.crosscompile_target.is_hybrid_or_purecap_cheri():
kernABI = KernelABI.HYBRID
else:
kernABI = KernelABI.NOCHERI
return kernABI
Expand All @@ -1691,7 +1697,10 @@ def _get_config_variants(self, platforms: list, kernABIs: list, combine_flags: l
def _get_kABIs_to_build(self):
default_kABI = self.get_default_kernel_abi()
kernABIs = [default_kABI]
if self.build_alternate_abi_kernels:
# XXX: Because the config option has _allow_unknown_targets it exists
# in the base class and thus still inherited by non-purecap-kernel
# targets
if self.crosscompile_target in self.purecap_kernel_targets and self.build_alternate_abi_kernels:
otherABI = KernelABI.PURECAP if default_kABI != KernelABI.PURECAP else KernelABI.HYBRID
kernABIs.append(otherABI)
return kernABIs
Expand Down
128 changes: 93 additions & 35 deletions tests/test_argument_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,37 +707,85 @@ def test_disk_image_path(target, expected_name):

@pytest.mark.parametrize("target,config_options,expected_name,extra_kernels", [
# RISCV kernconf tests
pytest.param("cheribsd-riscv64-purecap", [], "CHERI-QEMU", []),
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-fpga-kernels"], "CHERI-QEMU", []),
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-alternate-abi-kernels"],
"CHERI-QEMU", ["CHERI-PURECAP-QEMU"]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/no-build-alternate-abi-kernels"],
"CHERI-QEMU",
[]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/build-fpga-kernels"],
"CHERI-QEMU",
["CHERI-PURECAP-QEMU"]),
pytest.param("cheribsd-riscv64-purecap",
[],
"CHERI-QEMU",
["CHERI-PURECAP-QEMU"]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/build-alternate-abi-kernels",
"--cheribsd/default-kernel-abi", "purecap"],
"CHERI-PURECAP-QEMU", ["CHERI-QEMU"]),
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-fett-kernels"],
"CHERI-QEMU-FETT", ["CHERI-QEMU"]),
"CHERI-PURECAP-QEMU",
["CHERI-QEMU"]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/build-fett-kernels",
"--cheribsd/no-build-alternate-abi-kernels"],
"CHERI-QEMU-FETT",
["CHERI-QEMU"]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/build-fett-kernels"],
"CHERI-QEMU-FETT",
["CHERI-QEMU",
"CHERI-PURECAP-QEMU"]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/build-bench-kernels",
"--cheribsd/no-build-alternate-abi-kernels"],
"CHERI-QEMU",
["CHERI-QEMU-NODEBUG"]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/build-bench-kernels"],
"CHERI-QEMU",
["CHERI-QEMU-NODEBUG",
"CHERI-PURECAP-QEMU-NODEBUG",
"CHERI-PURECAP-QEMU"]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/build-fett-kernels",
"--cheribsd/build-fpga-kernels",
"--cheribsd/no-build-alternate-abi-kernels"],
"CHERI-QEMU-FETT",
["CHERI-QEMU",
"CHERI-FETT"]),
pytest.param("cheribsd-riscv64-purecap",
["--cheribsd/build-fett-kernels",
"--cheribsd/build-alternate-abi-kernels"],
"CHERI-QEMU-FETT", ["CHERI-QEMU", "CHERI-PURECAP-QEMU"]),
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-bench-kernels"],
"CHERI-QEMU", ["CHERI-QEMU-NODEBUG"]),
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-fett-kernels", "--cheribsd/build-fpga-kernels"],
"CHERI-QEMU-FETT", ["CHERI-QEMU", "CHERI-FETT"]),
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-fett-kernels", "--cheribsd/build-fpga-kernels",
"--cheribsd/build-alternate-abi-kernels"],
"CHERI-QEMU-FETT", ["CHERI-QEMU", "CHERI-PURECAP-QEMU", "CHERI-FETT", "CHERI-PURECAP-FETT"]),
"--cheribsd/build-fpga-kernels"],
"CHERI-QEMU-FETT",
["CHERI-QEMU",
"CHERI-PURECAP-QEMU",
"CHERI-FETT",
"CHERI-PURECAP-FETT"]),
# MIPS kernconf tests
pytest.param("cheribsd-mips64-purecap", ["--cheribsd/build-fpga-kernels"],
"CHERI_MALTA64", ["CHERI_DE4_USBROOT", "CHERI_DE4_NFSROOT"]),
pytest.param("cheribsd-mips64-purecap", ["--cheribsd/build-fpga-kernels", "--cheribsd/build-bench-kernels"],
"CHERI_MALTA64", ["CHERI_DE4_USBROOT_BENCHMARK", "CHERI_DE4_USBROOT", "CHERI_DE4_NFSROOT"]),
pytest.param("cheribsd-mips64-purecap",
["--cheribsd/build-fpga-kernels"],
"CHERI_MALTA64",
["CHERI_DE4_USBROOT",
"CHERI_DE4_NFSROOT"]),
pytest.param("cheribsd-mips64-purecap",
["--cheribsd/build-fpga-kernels",
"--cheribsd/build-bench-kernels"],
"CHERI_MALTA64",
["CHERI_DE4_USBROOT_BENCHMARK",
"CHERI_DE4_USBROOT",
"CHERI_DE4_NFSROOT"]),
# Morello kernconf tests
pytest.param("cheribsd-aarch64", [], "GENERIC", []),
pytest.param("cheribsd-morello-purecap", [], "GENERIC-MORELLO", []),
pytest.param("cheribsd-morello-purecap", ["--cheribsd/build-alternate-abi-kernels"],
"GENERIC-MORELLO", ["GENERIC-MORELLO-PURECAP"]),
pytest.param("cheribsd-aarch64",
[],
"GENERIC",
[]),
pytest.param("cheribsd-morello-purecap",
["--cheribsd/no-build-alternate-abi-kernels"],
"GENERIC-MORELLO",
[]),
pytest.param("cheribsd-morello-purecap",
[],
"GENERIC-MORELLO",
["GENERIC-MORELLO-PURECAP"]),
])
def test_kernel_configs(target, config_options: "list[str]", expected_name, extra_kernels):
config = _parse_arguments(config_options)
Expand All @@ -748,31 +796,41 @@ def test_kernel_configs(target, config_options: "list[str]", expected_name, extr

@pytest.mark.parametrize("target,config_options,expected_kernels", [
# RISCV kernconf tests
pytest.param("cheribsd-mfs-root-kernel-riscv64", [], ["QEMU-MFS-ROOT"]),
pytest.param("cheribsd-mfs-root-kernel-riscv64",
[],
["QEMU-MFS-ROOT"]),
pytest.param("cheribsd-mfs-root-kernel-riscv64",
["--cheribsd-mfs-root-kernel-riscv64/build-fpga-kernels"],
["QEMU-MFS-ROOT", "GFE"]),
pytest.param("cheribsd-mfs-root-kernel-riscv64-purecap",
["--cheribsd-mfs-root-kernel-riscv64-purecap/build-fpga-kernels"],
["CHERI-QEMU-MFS-ROOT", "CHERI-GFE"]),
["QEMU-MFS-ROOT",
"GFE"]),
pytest.param("cheribsd-mfs-root-kernel-riscv64-purecap",
["--cheribsd-mfs-root-kernel-riscv64-purecap/build-fpga-kernels",
"--cheribsd-mfs-root-kernel-riscv64-purecap/build-alternate-abi-kernels"],
["CHERI-QEMU-MFS-ROOT", "CHERI-PURECAP-QEMU-MFS-ROOT",
"CHERI-GFE", "CHERI-PURECAP-GFE"]),
"--cheribsd-mfs-root-kernel-riscv64-purecap/no-build-alternate-abi-kernels"],
["CHERI-QEMU-MFS-ROOT",
"CHERI-GFE"]),
pytest.param("cheribsd-mfs-root-kernel-riscv64-purecap",
["--cheribsd-mfs-root-kernel-riscv64-purecap/build-fpga-kernels"],
["CHERI-QEMU-MFS-ROOT",
"CHERI-PURECAP-QEMU-MFS-ROOT",
"CHERI-GFE",
"CHERI-PURECAP-GFE"]),
pytest.param("cheribsd-mfs-root-kernel-riscv64-purecap",
["--cheribsd-mfs-root-kernel-riscv64-purecap/build-fpga-kernels",
"--cheribsd-mfs-root-kernel-riscv64-purecap/build-alternate-abi-kernels",
"--cheribsd-mfs-root-kernel-riscv64-purecap/kernel-config=CHERI-QEMU-MFS-ROOT"],
["CHERI-QEMU-MFS-ROOT"]),
# MIPS kernconf tests
pytest.param("cheribsd-mfs-root-kernel-mips64", [], ["MALTA64_MFS_ROOT"]),
pytest.param("cheribsd-mfs-root-kernel-mips64",
[],
["MALTA64_MFS_ROOT"]),
pytest.param("cheribsd-mfs-root-kernel-mips64",
["--cheribsd-mfs-root-kernel-mips64/build-fpga-kernels"],
["MALTA64_MFS_ROOT", "BERI_DE4_MFS_ROOT"]),
["MALTA64_MFS_ROOT",
"BERI_DE4_MFS_ROOT"]),
pytest.param("cheribsd-mfs-root-kernel-mips64-purecap",
["--cheribsd-mfs-root-kernel-mips64-purecap/build-fpga-kernels"],
["CHERI_MALTA64_MFS_ROOT", "CHERI_DE4_MFS_ROOT"]),
["CHERI_MALTA64_MFS_ROOT",
"CHERI_DE4_MFS_ROOT"]),
pytest.param("cheribsd-mfs-root-kernel-mips64-purecap",
["--cheribsd-mfs-root-kernel-mips64-purecap/build-fpga-kernels",
"--cheribsd-mfs-root-kernel-mips64-purecap/kernel-config=CHERI_MALTA64_MFS_ROOT"],
Expand Down

0 comments on commit 03418a8

Please sign in to comment.