Skip to content

Commit 1ef3241

Browse files
committed
Remove error handling dependencies from tests
1 parent 034ddb6 commit 1ef3241

File tree

4 files changed

+44
-56
lines changed

4 files changed

+44
-56
lines changed

Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/runner/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ uefi = ["bootloader/uefi"]
1414
[dependencies]
1515
bootloader = { path = "../..", default-features = false }
1616
strip-ansi-escapes = "0.1.1"
17-
anyhow = "1.0.89"
1817
ureq = "2.10.1"
19-
fs-err = "2.11.0"
2018
sha2 = "0.10.8"
2119
tar = "0.4.41"
2220
lzma-rs = "0.3.0"

tests/runner/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub fn run_test_kernel_internal(
3636

3737
#[cfg(feature = "uefi")]
3838
{
39-
let mut ovmf_paths = OvmfPaths::find().unwrap();
40-
ovmf_paths.with_temp_vars().unwrap();
39+
let mut ovmf_paths = OvmfPaths::find();
40+
ovmf_paths.with_temp_vars();
4141

4242
let gpt_path = kernel_path.with_extension("gpt");
4343
let tftp_path = kernel_path.with_extension("tftp");

tests/runner/src/omvf.rs

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use anyhow::{bail, Result};
21
use sha2::{Digest, Sha256};
32
use std::{
43
env,
4+
fs::{copy, create_dir_all, read_to_string, remove_dir_all, rename, set_permissions, write},
55
io::{Cursor, Read},
66
path::{Path, PathBuf},
77
};
@@ -93,78 +93,78 @@ impl OvmfPaths {
9393
/// 1. Command-line arg
9494
/// 2. Environment variable
9595
/// 3. Prebuilt file (automatically downloaded)
96-
pub fn find_ovmf_file(file_type: OvmfFileType) -> Result<PathBuf> {
96+
pub fn find_ovmf_file(file_type: OvmfFileType) -> PathBuf {
9797
if let Some(path) = file_type.get_user_provided_path() {
9898
// The user provided an exact path to use; verify that it
9999
// exists.
100100
if path.exists() {
101-
Ok(path)
101+
path
102102
} else {
103-
bail!(
103+
panic!(
104104
"ovmf {} file does not exist: {}",
105105
file_type.as_str(),
106106
path.display()
107107
);
108108
}
109109
} else {
110-
let prebuilt_dir = update_prebuilt()?;
110+
let prebuilt_dir = update_prebuilt();
111111

112-
Ok(prebuilt_dir.join(format!(
112+
prebuilt_dir.join(format!(
113113
"x86_64/{}.{}",
114114
file_type.as_str(),
115115
file_type.extension()
116-
)))
116+
))
117117
}
118118
}
119119

120120
/// Find path to OVMF files by the strategy documented for
121121
/// [`Self::find_ovmf_file`].
122-
pub fn find() -> Result<Self> {
123-
let code = Self::find_ovmf_file(OvmfFileType::Code)?;
124-
let vars = Self::find_ovmf_file(OvmfFileType::Vars)?;
125-
let shell = Self::find_ovmf_file(OvmfFileType::Shell)?;
122+
pub fn find() -> Self {
123+
let code = Self::find_ovmf_file(OvmfFileType::Code);
124+
let vars = Self::find_ovmf_file(OvmfFileType::Vars);
125+
let shell = Self::find_ovmf_file(OvmfFileType::Shell);
126126

127-
Ok(Self {
127+
Self {
128128
code,
129129
vars,
130130
shell,
131131
temp_dir: None,
132132
temp_vars: None,
133-
})
133+
}
134134
}
135135

136136
/// Creates a copy with a writable, temp copy
137-
pub fn with_temp_vars(&mut self) -> Result<()> {
138-
let temp_dir = TempDir::new()?;
137+
pub fn with_temp_vars(&mut self) {
138+
let temp_dir = TempDir::new().expect("Failed to create temp directory");
139139
let temp_path = temp_dir.path();
140140

141141
// Make a copy of the OVMF vars file so that it can be used
142142
// read+write without modifying the original. Under AArch64, some
143143
// versions of OVMF won't boot if the vars file isn't writeable.
144144
let ovmf_vars = temp_path.join("ovmf_vars");
145-
fs_err::copy(&self.vars, &ovmf_vars)?;
145+
copy(&self.vars, &ovmf_vars).expect("Failed to copy vars file to a temp location");
146146
// Necessary, as for example on NixOS, the files are read-only inside
147147
// the Nix store.
148148
#[cfg(target_os = "linux")]
149-
fs_err::set_permissions(&ovmf_vars, Permissions::from_mode(0o666))?;
149+
set_permissions(&ovmf_vars, Permissions::from_mode(0o666))
150+
.expect("Failed to set permissions on temp vars file");
150151

151152
self.temp_vars = Some(ovmf_vars);
152153
self.temp_dir = Some(temp_dir);
153-
Ok(())
154154
}
155155
}
156156

157157
/// Update the local copy of the prebuilt OVMF files. Does nothing if the local
158158
/// copy is already up to date.
159-
fn update_prebuilt() -> Result<PathBuf> {
159+
fn update_prebuilt() -> PathBuf {
160160
let prebuilt_dir = Path::new(OVMF_PREBUILT_DIR);
161161
let hash_path = prebuilt_dir.join("sha256");
162162

163163
// Check if the hash file already has the expected hash in it. If so, assume
164164
// that we've already got the correct prebuilt downloaded and unpacked.
165-
if let Ok(current_hash) = fs_err::read_to_string(&hash_path) {
165+
if let Ok(current_hash) = read_to_string(&hash_path) {
166166
if current_hash == OVMF_PREBUILT_HASH {
167-
return Ok(prebuilt_dir.to_path_buf());
167+
return prebuilt_dir.to_path_buf();
168168
}
169169
}
170170

@@ -174,12 +174,12 @@ fn update_prebuilt() -> Result<PathBuf> {
174174
release = OVMF_PREBUILT_TAG
175175
);
176176

177-
let data = download_url(&url)?;
177+
let data = download_url(&url);
178178

179179
// Validate the hash.
180180
let actual_hash = format!("{:x}", Sha256::digest(&data));
181181
if actual_hash != OVMF_PREBUILT_HASH {
182-
bail!(
182+
panic!(
183183
"file hash {actual_hash} does not match {}",
184184
OVMF_PREBUILT_HASH
185185
);
@@ -189,27 +189,29 @@ fn update_prebuilt() -> Result<PathBuf> {
189189
println!("decompressing tarball");
190190
let mut decompressed = Vec::new();
191191
let mut compressed = Cursor::new(data);
192-
lzma_rs::xz_decompress(&mut compressed, &mut decompressed)?;
192+
lzma_rs::xz_decompress(&mut compressed, &mut decompressed)
193+
.expect("Failed to decompress tarball");
193194

194195
// Clear out the existing prebuilt dir, if present.
195-
let _ = fs_err::remove_dir_all(prebuilt_dir);
196+
let _ = remove_dir_all(prebuilt_dir);
196197

197198
// Extract the files.
198-
extract_prebuilt(&decompressed, prebuilt_dir)?;
199+
extract_prebuilt(&decompressed, prebuilt_dir);
199200

200201
// Rename the x64 directory to x86_64, to match `Arch::as_str`.
201-
fs_err::rename(prebuilt_dir.join("x64"), prebuilt_dir.join("x86_64"))?;
202+
rename(prebuilt_dir.join("x64"), prebuilt_dir.join("x86_64"))
203+
.expect("Failed to rename x64 artefacts");
202204

203205
// Write out the hash file. When we upgrade to a new release of
204206
// ovmf-prebuilt, the hash will no longer match, triggering a fresh
205207
// download.
206-
fs_err::write(&hash_path, actual_hash)?;
208+
write(&hash_path, actual_hash).expect("Failed to save calculated hash");
207209

208-
Ok(prebuilt_dir.to_path_buf())
210+
prebuilt_dir.to_path_buf()
209211
}
210212

211213
/// Download `url` and return the raw data.
212-
fn download_url(url: &str) -> Result<Vec<u8>> {
214+
fn download_url(url: &str) -> Vec<u8> {
213215
let agent: Agent = ureq::AgentBuilder::new()
214216
.user_agent("uefi-rs-ovmf-downloader")
215217
.build();
@@ -219,43 +221,42 @@ fn download_url(url: &str) -> Result<Vec<u8>> {
219221

220222
// Download the file.
221223
println!("downloading {url}");
222-
let resp = agent.get(url).call()?;
224+
let resp = agent.get(url).call().unwrap();
223225
let mut data = Vec::with_capacity(max_size_in_bytes);
224226
resp.into_reader()
225227
.take(max_size_in_bytes.try_into().unwrap())
226-
.read_to_end(&mut data)?;
228+
.read_to_end(&mut data)
229+
.unwrap();
227230
println!("received {} bytes", data.len());
228231

229-
Ok(data)
232+
data
230233
}
231234

232235
// Extract the tarball's files into `prebuilt_dir`.
233236
//
234237
// `tarball_data` is raw decompressed tar data.
235-
fn extract_prebuilt(tarball_data: &[u8], prebuilt_dir: &Path) -> Result<()> {
238+
fn extract_prebuilt(tarball_data: &[u8], prebuilt_dir: &Path) {
236239
let cursor = Cursor::new(tarball_data);
237240
let mut archive = Archive::new(cursor);
238241

239242
// Extract each file entry.
240-
for entry in archive.entries()? {
241-
let mut entry = entry?;
243+
for entry in archive.entries().unwrap() {
244+
let mut entry = entry.unwrap();
242245

243246
// Skip directories.
244247
if entry.size() == 0 {
245248
continue;
246249
}
247250

248-
let path = entry.path()?;
251+
let path = entry.path().unwrap();
249252
// Strip the leading directory, which is the release name.
250253
let path: PathBuf = path.components().skip(1).collect();
251254

252255
let dir = path.parent().unwrap();
253256
let dst_dir = prebuilt_dir.join(dir);
254257
let dst_path = prebuilt_dir.join(path);
255258
println!("unpacking to {}", dst_path.display());
256-
fs_err::create_dir_all(dst_dir)?;
257-
entry.unpack(dst_path)?;
259+
create_dir_all(dst_dir).unwrap();
260+
entry.unpack(dst_path).unwrap();
258261
}
259-
260-
Ok(())
261262
}

0 commit comments

Comments
 (0)