<!-- description --> @brief Used to execute the actual checks. We put the checks in this function so that we can validate the tests both at compile-time and at run-time. If a bsl::ut_check fails, the tests will either fail fast at run-time, or will produce a compile-time error. <!-- inputs/outputs --> @return Always returns bsl::exit_success.
| 46 | /// @return Always returns bsl::exit_success. |
| 47 | /// |
| 48 | [[nodiscard]] constexpr auto |
| 49 | tests() noexcept -> bsl::exit_code |
| 50 | { |
| 51 | helpers::init(); |
| 52 | constexpr auto func{&map_mk_elf_segments}; |
| 53 | |
| 54 | bsl::ut_scenario{"success"} = [&]() noexcept { |
| 55 | bsl::ut_given{} = [&]() noexcept { |
| 56 | bsl::array<elf_segment_t, HYPERVISOR_MAX_SEGMENTS> mut_segments{}; |
| 57 | root_page_table_t mut_rpt{}; |
| 58 | constexpr auto buf_size{0x2042_umx}; |
| 59 | bsl::array<bsl::uint8, buf_size.get()> mut_buf{}; |
| 60 | bsl::ut_when{} = [&]() noexcept { |
| 61 | mut_segments.front().addr = mut_buf.data(); |
| 62 | mut_segments.front().size = mut_buf.size().get(); |
| 63 | bsl::ut_then{} = [&]() noexcept { |
| 64 | helpers::ut_check(func(mut_segments.data(), &mut_rpt)); |
| 65 | }; |
| 66 | bsl::ut_cleanup{} = [&]() noexcept { |
| 67 | helpers::reset(); |
| 68 | }; |
| 69 | }; |
| 70 | }; |
| 71 | }; |
| 72 | |
| 73 | bsl::ut_scenario{"platform_virt_to_phys fails"} = [&]() noexcept { |
| 74 | bsl::ut_given{} = [&]() noexcept { |
| 75 | bsl::array<elf_segment_t, HYPERVISOR_MAX_SEGMENTS> mut_segments{}; |
| 76 | root_page_table_t mut_rpt{}; |
| 77 | constexpr auto buf_size{0x2042_umx}; |
| 78 | bsl::array<bsl::uint8, buf_size.get()> mut_buf{}; |
| 79 | bsl::ut_when{} = [&]() noexcept { |
| 80 | mut_segments.front().addr = mut_buf.data(); |
| 81 | mut_segments.front().size = mut_buf.size().get(); |
| 82 | helpers::g_mut_platform_virt_to_phys = 1; |
| 83 | bsl::ut_then{} = [&]() noexcept { |
| 84 | helpers::ut_fails(func(mut_segments.data(), &mut_rpt)); |
| 85 | }; |
| 86 | bsl::ut_cleanup{} = [&]() noexcept { |
| 87 | helpers::reset(); |
| 88 | }; |
| 89 | }; |
| 90 | }; |
| 91 | }; |
| 92 | |
| 93 | bsl::ut_scenario{"map_4k_page fails"} = [&]() noexcept { |
| 94 | bsl::ut_given{} = [&]() noexcept { |
| 95 | bsl::array<elf_segment_t, HYPERVISOR_MAX_SEGMENTS> mut_segments{}; |
| 96 | root_page_table_t mut_rpt{}; |
| 97 | constexpr auto buf_size{0x2042_umx}; |
| 98 | bsl::array<bsl::uint8, buf_size.get()> mut_buf{}; |
| 99 | bsl::ut_when{} = [&]() noexcept { |
| 100 | mut_segments.front().addr = mut_buf.data(); |
| 101 | mut_segments.front().size = mut_buf.size().get(); |
| 102 | helpers::g_mut_map_4k_page = 1; |
| 103 | bsl::ut_then{} = [&]() noexcept { |
| 104 | helpers::ut_fails(func(mut_segments.data(), &mut_rpt)); |
| 105 | }; |