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

Function tests

lib/tests/src/basic_page_pool_t/behavior.cpp:83–185  ·  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

81 /// @return Always returns bsl::exit_success.
82 ///
83 [[nodiscard]] constexpr auto
84 tests() noexcept -> bsl::exit_code
85 {
86 using pool_t = basic_page_pool_t<
87 tls_t,
88 bool,
89 HYPERVISOR_MK_DIRECT_MAP_ADDR.get(),
90 HYPERVISOR_MK_DIRECT_MAP_SIZE.get()>;
91
92 bsl::ut_scenario{"allocate empty"} = []() noexcept {
93 bsl::ut_given{} = []() noexcept {
94 pool_t mut_page_pool{};
95 bsl::span<basic_page_pool_node_t> mut_view{};
96 tls_t mut_tls{};
97 bool mut_return_nullptr{true};
98 bsl::ut_when{} = [&]() noexcept {
99 mut_page_pool.initialize(mut_view);
100 bsl::ut_then{} = [&]() noexcept {
101 auto const *const nd{
102 mut_page_pool.allocate<nd_t>(mut_tls, mut_return_nullptr)};
103 bsl::ut_check(nd == nullptr);
104 };
105 };
106 };
107 };
108
109 bsl::ut_scenario{"allocate until empty"} = []() noexcept {
110 bsl::ut_given{} = []() noexcept {
111 pool_t mut_page_pool{};
112 bsl::array<basic_page_pool_node_t, POOL_SIZE.get()> mut_pool{};
113 bsl::span mut_view{mut_pool};
114 tls_t mut_tls{};
115 bool mut_return_nullptr{true};
116 bsl::ut_when{} = [&]() noexcept {
117 initialize_pool(mut_view);
118 mut_page_pool.initialize(mut_view);
119 auto *const pmut_nd0{mut_page_pool.allocate<nd_t>(mut_tls, mut_return_nullptr)};
120 auto *const pmut_nd1{mut_page_pool.allocate<nd_t>(mut_tls, mut_return_nullptr)};
121 auto *const pmut_nd2{mut_page_pool.allocate<nd_t>(mut_tls, mut_return_nullptr)};
122 bsl::ut_required_step(pmut_nd0 == mut_pool.at_if(0_idx));
123 bsl::ut_required_step(pmut_nd1 == mut_pool.at_if(1_idx));
124 bsl::ut_required_step(pmut_nd2 == mut_pool.at_if(2_idx));
125 bsl::ut_then{} = [&]() noexcept {
126 auto *const pmut_nd3{
127 mut_page_pool.allocate<nd_t>(mut_tls, mut_return_nullptr)};
128 bsl::ut_check(pmut_nd3 == nullptr);
129 };
130 };
131 };
132 };
133
134 bsl::ut_scenario{"allocate until empty, then alloc more"} = []() noexcept {
135 bsl::ut_given{} = []() noexcept {
136 pool_t mut_page_pool{};
137 bsl::array<basic_page_pool_node_t, POOL_SIZE.get()> mut_pool{};
138 bsl::span mut_view{mut_pool};
139 tls_t mut_tls{};
140 bool mut_return_nd{false};

Callers 5

mainFunction · 0.70
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 3

ut_checkFunction · 0.85
initialize_poolFunction · 0.70
initializeMethod · 0.45

Tested by

no test coverage detected