From 06bd5dcbe325672a40b4c8ca33b3848aa13ae2c1 Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Mon, 28 Feb 2022 17:02:41 +0100 Subject: [PATCH] ci: Publish test results --- .github/workflows/build_and_run_test_app.yml | 35 ++- expat/test/test_expat.c | 238 +++++++++---------- test_app/CMakeLists.txt | 25 +- test_app/main/test_app_main.c | 4 - test_app/sdkconfig.defaults.esp32c3 | 1 - 5 files changed, 162 insertions(+), 141 deletions(-) delete mode 100644 test_app/sdkconfig.defaults.esp32c3 diff --git a/.github/workflows/build_and_run_test_app.yml b/.github/workflows/build_and_run_test_app.yml index a1f6f9b..a554f74 100644 --- a/.github/workflows/build_and_run_test_app.yml +++ b/.github/workflows/build_and_run_test_app.yml @@ -31,15 +31,15 @@ jobs: - name: Merge binaries working-directory: test_app/build run: | - pip install esptool - python -m esptool --chip esp32 merge_bin --fill-flash-size 4MB -o flash_image.bin @flash_args + . ${IDF_PATH}/export.sh + esptool.py --chip ${{ matrix.idf_target }} merge_bin --fill-flash-size 4MB -o flash_image.bin @flash_args - uses: actions/upload-artifact@v2 with: name: test_app_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }} - path: | - test_app/build/flash_image.bin + path: test_app/build/flash_image.bin - #run-qemu: # Keeping this here for future reference. QEMU tests are not passing now + # Keeping this here for future reference. QEMU tests are not passing now + #run-qemu: # name: Run Test App in QEMU # needs: build # strategy: @@ -63,6 +63,7 @@ jobs: name: Run Test App on target needs: build strategy: + fail-fast: false matrix: idf_ver: ["release-v4.3", "release-v4.4", "latest"] idf_target: ["esp32", "esp32c3", "esp32s3"] @@ -72,7 +73,7 @@ jobs: runs-on: [self-hosted, linux, docker, esp32] # Unfortunately `${{ matrix.idf_target }}` is not accepted here container: image: python:3.7-slim-buster - options: --privileged + options: --privileged # Privileged mode has access to serial ports steps: - uses: actions/checkout@v2 with: @@ -89,4 +90,24 @@ jobs: run: python -m esptool --chip ${{ matrix.idf_target }} write_flash 0x0 test_app/build/flash_image.bin - name: Run Test App on target working-directory: test_app - run: pytest -s --junit-xml=./test_app_results.xml --embedded-services esp --target=${{ matrix.idf_target }} + run: pytest -s --junit-xml=./test_app_results_${{ matrix.idf_target }}_${{ matrix.idf_ver }}.xml --embedded-services esp --target=${{ matrix.idf_target }} + - uses: actions/upload-artifact@v2 + if: always() + with: + name: test_app_results_${{ matrix.idf_target }}_${{ matrix.idf_ver }} + path: test_app/*.xml + + publish-results: + name: Publish Test App results + needs: run-target + if: always() # Run even if the previous step failed + runs-on: ubuntu-20.04 + steps: + - name: Download Test results + uses: actions/download-artifact@v2 + with: + path: test_results + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + files: test_results/**/*.xml diff --git a/expat/test/test_expat.c b/expat/test/test_expat.c index 3734ebe..70ccbd1 100644 --- a/expat/test/test_expat.c +++ b/expat/test/test_expat.c @@ -1,119 +1,119 @@ -/* - * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "unity.h" - -typedef struct { - int depth; - char output[512]; - int output_off; -} user_data_t; - -static void insert_space(user_data_t *user_data) -{ - const char align_str[] = " "; - - TEST_ASSERT(sizeof(user_data->output) >= user_data->output_off); - user_data->output[user_data->output_off++] = '\n'; - - for (int i = 0; i < user_data->depth; i++) { - for (int j = 0; j < strlen(align_str); ++j) { - TEST_ASSERT(sizeof(user_data->output) >= user_data->output_off); - user_data->output[user_data->output_off++] = align_str[j]; - } - } -} - -static void XMLCALL start_element(void *userData, const XML_Char *name, const XML_Char **atts) -{ - user_data_t *user_data = (user_data_t *) userData; - - insert_space(user_data); - - const int ret = snprintf(user_data->output + user_data->output_off, - sizeof(user_data->output) - user_data->output_off, - "<%s>", name); - TEST_ASSERT_EQUAL(strlen(name) + 2, ret); // 2 are the tag characters: "<>" - user_data->output_off += ret; - ++user_data->depth; -} - -static void XMLCALL end_element(void *userData, const XML_Char *name) -{ - user_data_t *user_data = (user_data_t *) userData; - - --user_data->depth; - insert_space(user_data); - - int ret = snprintf(user_data->output + user_data->output_off, sizeof(user_data->output) - user_data->output_off, - "", name); - TEST_ASSERT_EQUAL(strlen(name) + 3, ret); // 3 are the tag characters: "" - user_data->output_off += ret; -} - -static void data_handler(void *userData, const XML_Char *s, int len) -{ - user_data_t *user_data = (user_data_t *) userData; - - insert_space(user_data); - - // s is not zero-terminated - char tmp_str[len + 1]; - strlcpy(tmp_str, s, len + 1); - - int ret = snprintf(user_data->output + user_data->output_off, sizeof(user_data->output) - user_data->output_off, - "%s", tmp_str); - TEST_ASSERT_EQUAL(strlen(tmp_str), ret); - user_data->output_off += ret; -} - -TEST_CASE("Expat parses XML", "[expat]") -{ - const char test_in[] = "Page titleheader
  1. A
  2. "\ - "
  3. B
  4. C
"; - const char test_expected[] = "\n"\ - "\n"\ - " \n"\ - " Page title\n"\ - " \n"\ - " \n"\ - " \n"\ - " header\n"\ - " \n"\ - "
    \n"\ - "
  1. \n"\ - " A\n"\ - "
  2. \n"\ - "
  3. \n"\ - " B\n"\ - "
  4. \n"\ - "
  5. \n"\ - " C\n"\ - "
  6. \n"\ - "
\n"\ - " \n"\ - ""; - user_data_t user_data = { - .depth = 0, - .output = { '\0' }, - .output_off = 0 - }; - - XML_Parser parser = XML_ParserCreate(NULL); - XML_SetUserData(parser, &user_data); - XML_SetElementHandler(parser, start_element, end_element); - XML_SetCharacterDataHandler(parser, data_handler); - - TEST_ASSERT_NOT_EQUAL(XML_STATUS_ERROR, XML_Parse(parser, test_in, strlen(test_in), 1)); - XML_ParserFree(parser); - - TEST_ASSERT_EQUAL(0, user_data.depth); // all closing tags have been found - - TEST_ASSERT_EQUAL(strlen(test_expected), strlen(user_data.output)); - TEST_ASSERT_EQUAL_STRING(test_expected, user_data.output); -} +/* + * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "unity.h" + +typedef struct { + int depth; + char output[512]; + int output_off; +} user_data_t; + +static void insert_space(user_data_t *user_data) +{ + const char align_str[] = " "; + + TEST_ASSERT(sizeof(user_data->output) >= user_data->output_off); + user_data->output[user_data->output_off++] = '\n'; + + for (int i = 0; i < user_data->depth; i++) { + for (int j = 0; j < strlen(align_str); ++j) { + TEST_ASSERT(sizeof(user_data->output) >= user_data->output_off); + user_data->output[user_data->output_off++] = align_str[j]; + } + } +} + +static void XMLCALL start_element(void *userData, const XML_Char *name, const XML_Char **atts) +{ + user_data_t *user_data = (user_data_t *) userData; + + insert_space(user_data); + + const int ret = snprintf(user_data->output + user_data->output_off, + sizeof(user_data->output) - user_data->output_off, + "<%s>", name); + TEST_ASSERT_EQUAL(strlen(name) + 2, ret); // 2 are the tag characters: "<>" + user_data->output_off += ret; + ++user_data->depth; +} + +static void XMLCALL end_element(void *userData, const XML_Char *name) +{ + user_data_t *user_data = (user_data_t *) userData; + + --user_data->depth; + insert_space(user_data); + + int ret = snprintf(user_data->output + user_data->output_off, sizeof(user_data->output) - user_data->output_off, + "", name); + TEST_ASSERT_EQUAL(strlen(name) + 3, ret); // 3 are the tag characters: "" + user_data->output_off += ret; +} + +static void data_handler(void *userData, const XML_Char *s, int len) +{ + user_data_t *user_data = (user_data_t *) userData; + + insert_space(user_data); + + // s is not zero-terminated + char tmp_str[len + 1]; + strlcpy(tmp_str, s, len + 1); + + int ret = snprintf(user_data->output + user_data->output_off, sizeof(user_data->output) - user_data->output_off, + "%s", tmp_str); + TEST_ASSERT_EQUAL(strlen(tmp_str), ret); + user_data->output_off += ret; +} + +TEST_CASE("Expat parses XML", "[expat]") +{ + const char test_in[] = "Page titleheader
  1. A
  2. "\ + "
  3. B
  4. C
"; + const char test_expected[] = "\n"\ + "\n"\ + " \n"\ + " Page title\n"\ + " \n"\ + " \n"\ + " \n"\ + " header\n"\ + " \n"\ + "
    \n"\ + "
  1. \n"\ + " A\n"\ + "
  2. \n"\ + "
  3. \n"\ + " B\n"\ + "
  4. \n"\ + "
  5. \n"\ + " C\n"\ + "
  6. \n"\ + "
\n"\ + " \n"\ + ""; + user_data_t user_data = { + .depth = 0, + .output = { '\0' }, + .output_off = 0 + }; + + XML_Parser parser = XML_ParserCreate(NULL); + XML_SetUserData(parser, &user_data); + XML_SetElementHandler(parser, start_element, end_element); + XML_SetCharacterDataHandler(parser, data_handler); + + TEST_ASSERT_NOT_EQUAL(XML_STATUS_ERROR, XML_Parse(parser, test_in, strlen(test_in), 1)); + XML_ParserFree(parser); + + TEST_ASSERT_EQUAL(0, user_data.depth); // all closing tags have been found + + TEST_ASSERT_EQUAL(strlen(test_expected), strlen(user_data.output)); + TEST_ASSERT_EQUAL_STRING(test_expected, user_data.output); +} diff --git a/test_app/CMakeLists.txt b/test_app/CMakeLists.txt index 4085337..a08b4cb 100644 --- a/test_app/CMakeLists.txt +++ b/test_app/CMakeLists.txt @@ -1,25 +1,30 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) +include($ENV{IDF_PATH}/tools/cmake/version.cmake) -set(EXTRA_COMPONENT_DIRS ../libsodium ../expat ../esp_encrypted_img ../cbor ../jsmn ../qrcode) +# Add newly added components to one of these lines: +# 1. Add here if the component is compatible with IDF >= v4.3 +set(EXTRA_COMPONENT_DIRS ../libsodium ../expat ../cbor ../jsmn ../qrcode) +# 2. Add here if the component is compatible with IDF >= v4.4 if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "4.4") - list(APPEND EXTRA_COMPONENT_DIRS ../pid_ctrl) + list(APPEND EXTRA_COMPONENT_DIRS ../pid_ctrl ../esp_encrypted_img) endif() +# 3. Add here if the component is compatible with IDF >= v5.0 if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") list(APPEND EXTRA_COMPONENT_DIRS ../sh2lib ../nghttp) endif() - -# Set the components to include the tests for. -set(TEST_COMPONENTS libsodium expat esp_encrypted_img CACHE STRING "List of components to test") - -include($ENV{IDF_PATH}/tools/cmake/version.cmake) # $ENV{IDF_VERSION} was added after v4.3... -if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "4.4") - set(EXCLUDE_COMPONENTS esp_encrypted_img) -endif() +# !This section should NOT be touched when adding new component! +# Take all components in EXTRA_COMPONENT_DIRS, strip leading '../' and add it to TEST_COMPONENTS +# The build system will build and link unit tests, if the component contains 'test' subdirectory +set(TEST_COMPONENTS "" CACHE STRING "List of components to test") +foreach (CMP_DIR ${EXTRA_COMPONENT_DIRS}) + string(SUBSTRING ${CMP_DIR} 3 100 STRIPPED_CMP) # There should be no component name longer than 100 bytes... + list(APPEND TEST_COMPONENTS ${STRIPPED_CMP}) +endforeach() include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(idf_extra_test_app) diff --git a/test_app/main/test_app_main.c b/test_app/main/test_app_main.c index 26d18af..92888ad 100644 --- a/test_app/main/test_app_main.c +++ b/test_app/main/test_app_main.c @@ -4,15 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include #include "unity.h" void app_main(void) { UNITY_BEGIN(); - //unity_run_tests_by_tag("[libsodium]", false); unity_run_all_tests(); - //unity_run_menu(); UNITY_END(); } diff --git a/test_app/sdkconfig.defaults.esp32c3 b/test_app/sdkconfig.defaults.esp32c3 deleted file mode 100644 index d2265c0..0000000 --- a/test_app/sdkconfig.defaults.esp32c3 +++ /dev/null @@ -1 +0,0 @@ -CONFIG_ESP32C3_REV_MIN_0=y