Explorar el Código

hal: combine security peripherals test applications

harshal.patil hace 2 años
padre
commit
647c2dabfe

+ 0 - 5
components/hal/.build-test-rules.yml

@@ -7,8 +7,3 @@ components/hal/test_apps/ecc:
     - if: IDF_TARGET == "esp32c2"
     - if: IDF_TARGET == "esp32c2"
       temporary: true
       temporary: true
       reason: C2 ECC peripheral has a bug in ECC point verification, if value of K is zero the verification fails
       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.

+ 0 - 33
components/hal/test_apps/mpi/README.md

@@ -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 <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 <TARGET>
-```

+ 0 - 6
components/hal/test_apps/mpi/main/CMakeLists.txt

@@ -1,6 +0,0 @@
-set(srcs "app_main.c"
-         "test_mpi.c")
-
-idf_component_register(SRCS ${srcs}
-                       REQUIRES unity
-                       WHOLE_ARCHIVE)

+ 0 - 13
components/hal/test_apps/mpi/main/app_main.c

@@ -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();
-}

+ 0 - 16
components/hal/test_apps/mpi/pytest_mpi.py

@@ -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()

+ 3 - 1
components/hal/test_apps/mpi/CMakeLists.txt → components/hal/test_apps/security/CMakeLists.txt

@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16)
 
 
 set(COMPONENTS main)
 set(COMPONENTS main)
 
 
+set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
+
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)
 
 
-project(mpi_test)
+project(security_test)

+ 34 - 0
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 <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 <TARGET>
+```

+ 10 - 0
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)

+ 18 - 0
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);
+}

+ 0 - 0
components/hal/test_apps/mpi/main/test_params.h → components/hal/test_apps/security/main/mpi/mpi_params.h


+ 27 - 4
components/hal/test_apps/mpi/main/test_mpi.c → components/hal/test_apps/security/main/mpi/test_mpi.c

@@ -8,14 +8,15 @@
 
 
 #include "esp_log.h"
 #include "esp_log.h"
 #include "esp_private/periph_ctrl.h"
 #include "esp_private/periph_ctrl.h"
-#include "unity.h"
+#include "memory_checks.h"
+#include "unity_fixture.h"
 
 
 #if CONFIG_IDF_TARGET_ESP32
 #if CONFIG_IDF_TARGET_ESP32
 #define ESP_MPI_USE_MONT_EXP
 #define ESP_MPI_USE_MONT_EXP
 #endif
 #endif
 
 
 #include "hal/mpi_hal.h"
 #include "hal/mpi_hal.h"
-#include "test_params.h"
+#include "mpi_params.h"
 
 
 #define _DEBUG_ 0
 #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");
         TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(test_cases_Z_p[i], Z_p, test_cases_Z_words[i], "Result");
         printf("PASS\n");
         printf("PASS\n");
+        free(Z_p);
     }
     }
     esp_mpi_disable_hardware_hw_op();
     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");
         TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(exp_test_cases_Z_p[i], Z_p, exp_test_cases_m_words[i], "Result");
         printf("PASS\n");
         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();
     mpi_mul_mpi_mod_hw_op();
 }
 }
 
 
-TEST_CASE("Test MPI exponentiation", "[mpi][hal]")
+TEST(mpi, mpi_exponentiation)
 {
 {
     mpi_exp_mpi_mod_hw_op();
     mpi_exp_mpi_mod_hw_op();
 }
 }
+
+TEST_GROUP_RUNNER(mpi)
+{
+    RUN_TEST_CASE(mpi, mpi_multiplication);
+    RUN_TEST_CASE(mpi, mpi_exponentiation);
+}

+ 11 - 0
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()')

+ 1 - 0
components/hal/test_apps/mpi/sdkconfig.defaults → components/hal/test_apps/security/sdkconfig.defaults

@@ -1,2 +1,3 @@
 CONFIG_ESP_TASK_WDT_EN=y
 CONFIG_ESP_TASK_WDT_EN=y
 CONFIG_ESP_TASK_WDT_INIT=n
 CONFIG_ESP_TASK_WDT_INIT=n
+CONFIG_UNITY_ENABLE_FIXTURE=y