[chip dv] Update the SW aes_test.c to run in DV
This commit has 2 updates:
- Update AES SW test to be able to run in chip level DV
- Update AES SW test to be a test lib that implements the `run_test()` method
Signed-off-by: Srikrishna Iyer <sriyer@google.com>
[ci] Update to pick aes_test.c correctly for CI
Signed-off-by: Srikrishna Iyer <sriyer@google.com>
diff --git a/ci/run_verilator_pytest.sh b/ci/run_verilator_pytest.sh
index 4d0217b..d18313e 100755
--- a/ci/run_verilator_pytest.sh
+++ b/ci/run_verilator_pytest.sh
@@ -16,7 +16,7 @@
TEST_TARGETS=(
"examples/hello_usbdev/hello_usbdev_sim_verilator.elf"
- "tests/aes/aes_test_sim_verilator.elf"
+ "tests/aes_test_sim_verilator.elf"
"tests/consecutive_irqs/consecutive_irqs_test_sim_verilator.elf"
"tests/flash_ctrl/flash_test_sim_verilator.elf"
"tests/hmac/sha256_test_sim_verilator.elf"
diff --git a/sw/device/tests/aes/meson.build b/sw/device/tests/aes/meson.build
deleted file mode 100644
index 8ec3494..0000000
--- a/sw/device/tests/aes/meson.build
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright lowRISC contributors.
-# Licensed under the Apache License, Version 2.0, see LICENSE for details.
-# SPDX-License-Identifier: Apache-2.0
-
-foreach device_name, device_lib : sw_lib_arch_core_devices
- aes_test_elf = executable(
- 'aes_test_' + device_name,
- sources: ['aes_test.c'],
- name_suffix: 'elf',
- dependencies: [
- sw_lib_aes,
- sw_lib_uart,
- sw_lib_mem,
- riscv_crt,
- device_lib,
- ],
- )
-
- aes_test_embedded = custom_target(
- 'aes_test_' + device_name,
- command: make_embedded_target,
- input: aes_test_elf,
- output: make_embedded_target_outputs,
- build_by_default: true,
- )
-
- custom_target(
- 'aes_test_export_' + device_name,
- command: export_embedded_target,
- input: [aes_test_elf, aes_test_embedded],
- output: 'aes_test_export_' + device_name,
- build_always_stale: true,
- build_by_default: true,
- )
-endforeach
diff --git a/sw/device/tests/aes/aes_test.c b/sw/device/tests/aes_test.c
similarity index 76%
rename from sw/device/tests/aes/aes_test.c
rename to sw/device/tests/aes_test.c
index e7602f3..9c611df 100644
--- a/sw/device/tests/aes/aes_test.c
+++ b/sw/device/tests/aes_test.c
@@ -4,9 +4,9 @@
#include "sw/device/lib/aes.h"
-#include "sw/device/lib/arch/device.h"
-#include "sw/device/lib/common.h"
-#include "sw/device/lib/uart.h"
+#include "sw/device/lib/base/log.h"
+#include "sw/device/lib/runtime/check.h"
+#include "sw/device/lib/testing/test_main.h"
// The following plaintext, key and ciphertext are extracted from Appendix C of
// the Advanced Encryption Standard (AES) FIPS Publication 197 available at
@@ -25,17 +25,14 @@
0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf,
0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89};
-int main(int argc, char **argv) {
- bool has_error = false;
-
+bool test_main(void) {
// Wait for AES unit being idle
while (!aes_idle()) {
}
uint8_t buffer[16];
- uart_init(kUartBaudrate);
- uart_send_str("Running AES test\r\n");
+ LOG_INFO("Running AES test");
// Setup AES config
aes_cfg_t aes_cfg = {
@@ -52,9 +49,9 @@
// Check against golden cipher text
for (int i = 0; i < 16; i++) {
- if (cipher_text_gold_32_1[i] != buffer[i]) {
- has_error = true;
- }
+ CHECK(cipher_text_gold_32_1[i] == buffer[i],
+ "Encoded cipher_text[%d] mismatched: exp = %x, actual = %x", i,
+ cipher_text_gold_32_1[i], buffer[i]);
}
// Decode
@@ -65,19 +62,13 @@
// Check against input plain text
for (int i = 0; i < 16; i++) {
- if (plain_text_1[i] != buffer[i]) {
- has_error = true;
- }
+ CHECK(plain_text_1[i] == buffer[i],
+ "Decoded plain_text[%d] mismatched: exp = %x, actual = %x", i,
+ plain_text_1[i], buffer[i]);
}
// Clear
aes_clear();
- if (has_error) {
- uart_send_str("FAIL!\r\n");
- } else {
- uart_send_str("PASS!\r\n");
- }
-
- return 0;
+ return true;
}