diff options
author | Evan Benn <evanbenn@chromium.org> | 2022-07-28 15:38:36 +1000 |
---|---|---|
committer | Edward O'Callaghan <quasisec@chromium.org> | 2022-08-18 03:49:35 +0000 |
commit | 41d0de0ad81e98fe9e9500bd71e6c0bfbef1b5b9 (patch) | |
tree | 324e7757a341f0f2f965b653649e5c6d70e2094e /util | |
parent | cd4a62a7841ab794b654554778399fbc76933344 (diff) | |
download | flashrom-41d0de0ad81e98fe9e9500bd71e6c0bfbef1b5b9.tar.gz flashrom-41d0de0ad81e98fe9e9500bd71e6c0bfbef1b5b9.tar.bz2 flashrom-41d0de0ad81e98fe9e9500bd71e6c0bfbef1b5b9.zip |
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>
Diffstat (limited to 'util')
-rw-r--r-- | util/flashrom_tester/src/utils.rs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/util/flashrom_tester/src/utils.rs b/util/flashrom_tester/src/utils.rs index 5a932a060..717e103ea 100644 --- a/util/flashrom_tester/src/utils.rs +++ b/util/flashrom_tester/src/utils.rs @@ -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> { |