Skip to content

[multitop] Port normal/deep/random pwrmgr test to DT/multitop #26389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 59 additions & 23 deletions sw/device/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ load(
)
load("//rules/opentitan:keyutils.bzl", "ECDSA_ONLY_KEY_STRUCTS")
load("//hw/top:defs.bzl", "opentitan_if_ip", "opentitan_select_top")
load("//rules/opentitan:util.bzl", "flatten")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -3259,10 +3260,7 @@ opentitan_test(
# in CI/nightlies.
verilator = verilator_params(tags = ["manual"]),
deps = [
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//sw/device/lib/arch:device",
"//sw/device/lib/base:abs_mmio",
"//sw/device/lib/base:mmio",
"//sw/device/lib/dif:rstmgr",
"//sw/device/lib/dif:rv_plic",
"//sw/device/lib/runtime:log",
Expand Down Expand Up @@ -3357,6 +3355,60 @@ opentitan_test(
],
)

# List of IPs supported by the pwrmgr_sleep_all_wake_ups_impl
# library. Some of these can be top-specific.
PWRMGR_SUPPORTED_IPS = [
"aon_timer",
"adc_ctrl",
"pinmux",
"sensor_ctrl",
"sysrst_ctrl",
"usbdev",
]

cc_library(
name = "pwrmgr_sleep_all_wake_ups_impl",
srcs = ["pwrmgr_sleep_all_wake_ups_impl.c"],
hdrs = ["pwrmgr_sleep_all_wake_ups_impl.h"],
defines = flatten(
[
opentitan_if_ip(
ip,
["HAS_" + ip.upper()],
[],
)
for ip in PWRMGR_SUPPORTED_IPS
],
),
target_compatible_with = [OPENTITAN_CPU],
visibility = ["//sw/device/tests:__pkg__"],
deps = [
"//hw/top:dt",
"//hw/top:pwrmgr_c_regs",
"//sw/device/lib/arch:device",
"//sw/device/lib/base:mmio",
"//sw/device/lib/dif:pwrmgr",
"//sw/device/lib/dif:rv_plic",
"//sw/device/lib/runtime:ibex",
"//sw/device/lib/runtime:irq",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing:aon_timer_testutils",
"//sw/device/lib/testing:isr_testutils",
"//sw/device/lib/testing:pwrmgr_testutils",
"//sw/device/lib/testing:rv_plic_testutils",
"//sw/device/lib/testing/test_framework:ottf_main",
] + flatten(
[
opentitan_if_ip(
ip,
["//sw/device/lib/dif:" + ip],
[],
)
for ip in PWRMGR_SUPPORTED_IPS
],
),
)

opentitan_test(
name = "pwrmgr_normal_sleep_all_wake_ups",
srcs = ["pwrmgr_normal_sleep_all_wake_ups.c"],
Expand All @@ -3378,17 +3430,11 @@ opentitan_test(
# in CI/nightlies.
verilator = verilator_params(tags = ["manual"]),
deps = [
"//hw/top:pwrmgr_c_regs",
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//sw/device/lib/dif:pwrmgr",
"//sw/device/lib/dif:rv_plic",
":pwrmgr_sleep_all_wake_ups_impl",
"//sw/device/lib/runtime:irq",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing:aon_timer_testutils",
"//sw/device/lib/testing:pwrmgr_testutils",
"//sw/device/lib/testing:rv_plic_testutils",
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/device/tests/sim_dv:pwrmgr_sleep_all_wake_ups_impl",
],
)

Expand All @@ -3413,19 +3459,13 @@ opentitan_test(
# in CI/nightlies.
verilator = verilator_params(tags = ["manual"]),
deps = [
"//hw/top:pwrmgr_c_regs",
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
":pwrmgr_sleep_all_wake_ups_impl",
"//sw/device/lib/dif:pwrmgr",
"//sw/device/lib/dif:rv_plic",
"//sw/device/lib/runtime:irq",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing:aon_timer_testutils",
"//sw/device/lib/testing:isr_testutils",
"//sw/device/lib/testing:pwrmgr_testutils",
"//sw/device/lib/testing:ret_sram_testutils",
"//sw/device/lib/testing:rv_plic_testutils",
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/device/tests/sim_dv:pwrmgr_sleep_all_wake_ups_impl",
],
)

Expand Down Expand Up @@ -3456,8 +3496,7 @@ opentitan_test(
# in CI/nightlies.
verilator = verilator_params(tags = ["manual"]),
deps = [
"//hw/top:pwrmgr_c_regs",
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
":pwrmgr_sleep_all_wake_ups_impl",
"//sw/device/lib/arch:device",
"//sw/device/lib/dif:pwrmgr",
"//sw/device/lib/dif:rv_plic",
Expand All @@ -3469,7 +3508,6 @@ opentitan_test(
"//sw/device/lib/testing:ret_sram_testutils",
"//sw/device/lib/testing:rv_plic_testutils",
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/device/tests/sim_dv:pwrmgr_sleep_all_wake_ups_impl",
],
)

Expand Down Expand Up @@ -3518,17 +3556,15 @@ opentitan_test(
srcs = ["pwrmgr_sensor_ctrl_deep_sleep_wake_up.c"],
exec_env = {"//hw/top_earlgrey:sim_dv": None},
deps = [
"//hw/top:pwrmgr_c_regs",
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//sw/device/lib/dif:pwrmgr",
"//sw/device/lib/dif:rv_plic",
"//sw/device/lib/dif:sensor_ctrl",
"//sw/device/lib/runtime:irq",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing:isr_testutils",
"//sw/device/lib/testing:pwrmgr_testutils",
"//sw/device/lib/testing:rv_plic_testutils",
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/device/tests/sim_dv:pwrmgr_sleep_all_wake_ups_impl",
],
)

Expand Down
57 changes: 13 additions & 44 deletions sw/device/tests/pwrmgr_deep_sleep_all_wake_ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,19 @@
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/lib/dif/dif_pwrmgr.h"
#include "sw/device/lib/dif/dif_rv_plic.h"
#include "sw/device/lib/runtime/irq.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/aon_timer_testutils.h"
#include "sw/device/lib/testing/pwrmgr_testutils.h"
#include "sw/device/lib/testing/ret_sram_testutils.h"
#include "sw/device/lib/testing/rv_plic_testutils.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/tests/sim_dv/pwrmgr_sleep_all_wake_ups_impl.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
#include "pwrmgr_regs.h"
#include "sensor_ctrl_regs.h"
#include "sw/device/lib/testing/autogen/isr_testutils.h"
#include "sw/device/tests/pwrmgr_sleep_all_wake_ups_impl.h"

/*
PWRMGR DEEP SLEEP ALL WAKE UPS TEST

This test runs power manager wake up from deep sleep mode by
wake up inputs.

There are 6 wake up inputs.
0: sysrst_ctrl
1: adc_ctrl
2: pinmux
3: usb
4: aon_timer
5: sensor_ctrl

#5 is excluded because sensor_ctrl is not in the aon domain.
*/

OTTF_DEFINE_TEST_CONFIG();
Expand All @@ -53,48 +36,34 @@ bool test_main(void) {
ret_sram_testutils_init();

init_units();
// Enable all AST alerts in sensor_ctrl
for (uint32_t k = 0; k < SENSOR_CTRL_PARAM_NUM_ALERT_EVENTS; k++) {
CHECK_DIF_OK(
dif_sensor_ctrl_set_alert_en(&sensor_ctrl, k, kDifToggleEnabled));
}

// Enable all the AON interrupts used in this test.
rv_plic_testutils_irq_range_enable(&rv_plic, kTopEarlgreyPlicTargetIbex0,
kTopEarlgreyPlicIrqIdPwrmgrAonWakeup,
kTopEarlgreyPlicIrqIdPwrmgrAonWakeup);

// Enable pwrmgr interrupt.
CHECK_DIF_OK(dif_pwrmgr_irq_set_enabled(&pwrmgr, 0, kDifToggleEnabled));

uint32_t wakeup_unit = 0;

if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0)) == true) {
if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0))) {
LOG_INFO("POR reset");
CHECK_STATUS_OK(ret_sram_testutils_counter_clear(kCounterCases));
CHECK_STATUS_OK(
ret_sram_testutils_counter_get(kCounterCases, &wakeup_unit));
execute_test(wakeup_unit, /*deep_sleep=*/true);
} else {
CHECK_STATUS_OK(
ret_sram_testutils_counter_get(kCounterCases, &wakeup_unit));
check_wakeup_reason(wakeup_unit);
LOG_INFO("Woke up by source %d", wakeup_unit);
clear_wakeup(wakeup_unit);
delay_n_clear(4);
CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterCases));
}

while (true) {
CHECK_STATUS_OK(
ret_sram_testutils_counter_get(kCounterCases, &wakeup_unit));
if (wakeup_unit >= PWRMGR_PARAM_NUM_WKUPS) {
if (wakeup_unit >= get_wakeup_count()) {
return true;
} else if (kDeviceType != kDeviceSimDV &&
wakeup_unit == PWRMGR_PARAM_ADC_CTRL_AON_WKUP_REQ_IDX) {
// Skip ADC_CTRL and sensor control if not in sim_dv.
}
if (execute_test(wakeup_unit, /*deep_sleep=*/true)) {
CHECK(false, "This is not reachable since we entered deep sleep");
} else {
// Skip test.
CHECK_STATUS_OK(ret_sram_testutils_counter_increment(kCounterCases));
}
CHECK_STATUS_OK(
ret_sram_testutils_counter_get(kCounterCases, &wakeup_unit));
delay_n_clear(4);
execute_test(wakeup_unit, /*deep_sleep=*/true);
}

return false;
Expand Down
48 changes: 8 additions & 40 deletions sw/device/tests/pwrmgr_normal_sleep_all_wake_ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,18 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/lib/dif/dif_pwrmgr.h"
#include "sw/device/lib/dif/dif_rv_plic.h"
#include "sw/device/lib/runtime/irq.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/aon_timer_testutils.h"
#include "sw/device/lib/testing/pwrmgr_testutils.h"
#include "sw/device/lib/testing/rv_plic_testutils.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/tests/sim_dv/pwrmgr_sleep_all_wake_ups_impl.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
#include "pwrmgr_regs.h"
#include "sensor_ctrl_regs.h"
#include "sw/device/lib/testing/autogen/isr_testutils.h"
#include "sw/device/tests/pwrmgr_sleep_all_wake_ups_impl.h"

/*
PWRMGR NORMAL SLEEP ALL WAKE UPS test

This test runs power manager wake up from deep sleep mode by
wake up inputs.

There are 6 wake up inputs.
0: sysrst_ctrl
1: adc_ctrl
2: pinmux
3: usb
4: aon_timer
5: sensor_ctrl

*/

OTTF_DEFINE_TEST_CONFIG();
Expand All @@ -41,38 +24,23 @@ bool test_main(void) {
irq_external_ctrl(true);

init_units();
// Enable all AST alerts in sensor_ctrl
for (uint32_t k = 0; k < SENSOR_CTRL_PARAM_NUM_ALERT_EVENTS; k++) {
CHECK_DIF_OK(
dif_sensor_ctrl_set_alert_en(&sensor_ctrl, k, kDifToggleEnabled));
}

// Enable all the AON interrupts used in this test.
rv_plic_testutils_irq_range_enable(&rv_plic, kTopEarlgreyPlicTargetIbex0,
kTopEarlgreyPlicIrqIdPwrmgrAonWakeup,
kTopEarlgreyPlicIrqIdPwrmgrAonWakeup);

// Enable pwrmgr interrupt
CHECK_DIF_OK(dif_pwrmgr_irq_set_enabled(&pwrmgr, 0, kDifToggleEnabled));

if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0)) == true) {
if (UNWRAP(pwrmgr_testutils_is_wakeup_reason(&pwrmgr, 0))) {
LOG_INFO("POR reset");

for (size_t wakeup_unit = 0; wakeup_unit < PWRMGR_PARAM_NUM_WKUPS;
for (size_t wakeup_unit = 0; wakeup_unit < get_wakeup_count();
++wakeup_unit) {
if (kDeviceType != kDeviceSimDV &&
wakeup_unit == PWRMGR_PARAM_ADC_CTRL_AON_WKUP_REQ_IDX) {
if (!execute_test(wakeup_unit, /*deep_sleep=*/false)) {
continue;
}
LOG_INFO("Test %d begin", wakeup_unit);
execute_test(wakeup_unit, /*deep_sleep=*/false);
check_wakeup_reason(wakeup_unit);
LOG_INFO("Woke up by source %d", wakeup_unit);
clear_wakeup(wakeup_unit);
LOG_INFO("clean up done source %d", wakeup_unit);
}
return true;
} else {
LOG_ERROR("Unexpected wake up reason");
return false;
}

return false;
}
Loading
Loading