Skip to content

Commit 03418a8

Browse files
committed
cheribsd: Default to building alternate kernel ABIs
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.
1 parent 344dbe3 commit 03418a8

File tree

2 files changed

+112
-45
lines changed

2 files changed

+112
-45
lines changed

pycheribuild/projects/cross/cheribsd.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,12 @@ class BuildCHERIBSD(BuildFreeBSD):
16061606
use_llvm_binutils = True
16071607
has_installsysroot_target = True
16081608

1609+
# NB: Full CHERI-MIPS purecap kernel support was never merged
1610+
purecap_kernel_targets = [CompilationTargets.CHERIBSD_RISCV_HYBRID,
1611+
CompilationTargets.CHERIBSD_RISCV_PURECAP,
1612+
CompilationTargets.CHERIBSD_MORELLO_HYBRID,
1613+
CompilationTargets.CHERIBSD_MORELLO_PURECAP]
1614+
16091615
@classmethod
16101616
def setup_config_options(cls, kernel_only_target=False, install_directory_help=None, **kwargs):
16111617
if install_directory_help is None:
@@ -1626,15 +1632,9 @@ def setup_config_options(cls, kernel_only_target=False, install_directory_help=N
16261632
cls.mfs_root_image = cls.add_path_option(
16271633
"mfs-root-image", help="Path to an MFS root image to be embedded in the kernel for booting")
16281634

1629-
# NB: Full CHERI-MIPS purecap kernel support was never merged
1630-
purecap_kernel_targets = [CompilationTargets.CHERIBSD_RISCV_HYBRID,
1631-
CompilationTargets.CHERIBSD_RISCV_PURECAP,
1632-
CompilationTargets.CHERIBSD_MORELLO_HYBRID,
1633-
CompilationTargets.CHERIBSD_MORELLO_PURECAP]
1634-
16351635
cls.default_kernel_abi = cls.add_config_option(
16361636
"default-kernel-abi", show_help=True, _allow_unknown_targets=True,
1637-
only_add_for_targets=purecap_kernel_targets,
1637+
only_add_for_targets=cls.purecap_kernel_targets,
16381638
kind=KernelABI, default=KernelABI.HYBRID,
16391639
enum_choices=[KernelABI.HYBRID, KernelABI.PURECAP],
16401640
help="Select default kernel to build")
@@ -1643,7 +1643,8 @@ def setup_config_options(cls, kernel_only_target=False, install_directory_help=N
16431643
cls.build_alternate_abi_kernels = cls.add_bool_option(
16441644
"build-alternate-abi-kernels", show_help=True,
16451645
_allow_unknown_targets=True,
1646-
only_add_for_targets=purecap_kernel_targets,
1646+
only_add_for_targets=cls.purecap_kernel_targets,
1647+
default=True,
16471648
help="Also build kernels with non-default ABI (purecap or hybrid)")
16481649

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

16741675
def get_default_kernel_abi(self):
1675-
if self.crosscompile_target.is_hybrid_or_purecap_cheri():
1676+
# XXX: Because the config option has _allow_unknown_targets it exists
1677+
# in the base class and thus still inherited by non-purecap-kernel
1678+
# targets
1679+
if self.crosscompile_target in self.purecap_kernel_targets:
16761680
kernABI = self.default_kernel_abi
1681+
elif self.crosscompile_target.is_hybrid_or_purecap_cheri():
1682+
kernABI = KernelABI.HYBRID
16771683
else:
16781684
kernABI = KernelABI.NOCHERI
16791685
return kernABI
@@ -1691,7 +1697,10 @@ def _get_config_variants(self, platforms: list, kernABIs: list, combine_flags: l
16911697
def _get_kABIs_to_build(self):
16921698
default_kABI = self.get_default_kernel_abi()
16931699
kernABIs = [default_kABI]
1694-
if self.build_alternate_abi_kernels:
1700+
# XXX: Because the config option has _allow_unknown_targets it exists
1701+
# in the base class and thus still inherited by non-purecap-kernel
1702+
# targets
1703+
if self.crosscompile_target in self.purecap_kernel_targets and self.build_alternate_abi_kernels:
16951704
otherABI = KernelABI.PURECAP if default_kABI != KernelABI.PURECAP else KernelABI.HYBRID
16961705
kernABIs.append(otherABI)
16971706
return kernABIs

tests/test_argument_parsing.py

+93-35
Original file line numberDiff line numberDiff line change
@@ -707,37 +707,85 @@ def test_disk_image_path(target, expected_name):
707707

708708
@pytest.mark.parametrize("target,config_options,expected_name,extra_kernels", [
709709
# RISCV kernconf tests
710-
pytest.param("cheribsd-riscv64-purecap", [], "CHERI-QEMU", []),
711-
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-fpga-kernels"], "CHERI-QEMU", []),
712-
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-alternate-abi-kernels"],
713-
"CHERI-QEMU", ["CHERI-PURECAP-QEMU"]),
710+
pytest.param("cheribsd-riscv64-purecap",
711+
["--cheribsd/no-build-alternate-abi-kernels"],
712+
"CHERI-QEMU",
713+
[]),
714+
pytest.param("cheribsd-riscv64-purecap",
715+
["--cheribsd/build-fpga-kernels"],
716+
"CHERI-QEMU",
717+
["CHERI-PURECAP-QEMU"]),
718+
pytest.param("cheribsd-riscv64-purecap",
719+
[],
720+
"CHERI-QEMU",
721+
["CHERI-PURECAP-QEMU"]),
714722
pytest.param("cheribsd-riscv64-purecap",
715723
["--cheribsd/build-alternate-abi-kernels",
716724
"--cheribsd/default-kernel-abi", "purecap"],
717-
"CHERI-PURECAP-QEMU", ["CHERI-QEMU"]),
718-
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-fett-kernels"],
719-
"CHERI-QEMU-FETT", ["CHERI-QEMU"]),
725+
"CHERI-PURECAP-QEMU",
726+
["CHERI-QEMU"]),
727+
pytest.param("cheribsd-riscv64-purecap",
728+
["--cheribsd/build-fett-kernels",
729+
"--cheribsd/no-build-alternate-abi-kernels"],
730+
"CHERI-QEMU-FETT",
731+
["CHERI-QEMU"]),
732+
pytest.param("cheribsd-riscv64-purecap",
733+
["--cheribsd/build-fett-kernels"],
734+
"CHERI-QEMU-FETT",
735+
["CHERI-QEMU",
736+
"CHERI-PURECAP-QEMU"]),
737+
pytest.param("cheribsd-riscv64-purecap",
738+
["--cheribsd/build-bench-kernels",
739+
"--cheribsd/no-build-alternate-abi-kernels"],
740+
"CHERI-QEMU",
741+
["CHERI-QEMU-NODEBUG"]),
742+
pytest.param("cheribsd-riscv64-purecap",
743+
["--cheribsd/build-bench-kernels"],
744+
"CHERI-QEMU",
745+
["CHERI-QEMU-NODEBUG",
746+
"CHERI-PURECAP-QEMU-NODEBUG",
747+
"CHERI-PURECAP-QEMU"]),
748+
pytest.param("cheribsd-riscv64-purecap",
749+
["--cheribsd/build-fett-kernels",
750+
"--cheribsd/build-fpga-kernels",
751+
"--cheribsd/no-build-alternate-abi-kernels"],
752+
"CHERI-QEMU-FETT",
753+
["CHERI-QEMU",
754+
"CHERI-FETT"]),
720755
pytest.param("cheribsd-riscv64-purecap",
721756
["--cheribsd/build-fett-kernels",
722-
"--cheribsd/build-alternate-abi-kernels"],
723-
"CHERI-QEMU-FETT", ["CHERI-QEMU", "CHERI-PURECAP-QEMU"]),
724-
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-bench-kernels"],
725-
"CHERI-QEMU", ["CHERI-QEMU-NODEBUG"]),
726-
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-fett-kernels", "--cheribsd/build-fpga-kernels"],
727-
"CHERI-QEMU-FETT", ["CHERI-QEMU", "CHERI-FETT"]),
728-
pytest.param("cheribsd-riscv64-purecap", ["--cheribsd/build-fett-kernels", "--cheribsd/build-fpga-kernels",
729-
"--cheribsd/build-alternate-abi-kernels"],
730-
"CHERI-QEMU-FETT", ["CHERI-QEMU", "CHERI-PURECAP-QEMU", "CHERI-FETT", "CHERI-PURECAP-FETT"]),
757+
"--cheribsd/build-fpga-kernels"],
758+
"CHERI-QEMU-FETT",
759+
["CHERI-QEMU",
760+
"CHERI-PURECAP-QEMU",
761+
"CHERI-FETT",
762+
"CHERI-PURECAP-FETT"]),
731763
# MIPS kernconf tests
732-
pytest.param("cheribsd-mips64-purecap", ["--cheribsd/build-fpga-kernels"],
733-
"CHERI_MALTA64", ["CHERI_DE4_USBROOT", "CHERI_DE4_NFSROOT"]),
734-
pytest.param("cheribsd-mips64-purecap", ["--cheribsd/build-fpga-kernels", "--cheribsd/build-bench-kernels"],
735-
"CHERI_MALTA64", ["CHERI_DE4_USBROOT_BENCHMARK", "CHERI_DE4_USBROOT", "CHERI_DE4_NFSROOT"]),
764+
pytest.param("cheribsd-mips64-purecap",
765+
["--cheribsd/build-fpga-kernels"],
766+
"CHERI_MALTA64",
767+
["CHERI_DE4_USBROOT",
768+
"CHERI_DE4_NFSROOT"]),
769+
pytest.param("cheribsd-mips64-purecap",
770+
["--cheribsd/build-fpga-kernels",
771+
"--cheribsd/build-bench-kernels"],
772+
"CHERI_MALTA64",
773+
["CHERI_DE4_USBROOT_BENCHMARK",
774+
"CHERI_DE4_USBROOT",
775+
"CHERI_DE4_NFSROOT"]),
736776
# Morello kernconf tests
737-
pytest.param("cheribsd-aarch64", [], "GENERIC", []),
738-
pytest.param("cheribsd-morello-purecap", [], "GENERIC-MORELLO", []),
739-
pytest.param("cheribsd-morello-purecap", ["--cheribsd/build-alternate-abi-kernels"],
740-
"GENERIC-MORELLO", ["GENERIC-MORELLO-PURECAP"]),
777+
pytest.param("cheribsd-aarch64",
778+
[],
779+
"GENERIC",
780+
[]),
781+
pytest.param("cheribsd-morello-purecap",
782+
["--cheribsd/no-build-alternate-abi-kernels"],
783+
"GENERIC-MORELLO",
784+
[]),
785+
pytest.param("cheribsd-morello-purecap",
786+
[],
787+
"GENERIC-MORELLO",
788+
["GENERIC-MORELLO-PURECAP"]),
741789
])
742790
def test_kernel_configs(target, config_options: "list[str]", expected_name, extra_kernels):
743791
config = _parse_arguments(config_options)
@@ -748,31 +796,41 @@ def test_kernel_configs(target, config_options: "list[str]", expected_name, extr
748796

749797
@pytest.mark.parametrize("target,config_options,expected_kernels", [
750798
# RISCV kernconf tests
751-
pytest.param("cheribsd-mfs-root-kernel-riscv64", [], ["QEMU-MFS-ROOT"]),
799+
pytest.param("cheribsd-mfs-root-kernel-riscv64",
800+
[],
801+
["QEMU-MFS-ROOT"]),
752802
pytest.param("cheribsd-mfs-root-kernel-riscv64",
753803
["--cheribsd-mfs-root-kernel-riscv64/build-fpga-kernels"],
754-
["QEMU-MFS-ROOT", "GFE"]),
755-
pytest.param("cheribsd-mfs-root-kernel-riscv64-purecap",
756-
["--cheribsd-mfs-root-kernel-riscv64-purecap/build-fpga-kernels"],
757-
["CHERI-QEMU-MFS-ROOT", "CHERI-GFE"]),
804+
["QEMU-MFS-ROOT",
805+
"GFE"]),
758806
pytest.param("cheribsd-mfs-root-kernel-riscv64-purecap",
759807
["--cheribsd-mfs-root-kernel-riscv64-purecap/build-fpga-kernels",
760-
"--cheribsd-mfs-root-kernel-riscv64-purecap/build-alternate-abi-kernels"],
761-
["CHERI-QEMU-MFS-ROOT", "CHERI-PURECAP-QEMU-MFS-ROOT",
762-
"CHERI-GFE", "CHERI-PURECAP-GFE"]),
808+
"--cheribsd-mfs-root-kernel-riscv64-purecap/no-build-alternate-abi-kernels"],
809+
["CHERI-QEMU-MFS-ROOT",
810+
"CHERI-GFE"]),
811+
pytest.param("cheribsd-mfs-root-kernel-riscv64-purecap",
812+
["--cheribsd-mfs-root-kernel-riscv64-purecap/build-fpga-kernels"],
813+
["CHERI-QEMU-MFS-ROOT",
814+
"CHERI-PURECAP-QEMU-MFS-ROOT",
815+
"CHERI-GFE",
816+
"CHERI-PURECAP-GFE"]),
763817
pytest.param("cheribsd-mfs-root-kernel-riscv64-purecap",
764818
["--cheribsd-mfs-root-kernel-riscv64-purecap/build-fpga-kernels",
765819
"--cheribsd-mfs-root-kernel-riscv64-purecap/build-alternate-abi-kernels",
766820
"--cheribsd-mfs-root-kernel-riscv64-purecap/kernel-config=CHERI-QEMU-MFS-ROOT"],
767821
["CHERI-QEMU-MFS-ROOT"]),
768822
# MIPS kernconf tests
769-
pytest.param("cheribsd-mfs-root-kernel-mips64", [], ["MALTA64_MFS_ROOT"]),
823+
pytest.param("cheribsd-mfs-root-kernel-mips64",
824+
[],
825+
["MALTA64_MFS_ROOT"]),
770826
pytest.param("cheribsd-mfs-root-kernel-mips64",
771827
["--cheribsd-mfs-root-kernel-mips64/build-fpga-kernels"],
772-
["MALTA64_MFS_ROOT", "BERI_DE4_MFS_ROOT"]),
828+
["MALTA64_MFS_ROOT",
829+
"BERI_DE4_MFS_ROOT"]),
773830
pytest.param("cheribsd-mfs-root-kernel-mips64-purecap",
774831
["--cheribsd-mfs-root-kernel-mips64-purecap/build-fpga-kernels"],
775-
["CHERI_MALTA64_MFS_ROOT", "CHERI_DE4_MFS_ROOT"]),
832+
["CHERI_MALTA64_MFS_ROOT",
833+
"CHERI_DE4_MFS_ROOT"]),
776834
pytest.param("cheribsd-mfs-root-kernel-mips64-purecap",
777835
["--cheribsd-mfs-root-kernel-mips64-purecap/build-fpga-kernels",
778836
"--cheribsd-mfs-root-kernel-mips64-purecap/kernel-config=CHERI_MALTA64_MFS_ROOT"],

0 commit comments

Comments
 (0)