hal: combine security peripherals test applications

This commit is contained in:
harshal.patil 2023-05-11 12:20:27 +05:30
parent a8a2b08b4c
commit 647c2dabfe
13 changed files with 104 additions and 78 deletions

View File

@ -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.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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