فهرست منبع

esp_app_format: Added test-app

Laukik Hase 3 سال پیش
والد
کامیت
fb93901d5b

+ 0 - 4
components/esp_app_format/test/CMakeLists.txt

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

+ 8 - 0
components/esp_app_format/test_apps/CMakeLists.txt

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

+ 2 - 0
components/esp_app_format/test_apps/README.md

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

+ 3 - 0
components/esp_app_format/test_apps/main/CMakeLists.txt

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

+ 29 - 6
components/esp_app_format/test/test_app_desc.c → components/esp_app_format/test_apps/main/test_app_desc.c

@@ -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_GROUP(esp_app_format);
+
+TEST_SETUP(esp_app_format)
+{
+}
+
+TEST_TEAR_DOWN(esp_app_format)
+{
+}
 
-TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]")
+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);
+}

+ 11 - 0
components/esp_app_format/test_apps/pytest_esp_app_format.py

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

+ 11 - 0
components/esp_app_format/test_apps/sdkconfig.defaults

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