mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
flashrom_tester: Write a newline with the wp prompt
Write a newline after the hardware write protect prompt. Automated tests read stdout and wait for this message, and split on newline, so write a newline. Also modify the function to not be recursive. Try to handle a closed input correctly - panicing in that case. Behaviour is now to wait for a newline instead of for 1 character. BUG=b:240512896 BRANCH=None TEST=tast run localhost:2222 firmware.FlashromTester TEST=flashrom_tester < /dev/null TEST=flashrom_tester; type some things, hold enter, then close stdin Change-Id: I07ec242ca0d41787030d5d27fc88d78ed884d746 Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/flashrom/+/3809595 Reviewed-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66587 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
parent
cd4a62a784
commit
41d0de0ad8
@ -103,17 +103,17 @@ pub fn toggle_hw_wp(dis: bool) -> Result<(), String> {
|
|||||||
// The easist way to toggle the hardware write-protect is
|
// The easist way to toggle the hardware write-protect is
|
||||||
// to {dis}connect the battery (and/or open the WP screw).
|
// to {dis}connect the battery (and/or open the WP screw).
|
||||||
let s = if dis { "dis" } else { "" };
|
let s = if dis { "dis" } else { "" };
|
||||||
info!("Prompt for hardware WP {}able", s);
|
// Print a failure message, but not on the first try.
|
||||||
eprintln!(" > {}connect the battery (and/or open the WP screw)", s);
|
let mut fail_msg = None;
|
||||||
pause();
|
while dis == get_hardware_wp()? {
|
||||||
let wp = get_hardware_wp()?;
|
if let Some(msg) = fail_msg {
|
||||||
if wp && dis {
|
eprintln!("{msg}");
|
||||||
eprintln!("Hardware write protect is still ENABLED!");
|
}
|
||||||
return toggle_hw_wp(dis);
|
fail_msg = Some(format!("Hardware write protect is still {}!", !dis));
|
||||||
}
|
// The following message is read by the tast test. Do not modify.
|
||||||
if !wp && !dis {
|
info!("Prompt for hardware WP {}able", s);
|
||||||
eprintln!("Hardware write protect is still DISABLED!");
|
eprintln!(" > {}connect the battery (and/or open the WP screw)", s);
|
||||||
return toggle_hw_wp(dis);
|
pause();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -126,12 +126,16 @@ pub fn ac_power_warning() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn pause() {
|
fn pause() {
|
||||||
let mut stdout = std::io::stdout();
|
// The following message is read by the tast test. Do not modify.
|
||||||
// We want the cursor to stay at the end of the line, so we print without a newline
|
println!("Press enter to continue...");
|
||||||
// and flush manually.
|
// Rust stdout is always LineBuffered at time of writing.
|
||||||
stdout.write(b"Press any key to continue...").unwrap();
|
// But this is not guaranteed, so flush anyway.
|
||||||
stdout.flush().unwrap();
|
std::io::stdout().flush().unwrap();
|
||||||
std::io::stdin().read(&mut [0]).unwrap();
|
// This reads one line, there is no guarantee the line came
|
||||||
|
// after the above prompt. But it is good enough.
|
||||||
|
if std::io::stdin().read_line(&mut String::new()).unwrap() == 0 {
|
||||||
|
panic!("stdin closed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_hardware_wp() -> std::result::Result<bool, String> {
|
pub fn get_hardware_wp() -> std::result::Result<bool, String> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user