|
| 1 | +#include <catch2/catch_test_macros.hpp> |
| 2 | + |
| 3 | +#include <tinykvm/machine.hpp> |
| 4 | +extern std::vector<uint8_t> load_file(const std::string& filename); |
| 5 | +static const uint64_t MAX_MEMORY = 8ul << 20; /* 8MB */ |
| 6 | +static const std::vector<std::string> env{ |
| 7 | + "LC_TYPE=C", "LC_ALL=C", "USER=root"}; |
| 8 | + |
| 9 | +TEST_CASE("Initialize KVM", "[Initialize]") |
| 10 | +{ |
| 11 | + // Create KVM file descriptors etc. |
| 12 | + tinykvm::Machine::init(); |
| 13 | +} |
| 14 | + |
| 15 | +TEST_CASE("Verify Rust ELF", "[ELF]") |
| 16 | +{ |
| 17 | + const auto binary = load_file("../unit/elf/rust.elf"); |
| 18 | + |
| 19 | + tinykvm::Machine machine { binary, { .max_mem = MAX_MEMORY } }; |
| 20 | + // We need to create a Linux environment for runtimes to work well |
| 21 | + machine.setup_linux({"verify"}, env); |
| 22 | + |
| 23 | + // Run for at most 4 seconds before giving up |
| 24 | + machine.run(4.0f); |
| 25 | + |
| 26 | + REQUIRE(machine.return_value() == 231); |
| 27 | +} |
| 28 | + |
| 29 | +TEST_CASE("Verify Rust ELF (himem)", "[ELF]") |
| 30 | +{ |
| 31 | + const auto binary = load_file("../unit/elf/rust.elf"); |
| 32 | + |
| 33 | + const uint64_t HIMEM = 128ULL << 30; /* 128GB */ |
| 34 | + tinykvm::Machine machine{binary, { |
| 35 | + .max_mem = MAX_MEMORY, |
| 36 | + .dylink_address_hint = HIMEM + 0x200000, |
| 37 | + .vmem_base_address = HIMEM |
| 38 | + }}; |
| 39 | + // We need to create a Linux environment for runtimes to work well |
| 40 | + machine.setup_linux({"verify"}, env); |
| 41 | + REQUIRE(machine.entry_address() > HIMEM); |
| 42 | + |
| 43 | + // Run for at most 4 seconds before giving up |
| 44 | + machine.run(4.0f); |
| 45 | + |
| 46 | + REQUIRE(machine.return_value() == 231); |
| 47 | +} |
0 commit comments