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
|
||||
// to {dis}connect the battery (and/or open the WP screw).
|
||||
let s = if dis { "dis" } else { "" };
|
||||
info!("Prompt for hardware WP {}able", s);
|
||||
eprintln!(" > {}connect the battery (and/or open the WP screw)", s);
|
||||
pause();
|
||||
let wp = get_hardware_wp()?;
|
||||
if wp && dis {
|
||||
eprintln!("Hardware write protect is still ENABLED!");
|
||||
return toggle_hw_wp(dis);
|
||||
}
|
||||
if !wp && !dis {
|
||||
eprintln!("Hardware write protect is still DISABLED!");
|
||||
return toggle_hw_wp(dis);
|
||||
// Print a failure message, but not on the first try.
|
||||
let mut fail_msg = None;
|
||||
while dis == get_hardware_wp()? {
|
||||
if let Some(msg) = fail_msg {
|
||||
eprintln!("{msg}");
|
||||
}
|
||||
fail_msg = Some(format!("Hardware write protect is still {}!", !dis));
|
||||
// The following message is read by the tast test. Do not modify.
|
||||
info!("Prompt for hardware WP {}able", s);
|
||||
eprintln!(" > {}connect the battery (and/or open the WP screw)", s);
|
||||
pause();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -126,12 +126,16 @@ pub fn ac_power_warning() {
|
||||
}
|
||||
|
||||
fn pause() {
|
||||
let mut stdout = std::io::stdout();
|
||||
// We want the cursor to stay at the end of the line, so we print without a newline
|
||||
// and flush manually.
|
||||
stdout.write(b"Press any key to continue...").unwrap();
|
||||
stdout.flush().unwrap();
|
||||
std::io::stdin().read(&mut [0]).unwrap();
|
||||
// The following message is read by the tast test. Do not modify.
|
||||
println!("Press enter to continue...");
|
||||
// Rust stdout is always LineBuffered at time of writing.
|
||||
// But this is not guaranteed, so flush anyway.
|
||||
std::io::stdout().flush().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> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user