MCPcopy Create free account
hub / github.com/Bareflank/hypervisor / tests

Function tests

loader/tests/src/test_platform.cpp:60–119  ·  view source on GitHub ↗

<!-- 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.

Source from the content-addressed store, hash-verified

58 /// @return Always returns bsl::exit_success.
59 ///
60 [[nodiscard]] constexpr auto
61 tests() noexcept -> bsl::exit_code
62 {
63 helpers::init();
64
65 bsl::ut_scenario{"platform_alloc success"} = [&]() noexcept {
66 bsl::ut_given{} = [&]() noexcept {
67 bsl::ut_when{} = [&]() noexcept {
68 auto const *const ptr{platform_alloc(HYPERVISOR_PAGE_SIZE)};
69 bsl::ut_then{} = [&]() noexcept {
70 bsl::ut_check(nullptr != ptr);
71 };
72 bsl::ut_cleanup{} = [&]() noexcept {
73 platform_free(ptr, HYPERVISOR_PAGE_SIZE);
74 };
75 };
76 };
77 };
78
79 bsl::ut_scenario{"platform_alloc non-aligned success"} = [&]() noexcept {
80 bsl::ut_given{} = [&]() noexcept {
81 constexpr auto size{0x2042_umx};
82 bsl::ut_when{} = [&]() noexcept {
83 auto const *const ptr{platform_alloc(size.get())};
84 bsl::ut_then{} = [&]() noexcept {
85 bsl::ut_check(nullptr != ptr);
86 };
87 bsl::ut_cleanup{} = [&]() noexcept {
88 platform_free(ptr, HYPERVISOR_PAGE_SIZE);
89 };
90 };
91 };
92 };
93
94 bsl::ut_scenario{"platform_alloc fails"} = [&]() noexcept {
95 bsl::ut_given{} = [&]() noexcept {
96 bsl::ut_when{} = [&]() noexcept {
97 helpers::g_mut_platform_alloc = 1;
98 auto const *const ptr{platform_alloc(HYPERVISOR_PAGE_SIZE)};
99 bsl::ut_then{} = [&]() noexcept {
100 bsl::ut_check(nullptr == ptr);
101 };
102 };
103 };
104
105 bsl::ut_given{} = [&]() noexcept {
106 bsl::ut_when{} = [&]() noexcept {
107 helpers::g_mut_platform_alloc = 2;
108 auto const *const ptr1{platform_alloc(HYPERVISOR_PAGE_SIZE)};
109 auto const *const ptr2{platform_alloc(HYPERVISOR_PAGE_SIZE)};
110 bsl::ut_then{} = [&]() noexcept {
111 bsl::ut_check(nullptr != ptr1);
112 bsl::ut_check(nullptr == ptr2);
113 };
114 bsl::ut_cleanup{} = [&]() noexcept {
115 platform_free(ptr1, HYPERVISOR_PAGE_SIZE);
116 };
117 };

Callers 1

mainFunction · 0.70

Calls 4

initFunction · 0.85
ut_checkFunction · 0.85
platform_allocFunction · 0.70
platform_freeFunction · 0.70

Tested by

no test coverage detected