Skip to content

Commit c6c6f01

Browse files
committed
Update unit tests to work on Ubuntu 24.04
1 parent 6e22792 commit c6c6f01

File tree

8 files changed

+23
-32
lines changed

8 files changed

+23
-32
lines changed

tests/unit/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ enable_testing()
1111
function(add_unit_test NAME)
1212
add_executable(${NAME}
1313
${ARGN}
14-
../../src/functions.cpp
1514
codebuilder.cpp
1615
)
1716
target_link_libraries(${NAME} tinykvm Catch2WithMain)

tests/unit/basic.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <tinykvm/machine.hpp>
44
extern std::vector<uint8_t> build_and_load(const std::string& code);
5-
extern void setup_kvm_system_calls();
65
static const uint64_t MAX_MEMORY = 8ul << 20; /* 8MB */
76
static const std::vector<std::string> env {
87
"LC_TYPE=C", "LC_ALL=C", "USER=root"
@@ -12,8 +11,6 @@ TEST_CASE("Initialize KVM", "[Initialize]")
1211
{
1312
// Create KVM file descriptors etc.
1413
tinykvm::Machine::init();
15-
// Install Linux and POSIX system call handlers
16-
setup_kvm_system_calls();
1714
}
1815

1916
TEST_CASE("Instantiate machines", "[Instantiate]")
@@ -25,11 +22,9 @@ int main() {
2522

2623
tinykvm::Machine machine { binary, { .max_mem = MAX_MEMORY } };
2724

28-
// The stack is automatically set to under the program area
29-
// The default program area is at 4MB on Linux
30-
REQUIRE(machine.stack_address() == 0x400000);
3125
// The starting address is somewhere in the program area
3226
REQUIRE(machine.start_address() > 0x400000);
27+
REQUIRE(machine.stack_address() > machine.start_address());
3328
}
3429

3530
TEST_CASE("Runtime setup and execution", "[Output]")

tests/unit/codebuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ std::string build(const std::string& code, const std::string& compiler_args)
6161
(void)snprintf(bin_filename, sizeof(bin_filename),
6262
"/tmp/binary-%08X", checksum);
6363

64-
auto cc = env_with_default("cc", "gcc");
64+
auto cc = env_with_default("CC", "gcc");
6565
auto command = compile_command(cc, bin_filename, code_filename, compiler_args);
6666
if constexpr (VERBOSE_COMPILER) {
6767
printf("Command: %s\n", command.c_str());

tests/unit/fork.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
#include <tinykvm/machine.hpp>
55
extern std::vector<uint8_t> build_and_load(const std::string& code);
6-
extern void setup_kvm_system_calls();
76
static const uint64_t MAX_MEMORY = 8ul << 20; /* 8MB */
8-
static const uint64_t MAX_COWMEM = 1ul << 20; /* 1MB */
7+
static const uint64_t MAX_COWMEM = 3ul << 20; /* 1MB */
98
static const std::vector<std::string> env {
109
"LC_TYPE=C", "LC_ALL=C", "USER=root"
1110
};
@@ -14,8 +13,6 @@ TEST_CASE("Initialize KVM", "[Initialize]")
1413
{
1514
// Create KVM file descriptors etc.
1615
tinykvm::Machine::init();
17-
// Install Linux and POSIX system call handlers
18-
setup_kvm_system_calls();
1916
}
2017

2118
TEST_CASE("Execute function in fork", "[Fork]")
@@ -113,7 +110,10 @@ extern void prints_hello_world() {
113110
write(1, "Hello World!", 12);
114111
})M");
115112

116-
tinykvm::Machine machine { binary, { .max_mem = MAX_MEMORY } };
113+
tinykvm::Machine machine { binary, {
114+
.max_mem = MAX_MEMORY,
115+
.split_hugepages = true
116+
} };
117117
machine.setup_linux({"fork"}, env);
118118
machine.run(4.0f);
119119

@@ -134,7 +134,8 @@ extern void prints_hello_world() {
134134

135135
// Create fork
136136
auto fork = tinykvm::Machine { machine, {
137-
.max_mem = MAX_MEMORY, .max_cow_mem = MAX_COWMEM
137+
.max_mem = MAX_MEMORY, .max_cow_mem = MAX_COWMEM,
138+
.split_hugepages = true
138139
} };
139140
REQUIRE(fork.banked_memory_pages() > 0);
140141

@@ -239,7 +240,9 @@ extern int get_value() {
239240
return value;
240241
})M");
241242

242-
tinykvm::Machine machine { binary, { .max_mem = MAX_MEMORY } };
243+
tinykvm::Machine machine { binary, { .max_mem = MAX_MEMORY,
244+
.split_hugepages = true
245+
} };
243246
// We need to create a Linux environment for runtimes to work well
244247
machine.setup_linux({"fork"}, env);
245248

@@ -255,10 +258,12 @@ extern int get_value() {
255258

256259
// Create fork
257260
auto fork1 = tinykvm::Machine { machine, {
258-
.max_mem = MAX_MEMORY, .max_cow_mem = MAX_COWMEM
261+
.max_mem = MAX_MEMORY, .max_cow_mem = MAX_COWMEM,
262+
.split_hugepages = true
259263
} };
260264
auto fork2 = tinykvm::Machine { machine, {
261-
.max_mem = MAX_MEMORY, .max_cow_mem = MAX_COWMEM
265+
.max_mem = MAX_MEMORY, .max_cow_mem = MAX_COWMEM,
266+
.split_hugepages = true
262267
} };
263268

264269
auto funcaddr = machine.address_of("get_value");
@@ -285,11 +290,13 @@ extern int get_value() {
285290
fork1.reset_to(machine, {
286291
.max_mem = MAX_MEMORY,
287292
.max_cow_mem = MAX_COWMEM,
293+
.split_hugepages = true
288294
});
289295

290296
fork2.reset_to(machine, {
291297
.max_mem = MAX_MEMORY,
292298
.max_cow_mem = MAX_COWMEM,
299+
.split_hugepages = true
293300
});
294301

295302
// Value now starts at 1 due to the change in main VM

tests/unit/remote.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ extern std::pair<
66
std::string,
77
std::vector<uint8_t>
88
> build_and_load(const std::string& code, const std::string& args);
9-
extern void setup_kvm_system_calls();
109
static const uint64_t MAX_MEMORY = 8ul << 20; /* 8MB */
1110
static const uint64_t MAX_COWMEM = 1ul << 20; /* 1MB */
1211
static const std::vector<std::string> env {
@@ -17,8 +16,6 @@ TEST_CASE("Initialize KVM", "[Remote]")
1716
{
1817
// Create KVM file descriptors etc.
1918
tinykvm::Machine::init();
20-
// Install Linux and POSIX system call handlers
21-
setup_kvm_system_calls();
2219
}
2320

2421
TEST_CASE("Print from remote VM", "[Remote]")

tests/unit/reset.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <tinykvm/machine.hpp>
55
extern std::vector<uint8_t> build_and_load(const std::string& code);
6-
extern void setup_kvm_system_calls();
76
static const uint64_t MAX_MEMORY = 32ul << 20; /* 32MB */
87
static const uint64_t MAX_COWMEM = 8ul << 20; /* 8MB */
98
static const std::vector<std::string> env {
@@ -14,8 +13,6 @@ TEST_CASE("Initialize KVM", "[Initialize]")
1413
{
1514
// Create KVM file descriptors etc.
1615
tinykvm::Machine::init();
17-
// Install Linux and POSIX system call handlers
18-
setup_kvm_system_calls();
1916
}
2017

2118
TEST_CASE("Execute function in reset VM", "[Reset]")
@@ -100,11 +97,13 @@ extern long some_syscall();
10097
10198
extern long hello_world(const char *arg) {
10299
printf("%s\n", arg);
100+
fflush(stdout);
103101
return some_syscall();
104102
}
105103
extern void crash(const char *arg) {
106104
some_syscall();
107105
printf("%s\n", arg);
106+
fflush(stdout);
108107
some_syscall();
109108
assert(0);
110109
})M");
@@ -139,7 +138,7 @@ extern void crash(const char *arg) {
139138
bool output_is_hello_world = false;
140139
fork.set_printer([&] (const char* data, size_t size) {
141140
std::string text{data, data + size};
142-
if (text == "Hello World!\n")
141+
if (text == "Hello World!")
143142
output_is_hello_world = true;
144143
});
145144

tests/unit/tegridy.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <tinykvm/machine.hpp>
44
extern std::vector<uint8_t> build_and_load(const std::string&);
5-
extern void setup_kvm_system_calls();
65
static const uint64_t MAX_MEMORY = 8ul << 20; /* 8MB */
76
static const std::vector<std::string> env{
87
"LC_TYPE=C", "LC_ALL=C", "USER=root"};
@@ -11,8 +10,6 @@ TEST_CASE("Initialize KVM", "[Initialize]")
1110
{
1211
// Create KVM file descriptors etc.
1312
tinykvm::Machine::init();
14-
// Install Linux and POSIX system call handlers
15-
setup_kvm_system_calls();
1613
}
1714

1815
TEST_CASE("Writes to kernel memory", "[Integrity]")
@@ -45,7 +42,7 @@ void still_works()
4542
bool output_is_hello_world = false;
4643
machine.set_printer([&] (const char* data, size_t size) {
4744
std::string text{data, data + size};
48-
if (text == "Hello World!\n")
45+
if (text == "Hello World!")
4946
output_is_hello_world = true;
5047
});
5148

@@ -97,7 +94,7 @@ void still_works()
9794
bool output_is_hello_world = false;
9895
machine.set_printer([&] (const char* data, size_t size) {
9996
std::string text{data, data + size};
100-
if (text == "Hello World!\n")
97+
if (text == "Hello World!")
10198
output_is_hello_world = true;
10299
});
103100

tests/unit/timeout.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <tinykvm/machine.hpp>
66
extern std::vector<uint8_t> build_and_load(const std::string& code);
7-
extern void setup_kvm_system_calls();
87
static const uint64_t MAX_MEMORY = 32ul << 20; /* 32MB */
98
static const uint64_t MAX_COWMEM = 8ul << 20; /* 8MB */
109
static const std::vector<std::string> env {
@@ -15,8 +14,6 @@ TEST_CASE("Initialize KVM", "[Initialize]")
1514
{
1615
// Create KVM file descriptors etc.
1716
tinykvm::Machine::init();
18-
// Install Linux and POSIX system call handlers
19-
setup_kvm_system_calls();
2017
}
2118

2219
TEST_CASE("Multiple timeouts inside guest", "[Timeout]")

0 commit comments

Comments
 (0)