mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
flashrom_tester: Fix cargo check and clippy warnings
Change-Id: I50c5af61e06df1bb6956f347cb6806a7eca6ce0e Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67472 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Peter Marheine <pmarheine@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
parent
813c68ad9c
commit
1f65e9029b
@ -67,7 +67,7 @@ pub struct IOOpt<'a> {
|
|||||||
pub region: Option<(&'a str, &'a str)>, // --image
|
pub region: Option<(&'a str, &'a str)>, // --image
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct FlashromCmd {
|
pub struct FlashromCmd {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub fc: FlashChip,
|
pub fc: FlashChip,
|
||||||
@ -84,9 +84,9 @@ fn flashrom_extract_size(stdout: &str) -> Result<i64, FlashromError> {
|
|||||||
.last()
|
.last()
|
||||||
.map(str::parse::<i64>)
|
.map(str::parse::<i64>)
|
||||||
{
|
{
|
||||||
None => return Err("Found no purely-numeric lines in flashrom output".into()),
|
None => Err("Found no purely-numeric lines in flashrom output".into()),
|
||||||
Some(Err(e)) => {
|
Some(Err(e)) => {
|
||||||
return Err(format!("Failed to parse flashrom size output as integer: {}", e).into())
|
Err(format!("Failed to parse flashrom size output as integer: {}", e).into())
|
||||||
}
|
}
|
||||||
Some(Ok(sz)) => Ok(sz),
|
Some(Ok(sz)) => Ok(sz),
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ impl crate::Flashrom for FlashromCmd {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (stdout, _) = self.dispatch(opts, "wp_list")?;
|
let (stdout, _) = self.dispatch(opts, "wp_list")?;
|
||||||
if stdout.len() == 0 {
|
if stdout.is_empty() {
|
||||||
return Err(
|
return Err(
|
||||||
"wp_list isn't supported on platforms using the Linux kernel SPI driver wp_list"
|
"wp_list isn't supported on platforms using the Linux kernel SPI driver wp_list"
|
||||||
.into(),
|
.into(),
|
||||||
@ -208,7 +208,7 @@ impl crate::Flashrom for FlashromCmd {
|
|||||||
|
|
||||||
let opts = FlashromOpt {
|
let opts = FlashromOpt {
|
||||||
wp_opt: WPOpt {
|
wp_opt: WPOpt {
|
||||||
range: range,
|
range,
|
||||||
enable: en,
|
enable: en,
|
||||||
disable: !en,
|
disable: !en,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -249,7 +249,7 @@ impl crate::Flashrom for FlashromCmd {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (stdout, _) = self.dispatch(opts, "read_region_into_file")?;
|
self.dispatch(opts, "read_region_into_file")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,11 +405,6 @@ pub fn dut_ctrl_toggle_wp(en: bool) -> Result<(Vec<u8>, Vec<u8>), FlashromError>
|
|||||||
dut_ctrl(&args)
|
dut_ctrl(&args)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dut_ctrl_servo_type() -> Result<(Vec<u8>, Vec<u8>), FlashromError> {
|
|
||||||
let args = ["servo_type"];
|
|
||||||
dut_ctrl(&args)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dut_ctrl(args: &[&str]) -> Result<(Vec<u8>, Vec<u8>), FlashromError> {
|
fn dut_ctrl(args: &[&str]) -> Result<(Vec<u8>, Vec<u8>), FlashromError> {
|
||||||
let output = match Command::new("dut-control").args(args).output() {
|
let output = match Command::new("dut-control").args(args).output() {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
@ -431,7 +426,7 @@ fn dut_ctrl(args: &[&str]) -> Result<(Vec<u8>, Vec<u8>), FlashromError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn hex_range_string(s: i64, l: i64) -> String {
|
fn hex_range_string(s: i64, l: i64) -> String {
|
||||||
format!("{:#08X},{:#08X}", s, l).to_string()
|
format!("{:#08X},{:#08X}", s, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a flash vendor and name from the first matching line of flashrom output.
|
/// Get a flash vendor and name from the first matching line of flashrom output.
|
||||||
|
@ -49,7 +49,7 @@ pub use libflashrom::{
|
|||||||
FLASHROM_MSG_INFO, FLASHROM_MSG_SPEW, FLASHROM_MSG_WARN,
|
FLASHROM_MSG_INFO, FLASHROM_MSG_SPEW, FLASHROM_MSG_WARN,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum FlashChip {
|
pub enum FlashChip {
|
||||||
EC,
|
EC,
|
||||||
HOST,
|
HOST,
|
||||||
@ -59,23 +59,21 @@ pub enum FlashChip {
|
|||||||
|
|
||||||
impl FlashChip {
|
impl FlashChip {
|
||||||
pub fn from(s: &str) -> Result<FlashChip, &str> {
|
pub fn from(s: &str) -> Result<FlashChip, &str> {
|
||||||
let r = match s {
|
match s {
|
||||||
"ec" => Ok(FlashChip::EC),
|
"ec" => Ok(FlashChip::EC),
|
||||||
"host" => Ok(FlashChip::HOST),
|
"host" => Ok(FlashChip::HOST),
|
||||||
"servo" => Ok(FlashChip::SERVO),
|
"servo" => Ok(FlashChip::SERVO),
|
||||||
"dediprog" => Ok(FlashChip::DEDIPROG),
|
"dediprog" => Ok(FlashChip::DEDIPROG),
|
||||||
_ => Err("cannot convert str to enum"),
|
_ => Err("cannot convert str to enum"),
|
||||||
};
|
}
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
pub fn to(fc: FlashChip) -> &'static str {
|
pub fn to(fc: FlashChip) -> &'static str {
|
||||||
let r = match fc {
|
match fc {
|
||||||
FlashChip::EC => "ec",
|
FlashChip::EC => "ec",
|
||||||
FlashChip::HOST => "host",
|
FlashChip::HOST => "host",
|
||||||
FlashChip::SERVO => "ft2231_spi:type=servo-v2",
|
FlashChip::SERVO => "ft2231_spi:type=servo-v2",
|
||||||
FlashChip::DEDIPROG => "dediprog",
|
FlashChip::DEDIPROG => "dediprog",
|
||||||
};
|
}
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the programmer string and optional programmer options
|
/// Return the programmer string and optional programmer options
|
||||||
@ -97,7 +95,7 @@ impl FlashChip {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct FlashromError {
|
pub struct FlashromError {
|
||||||
msg: String,
|
msg: String,
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fmt::Debug;
|
|
||||||
use std::io::Result as IoResult;
|
use std::io::Result as IoResult;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ mod tests {
|
|||||||
|
|
||||||
for record in records {
|
for record in records {
|
||||||
if logger.enabled(record.metadata()) {
|
if logger.enabled(record.metadata()) {
|
||||||
logger.log(&record);
|
logger.log(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,9 +42,7 @@ use rand::prelude::*;
|
|||||||
pub fn gen_rand_testdata(path: &str, size: usize) -> std::io::Result<()> {
|
pub fn gen_rand_testdata(path: &str, size: usize) -> std::io::Result<()> {
|
||||||
let mut buf = BufWriter::new(File::create(path)?);
|
let mut buf = BufWriter::new(File::create(path)?);
|
||||||
|
|
||||||
let mut a: Vec<u8> = Vec::with_capacity(size);
|
let mut a: Vec<u8> = vec![0; size];
|
||||||
// Pad out array to be filled in by Rng::fill().
|
|
||||||
a.resize(size, 0b0);
|
|
||||||
thread_rng().fill(a.as_mut_slice());
|
thread_rng().fill(a.as_mut_slice());
|
||||||
|
|
||||||
buf.write_all(a.as_slice())?;
|
buf.write_all(a.as_slice())?;
|
||||||
|
@ -69,8 +69,8 @@ impl<'a> TestEnv<'a> {
|
|||||||
pub fn create(chip_type: FlashChip, cmd: &'a dyn Flashrom) -> Result<Self, FlashromError> {
|
pub fn create(chip_type: FlashChip, cmd: &'a dyn Flashrom) -> Result<Self, FlashromError> {
|
||||||
let rom_sz = cmd.get_size()?;
|
let rom_sz = cmd.get_size()?;
|
||||||
let out = TestEnv {
|
let out = TestEnv {
|
||||||
chip_type: chip_type,
|
chip_type,
|
||||||
cmd: cmd,
|
cmd,
|
||||||
layout: utils::get_layout_sizes(rom_sz)?,
|
layout: utils::get_layout_sizes(rom_sz)?,
|
||||||
wp: WriteProtectState::from_hardware(cmd, chip_type)?,
|
wp: WriteProtectState::from_hardware(cmd, chip_type)?,
|
||||||
original_flash_contents: "/tmp/flashrom_tester_golden.bin".into(),
|
original_flash_contents: "/tmp/flashrom_tester_golden.bin".into(),
|
||||||
@ -462,7 +462,7 @@ impl<T: TestCase + ?Sized> TestCase for &T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum TestConclusion {
|
pub enum TestConclusion {
|
||||||
Pass,
|
Pass,
|
||||||
Fail,
|
Fail,
|
||||||
@ -514,7 +514,7 @@ where
|
|||||||
results
|
results
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum OutputFormat {
|
pub enum OutputFormat {
|
||||||
Pretty,
|
Pretty,
|
||||||
Json,
|
Json,
|
||||||
|
@ -43,8 +43,8 @@ use std::fs::{self, File};
|
|||||||
use std::io::{BufRead, Write};
|
use std::io::{BufRead, Write};
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
|
|
||||||
const LAYOUT_FILE: &'static str = "/tmp/layout.file";
|
const LAYOUT_FILE: &str = "/tmp/layout.file";
|
||||||
const ELOG_FILE: &'static str = "/tmp/elog.file";
|
const ELOG_FILE: &str = "/tmp/elog.file";
|
||||||
|
|
||||||
/// Iterate over tests, yielding only those tests with names matching filter_names.
|
/// Iterate over tests, yielding only those tests with names matching filter_names.
|
||||||
///
|
///
|
||||||
@ -79,6 +79,7 @@ fn filter_tests<'n, 't: 'n, T: TestCase>(
|
|||||||
/// test_names is the case-insensitive names of tests to run; if None, then all
|
/// test_names is the case-insensitive names of tests to run; if None, then all
|
||||||
/// tests are run. Provided names that don't match any known test will be logged
|
/// tests are run. Provided names that don't match any known test will be logged
|
||||||
/// as a warning.
|
/// as a warning.
|
||||||
|
#[allow(clippy::or_fun_call)] // This is used for to_string here and we don't care.
|
||||||
pub fn generic<'a, TN: Iterator<Item = &'a str>>(
|
pub fn generic<'a, TN: Iterator<Item = &'a str>>(
|
||||||
cmd: &dyn Flashrom,
|
cmd: &dyn Flashrom,
|
||||||
fc: FlashChip,
|
fc: FlashChip,
|
||||||
@ -132,11 +133,8 @@ pub fn generic<'a, TN: Iterator<Item = &'a str>>(
|
|||||||
|
|
||||||
// Limit the tests to only those requested, unless none are requested
|
// Limit the tests to only those requested, unless none are requested
|
||||||
// in which case all tests are included.
|
// in which case all tests are included.
|
||||||
let mut filter_names: Option<HashSet<String>> = if let Some(names) = test_names {
|
let mut filter_names: Option<HashSet<String>> =
|
||||||
Some(names.map(|s| s.to_lowercase()).collect())
|
test_names.map(|names| names.map(|s| s.to_lowercase()).collect());
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
let tests = filter_tests(tests, &mut filter_names);
|
let tests = filter_tests(tests, &mut filter_names);
|
||||||
|
|
||||||
let chip_name = cmd
|
let chip_name = cmd
|
||||||
@ -153,15 +151,15 @@ pub fn generic<'a, TN: Iterator<Item = &'a str>>(
|
|||||||
warn!("No test matches filter name \"{}\"", leftover);
|
warn!("No test matches filter name \"{}\"", leftover);
|
||||||
}
|
}
|
||||||
|
|
||||||
let os_rel = sys_info::os_release().unwrap_or("<Unknown OS>".to_string());
|
let os_release = sys_info::os_release().unwrap_or("<Unknown OS>".to_string());
|
||||||
let system_info = cros_sysinfo::system_info().unwrap_or("<Unknown System>".to_string());
|
let system_info = cros_sysinfo::system_info().unwrap_or("<Unknown System>".to_string());
|
||||||
let bios_info = cros_sysinfo::bios_info().unwrap_or("<Unknown BIOS>".to_string());
|
let bios_info = cros_sysinfo::bios_info().unwrap_or("<Unknown BIOS>".to_string());
|
||||||
|
|
||||||
let meta_data = tester::ReportMetaData {
|
let meta_data = tester::ReportMetaData {
|
||||||
chip_name: chip_name,
|
chip_name,
|
||||||
os_release: os_rel,
|
os_release,
|
||||||
system_info: system_info,
|
system_info,
|
||||||
bios_info: bios_info,
|
bios_info,
|
||||||
};
|
};
|
||||||
tester::collate_all_test_runs(&results, meta_data, output_format);
|
tester::collate_all_test_runs(&results, meta_data, output_format);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -143,14 +143,14 @@ pub fn get_hardware_wp() -> std::result::Result<bool, String> {
|
|||||||
match wp_s_val {
|
match wp_s_val {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
if v == 1 {
|
if v == 1 {
|
||||||
return Ok(true);
|
Ok(true)
|
||||||
} else if v == 0 {
|
} else if v == 0 {
|
||||||
return Ok(false);
|
Ok(false)
|
||||||
} else {
|
} else {
|
||||||
return Err("Unknown write protect value".into());
|
Err("Unknown write protect value".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => return Err("Cannot parse write protect value".into()),
|
Err(_) => Err("Cannot parse write protect value".into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user