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

Function tests

loader/tests/src/test_stop_vmm_per_cpu.cpp:49–154  ·  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

47 /// @return Always returns bsl::exit_success.
48 ///
49 [[nodiscard]] constexpr auto
50 tests() noexcept -> bsl::exit_code
51 {
52 helpers::init();
53 constexpr auto func{&stop_vmm_per_cpu};
54
55 bsl::ut_scenario{"success"} = [&]() noexcept {
56 bsl::ut_given{} = [&]() noexcept {
57 start_vmm_args_t mut_args{};
58 helpers::file_t mut_mk_elf_file{};
59 helpers::file_t mut_ext_elf_files{};
60 bsl::ut_when{} = [&]() noexcept {
61 helpers::init_file(mut_mk_elf_file);
62 helpers::init_file(mut_ext_elf_files);
63 mut_args.ver = bsl::safe_u64::magic_1().get();
64 mut_args.num_pages_in_page_pool = bsl::safe_u32::magic_1().get();
65 mut_args.mk_elf_file.addr = helpers::to_u8_ptr(&mut_mk_elf_file);
66 mut_args.mk_elf_file.size = sizeof(mut_mk_elf_file);
67 mut_args.ext_elf_files[0].addr = helpers::to_u8_ptr(&mut_ext_elf_files);
68 mut_args.ext_elf_files[0].size = sizeof(mut_ext_elf_files);
69 helpers::ut_check(loader_init());
70 helpers::ut_check(start_vmm(&mut_args));
71 helpers::ut_check(start_vmm_per_cpu(1U));
72 bsl::ut_then{} = [&]() noexcept {
73 helpers::ut_check(func(1U));
74 };
75 bsl::ut_cleanup{} = [&]() noexcept {
76 helpers::ut_check(loader_fini());
77 helpers::reset();
78 };
79 };
80 };
81 };
82
83 bsl::ut_scenario{"invalid cpu"} = [&]() noexcept {
84 bsl::ut_then{} = [&]() noexcept {
85 helpers::ut_fails(func(42U));
86 };
87 };
88
89 bsl::ut_scenario{"cpu already running"} = [&]() noexcept {
90 bsl::ut_then{} = [&]() noexcept {
91 helpers::ut_check(func({}));
92 };
93 };
94
95 bsl::ut_scenario{"stop twice"} = [&]() noexcept {
96 bsl::ut_given{} = [&]() noexcept {
97 start_vmm_args_t mut_args{};
98 helpers::file_t mut_mk_elf_file{};
99 helpers::file_t mut_ext_elf_files{};
100 bsl::ut_when{} = [&]() noexcept {
101 helpers::init_file(mut_mk_elf_file);
102 helpers::init_file(mut_ext_elf_files);
103 mut_args.ver = bsl::safe_u64::magic_1().get();
104 mut_args.num_pages_in_page_pool = bsl::safe_u32::magic_1().get();
105 mut_args.mk_elf_file.addr = helpers::to_u8_ptr(&mut_mk_elf_file);
106 mut_args.mk_elf_file.size = sizeof(mut_mk_elf_file);

Callers 1

mainFunction · 0.70

Calls 11

initFunction · 0.85
init_fileFunction · 0.85
to_u8_ptrFunction · 0.85
ut_checkFunction · 0.85
loader_initFunction · 0.85
start_vmmFunction · 0.85
start_vmm_per_cpuFunction · 0.85
loader_finiFunction · 0.85
resetFunction · 0.85
ut_failsFunction · 0.85
finiFunction · 0.85

Tested by

no test coverage detected