Skip to content

Commit e13d86b

Browse files
committed
[cov] Wait for coverage reports in rescue tests
In some rescue tests, the tests will exit before the coverage report is received. This change adds a wait for coverage report in the rescue tests when the `ot_coverage_enabled` feature is enabled. Change-Id: I523b49c6d78bd842c4a3195ff4493eb1afd827ff Signed-off-by: Yi-Hsuan Deng <[email protected]>
1 parent 35d271d commit e13d86b

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

sw/host/opentitanlib/src/rescue/serial.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ impl Rescue for RescueSerial {
151151

152152
fn reboot(&self) -> Result<()> {
153153
self.set_mode(Self::REBOOT)?;
154+
#[cfg(feature = "ot_coverage_enabled")]
155+
UartConsole::wait_for_coverage(&*self.uart, Self::ONE_SECOND)?;
154156
Ok(())
155157
}
156158

sw/host/tests/rescue/rescue_test.rs

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ use opentitanlib::test_utils::init::InitializeTest;
2424
use opentitanlib::uart::console::UartConsole;
2525
use opentitanlib::util::file::FromReader;
2626

27+
#[cfg(feature = "ot_coverage_enabled")]
28+
use opentitanlib::transport::Capability;
29+
2730
#[derive(Debug, Parser)]
2831
struct Opts {
2932
#[command(flatten)]
@@ -86,6 +89,17 @@ fn get_device_id_test(
8689
let rescue = params.create(transport)?;
8790
rescue.enter(transport, EntryMode::Reset)?;
8891
let actual_device_id_from_rescue = rescue.get_device_id()?;
92+
#[cfg(feature = "ot_coverage_enabled")]
93+
{
94+
rescue.reboot()?;
95+
96+
if params.protocol != RescueProtocol::Xmodem {
97+
let uart = transport.uart("console")?;
98+
UartConsole::wait_for(&*uart, r"rescue ready", Duration::from_secs(5))?;
99+
UartConsole::wait_for_coverage(&*uart, Duration::from_secs(5))?;
100+
}
101+
}
102+
89103
let mut actual_id_bytes = Vec::new();
90104
actual_device_id_from_rescue.write(&mut actual_id_bytes)?;
91105
// Reverse the entire byte sequence to match the expected hex string format.
@@ -129,6 +143,18 @@ fn get_boot_log_test(
129143
let boot_log = rescue
130144
.get_boot_log()
131145
.context("Failed to get boot log from rescue")?;
146+
147+
#[cfg(feature = "ot_coverage_enabled")]
148+
{
149+
rescue.reboot()?;
150+
151+
if params.protocol != RescueProtocol::Xmodem {
152+
let uart = transport.uart("console")?;
153+
UartConsole::wait_for(&*uart, r"rescue ready", Duration::from_secs(5))?;
154+
UartConsole::wait_for_coverage(&*uart, Duration::from_secs(5))?;
155+
}
156+
}
157+
132158
let rom_ext_manifest = image
133159
.subimages()?
134160
.first()
@@ -188,6 +214,17 @@ fn get_owner_page_test(
188214
.get_raw(RescueMode::GetOwnerPage0)
189215
.context("Failed to get owner page from rescue")?;
190216

217+
#[cfg(feature = "ot_coverage_enabled")]
218+
{
219+
rescue.reboot()?;
220+
221+
if params.protocol != RescueProtocol::Xmodem {
222+
let uart = transport.uart("console")?;
223+
UartConsole::wait_for(&*uart, r"rescue ready", Duration::from_secs(5))?;
224+
UartConsole::wait_for_coverage(&*uart, Duration::from_secs(5))?;
225+
}
226+
}
227+
191228
let mut cursor = std::io::Cursor::new(&data);
192229
let header = TlvHeader::read(&mut cursor)?;
193230
let owner_block_from_rescue = OwnerBlock::read(&mut cursor, header)?;
@@ -215,7 +252,7 @@ fn load_owner_block(
215252
let capture = UartConsole::wait_for(
216253
&*uart,
217254
r"(?msR)OWNER_PAGE_0: (.*?)\r\n",
218-
Duration::from_secs(1),
255+
Duration::from_secs(5),
219256
)?;
220257
if capture.len() < 2 {
221258
return Err(anyhow!(
@@ -256,11 +293,10 @@ where
256293
}
257294

258295
macro_rules! expect_disallowed_cmd {
259-
($command_allow_list:expr, $command_tag:expr, $operation:expr, $reset:expr, $expected_err_str:expr $(,)?) => {
296+
($command_allow_list:expr, $command_tag:expr, $operation:expr, $expected_err_str:expr $(,)?) => {
260297
if !$command_allow_list.contains(&$command_tag) {
261298
log::info!("Testing disallowed command: {}", $command_tag,);
262299
expect_err_from_rescue_result($operation, $expected_err_str)?;
263-
($reset)?;
264300
}
265301
};
266302
}
@@ -318,39 +354,34 @@ fn disability_test(
318354
config.command_allow,
319355
CommandTag::Rescue,
320356
rescue.update_firmware(BootSlot::SlotA, &DUMMY_BYTES),
321-
rescue.enter(transport, EntryMode::Reset),
322357
&get_expected_err_msg(CommandTag::Rescue, params)
323358
);
324359

325360
expect_disallowed_cmd!(
326361
config.command_allow,
327362
CommandTag::RescueB,
328363
rescue.update_firmware(BootSlot::SlotB, &DUMMY_BYTES),
329-
rescue.enter(transport, EntryMode::Reset),
330364
&get_expected_err_msg(CommandTag::RescueB, params)
331365
);
332366

333367
expect_disallowed_cmd!(
334368
config.command_allow,
335369
CommandTag::GetDeviceId,
336370
rescue.get_device_id(),
337-
rescue.enter(transport, EntryMode::Reset),
338371
&get_expected_err_msg(CommandTag::GetDeviceId, params)
339372
);
340373

341374
expect_disallowed_cmd!(
342375
config.command_allow,
343376
CommandTag::GetBootLog,
344377
rescue.get_boot_log(),
345-
rescue.enter(transport, EntryMode::Reset),
346378
&get_expected_err_msg(CommandTag::GetBootLog, params)
347379
);
348380

349381
expect_disallowed_cmd!(
350382
config.command_allow,
351383
CommandTag::GetOwnerPage0,
352384
rescue.get_raw(RescueMode::GetOwnerPage0),
353-
rescue.enter(transport, EntryMode::Reset),
354385
&get_expected_err_msg(CommandTag::GetOwnerPage0, params)
355386
);
356387

@@ -360,7 +391,6 @@ fn disability_test(
360391
config.command_allow,
361392
CommandTag::GetOwnerPage1,
362393
rescue.get_raw(RescueMode::GetOwnerPage1),
363-
rescue.enter(transport, EntryMode::Reset),
364394
&get_expected_err_msg(CommandTag::GetOwnerPage1, params)
365395
);
366396
}
@@ -383,7 +413,6 @@ fn disability_test(
383413
config.command_allow,
384414
CommandTag::Empty,
385415
rescue.empty(DUMMY_PAYLOAD.as_ref()),
386-
rescue.enter(transport, EntryMode::Reset),
387416
&boot_svc_req_sub_cmd_err_msg,
388417
);
389418

@@ -392,42 +421,50 @@ fn disability_test(
392421
config.command_allow,
393422
CommandTag::MinBl0SecVerRequest,
394423
rescue.set_min_bl0_sec_ver(NEW_BL0_VER),
395-
rescue.enter(transport, EntryMode::Reset),
396424
&boot_svc_req_sub_cmd_err_msg,
397425
);
398426

399427
expect_disallowed_cmd!(
400428
config.command_allow,
401429
CommandTag::NextBl0SlotRequest,
402430
rescue.set_next_bl0_slot(BootSlot::SlotA, BootSlot::SlotA),
403-
rescue.enter(transport, EntryMode::Reset),
404431
&boot_svc_req_sub_cmd_err_msg,
405432
);
406433

407434
expect_disallowed_cmd!(
408435
config.command_allow,
409436
CommandTag::OwnershipUnlockRequest,
410437
rescue.ownership_unlock(OwnershipUnlockRequest::default()),
411-
rescue.enter(transport, EntryMode::Reset),
412438
&boot_svc_req_sub_cmd_err_msg,
413439
);
414440

415441
expect_disallowed_cmd!(
416442
config.command_allow,
417443
CommandTag::OwnershipActivateRequest,
418444
rescue.ownership_activate(OwnershipActivateRequest::default()),
419-
rescue.enter(transport, EntryMode::Reset),
420445
&boot_svc_req_sub_cmd_err_msg,
421446
);
422447

423448
expect_disallowed_cmd!(
424449
config.command_allow,
425450
CommandTag::BootSvcRsp,
426451
rescue.get_boot_svc(),
427-
rescue.enter(transport, EntryMode::Reset),
428452
&get_expected_err_msg(CommandTag::BootSvcRsp, params)
429453
);
430454

455+
#[cfg(feature = "ot_coverage_enabled")]
456+
{
457+
rescue.reboot()?;
458+
if params.protocol != RescueProtocol::Xmodem {
459+
transport.capabilities()?.request(Capability::UART).ok()?;
460+
let uart = transport
461+
.uart("console")
462+
.expect("Failed to init Uart console");
463+
UartConsole::wait_for(&*uart, r"Finished", Duration::from_secs(5))?;
464+
UartConsole::wait_for_coverage(&*uart, Duration::from_secs(5))?;
465+
}
466+
}
467+
431468
Ok(())
432469
}
433470
}

0 commit comments

Comments
 (0)