-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from vChavezB/tests
Added simulation tests with renode and pipeline
- Loading branch information
Showing
17 changed files
with
643 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright (c) 2024, Victor Chavez ([email protected]) | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: Build | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-22.04 | ||
container: ghcr.io/zephyrproject-rtos/ci:v0.26.2 | ||
env: | ||
CMAKE_PREFIX_PATH: /opt/toolchains | ||
ZEPHYR_VERSION: 3.6.0 | ||
BOARD: nrf52840dk_nrf52840 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Initialize | ||
run: | | ||
cd /tmp/ | ||
west init --mr v$ZEPHYR_VERSION | ||
west update -o=--depth=1 -n | ||
- name: Build Uptime Sample | ||
working-directory: /tmp/ | ||
run: | | ||
west build $GITHUB_WORKSPACE/samples/uptime -b $BOARD --build-dir $GITHUB_WORKSPACE/samples/uptime/build | ||
- name: Build Central | ||
working-directory: /tmp/ | ||
run: | | ||
west build $GITHUB_WORKSPACE/tests/renode/ble_central -b $BOARD --build-dir $GITHUB_WORKSPACE/tests/renode/ble_central/build | ||
- name : Upload Firmware | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: zephyr-build | ||
path: | | ||
samples/uptime/build/zephyr/zephyr.elf | ||
tests/renode/ble_central/build/zephyr/zephyr.elf | ||
test: | ||
needs: build | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Download zephyr binaries | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: zephyr-build | ||
|
||
- name: Run tests on latest Renode | ||
uses: antmicro/[email protected] | ||
with: | ||
renode-version: '1.13.3' | ||
tests-to-run: 'tests/renode/uptime_test.robot' | ||
renode-path: renode-1.13 | ||
artifacts-path: ${{ github.workspace }} | ||
|
||
|
||
- name: Archive latest results | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: test-results-latest | ||
path: | | ||
report.html | ||
log.html | ||
robot_output.xml | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
build* | ||
*.pyc | ||
*.idea | ||
*/.vscode/* | ||
tests/renode/logs/* | ||
tests/renode/*.html | ||
tests/renode/*.xml | ||
tests/renode/snapshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,33 @@ The definition of BLE services and characteristics can be done at compile time | |
A demo is located in the samples folder. This demo can be used as a reference on how to use this module. | ||
|
||
|
||
# Tests | ||
|
||
Some basic tests are done with [Renode](https://renode.readthedocs.io/en/latest/) to simulate the correct setup of the BLE Services and characteristics. | ||
|
||
## Requirements | ||
|
||
- Renode v1.13.3 | ||
- Robot framework | ||
|
||
## Robot | ||
|
||
To run the unit test suite with robot execute: | ||
|
||
```bash | ||
renode-test -t tests/renode/uptime_test.robot | ||
``` | ||
|
||
## Debug | ||
|
||
If you want to manually debug the tests instead load the Renode script | ||
|
||
```bash | ||
renode tests/renode/uptime.resc | ||
``` | ||
|
||
|
||
## Contact | ||
|
||
Contact for issues, contributions as git patches or general information at [email protected] | ||
Contact for issues, contributions as git patches or general information at vchavezb(at)protonmail.com | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/*!***************************************************************** | ||
* Copyright 2023, Victor Chavez | ||
* Copyright 2023-2024, Victor Chavez | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* @file ble.cpp | ||
* @author Victor Chavez ([email protected]) | ||
* @file main.cpp | ||
* @author Victor Chavez ([email protected]) | ||
* | ||
* @brief | ||
* BLE connection implementation for uptime service demo | ||
|
@@ -12,7 +12,9 @@ | |
* - OS: Zephyr v3.2.x | ||
********************************************************************/ | ||
#include <zephyr/bluetooth/conn.h> | ||
#include <zephyr/logging/log.h> | ||
#include "ble.hpp" | ||
LOG_MODULE_REGISTER(ble, CONFIG_LOG_DEFAULT_LEVEL); | ||
|
||
namespace ble | ||
{ | ||
|
@@ -27,24 +29,24 @@ static void connected(bt_conn *conn, uint8_t conn_err) | |
|
||
if (conn_err) | ||
{ | ||
printk("Connection failed (err %d)\n", conn_err); | ||
LOG_INF("Connection failed (err %d)", conn_err); | ||
return; | ||
} | ||
|
||
err = bt_conn_get_info(conn, &info); | ||
if (err) | ||
{ | ||
printk("Failed to get connection info (err %d)\n", err); | ||
LOG_ERR("Failed to get connection info (err %d)", err); | ||
} | ||
else | ||
{ | ||
printk("Connected: %s\n", addr); | ||
LOG_INF("Connected: %s\n", addr); | ||
} | ||
} | ||
|
||
static void disconnected(struct bt_conn *conn, uint8_t reason) | ||
{ | ||
printk("Disconnected (reason 0x%02x)\n", reason); | ||
LOG_INF("Disconnected (reason 0x%02x)", reason); | ||
} | ||
|
||
BT_CONN_CB_DEFINE(conn_callbacks) = | ||
|
@@ -71,7 +73,7 @@ static int start_adv(void) | |
nullptr, | ||
0); | ||
if (err) { | ||
printk("Failed to create advertiser set (err %d)\n", err); | ||
LOG_ERR("Failed to create advertiser set (err %d)", err); | ||
return err; | ||
} | ||
return 0; | ||
|
@@ -85,15 +87,15 @@ int init() | |
err = bt_enable(NULL); | ||
if (err) | ||
{ | ||
printk("Bluetooth init failed (err %d)\n", err); | ||
LOG_ERR("Bluetooth init failed (err %d)", err); | ||
break; | ||
} | ||
|
||
printk("Bluetooth initialized\n"); | ||
LOG_INF("Bluetooth initialized\n"); | ||
err = start_adv(); | ||
if (err) | ||
{ | ||
printk("Advertising failed to create (err %d)\n", err); | ||
LOG_ERR("Advertising failed to create (err %d)", err); | ||
break; | ||
} | ||
}while(0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/*!***************************************************************** | ||
* Copyright 2023, Victor Chavez | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* @file ble.hpp | ||
* @author Victor Chavez ([email protected]) | ||
* @file main.cpp | ||
* @author Victor Chavez ([email protected]) | ||
* | ||
* @brief | ||
* BLE connection functions for uptime service demo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/*!***************************************************************** | ||
* Copyright 2023, Victor Chavez | ||
* Copyright 2023-2024, Victor Chavez | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* @file main.cpp | ||
* @author Victor Chavez ([email protected]) | ||
* @author Victor Chavez ([email protected]) | ||
* | ||
* @brief | ||
* Main source file that implements an uptime service demo for the BLE utils module | ||
|
@@ -14,18 +14,20 @@ | |
|
||
#include "ble.hpp" | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
#include "uptime_service.hpp" | ||
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); | ||
|
||
uptime::Service uptime_service; | ||
|
||
int main(void) | ||
{ | ||
printk("Starting Uptime BLE Utils sample\n"); | ||
LOG_INF("Starting Uptime BLE Utils sample"); | ||
uptime_service.init(); | ||
ble::init(); | ||
for (;;) | ||
{ | ||
const uint32_t uptime_ms = k_uptime_get_32(); | ||
const uint32_t uptime_ms = k_uptime_get_32(); | ||
uptime_service.update(uptime_ms/1000U); | ||
k_sleep(K_MSEC(1000)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
/*!***************************************************************** | ||
* Copyright 2023, Victor Chavez | ||
* Copyright 2023-2024, Victor Chavez | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* @file uptime_service.cpp | ||
* @author Victor Chavez ([email protected]) | ||
* @date 13.03.2023 | ||
* @file main.cpp | ||
* @author Victor Chavez ([email protected]) | ||
* | ||
* @brief | ||
* BLE Service implementation | ||
|
@@ -12,24 +11,15 @@ | |
* - language: C++17 | ||
* - OS: Zephyr v3.2.x | ||
********************************************************************/ | ||
|
||
#include <zephyr/logging/log.h> | ||
#include "uptime_service.hpp" | ||
|
||
LOG_MODULE_REGISTER(uptime_svc, CONFIG_LOG_DEFAULT_LEVEL); | ||
|
||
namespace uptime | ||
{ | ||
|
||
namespace uuid | ||
{ | ||
static constexpr bt_uuid_128 svc_base = ble_utils::uuid::uuid128_init(0xABCD0000, | ||
0x1234, | ||
0x5678, | ||
0x9ABC, | ||
0xDEF012345678); | ||
|
||
static constexpr bt_uuid_128 char_basic = ble_utils::uuid::derive_uuid(svc_base,0x0001); | ||
static constexpr bt_uuid_128 char_notify = ble_utils::uuid::derive_uuid(svc_base,0x0002); | ||
static constexpr bt_uuid_128 char_indicate = ble_utils::uuid::derive_uuid(svc_base,0x0003); | ||
} | ||
|
||
|
||
namespace characteristic | ||
{ | ||
|
@@ -61,19 +51,35 @@ Notify::Notify(): | |
{ | ||
} | ||
|
||
void Notify::ccc_changed(CCCValue_e value) | ||
{ | ||
int val = static_cast<int>(value); | ||
LOG_INF("Characteristic Notify Uptime CCC changed %d\n",val); | ||
} | ||
|
||
Indicate::Indicate(): | ||
ble_utils::gatt::CharacteristicIndicate((const bt_uuid*)&uuid::char_indicate) | ||
{ | ||
} | ||
|
||
void Indicate::ccc_changed(CCCValue_e value) | ||
{ | ||
int val = static_cast<int>(value); | ||
LOG_INF("Characteristic Indicate Uptime CCC changed %d\n",val); | ||
} | ||
void Indicate::indicate_rsp() | ||
{ | ||
LOG_INF("Characteristic Indicate Uptime Completed\n"); | ||
} | ||
|
||
} // namespace characteristic | ||
|
||
Service::Service(): | ||
ble_utils::gatt::Service((const bt_uuid*)&uuid::svc_base) | ||
{ | ||
register_char(&m_basic); | ||
register_char(&m_notify); | ||
register_char(&m_indicate); | ||
register_char(&m_notify); | ||
} | ||
|
||
void Service::update(uint32_t uptime) | ||
|
Oops, something went wrong.