From 3a628ca1fcc1799c55de2635024ac178961cf702 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 23 Nov 2026 12:19:54 +0100 Subject: tests: let ecam_builder set bridge bus numbers This change extends the ecam_builder to support additional configuration data for PCI bridges, namely the secondary and subordinate bus numbers. This extension is required to support upcoming PCI bridge walk tests by allowing the tests to configure PCI bridge topologies. The builder test reads both of the new bus numbers to verify they are set correctly. Additionally, this change introduces a new test support function in kstd, called require_ok. require_ok asserts that a kstd::result contains a success value and moves that value out of the result. In the case of a failed result, the source location of the require_ok call as well as the error message are reported and the test case is aborted. Both ecam_builder::window_for and the ecam_builder tests use this new function. --- .../test_support/devices/pci/ecam_builder.cpp | 17 ++++- .../test_support/devices/pci/ecam_builder.hpp | 14 ++++ .../devices/pci/ecam_builder.tests.cpp | 88 +++++++++++----------- 3 files changed, 73 insertions(+), 46 deletions(-) (limited to 'kernel') diff --git a/kernel/kernel/test_support/devices/pci/ecam_builder.cpp b/kernel/kernel/test_support/devices/pci/ecam_builder.cpp index 78b0b32c..a9bb1256 100644 --- a/kernel/kernel/test_support/devices/pci/ecam_builder.cpp +++ b/kernel/kernel/test_support/devices/pci/ecam_builder.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -62,6 +63,18 @@ namespace kernel::tests::devices::pci return *this; } + auto ecam_builder::function_builder::secondary_bus(std::uint8_t id) -> function_builder & + { + m_window.write(secondary_bus_offset, id); + return *this; + } + + auto ecam_builder::function_builder::subordinate_bus(std::uint8_t id) -> function_builder & + { + m_window.write(subordinate_bus_offset, id); + return *this; + } + auto ecam_builder::function_builder::function(std::uint8_t bus, std::uint8_t device, std::uint8_t number) -> function_builder { @@ -98,9 +111,7 @@ namespace kernel::tests::devices::pci (function_number << function_number_address_shift)); auto window = mmio_window::map(address, pci_function_size, mmio_window::access::writable); - REQUIRE(window); - - return std::move(*window); + return kstd::tests::require_ok(std::move(window)); } } // namespace kernel::tests::devices::pci diff --git a/kernel/kernel/test_support/devices/pci/ecam_builder.hpp b/kernel/kernel/test_support/devices/pci/ecam_builder.hpp index 31334959..3c0cf036 100644 --- a/kernel/kernel/test_support/devices/pci/ecam_builder.hpp +++ b/kernel/kernel/test_support/devices/pci/ecam_builder.hpp @@ -30,6 +30,8 @@ namespace kernel::tests::devices::pci constexpr auto static subclass_code_offset = kstd::bytes{0x0a}; constexpr auto static class_code_offset = kstd::bytes{0x0b}; constexpr auto static header_type_offset = kstd::bytes{0x0e}; + constexpr auto static secondary_bus_offset = kstd::bytes{0x19}; + constexpr auto static subordinate_bus_offset = kstd::bytes{0x1a}; struct function_builder { @@ -82,6 +84,18 @@ namespace kernel::tests::devices::pci //! @return A reference to this function builder. auto revision_id(std::uint8_t id) -> function_builder &; + //! Set the secondary bus number for this function. + //! + //! @param id The secondary bus number to set. + //! @return A reference to this function builder. + auto secondary_bus(std::uint8_t id) -> function_builder &; + + //! Set the subordinate bus number for this function. + //! + //! @param id The subordinate bus number to set. + //! @return A reference to this function builder. + auto subordinate_bus(std::uint8_t id) -> function_builder &; + //! Begin building another function. //! //! @param bus The bus number the device is attached to. diff --git a/kernel/kernel/test_support/devices/pci/ecam_builder.tests.cpp b/kernel/kernel/test_support/devices/pci/ecam_builder.tests.cpp index 0ca6af69..3b300581 100644 --- a/kernel/kernel/test_support/devices/pci/ecam_builder.tests.cpp +++ b/kernel/kernel/test_support/devices/pci/ecam_builder.tests.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -12,6 +13,7 @@ using kernel::tests::devices::pci::ecam_builder; using mmio_window = kapi::memory::mmio_window; +using kstd::tests::require_ok; namespace { @@ -29,6 +31,8 @@ namespace constexpr auto test_revision = 0x04; constexpr auto test_header_type_endpoint = 0x00; constexpr auto test_multifunction = 0x80; + constexpr auto test_secondary_bus = 0xa0; + constexpr auto test_subordinate_bus = 0xa1; } // namespace SCENARIO("Building PCI ECAM structures using the ecam_builder", "[smoke][devices][pci]") @@ -44,31 +48,28 @@ SCENARIO("Building PCI ECAM structures using the ecam_builder", "[smoke][devices THEN("the previous bus is unaffected") { auto base = test_ecam_base; - auto window = mmio_window::map(base, bytes_per_bus, mmio_window::access::read_only); - REQUIRE(window); + auto window = require_ok(mmio_window::map(base, bytes_per_bus, mmio_window::access::read_only)); - REQUIRE(window->read(kstd::bytes{}) == 0); - REQUIRE(window->read(bytes_per_bus - kstd::bytes{4}) == 0); + REQUIRE(window.read(kstd::bytes{}) == 0); + REQUIRE(window.read(bytes_per_bus - kstd::bytes{4}) == 0); } THEN("the bus is cleared") { auto base = test_ecam_base + bytes_per_bus; - auto window = mmio_window::map(base, bytes_per_bus, mmio_window::access::read_only); - REQUIRE(window); + auto window = require_ok(mmio_window::map(base, bytes_per_bus, mmio_window::access::read_only)); - REQUIRE(window->read(kstd::bytes{}) == 0xffff'ffff); - REQUIRE(window->read(bytes_per_bus - kstd::bytes{4}) == 0xffff'ffff); + REQUIRE(window.read(kstd::bytes{}) == 0xffff'ffff); + REQUIRE(window.read(bytes_per_bus - kstd::bytes{4}) == 0xffff'ffff); } THEN("the next bus is unaffected") { auto base = test_ecam_base + 2 * bytes_per_bus; - auto window = mmio_window::map(base, bytes_per_bus, mmio_window::access::read_only); - REQUIRE(window); + auto window = require_ok(mmio_window::map(base, bytes_per_bus, mmio_window::access::read_only)); - REQUIRE(window->read(kstd::bytes{}) == 0); - REQUIRE(window->read(bytes_per_bus - kstd::bytes{4}) == 0); + REQUIRE(window.read(kstd::bytes{}) == 0); + REQUIRE(window.read(bytes_per_bus - kstd::bytes{4}) == 0); } } @@ -85,22 +86,25 @@ SCENARIO("Building PCI ECAM structures using the ecam_builder", "[smoke][devices .subclass_code(test_subclass_vga) .programming_interface(test_prog_if_8514) .header_type(test_header_type_endpoint | test_multifunction) - .revision_id(test_revision); + .revision_id(test_revision) + .secondary_bus(test_secondary_bus) + .subordinate_bus(test_subordinate_bus); THEN("the values are written correctly") { auto base = test_ecam_base + bus * bytes_per_bus + device * bytes_per_device + function * bytes_per_function; - auto window = mmio_window::map(base, bytes_per_function, mmio_window::access::read_only); - REQUIRE(window); - - REQUIRE(window->read(ecam_builder::vendor_id_offset) == test_vendor); - REQUIRE(window->read(ecam_builder::device_id_offset) == test_device); - REQUIRE(window->read(ecam_builder::class_code_offset) == test_class_display_ctrl); - REQUIRE(window->read(ecam_builder::subclass_code_offset) == test_subclass_vga); - REQUIRE(window->read(ecam_builder::programming_interface_offset) == test_prog_if_8514); - REQUIRE(window->read(ecam_builder::revision_id_offset) == test_revision); - REQUIRE(window->read(ecam_builder::header_type_offset) == + auto window = require_ok(mmio_window::map(base, bytes_per_function, mmio_window::access::read_only)); + + REQUIRE(window.read(ecam_builder::vendor_id_offset) == test_vendor); + REQUIRE(window.read(ecam_builder::device_id_offset) == test_device); + REQUIRE(window.read(ecam_builder::class_code_offset) == test_class_display_ctrl); + REQUIRE(window.read(ecam_builder::subclass_code_offset) == test_subclass_vga); + REQUIRE(window.read(ecam_builder::programming_interface_offset) == test_prog_if_8514); + REQUIRE(window.read(ecam_builder::revision_id_offset) == test_revision); + REQUIRE(window.read(ecam_builder::header_type_offset) == (test_header_type_endpoint | test_multifunction)); + REQUIRE(window.read(ecam_builder::secondary_bus_offset) == test_secondary_bus); + REQUIRE(window.read(ecam_builder::subordinate_bus_offset) == test_subordinate_bus); } } @@ -130,32 +134,30 @@ SCENARIO("Building PCI ECAM structures using the ecam_builder", "[smoke][devices THEN("the values are written correctly") { auto base = test_ecam_base + bus * bytes_per_bus + device * bytes_per_device + function * bytes_per_function; - auto window = mmio_window::map(base, bytes_per_function, mmio_window::access::read_only); - REQUIRE(window); - - REQUIRE(window->read(ecam_builder::vendor_id_offset) == test_vendor); - REQUIRE(window->read(ecam_builder::device_id_offset) == test_device); - REQUIRE(window->read(ecam_builder::class_code_offset) == test_class_display_ctrl); - REQUIRE(window->read(ecam_builder::subclass_code_offset) == test_subclass_vga); - REQUIRE(window->read(ecam_builder::programming_interface_offset) == test_prog_if_8514); - REQUIRE(window->read(ecam_builder::revision_id_offset) == test_revision); - REQUIRE(window->read(ecam_builder::header_type_offset) == + auto window = require_ok(mmio_window::map(base, bytes_per_function, mmio_window::access::read_only)); + + REQUIRE(window.read(ecam_builder::vendor_id_offset) == test_vendor); + REQUIRE(window.read(ecam_builder::device_id_offset) == test_device); + REQUIRE(window.read(ecam_builder::class_code_offset) == test_class_display_ctrl); + REQUIRE(window.read(ecam_builder::subclass_code_offset) == test_subclass_vga); + REQUIRE(window.read(ecam_builder::programming_interface_offset) == test_prog_if_8514); + REQUIRE(window.read(ecam_builder::revision_id_offset) == test_revision); + REQUIRE(window.read(ecam_builder::header_type_offset) == (test_header_type_endpoint | test_multifunction)); } THEN("the first function is unchanged") { auto base = test_ecam_base + bytes_per_bus; - auto window = mmio_window::map(base, bytes_per_function, mmio_window::access::read_only); - REQUIRE(window); - - REQUIRE(window->read(ecam_builder::vendor_id_offset) == 0); - REQUIRE(window->read(ecam_builder::device_id_offset) == 0); - REQUIRE(window->read(ecam_builder::class_code_offset) == 0); - REQUIRE(window->read(ecam_builder::subclass_code_offset) == 0); - REQUIRE(window->read(ecam_builder::programming_interface_offset) == 0); - REQUIRE(window->read(ecam_builder::revision_id_offset) == 0); - REQUIRE(window->read(ecam_builder::header_type_offset) == 0); + auto window = require_ok(mmio_window::map(base, bytes_per_function, mmio_window::access::read_only)); + + REQUIRE(window.read(ecam_builder::vendor_id_offset) == 0); + REQUIRE(window.read(ecam_builder::device_id_offset) == 0); + REQUIRE(window.read(ecam_builder::class_code_offset) == 0); + REQUIRE(window.read(ecam_builder::subclass_code_offset) == 0); + REQUIRE(window.read(ecam_builder::programming_interface_offset) == 0); + REQUIRE(window.read(ecam_builder::revision_id_offset) == 0); + REQUIRE(window.read(ecam_builder::header_type_offset) == 0); } } } -- cgit v1.2.3