aboutsummaryrefslogtreecommitdiffstats
path: root/util/flashrom_tester/src/tester.rs
diff options
context:
space:
mode:
authorEvan Benn <evanbenn@chromium.org>2022-11-01 11:43:10 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2022-11-09 01:32:24 +0000
commitc726a693d68f4169846811fdc332428b44cf7ab3 (patch)
tree1992d4b0745334218a8cc3d26528d538677f3c93 /util/flashrom_tester/src/tester.rs
parent8170c895689d72f2206169d749b69bd1eff7cebf (diff)
downloadflashrom-c726a693d68f4169846811fdc332428b44cf7ab3.tar.gz
flashrom-c726a693d68f4169846811fdc332428b44cf7ab3.tar.bz2
flashrom-c726a693d68f4169846811fdc332428b44cf7ab3.zip
flashrom_tester: Use path types for things that are paths
Use Path and PathBuf for things that are paths. BUG=b:243460685 BRANCH=None TEST=/usr/bin/flashrom_tester --flashrom_binary /usr/sbin/flashrom host TEST=/usr/bin/flashrom_tester --libflashrom host Change-Id: I69531bec5436a60430eae975eeab02c8835962bf Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69064 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'util/flashrom_tester/src/tester.rs')
-rw-r--r--util/flashrom_tester/src/tester.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/util/flashrom_tester/src/tester.rs b/util/flashrom_tester/src/tester.rs
index 292fb78c..6ce3889e 100644
--- a/util/flashrom_tester/src/tester.rs
+++ b/util/flashrom_tester/src/tester.rs
@@ -42,6 +42,8 @@ use serde_json::json;
use std::fs::File;
use std::io::Write;
use std::mem::MaybeUninit;
+use std::path::Path;
+use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Mutex;
@@ -60,13 +62,11 @@ pub struct TestEnv<'a> {
pub wp: WriteProtectState<'a, 'static>,
/// The path to a file containing the flash contents at test start.
- // TODO(pmarheine) migrate this to a PathBuf for clarity
- original_flash_contents: String,
+ original_flash_contents: PathBuf,
/// The path to a file containing flash-sized random data
- // TODO(pmarheine) make this a PathBuf too
- random_data: String,
+ random_data: PathBuf,
/// The path to a file containing layout data.
- pub layout_file: String,
+ pub layout_file: PathBuf,
}
impl<'a> TestEnv<'a> {
@@ -83,7 +83,7 @@ impl<'a> TestEnv<'a> {
wp: WriteProtectState::from_hardware(cmd, chip_type)?,
original_flash_contents: "/tmp/flashrom_tester_golden.bin".into(),
random_data: "/tmp/random_content.bin".into(),
- layout_file: create_layout_file(rom_sz, "/tmp/", print_layout),
+ layout_file: create_layout_file(rom_sz, Path::new("/tmp/"), print_layout),
};
info!("Stashing golden image for verification/recovery on completion");
@@ -122,7 +122,7 @@ impl<'a> TestEnv<'a> {
/// Return the path to a file that contains random data and is the same size
/// as the flash chip.
- pub fn random_data_file(&self) -> &str {
+ pub fn random_data_file(&self) -> &Path {
&self.random_data
}
@@ -156,7 +156,7 @@ impl<'a> TestEnv<'a> {
/// path.
///
/// Returns Err if they are not the same.
- pub fn verify(&self, contents_path: &str) -> Result<(), FlashromError> {
+ pub fn verify(&self, contents_path: &Path) -> Result<(), FlashromError> {
self.cmd.verify_from_file(contents_path)?;
Ok(())
}
@@ -496,12 +496,11 @@ fn decode_test_result(res: TestResult, con: TestConclusion) -> (TestConclusion,
}
}
-fn create_layout_file(rom_sz: i64, tmp_dir: &str, print_layout: bool) -> String {
+fn create_layout_file(rom_sz: i64, tmp_dir: &Path, print_layout: bool) -> PathBuf {
info!("Calculate ROM partition sizes & Create the layout file.");
let layout_sizes = utils::get_layout_sizes(rom_sz).expect("Could not partition rom");
- let mut layout_file = tmp_dir.to_string();
- layout_file.push_str("/layout.file");
+ let layout_file = tmp_dir.join("layout.file");
let mut f = File::create(&layout_file).expect("Could not create layout file");
let mut buf: Vec<u8> = vec![];
utils::construct_layout_file(&mut buf, &layout_sizes).expect("Could not construct layout file");