Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to edgehog_device #56

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# This file is part of Edgehog.
#
# Copyright 2022 SECO Mind
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: "Edgehog Test Suite"
on:
# Run when pushing to stable branches
push:
branches:
- 'main'
pull_request:

jobs:
test-qemu:
runs-on: ubuntu-latest
container: harlem88/qemu-xtensa-idf:4.3
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Checkout astarte-device-sdk
uses: actions/checkout@v2
with:
repository: astarte-platform/astarte-device-sdk-esp32
ref: release-1.0
path: ./examples/edgehog_app/components/astarte-device-sdk-esp32
- name: Build with idf.py
run: |
. $IDF_PATH/export.sh
idf.py reconfigure
idf.py build
working-directory: ./test/app_test
shell: bash
- name: pytest
run: pytest --embedded-services=idf,qemu -s
working-directory: ./test/app_test
shell: bash
16 changes: 9 additions & 7 deletions src/edgehog_telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ edgehog_telemetry_t *edgehog_telemetry_new(

edgehog_telemetry->telemetry_config_len = telemetry_config_len;

edgehog_telemetry->telemetry_config = calloc(
edgehog_telemetry->telemetry_config_len, sizeof(edgehog_device_telemetry_config_t));
if (!edgehog_telemetry->telemetry_config) {
ESP_LOGE(TAG, "Out of memory %s: %d", __FILE__, __LINE__);
goto error;
if (edgehog_telemetry->telemetry_config_len > 0) {
edgehog_telemetry->telemetry_config = calloc(
edgehog_telemetry->telemetry_config_len, sizeof(edgehog_device_telemetry_config_t));
if (!edgehog_telemetry->telemetry_config) {
ESP_LOGE(TAG, "Out of memory %s: %d", __FILE__, __LINE__);
goto error;
}
memcpy(edgehog_telemetry->telemetry_config, telemetry_config,
telemetry_config_len * sizeof(edgehog_device_telemetry_config_t));
}
memcpy(edgehog_telemetry->telemetry_config, telemetry_config,
telemetry_config_len * sizeof(edgehog_device_telemetry_config_t));

astarte_list_init(&edgehog_telemetry->timer_list);

Expand Down
6 changes: 6 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(srcs_test "test_edgehog_device.c"
"test_edgehog_device_telemetry.c")

idf_component_register(SRCS "${srcs_test}"
INCLUDE_DIRS "." "../include" "../private" "../src"
REQUIRES unity astarte-device-sdk-esp32 nvs_flash)
12 changes: 12 additions & 0 deletions test/app_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.5)

set(EXTRA_COMPONENT_DIRS "../../examples/edgehog_app/components"
"../..")

set(test_components "edgehog-esp32-device")

set(TEST_COMPONENTS "${test_components}"
STRING "List of components to test")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(edgehog-esp32-device-test)
14 changes: 14 additions & 0 deletions test/app_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := edgehog-esp32-device-test

# Include the components directory of the main application:
#
EXTRA_COMPONENT_DIRS := $(realpath ../../examples/edgehog_app/components)

TEST_COMPONENTS ?= edgehog-esp32-device

include $(IDF_PATH)/make/project.mk
41 changes: 41 additions & 0 deletions test/app_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ESP-IDF pytest-embedded

1. how `pytest_embedded_serial_esp` auto-detect chip target and port
2. how `pytest_embedded_idf` auto flash the app into the target chip

## Prerequisites

1. Connect to the target chips
2. Install following packages
- `pytest_embedded`
- `pytest_embedded_serial_esp`
- `pytest_embedded_idf`
3. cd into the app folder
4. run `idf.py build` under the apps you want to test

##idf
```shell
$ pytest --embedded-services=esp,idf
```

The ... idf app qemu flash image automatically and run this with qemu.

## Prerequisites

1. Prepare QEMU program which supports xtensa, name it `qemu-system-xtensa` and add its parent directory into `$PATH`
2. Install following packages
- `pytest_embedded`
- `pytest_embedded_idf`
- `pytest_embedded_qemu`
- `esptool` (for sending commands to QEMU via socket)
3. cd into the app folder
4. run `idf.py build` under the apps you want to test

## Test Steps

## qemu
```shell
$ pytest --embedded-services=idf,qemu
```

QEMU flash image would be created automatically if not exists
2 changes: 2 additions & 0 deletions test/app_test/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
idf_component_register(SRCS "test_main.c"
INCLUDE_DIRS ".")
4 changes: 4 additions & 0 deletions test/app_test/main/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
17 changes: 17 additions & 0 deletions test/app_test/main/test_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <unity.h>
#include <nvs_flash.h>
#include <nvs.h>

void app_main(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 );

UNITY_BEGIN();
unity_run_all_tests();
UNITY_END();
}
12 changes: 12 additions & 0 deletions test/app_test/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[pytest]

# log related
log_cli = True
log_cli_level = INFO
log_cli_format = %(asctime)s %(levelname)s %(message)s
log_cli_date_format = %Y-%m-%d %H:%M:%S

log_file = test.log
log_file_level = INFO
log_file_format = %(asctime)s %(levelname)s %(message)s
log_file_date_format = %Y-%m-%d %H:%M:%S
Loading