diff options
| author | Evan Benn <evanbenn@chromium.org> | 2022-11-01 11:43:10 +1100 | 
|---|---|---|
| committer | Edward O'Callaghan <quasisec@chromium.org> | 2022-11-09 01:32:24 +0000 | 
| commit | c726a693d68f4169846811fdc332428b44cf7ab3 (patch) | |
| tree | 1992d4b0745334218a8cc3d26528d538677f3c93 /util/flashrom_tester/src | |
| parent | 8170c895689d72f2206169d749b69bd1eff7cebf (diff) | |
| download | flashrom-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')
| -rw-r--r-- | util/flashrom_tester/src/rand_util.rs | 7 | ||||
| -rw-r--r-- | util/flashrom_tester/src/tester.rs | 21 | ||||
| -rw-r--r-- | util/flashrom_tester/src/tests.rs | 2 | 
3 files changed, 15 insertions, 15 deletions
diff --git a/util/flashrom_tester/src/rand_util.rs b/util/flashrom_tester/src/rand_util.rs index 1b0912be..a040c89a 100644 --- a/util/flashrom_tester/src/rand_util.rs +++ b/util/flashrom_tester/src/rand_util.rs @@ -36,10 +36,11 @@  use std::fs::File;  use std::io::prelude::*;  use std::io::BufWriter; +use std::path::Path;  use rand::prelude::*; -pub fn gen_rand_testdata(path: &str, size: usize) -> std::io::Result<()> { +pub fn gen_rand_testdata(path: &Path, size: usize) -> std::io::Result<()> {      let mut buf = BufWriter::new(File::create(path)?);      let mut a: Vec<u8> = vec![0; size]; @@ -58,8 +59,8 @@ mod tests {      fn gen_rand_testdata() {          use super::gen_rand_testdata; -        let path0 = "/tmp/idk_test00"; -        let path1 = "/tmp/idk_test01"; +        let path0 = Path::new("/tmp/idk_test00"); +        let path1 = Path::new("/tmp/idk_test01");          let sz = 1024;          gen_rand_testdata(path0, sz).unwrap(); 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"); diff --git a/util/flashrom_tester/src/tests.rs b/util/flashrom_tester/src/tests.rs index 3e1737e3..af342088 100644 --- a/util/flashrom_tester/src/tests.rs +++ b/util/flashrom_tester/src/tests.rs @@ -224,7 +224,7 @@ fn elog_sanity_test(env: &mut TestEnv) -> TestResult {      const ELOG_RW_REGION_NAME: &str = "RW_ELOG";      env.cmd -        .read_region_into_file(ELOG_FILE, ELOG_RW_REGION_NAME)?; +        .read_region_into_file(ELOG_FILE.as_ref(), ELOG_RW_REGION_NAME)?;      // Just checking for the magic numer      // TODO: improve this test to read the events  | 
