diff --git a/.gitlab/ci/build.yml b/.gitlab/ci/build.yml index c47cb5bad0..11fc00481b 100644 --- a/.gitlab/ci/build.yml +++ b/.gitlab/ci/build.yml @@ -163,6 +163,14 @@ build_pytest_examples_esp32h2: IDF_TARGET: esp32h2 TEST_DIR: examples +build_pytest_components_esp32h2: + extends: + - .build_pytest_template + - .rules:build:component_ut-esp32h2 + variables: + IDF_TARGET: esp32h2 + TEST_DIR: components + build_pytest_components_esp32: extends: - .build_pytest_template diff --git a/.gitlab/ci/dependencies/dependencies.yml b/.gitlab/ci/dependencies/dependencies.yml index eb8717dd59..d3bcd1e6e8 100644 --- a/.gitlab/ci/dependencies/dependencies.yml +++ b/.gitlab/ci/dependencies/dependencies.yml @@ -137,6 +137,7 @@ build:integration_test: - usb # USB Device & Host tests - spi_multi # UT_C2_SPI_DUAL - adc # component_ut_pytest_esp32x_adc + - i154 patterns: - "{0}-{1}-{2}" - "{0}-{2}" diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index 817a6797d8..708442fccc 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -542,6 +542,8 @@ changes: *patterns-component_ut-adc - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:component_ut-esp32: rules: @@ -565,6 +567,8 @@ changes: *patterns-component_ut-adc - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:component_ut-esp32c2: rules: @@ -584,6 +588,8 @@ changes: *patterns-component_ut-adc - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:component_ut-esp32c3: rules: @@ -606,6 +612,32 @@ changes: *patterns-component_ut-adc - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 + +.rules:build:component_ut-esp32h2: + rules: + - <<: *if-revert-branch + when: never + - <<: *if-protected + - <<: *if-label-build + - <<: *if-label-component_ut + - <<: *if-label-component_ut_esp32h2 + - <<: *if-label-target_test + - <<: *if-label-unit_test + - <<: *if-label-unit_test_esp32h2 + - <<: *if-dev-push + changes: *patterns-build_components + - <<: *if-dev-push + changes: *patterns-build_system + - <<: *if-dev-push + changes: *patterns-component_ut + - <<: *if-dev-push + changes: *patterns-component_ut-adc + - <<: *if-dev-push + changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:component_ut-esp32s2: rules: @@ -628,6 +660,8 @@ changes: *patterns-component_ut-adc - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:component_ut-esp32s3: rules: @@ -650,6 +684,8 @@ changes: *patterns-component_ut-adc - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:custom_test: rules: @@ -674,6 +710,8 @@ changes: *patterns-custom_test - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:custom_test-esp32: rules: @@ -693,6 +731,8 @@ changes: *patterns-custom_test - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:custom_test-esp32c2: rules: @@ -709,6 +749,8 @@ changes: *patterns-build_system - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:custom_test-esp32c3: rules: @@ -727,6 +769,8 @@ changes: *patterns-custom_test - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:custom_test-esp32s2: rules: @@ -745,6 +789,8 @@ changes: *patterns-custom_test - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:custom_test-esp32s3: rules: @@ -763,6 +809,8 @@ changes: *patterns-custom_test - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:docker: rules: @@ -846,6 +894,8 @@ changes: *patterns-example_test-usb - <<: *if-dev-push changes: *patterns-example_test-wifi + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:example_test-esp32c2: rules: @@ -870,6 +920,8 @@ changes: *patterns-example_test-usb - <<: *if-dev-push changes: *patterns-example_test-wifi + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:example_test-esp32c3: rules: @@ -899,6 +951,8 @@ changes: *patterns-example_test-usb - <<: *if-dev-push changes: *patterns-example_test-wifi + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:example_test-esp32h2: rules: @@ -957,6 +1011,8 @@ changes: *patterns-example_test-usb - <<: *if-dev-push changes: *patterns-example_test-wifi + - <<: *if-dev-push + changes: *patterns-target_test-i154 .rules:build:example_test-esp32s3: rules: @@ -1112,6 +1168,8 @@ changes: *patterns-build_system - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 - <<: *if-dev-push changes: *patterns-unit_test - <<: *if-dev-push @@ -1135,6 +1193,8 @@ changes: *patterns-build_system - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 - <<: *if-dev-push changes: *patterns-unit_test - <<: *if-dev-push @@ -1157,6 +1217,8 @@ changes: *patterns-build_system - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 - <<: *if-dev-push changes: *patterns-unit_test-sdio - <<: *if-dev-push @@ -1177,6 +1239,8 @@ changes: *patterns-build_system - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 - <<: *if-dev-push changes: *patterns-unit_test - <<: *if-dev-push @@ -1199,6 +1263,8 @@ changes: *patterns-build_system - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 - <<: *if-dev-push changes: *patterns-unit_test - <<: *if-dev-push @@ -1221,6 +1287,8 @@ changes: *patterns-build_system - <<: *if-dev-push changes: *patterns-downloadable-tools + - <<: *if-dev-push + changes: *patterns-target_test-i154 - <<: *if-dev-push changes: *patterns-unit_test - <<: *if-dev-push @@ -1339,6 +1407,19 @@ - <<: *if-dev-push changes: *patterns-component_ut-adc +.rules:test:component_ut-esp32h2-i154: + rules: + - <<: *if-revert-branch + when: never + - <<: *if-protected + - <<: *if-label-build-only + when: never + - <<: *if-label-component_ut + - <<: *if-label-component_ut_esp32h2 + - <<: *if-label-target_test + - <<: *if-dev-push + changes: *patterns-target_test-i154 + .rules:test:component_ut-esp32s2: rules: - <<: *if-revert-branch diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 0c033bf0cb..8075cb7c75 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -516,6 +516,14 @@ component_ut_pytest_esp32c3_sdspi: - build_pytest_components_esp32c3 tags: [ esp32c3, sdcard_spimode ] +component_ut_pytest_esp32h2_i154: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32h2-i154 + needs: + - build_pytest_components_esp32h2 + tags: [ esp32h2, ieee802154 ] + example_test_pytest_openthread_br: extends: - .pytest_examples_dir_template diff --git a/components/ieee802154/.build-test-rules.yml b/components/ieee802154/.build-test-rules.yml new file mode 100644 index 0000000000..5f0efd6f3e --- /dev/null +++ b/components/ieee802154/.build-test-rules.yml @@ -0,0 +1,6 @@ +# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps + +components/ieee802154/test_apps/test_ieee802154: + enable: + - if: IDF_TARGET == "esp32h2" + reason: only test on esp32h2 diff --git a/components/ieee802154/test_apps/test_ieee802154/CMakeLists.txt b/components/ieee802154/test_apps/test_ieee802154/CMakeLists.txt new file mode 100644 index 0000000000..6f32785a15 --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/CMakeLists.txt @@ -0,0 +1,5 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(test_ieee802154) diff --git a/components/ieee802154/test_apps/test_ieee802154/README.md b/components/ieee802154/test_apps/test_ieee802154/README.md new file mode 100644 index 0000000000..5fc553bde4 --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/README.md @@ -0,0 +1,3 @@ +| Supported Targets | ESP32-H2 | +| ----------------- | -------- | + diff --git a/components/ieee802154/test_apps/test_ieee802154/main/CMakeLists.txt b/components/ieee802154/test_apps/test_ieee802154/main/CMakeLists.txt new file mode 100644 index 0000000000..d0a58e94a0 --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/main/CMakeLists.txt @@ -0,0 +1,11 @@ +set(srcs "test_app_main.c" + "src/ieee802154_cmd.c") + +set(include "." + "include") + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE +idf_component_register(SRCS ${srcs} + INCLUDE_DIRS include + WHOLE_ARCHIVE) diff --git a/components/ieee802154/test_apps/test_ieee802154/main/include/ieee802154_cmd.h b/components/ieee802154/test_apps/test_ieee802154/main/include/ieee802154_cmd.h new file mode 100644 index 0000000000..d17a06fa97 --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/main/include/ieee802154_cmd.h @@ -0,0 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#pragma once + +void register_ieee802154_cmd(void); diff --git a/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c b/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c new file mode 100644 index 0000000000..c7dde2f060 --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c @@ -0,0 +1,162 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include +#include +#include "esp_system.h" +#include "esp_log.h" +#include "esp_ieee802154.h" +#include "esp_console.h" +#include "linenoise/linenoise.h" +#include "argtable3/argtable3.h" +#include "ieee802154_cmd.h" +#include "esp_phy_init.h" + +static uint8_t s_tx_frame[131] = { 0 }; +static const char* TAG = "i154test"; + +static void register_rx(void); +static void register_tx(void); + +void register_ieee802154_cmd(void) +{ + register_rx(); + register_tx(); +} + +static struct { + struct arg_int *length; + struct arg_lit *cca_enable; + struct arg_int *frame; + struct arg_int *offset; + struct arg_end *end; +} tx_args; + +static int process_tx(int argc, char **argv) +{ + uint8_t tx_frame[128] = { 0 }; + uint8_t offset = 0; + bool cca = false; + int nerrors = arg_parse(argc, argv, (void **) &tx_args); + if (nerrors != 0) { + arg_print_errors(stderr, tx_args.end, argv[0]); + return 1; + } + memset(tx_frame, 0, sizeof(tx_frame)); + + if (tx_args.offset->count && (tx_args.offset->ival[0] >= 0 && tx_args.offset->ival[0] <= 3)) { + offset = tx_args.offset->ival[0]; + } + + if (tx_args.length->count) { + tx_frame[0] = tx_args.length->ival[0]; + + for (uint8_t i = 0; i < tx_frame[0]; i++) { + tx_frame[i + 1] = i; + } + } else if (tx_args.frame->count) { + tx_frame[0] = tx_args.frame->count; + + for (uint8_t i = 0; i < tx_frame[0]; i++) { + tx_frame[i + 1] = tx_args.frame->ival[i]; + } + } + if (tx_args.cca_enable->count) { + cca = true; + } + memcpy(s_tx_frame+offset, tx_frame, sizeof(tx_frame)); + esp_ieee802154_transmit(s_tx_frame, cca); + return 0; +} + +static void register_tx(void) +{ + tx_args.length = + arg_int0("l", "length", "", "frame length"); + tx_args.cca_enable = + arg_lit0("C", "cca_enable", "set cca trigging tx mode true"); + tx_args.frame = + arg_intn(NULL, NULL, "", 0, 127, "transmit raw frame"); + tx_args.offset = + arg_int0("o", "offset", "", "tx buffer offset"); + tx_args.end = arg_end(5); + + const esp_console_cmd_t cmd = { + .command = "tx", + .help = "transmit IEEE 802154 MAC frame", + .hint = NULL, + .func = &process_tx, + .argtable = &tx_args + }; + ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); +} + +static struct { + struct arg_int *receive; + struct arg_end *end; +} rx_args; + +static int process_rx(int argc, char **argv) +{ + int nerrors = arg_parse(argc, argv, (void **) &rx_args); + if (nerrors != 0) { + arg_print_errors(stderr, rx_args.end, argv[0]); + return 1; + } + + if (rx_args.receive->count == 1) { + if (rx_args.receive->ival[0] == 0) { + esp_ieee802154_sleep(); + ESP_LOGI(TAG, "radio exit receive mode"); + } else if (rx_args.receive->ival[0] == 1) { // receive, non-blocking + ESP_LOGI(TAG, "RX Start"); + esp_ieee802154_receive(); + esp_ieee802154_set_rx_when_idle(true); + } else { + ESP_LOGE(TAG, "no valid arguments"); + return 1; + } + } else { + ESP_LOGE(TAG, "no valid arguments"); + return 1; + } + return 0; +} + +static void register_rx(void) +{ + rx_args.receive = + arg_int0("r", "receive", "", "configure the radio receive mode, 0: disable; 1: enable"); + rx_args.end = arg_end(2); + + const esp_console_cmd_t cmd = { + .command = "rx", + .help = "enable/disable the receive mode", + .hint = NULL, + .func = &process_rx, + .argtable = &rx_args + }; + ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); +} + +void esp_ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info) +{ + ESP_EARLY_LOGI(TAG, "Tx Done %d bytes", frame[0]); + for(uint8_t idx = 1; idx < frame[0]; idx+=8) { + ESP_EARLY_LOGI(TAG, "%02x %02x %02x %02x %02x %02x %02x %02x", + frame[idx], frame[idx+1], frame[idx+2], frame[idx+3], + frame[idx+4], frame[idx+5], frame[idx+6], frame[idx+7]); + } +} + +void esp_ieee802154_receive_done(uint8_t *frame, esp_ieee802154_frame_info_t *frame_info) +{ + ESP_EARLY_LOGI(TAG, "Rx Done %d bytes", frame[0]); + for(uint8_t idx = 1; idx < frame[0]; idx+=8) { + ESP_EARLY_LOGI(TAG, "%02x %02x %02x %02x %02x %02x %02x %02x", + frame[idx], frame[idx+1], frame[idx+2], frame[idx+3], + frame[idx+4], frame[idx+5], frame[idx+6], frame[idx+7]); + } +} diff --git a/components/ieee802154/test_apps/test_ieee802154/main/test_app_main.c b/components/ieee802154/test_apps/test_ieee802154/main/test_app_main.c new file mode 100644 index 0000000000..a19f5e08c0 --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/main/test_app_main.c @@ -0,0 +1,53 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include +#include +#include "esp_system.h" +#include "esp_log.h" +#include "esp_console.h" +#include "esp_vfs_dev.h" +#include "esp_vfs_fat.h" +#include "nvs.h" +#include "nvs_flash.h" +#include "esp_ieee802154.h" +#include "esp_phy_init.h" +#include "ieee802154_cmd.h" + +#define PROMPT_STR "ieee802154" + +static void initialize_nvs(void) +{ + esp_err_t err = nvs_flash_init(); + if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK( nvs_flash_erase() ); + err = nvs_flash_init(); + } + ESP_ERROR_CHECK(err); +} + +void app_main(void) +{ + esp_ieee802154_enable(); + esp_phy_enable(); + esp_console_repl_t *repl = NULL; + esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); + /* Prompt to be printed before each line. + * This can be customized, made dynamic, etc. + */ + repl_config.prompt = PROMPT_STR ">"; + repl_config.max_cmdline_length = 256; + + initialize_nvs(); + + /* Register commands */ + esp_console_register_help_command(); + register_ieee802154_cmd(); + + esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); + ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl)); + + ESP_ERROR_CHECK(esp_console_start_repl(repl)); +} diff --git a/components/ieee802154/test_apps/test_ieee802154/pytest_test_ieee802154.py b/components/ieee802154/test_apps/test_ieee802154/pytest_test_ieee802154.py new file mode 100644 index 0000000000..5953fb18b7 --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/pytest_test_ieee802154.py @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +from typing import Tuple + +import pytest +from pytest_embedded_idf.dut import IdfDut + + +@pytest.mark.esp32h2 +@pytest.mark.ieee802154 +@pytest.mark.parametrize( + 'count, config, beta_target', [ + (2, 'release', 'esp32h2beta2'), + ], indirect=True +) +def test_based_txrx(dut: Tuple[IdfDut, IdfDut]) -> None: + transmit = dut[0] + receive = dut[1] + receive.expect('ieee802154>', timeout=60) + receive.write('rx -r 1') + receive.expect('RX Start', timeout=60) + transmit.expect('ieee802154>', timeout=60) + transmit.write('tx -l 10') + transmit.expect('Tx Done 10 bytes', timeout=60) + transmit.expect('00 01 02 03 04 05 06 07', timeout=60) + transmit.expect('08 09 00 00 00 00 00 00', timeout=60) + receive.expect('Rx Done 10 bytes', timeout=60) + receive.expect('00 01 02 03 04 05 06 07', timeout=60) diff --git a/components/ieee802154/test_apps/test_ieee802154/sdkconfig.ci.release b/components/ieee802154/test_apps/test_ieee802154/sdkconfig.ci.release new file mode 100644 index 0000000000..3cff15d49e --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/sdkconfig.ci.release @@ -0,0 +1,3 @@ +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/components/ieee802154/test_apps/test_ieee802154/sdkconfig.defaults b/components/ieee802154/test_apps/test_ieee802154/sdkconfig.defaults new file mode 100644 index 0000000000..44d488b4de --- /dev/null +++ b/components/ieee802154/test_apps/test_ieee802154/sdkconfig.defaults @@ -0,0 +1,5 @@ +# This file was generated using idf.py save-defconfig. It can be edited manually. +# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration +# +CONFIG_IDF_TARGET="esp32h2" +CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2=y diff --git a/pytest.ini b/pytest.ini index a75c5de62d..09d42ed412 100644 --- a/pytest.ini +++ b/pytest.ini @@ -65,6 +65,7 @@ markers = adc: ADC related tests should run on adc runners # multi-dut markers + ieee082154: ieee082154 related tests should run on ieee082154 runners. i154_multi_dut: tests should be used for i154, such as openthread. wifi_two_dut: tests should be run on runners which has two wifi duts connected. generic_multi_device: generic multiple devices whose corresponding gpio pins are connected to each other.