Skip to content

Commit 5535171

Browse files
committed
[tests] Add dual OTTF console test
Signed-off-by: Amaury Pouly <[email protected]> (cherry picked from commit 7b05122)
1 parent 92bfbaf commit 5535171

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

sw/device/tests/BUILD

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4614,6 +4614,30 @@ opentitan_test(
46144614
],
46154615
)
46164616

4617+
opentitan_test(
4618+
name = "ottf_dual_console_test",
4619+
srcs = ["ottf_dual_console_test.c"],
4620+
exec_env = dicts.add(
4621+
{
4622+
"//hw/top_earlgrey:fpga_cw310_sival_rom_ext": None,
4623+
"//hw/top_earlgrey:fpga_cw310_rom_with_fake_keys": None,
4624+
},
4625+
EARLGREY_CW340_TEST_ENVS,
4626+
),
4627+
fpga = fpga_params(
4628+
test_cmd = """
4629+
--bootstrap="{firmware}"
4630+
""",
4631+
test_harness = "//sw/host/tests/chip/ottf_dual_console",
4632+
),
4633+
deps = [
4634+
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
4635+
"//sw/device/lib/runtime:log",
4636+
"//sw/device/lib/testing:uart_testutils",
4637+
"//sw/device/lib/testing/test_framework:ottf_main",
4638+
],
4639+
)
4640+
46174641
opentitan_test(
46184642
name = "sram_ctrl_sleep_sram_ret_contents_no_scramble_test",
46194643
srcs = ["sram_ctrl_sleep_sram_ret_contents_no_scramble_test.c"],
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright lowRISC contributors (OpenTitan project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "sw/device/lib/base/status.h"
6+
#include "sw/device/lib/runtime/log.h"
7+
#include "sw/device/lib/testing/test_framework/check.h"
8+
#include "sw/device/lib/testing/test_framework/ottf_console.h"
9+
#include "sw/device/lib/testing/test_framework/ottf_main.h"
10+
#include "sw/device/lib/testing/uart_testutils.h"
11+
#include "sw/device/lib/ujson/ujson.h"
12+
13+
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
14+
15+
/**
16+
* Tests ...
17+
*/
18+
19+
OTTF_DEFINE_TEST_CONFIG();
20+
21+
static dif_pinmux_t pinmux;
22+
static ottf_console_t debug_console;
23+
24+
bool test_main(void) {
25+
CHECK_DIF_OK(dif_pinmux_init(
26+
mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR), &pinmux));
27+
CHECK_STATUS_OK(uart_testutils_select_pinmux(&pinmux, /* UART */ 1,
28+
kUartPinmuxChannelDut));
29+
ottf_console_configure_uart(&debug_console, TOP_EARLGREY_UART1_BASE_ADDR);
30+
LOG_INFO("Main UART console");
31+
base_fprintf(ottf_console_get_buffer_sink(&debug_console),
32+
"Second UART console\n");
33+
return true;
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
load("@rules_rust//rust:defs.bzl", "rust_binary")
6+
7+
package(default_visibility = ["//visibility:public"])
8+
9+
rust_binary(
10+
name = "ottf_dual_console",
11+
srcs = [
12+
"src/main.rs",
13+
],
14+
deps = [
15+
"//sw/host/opentitanlib",
16+
"//third_party/rust/crates:anyhow",
17+
"//third_party/rust/crates:clap",
18+
"//third_party/rust/crates:humantime",
19+
"//third_party/rust/crates:log",
20+
"//third_party/rust/crates:regex",
21+
"@crate_index//:object",
22+
],
23+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright lowRISC contributors (OpenTitan project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
use anyhow::Result;
6+
use clap::Parser;
7+
use std::time::Duration;
8+
9+
use opentitanlib::app::TransportWrapper;
10+
use opentitanlib::execute_test;
11+
use opentitanlib::test_utils::init::InitializeTest;
12+
use opentitanlib::uart::console::UartConsole;
13+
14+
#[derive(Debug, Parser)]
15+
struct Opts {
16+
#[command(flatten)]
17+
init: InitializeTest,
18+
19+
/// Console receive timeout.
20+
#[arg(long, value_parser = humantime::parse_duration, default_value = "20s")]
21+
timeout: Duration,
22+
23+
/// Name of the UART interface to connect to the debug OTTF console.
24+
#[arg(long, default_value = "dut")]
25+
debug_console: String,
26+
}
27+
28+
fn ottf_dual_console_test(opts: &Opts, transport: &TransportWrapper) -> Result<()> {
29+
let uart = transport.uart("console")?;
30+
let debug_uart = transport.uart(&opts.debug_console)?;
31+
32+
let _ = UartConsole::wait_for(&*uart, r"Running [^\r\n]*", opts.timeout)?;
33+
let _ = UartConsole::wait_for(&*uart, r"Main UART console", opts.timeout)?;
34+
let _ = UartConsole::wait_for(&*debug_uart, r"Second UART console", opts.timeout)?;
35+
let _ = UartConsole::wait_for(&*uart, r"PASS!", opts.timeout)?;
36+
Ok(())
37+
}
38+
39+
fn main() -> Result<()> {
40+
let opts = Opts::parse();
41+
opts.init.init_logging();
42+
let transport = opts.init.init_target()?;
43+
execute_test!(ottf_dual_console_test, &opts, &transport);
44+
Ok(())
45+
}

0 commit comments

Comments
 (0)