aboutsummaryrefslogtreecommitdiffstats
path: root/liblfvm/tests/vm_config.cc
diff options
context:
space:
mode:
Diffstat (limited to 'liblfvm/tests/vm_config.cc')
-rw-r--r--liblfvm/tests/vm_config.cc216
1 files changed, 216 insertions, 0 deletions
diff --git a/liblfvm/tests/vm_config.cc b/liblfvm/tests/vm_config.cc
new file mode 100644
index 0000000..3ba27f3
--- /dev/null
+++ b/liblfvm/tests/vm_config.cc
@@ -0,0 +1,216 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+#include <cstdint>
+#include <limits>
+#include <system_error>
+
+#include <catch2/catch_test_macros.hpp>
+
+import nihil;
+import liblfvm;
+
+TEST_CASE("vm_config: memory_size", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ REQUIRE(vm->memory_size() > 0);
+
+ auto r = vm->memory_size(1024);
+ REQUIRE(r);
+ REQUIRE(vm->memory_size() == 1024);
+
+ r = vm->memory_size(4096);
+ REQUIRE(r);
+ REQUIRE(vm->memory_size() == 4096);
+
+ r = vm->memory_size(std::numeric_limits<std::uint64_t>::max());
+ REQUIRE(!r);
+ REQUIRE(r.error() == std::errc::value_too_large);
+ REQUIRE(vm->memory_size() == 4096);
+
+ r = vm->memory_size(0);
+ REQUIRE(!r);
+ REQUIRE(r.error() == std::errc::invalid_argument);
+ REQUIRE(vm->memory_size() == 4096);
+}
+
+TEST_CASE("set_vm_option: memory", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ auto r = set_vm_option(*vm, "memory=2g");
+ REQUIRE(r);
+ REQUIRE(vm->memory_size() ==
+ (static_cast<std::int64_t>(2) * 1024 * 1024 * 1024));
+
+ r = set_vm_option(*vm, "memory=0");
+ REQUIRE(!r);
+}
+
+TEST_CASE("vm_config: ncpus", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ REQUIRE(vm->ncpus() > 0);
+
+ auto r = vm->ncpus(1);
+ REQUIRE(r);
+ REQUIRE(vm->ncpus() == 1);
+
+ r = vm->ncpus(16);
+ REQUIRE(r);
+ REQUIRE(vm->ncpus() == 16);
+
+ r = vm->ncpus(0);
+ REQUIRE(!r);
+ REQUIRE(r.error() == std::errc::invalid_argument);
+ REQUIRE(vm->ncpus() == 16);
+}
+
+TEST_CASE("set_vm_option: ncpus", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ auto r = set_vm_option(*vm, "ncpus=2");
+ REQUIRE(r);
+ REQUIRE(vm->ncpus() == 2);
+
+ r = set_vm_option(*vm, "ncpus=0");
+ REQUIRE(!r);
+}
+
+TEST_CASE("vm_config: destroy_on_poweroff", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ vm->destroy_on_poweroff(true);
+ REQUIRE(vm->destroy_on_poweroff() == true);
+
+ vm->destroy_on_poweroff(false);
+ REQUIRE(vm->destroy_on_poweroff() == false);
+}
+
+TEST_CASE("vm_config: wire_memory", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ vm->wire_memory(true);
+ REQUIRE(vm->wire_memory() == true);
+
+ vm->wire_memory(false);
+ REQUIRE(vm->wire_memory() == false);
+}
+
+TEST_CASE("set_vm_option: wire_memory", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ auto r = set_vm_option(*vm, "wire_memory=yes");
+ REQUIRE(r);
+ REQUIRE(vm->wire_memory() == true);
+
+ r = set_vm_option(*vm, "wire_memory=off");
+ REQUIRE(r);
+ REQUIRE(vm->wire_memory() == false);
+
+ r = set_vm_option(*vm, "wire_memory=0");
+ REQUIRE(!r);
+}
+
+TEST_CASE("vm_config: include_memory_in_core", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ vm->include_memory_in_core(true);
+ REQUIRE(vm->include_memory_in_core() == true);
+
+ vm->include_memory_in_core(false);
+ REQUIRE(vm->include_memory_in_core() == false);
+}
+
+TEST_CASE("set_vm_option: include_memory_in_core", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ auto r = set_vm_option(*vm, "include_memory_in_core=yes");
+ REQUIRE(r);
+ REQUIRE(vm->include_memory_in_core() == true);
+
+ r = set_vm_option(*vm, "include_memory_in_core=off");
+ REQUIRE(r);
+ REQUIRE(vm->include_memory_in_core() == false);
+
+ r = set_vm_option(*vm, "include_memory_in_core=0");
+ REQUIRE(!r);
+}
+
+TEST_CASE("vm_config: yield_on_halt", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ vm->yield_on_halt(true);
+ REQUIRE(vm->yield_on_halt() == true);
+
+ vm->yield_on_halt(false);
+ REQUIRE(vm->yield_on_halt() == false);
+}
+
+TEST_CASE("vm_config: exit_on_pause", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ vm->exit_on_pause(true);
+ REQUIRE(vm->exit_on_pause() == true);
+
+ vm->exit_on_pause(false);
+ REQUIRE(vm->exit_on_pause() == false);
+}
+
+TEST_CASE("vm_config: rtc_is_utc", "[lfvm]")
+{
+ using namespace lfvm;
+
+ auto vm = make_vm_config("test");
+ REQUIRE(vm);
+
+ vm->rtc_is_utc(true);
+ REQUIRE(vm->rtc_is_utc() == true);
+
+ vm->rtc_is_utc(false);
+ REQUIRE(vm->rtc_is_utc() == false);
+}