From 647c2dabfe9d0a8d247996412efbee7f7946794e Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Thu, 11 May 2023 12:20:27 +0530 Subject: [PATCH] hal: combine security peripherals test applications --- components/hal/.build-test-rules.yml | 5 --- components/hal/test_apps/mpi/README.md | 33 ------------------ .../hal/test_apps/mpi/main/CMakeLists.txt | 6 ---- components/hal/test_apps/mpi/main/app_main.c | 13 ------- components/hal/test_apps/mpi/pytest_mpi.py | 16 --------- .../{mpi => security}/CMakeLists.txt | 4 ++- components/hal/test_apps/security/README.md | 34 +++++++++++++++++++ .../test_apps/security/main/CMakeLists.txt | 10 ++++++ .../hal/test_apps/security/main/app_main.c | 18 ++++++++++ .../main/mpi/mpi_params.h} | 0 .../main => security/main/mpi}/test_mpi.c | 31 ++++++++++++++--- .../hal/test_apps/security/pytest_security.py | 11 ++++++ .../{mpi => security}/sdkconfig.defaults | 1 + 13 files changed, 104 insertions(+), 78 deletions(-) delete mode 100644 components/hal/test_apps/mpi/README.md delete mode 100644 components/hal/test_apps/mpi/main/CMakeLists.txt delete mode 100644 components/hal/test_apps/mpi/main/app_main.c delete mode 100644 components/hal/test_apps/mpi/pytest_mpi.py rename components/hal/test_apps/{mpi => security}/CMakeLists.txt (53%) create mode 100644 components/hal/test_apps/security/README.md create mode 100644 components/hal/test_apps/security/main/CMakeLists.txt create mode 100644 components/hal/test_apps/security/main/app_main.c rename components/hal/test_apps/{mpi/main/test_params.h => security/main/mpi/mpi_params.h} (100%) rename components/hal/test_apps/{mpi/main => security/main/mpi}/test_mpi.c (86%) create mode 100644 components/hal/test_apps/security/pytest_security.py rename components/hal/test_apps/{mpi => security}/sdkconfig.defaults (63%) diff --git a/components/hal/.build-test-rules.yml b/components/hal/.build-test-rules.yml index 453b1e3a40..4e02657514 100644 --- a/components/hal/.build-test-rules.yml +++ b/components/hal/.build-test-rules.yml @@ -7,8 +7,3 @@ components/hal/test_apps/ecc: - if: IDF_TARGET == "esp32c2" temporary: true reason: C2 ECC peripheral has a bug in ECC point verification, if value of K is zero the verification fails - -components/hal/test_apps/mpi: - disable: - - if: SOC_MPI_SUPPORTED != 1 - reason: Hardware MPI support not available for such targets. diff --git a/components/hal/test_apps/mpi/README.md b/components/hal/test_apps/mpi/README.md deleted file mode 100644 index 7bf5d8ff56..0000000000 --- a/components/hal/test_apps/mpi/README.md +++ /dev/null @@ -1,33 +0,0 @@ -| Supported Targets | ESP32 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | - -## MPI peripheral test - -This application contains basic test cases for the MPI peripheral without using any OS functionality or higher abstraction layer. - -This contains tests for the following features of MPI peripheral: - -- MPI Modular Multiplication -- MPI Multiplication -- MPI Modular Exponentiation - -# Building - -```bash -idf.py set-target -idf.py build -``` - -# Running the app manually - -```bash -idf.py flash monitor -``` - -Enter the test that you want to run locally - -# Running tests - -```bash -pytest --target -``` diff --git a/components/hal/test_apps/mpi/main/CMakeLists.txt b/components/hal/test_apps/mpi/main/CMakeLists.txt deleted file mode 100644 index c1e569ffca..0000000000 --- a/components/hal/test_apps/mpi/main/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(srcs "app_main.c" - "test_mpi.c") - -idf_component_register(SRCS ${srcs} - REQUIRES unity - WHOLE_ARCHIVE) diff --git a/components/hal/test_apps/mpi/main/app_main.c b/components/hal/test_apps/mpi/main/app_main.c deleted file mode 100644 index ecde0a6c5d..0000000000 --- a/components/hal/test_apps/mpi/main/app_main.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ - -#include "unity.h" -#include "unity_test_runner.h" - -void app_main(void) -{ - unity_run_menu(); -} diff --git a/components/hal/test_apps/mpi/pytest_mpi.py b/components/hal/test_apps/mpi/pytest_mpi.py deleted file mode 100644 index 247537496a..0000000000 --- a/components/hal/test_apps/mpi/pytest_mpi.py +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: CC0-1.0 - -import pytest -from pytest_embedded import Dut - - -@pytest.mark.esp32 -@pytest.mark.esp32s2 -@pytest.mark.esp32s3 -@pytest.mark.esp32c3 -@pytest.mark.esp32c6 -@pytest.mark.esp32h2 -@pytest.mark.generic -def test_bignum(dut: Dut) -> None: - dut.run_all_single_board_cases() diff --git a/components/hal/test_apps/mpi/CMakeLists.txt b/components/hal/test_apps/security/CMakeLists.txt similarity index 53% rename from components/hal/test_apps/mpi/CMakeLists.txt rename to components/hal/test_apps/security/CMakeLists.txt index b1cc26cf58..17bab1cc66 100644 --- a/components/hal/test_apps/mpi/CMakeLists.txt +++ b/components/hal/test_apps/security/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16) set(COMPONENTS main) +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components") + include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(mpi_test) +project(security_test) diff --git a/components/hal/test_apps/security/README.md b/components/hal/test_apps/security/README.md new file mode 100644 index 0000000000..32319a6e43 --- /dev/null +++ b/components/hal/test_apps/security/README.md @@ -0,0 +1,34 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | + +## Security peripherals test + +This is a combined security peripherals verification application using mostly HAL APIs. This application is intentionally kept simple and does not use any higher layer constructs. This application can help in the early verification of the new SoC. + +This contains tests for the following features of the security peripherals: + +- MPI peripheral + - MPI Modular Multiplication + - MPI Multiplication + - MPI Modular Exponentiation + +# Building + +```bash +idf.py set-target +idf.py build +``` + +# Running the app manually + +```bash +idf.py flash monitor +``` + +Enter the test that you want to run locally + +# Running tests + +```bash +pytest --target +``` diff --git a/components/hal/test_apps/security/main/CMakeLists.txt b/components/hal/test_apps/security/main/CMakeLists.txt new file mode 100644 index 0000000000..ba1f2bd743 --- /dev/null +++ b/components/hal/test_apps/security/main/CMakeLists.txt @@ -0,0 +1,10 @@ +set(srcs "app_main.c") + +if(CONFIG_SOC_MPI_SUPPORTED) + list(APPEND srcs "mpi/test_mpi.c") +endif() + + +idf_component_register(SRCS ${srcs} + REQUIRES test_utils unity + WHOLE_ARCHIVE) diff --git a/components/hal/test_apps/security/main/app_main.c b/components/hal/test_apps/security/main/app_main.c new file mode 100644 index 0000000000..1b66c356b0 --- /dev/null +++ b/components/hal/test_apps/security/main/app_main.c @@ -0,0 +1,18 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#include "unity_fixture.h" +#include "unity_fixture_extras.h" + +static void run_all_tests(void) +{ + RUN_TEST_GROUP(mpi); +} + +void app_main(void) +{ + UNITY_MAIN_FUNC(run_all_tests); +} diff --git a/components/hal/test_apps/mpi/main/test_params.h b/components/hal/test_apps/security/main/mpi/mpi_params.h similarity index 100% rename from components/hal/test_apps/mpi/main/test_params.h rename to components/hal/test_apps/security/main/mpi/mpi_params.h diff --git a/components/hal/test_apps/mpi/main/test_mpi.c b/components/hal/test_apps/security/main/mpi/test_mpi.c similarity index 86% rename from components/hal/test_apps/mpi/main/test_mpi.c rename to components/hal/test_apps/security/main/mpi/test_mpi.c index 9a7d67adf2..e0e0094b7e 100644 --- a/components/hal/test_apps/mpi/main/test_mpi.c +++ b/components/hal/test_apps/security/main/mpi/test_mpi.c @@ -8,14 +8,15 @@ #include "esp_log.h" #include "esp_private/periph_ctrl.h" -#include "unity.h" +#include "memory_checks.h" +#include "unity_fixture.h" #if CONFIG_IDF_TARGET_ESP32 #define ESP_MPI_USE_MONT_EXP #endif #include "hal/mpi_hal.h" -#include "test_params.h" +#include "mpi_params.h" #define _DEBUG_ 0 @@ -81,6 +82,7 @@ static void mpi_mul_mpi_mod_hw_op(void) TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(test_cases_Z_p[i], Z_p, test_cases_Z_words[i], "Result"); printf("PASS\n"); + free(Z_p); } esp_mpi_disable_hardware_hw_op(); } @@ -131,15 +133,36 @@ static void mpi_exp_mpi_mod_hw_op(void) TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(exp_test_cases_Z_p[i], Z_p, exp_test_cases_m_words[i], "Result"); printf("PASS\n"); + free(Z_p); } } -TEST_CASE("Test MPI multiplication", "[mpi][hal]") +TEST_GROUP(mpi); + +TEST_SETUP(mpi) +{ + test_utils_record_free_mem(); + TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL)); +} + +TEST_TEAR_DOWN(mpi) +{ + test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL), + test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL)); +} + +TEST(mpi, mpi_multiplication) { mpi_mul_mpi_mod_hw_op(); } -TEST_CASE("Test MPI exponentiation", "[mpi][hal]") +TEST(mpi, mpi_exponentiation) { mpi_exp_mpi_mod_hw_op(); } + +TEST_GROUP_RUNNER(mpi) +{ + RUN_TEST_CASE(mpi, mpi_multiplication); + RUN_TEST_CASE(mpi, mpi_exponentiation); +} diff --git a/components/hal/test_apps/security/pytest_security.py b/components/hal/test_apps/security/pytest_security.py new file mode 100644 index 0000000000..a6b6142ae4 --- /dev/null +++ b/components/hal/test_apps/security/pytest_security.py @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_security(dut: Dut) -> None: + dut.expect('main_task: Returned from app_main()') diff --git a/components/hal/test_apps/mpi/sdkconfig.defaults b/components/hal/test_apps/security/sdkconfig.defaults similarity index 63% rename from components/hal/test_apps/mpi/sdkconfig.defaults rename to components/hal/test_apps/security/sdkconfig.defaults index a4ba403514..ce9141d1c1 100644 --- a/components/hal/test_apps/mpi/sdkconfig.defaults +++ b/components/hal/test_apps/security/sdkconfig.defaults @@ -1,2 +1,3 @@ CONFIG_ESP_TASK_WDT_EN=y CONFIG_ESP_TASK_WDT_INIT=n +CONFIG_UNITY_ENABLE_FIXTURE=y