Skip to content
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

[sw,multitop] port kmac_{app_rom,mode_cshake,mode_kmac}_test to devicetables #26243

Merged
merged 3 commits into from
Feb 13, 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
57 changes: 45 additions & 12 deletions sw/device/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2421,13 +2421,43 @@ opentitan_test(
],
)

# TODO(lowrisc/opentitan#26250): it would be good if execution environments
# could provide a mechanism for obtaining their hashfiles, rather than us
# hardcoding all these hashfile mappings here.
_KMAC_APP_ROM_LIST = [
("//sw/device/lib/testing/test_rom:test_rom_sim_verilator_hashfile", "sim_verilator"),
("//sw/device/lib/testing/test_rom:test_rom_fpga_cw310_hashfile", "fpga_cw310_test_rom"),
("//sw/device/silicon_creator/rom:mask_rom_fpga_cw310_hashfile", "fpga_cw310_rom_with_fake_keys"),
("//sw/device/silicon_creator/rom:mask_rom_fpga_cw310_hashfile", "fpga_cw310_sival"),
("//sw/device/silicon_creator/rom:mask_rom_fpga_cw340_hashfile", "fpga_cw340_sival"),
("//sw/device/lib/testing/test_rom:test_rom_sim_dv_hashfile", "sim_dv"),
(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for the future: we should find a way to make the execution environment provide the hashmap to avoid this manual list. This requires some bazel hacking, or it could just be done as part of the build system revamp for multitop that we are going to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this as a TODO comment to the code I think as well

"//sw/device/lib/testing/test_rom:test_rom_sim_verilator_hashfile",
"sim_verilator",
["//hw/top_earlgrey"],
),
(
"//sw/device/lib/testing/test_rom:test_rom_fpga_cw310_hashfile",
"fpga_cw310_test_rom",
["//hw/top_earlgrey"],
),
(
"//sw/device/silicon_creator/rom:mask_rom_fpga_cw310_hashfile",
"fpga_cw310_rom_with_fake_keys",
["//hw/top_earlgrey"],
),
(
"//sw/device/silicon_creator/rom:mask_rom_fpga_cw310_hashfile",
"fpga_cw310_sival",
["//hw/top_earlgrey"],
),
(
"//sw/device/silicon_creator/rom:mask_rom_fpga_cw340_hashfile",
"fpga_cw340_sival",
["//hw/top_earlgrey"],
),
(
"//sw/device/lib/testing/test_rom:test_rom_sim_dv_hashfile",
"sim_dv",
[
"//hw/top_earlgrey",
"//hw/top_darjeeling",
],
),
]

[
Expand All @@ -2438,24 +2468,25 @@ _KMAC_APP_ROM_LIST = [
hashfile,
],
exec_env = {
"//hw/top_earlgrey:{}".format(exec_env): None,
"{}:{}".format(top, exec_env): None
for top in tops
},
deps = [
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//hw/top:dt",
"//sw/device/lib/base:mmio",
"//sw/device/lib/dif:rom_ctrl",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing/test_framework:ottf_main",
],
)
for (hashfile, exec_env) in _KMAC_APP_ROM_LIST
for (hashfile, exec_env, tops) in _KMAC_APP_ROM_LIST
]

test_suite(
name = "kmac_app_rom_test",
tests = [
"kmac_app_rom_test_{}".format(exec_env)
for (_, exec_env) in _KMAC_APP_ROM_LIST
for (_, exec_env, _) in _KMAC_APP_ROM_LIST
],
)

Expand Down Expand Up @@ -2587,11 +2618,12 @@ opentitan_test(
EARLGREY_SILICON_OWNER_ROM_EXT_ENVS,
{
"//hw/top_earlgrey:silicon_creator": None,
"//hw/top_darjeeling:sim_dv": None,
},
),
verilator = verilator_params(timeout = "long"),
deps = [
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//hw/top:dt",
"//sw/device/lib/arch:device",
"//sw/device/lib/base:macros",
"//sw/device/lib/base:mmio",
Expand All @@ -2609,10 +2641,11 @@ opentitan_test(
EARLGREY_SILICON_OWNER_ROM_EXT_ENVS,
{
"//hw/top_earlgrey:silicon_creator": None,
"//hw/top_darjeeling:sim_dv": None,
},
),
deps = [
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//hw/top:dt",
"//sw/device/lib/arch:device",
"//sw/device/lib/base:macros",
"//sw/device/lib/base:mmio",
Expand Down
10 changes: 5 additions & 5 deletions sw/device/tests/kmac_app_rom_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "dt/dt_rom_ctrl.h" // Generated
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_rom_ctrl.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"

extern const uint32_t kRomImageHash[ROM_CTRL_DIGEST_MULTIREG_COUNT];

static dif_rom_ctrl_t rom_ctrl;
static dt_rom_ctrl_t kRomCtrlDt = (dt_rom_ctrl_t)0;
static_assert(kDtRomCtrlCount >= 1,
"This test requires at least one rom_ctrl instance");

OTTF_DEFINE_TEST_CONFIG();

Expand All @@ -22,9 +24,7 @@ bool test_main(void) {
dif_rom_ctrl_digest_t expected_digest;

// initialize rom_ctrl
mmio_region_t rom_ctrl_reg =
mmio_region_from_addr(TOP_EARLGREY_ROM_CTRL_REGS_BASE_ADDR);
CHECK_DIF_OK(dif_rom_ctrl_init(rom_ctrl_reg, &rom_ctrl));
CHECK_DIF_OK(dif_rom_ctrl_init_from_dt(kRomCtrlDt, &rom_ctrl));

// get computed and expected digests and check that they match
CHECK_DIF_OK(dif_rom_ctrl_get_digest(&rom_ctrl, &computed_digest));
Expand Down
9 changes: 5 additions & 4 deletions sw/device/tests/kmac_mode_cshake_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "dt/dt_kmac.h" // Generated
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
Expand All @@ -10,8 +11,6 @@
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"

OTTF_DEFINE_TEST_CONFIG();

#define DIGEST_LEN_CSHAKE_MAX 4
Expand Down Expand Up @@ -92,9 +91,11 @@ bool test_main(void) {

// Intialize KMAC hardware.
dif_kmac_t kmac;
dt_kmac_t kKmacDt = (dt_kmac_t)0;
static_assert(kDtKmacCount >= 1,
"This test requires at least one KMAC instance");
dif_kmac_operation_state_t kmac_operation_state;
CHECK_DIF_OK(
dif_kmac_init(mmio_region_from_addr(TOP_EARLGREY_KMAC_BASE_ADDR), &kmac));
CHECK_DIF_OK(dif_kmac_init_from_dt(kKmacDt, &kmac));

// Configure KMAC hardware using software entropy.
dif_kmac_config_t config = (dif_kmac_config_t){
Expand Down
9 changes: 5 additions & 4 deletions sw/device/tests/kmac_mode_kmac_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "dt/dt_kmac.h" // Generated
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
Expand All @@ -10,8 +11,6 @@
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"

OTTF_DEFINE_TEST_CONFIG();

#define DIGEST_LEN_KMAC_MAX 100
Expand Down Expand Up @@ -193,9 +192,11 @@ bool test_main(void) {

// Intialize KMAC hardware.
dif_kmac_t kmac;
dt_kmac_t kKmacDt = (dt_kmac_t)0;
static_assert(kDtKmacCount >= 1,
"This test requires at least one KMAC instance");
dif_kmac_operation_state_t kmac_operation_state;
CHECK_DIF_OK(
dif_kmac_init(mmio_region_from_addr(TOP_EARLGREY_KMAC_BASE_ADDR), &kmac));
CHECK_DIF_OK(dif_kmac_init_from_dt(kKmacDt, &kmac));

// Configure KMAC hardware using software entropy.
dif_kmac_config_t config = (dif_kmac_config_t){
Expand Down
Loading