forked from vmware-archive/node-replicated-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths01_kernel_low_tests.rs
More file actions
159 lines (135 loc) · 5.03 KB
/
Copy paths01_kernel_low_tests.rs
File metadata and controls
159 lines (135 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright © 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! A set of integration tests to ensure OS functionality is as expected.
//! These tests spawn a QEMU instance and run the OS on it.
//! The output from serial/QEMU is parsed and verified for expected output.
//!
//! The naming scheme of the tests ensures a somewhat useful order of test
//! execution taking into account the dependency chain:
//! * `s01_*`: Low level kernel services: SSE, memory allocation etc.
use rexpect::errors::*;
use rexpect::process::wait::WaitStatus;
use testutils::builder::BuildArgs;
use testutils::helpers::spawn_nrk;
use testutils::runner_args::{check_for_exit, check_for_successful_exit, RunnerArgs};
use testutils::ExitStatus;
/// Make sure the page-fault handler functions as expected.
/// In essence a trap should be raised and we should get a backtrace.
#[test]
fn s01_pfault() {
let build = BuildArgs::default().build();
let cmdline = RunnerArgs::new_with_build("pfault", &build);
let mut output = String::new();
let mut qemu_run = || -> Result<WaitStatus> {
let mut p = spawn_nrk(&cmdline)?;
p.exp_string("[IRQ] Page Fault")?;
p.exp_regex("Backtrace:")?;
output = p.exp_eof()?;
p.process.exit()
};
check_for_exit(ExitStatus::PageFault, &cmdline, qemu_run(), output);
}
/// Make sure general protection fault handling works as expected.
///
/// Again we'd expect a trap and a backtrace.
#[test]
fn s01_gpfault() {
let build = BuildArgs::default().build();
let cmdline = RunnerArgs::new_with_build("gpfault", &build);
let mut output = String::new();
let mut qemu_run = || -> Result<WaitStatus> {
let mut p = spawn_nrk(&cmdline)?;
p.exp_string("[IRQ] GENERAL PROTECTION FAULT")?;
p.exp_regex("frame #1 - 0x[0-9a-fA-F]+")?;
output = p.exp_eof()?;
p.process.exit()
};
check_for_exit(
ExitStatus::GeneralProtectionFault,
&cmdline,
qemu_run(),
output,
);
}
/// Make sure the double-fault handler works as expected.
///
/// Also the test verifies that we use a separate stack for
/// faults that can always happen unexpected.
#[test]
fn s01_double_fault() {
let build = BuildArgs::default()
.kernel_feature("cause-double-fault")
.build();
let cmdline = RunnerArgs::new_with_build("double-fault", &build).qemu_arg("-d int,cpu_reset");
let mut output = String::new();
let mut qemu_run = || -> Result<WaitStatus> {
let mut p = spawn_nrk(&cmdline)?;
p.exp_string("[IRQ] Double Fault")?;
output = p.exp_eof()?;
p.process.exit()
};
check_for_exit(ExitStatus::UnrecoverableError, &cmdline, qemu_run(), output);
}
/// Make sure we can do kernel memory allocations.
///
/// This smoke tests the physical memory allocator
/// and the global allocator integration.
#[test]
fn s01_alloc() {
let build = BuildArgs::default().build();
let cmdline = RunnerArgs::new_with_build("alloc", &build);
let mut output = String::new();
let mut qemu_run = || -> Result<WaitStatus> {
let mut p = spawn_nrk(&cmdline)?;
output += p.exp_string("small allocations work.")?.as_str();
output += p.exp_string("large allocations work.")?.as_str();
output += p.exp_eof()?.as_str();
p.process.exit()
};
check_for_successful_exit(&cmdline, qemu_run(), output);
}
/// Test that makes use of SSE in kernel-space and see if it works.AsMut
///
/// Tests that we have correctly set-up the hardware to deal with floating
/// point.
#[test]
fn s01_sse() {
let build = BuildArgs::default().build();
let cmdline = RunnerArgs::new_with_build("sse", &build);
let mut output = String::new();
let mut qemu_run = || -> Result<WaitStatus> {
let mut p = spawn_nrk(&cmdline)?;
p.exp_string("division = 4.566210045662101")?;
p.exp_string("division by zero = inf")?;
output = p.exp_eof()?;
p.process.exit()
};
check_for_successful_exit(&cmdline, qemu_run(), output);
}
#[test]
fn s01_time() {
eprintln!("Doing a release build, this might take a while...");
let build = BuildArgs::default().release().build();
let cmdline = RunnerArgs::new_with_build("time", &build);
let mut output = String::new();
let mut qemu_run = || -> Result<WaitStatus> {
let mut p = spawn_nrk(&cmdline)?;
output = p.exp_eof()?;
p.process.exit()
};
check_for_successful_exit(&cmdline, qemu_run(), output);
}
#[test]
fn s01_timer() {
let build = BuildArgs::default().kernel_feature("test-timer").build();
let cmdline = RunnerArgs::new_with_build("timer", &build);
let mut output = String::new();
let mut qemu_run = || -> Result<WaitStatus> {
let mut p = spawn_nrk(&cmdline)?;
output += p.exp_string("Setting the timer")?.as_str();
output += p.exp_string("Got a timer interrupt")?.as_str();
output += p.exp_eof()?.as_str();
p.process.exit()
};
check_for_successful_exit(&cmdline, qemu_run(), output);
}