esp_app_format: Added test-app

This commit is contained in:
Laukik Hase 2022-07-29 15:54:53 +05:30
parent 0071ea498f
commit fb93901d5b
No known key found for this signature in database
GPG Key ID: 11C571361F51A199
7 changed files with 64 additions and 10 deletions

View File

@ -1,4 +0,0 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES cmock test_utils app_update bootloader_support nvs_flash driver
)

View File

@ -0,0 +1,8 @@
# This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
set(COMPONENTS main)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp_app_format_test)

View File

@ -0,0 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- |

View File

@ -0,0 +1,3 @@
idf_component_register(SRCS "test_app_desc.c"
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES esp_app_format unity)

View File

@ -3,11 +3,24 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <string.h>
#include "esp_app_desc.h"
#include "unity.h"
#include "unity_fixture.h"
TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]")
TEST_GROUP(esp_app_format);
TEST_SETUP(esp_app_format)
{
}
TEST_TEAR_DOWN(esp_app_format)
{
}
TEST(esp_app_format, esp_app_get_elf_sha256_test)
{
const int sha256_hex_len = CONFIG_APP_RETRIEVE_LEN_ELF_SHA;
char dst[sha256_hex_len + 2];
@ -16,17 +29,17 @@ TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]")
size_t len;
char ref_sha256[sha256_hex_len + 1];
const esp_app_desc_t* desc = esp_get_app_description();
const esp_app_desc_t* desc = esp_app_get_description();
for (int i = 0; i < sizeof(ref_sha256) / 2; ++i) {
snprintf(ref_sha256 + 2*i, 3, "%02x", desc->app_elf_sha256[i]);
}
ref_sha256[sha256_hex_len] = 0;
printf("Ref: %s\n", ref_sha256);
printf("\nRef: %s\n", ref_sha256);
memset(dst, fill, sizeof(dst));
len = sizeof(dst);
res = esp_get_app_elf_sha256(dst, len);
res = esp_app_get_elf_sha256(dst, len);
printf("%d: %s (%d)\n", len, dst, res);
TEST_ASSERT_EQUAL(sha256_hex_len + 1, res);
TEST_ASSERT_EQUAL(0, memcmp(dst, ref_sha256, res - 1));
@ -35,7 +48,7 @@ TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]")
memset(dst, fill, sizeof(dst));
len = 9;
res = esp_get_app_elf_sha256(dst, len);
res = esp_app_get_elf_sha256(dst, len);
printf("%d: %s (%d)\n", len, dst, res);
TEST_ASSERT_EQUAL(9, res);
TEST_ASSERT_EQUAL(0, memcmp(dst, ref_sha256, res - 1));
@ -44,7 +57,7 @@ TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]")
memset(dst, fill, sizeof(dst));
len = 8;
res = esp_get_app_elf_sha256(dst, len);
res = esp_app_get_elf_sha256(dst, len);
printf("%d: %s (%d)\n", len, dst, res);
// should output even number of characters plus '\0'
TEST_ASSERT_EQUAL(7, res);
@ -53,3 +66,13 @@ TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]")
TEST_ASSERT_EQUAL_HEX(fill, dst[7]);
TEST_ASSERT_EQUAL_HEX(fill, dst[8]);
}
TEST_GROUP_RUNNER(esp_app_format)
{
RUN_TEST_CASE(esp_app_format, esp_app_get_elf_sha256_test)
}
void app_main(void)
{
UNITY_MAIN(esp_app_format);
}

View File

@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: 2022 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_esp_app_format(dut: Dut) -> None:
dut.expect_unity_test_output()

View File

@ -0,0 +1,11 @@
# General options for additional checks
CONFIG_HEAP_POISONING_COMPREHENSIVE=y
CONFIG_COMPILER_WARN_WRITE_STRINGS=y
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
CONFIG_COMPILER_STACK_CHECK=y
# Enable Unity fixture support
CONFIG_UNITY_ENABLE_FIXTURE=y
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n