Skip to content

Commit

Permalink
Merge pull request #2 from vChavezB/tests
Browse files Browse the repository at this point in the history
Added simulation tests with renode and pipeline
  • Loading branch information
vChavezB authored Apr 13, 2024
2 parents 573d721 + 1854c40 commit ec8b3c6
Show file tree
Hide file tree
Showing 17 changed files with 643 additions and 55 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/build_test.yml
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
7 changes: 7 additions & 0 deletions .gitignore
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
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 4 additions & 1 deletion samples/uptime/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2023, Victor Chavez
# Copyright 2024, Victor Chavez
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -14,3 +14,6 @@ CONFIG_LIB_CPLUSPLUS=y
CONFIG_STD_CPP17=y
CONFIG_NEWLIB_LIBC=y
CONFIG_BLE_UTILS=y
CONFIG_BT_ASSERT=n
CONFIG_LOG=y
CONFIG_BT_HCI_ACL_FLOW_CONTROL=n
24 changes: 13 additions & 11 deletions samples/uptime/src/ble.cpp
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
Expand All @@ -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
{
Expand All @@ -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) =
Expand All @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions samples/uptime/src/ble.hpp
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
Expand Down
10 changes: 6 additions & 4 deletions samples/uptime/src/main.cpp
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
Expand All @@ -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));
}
Expand Down
42 changes: 24 additions & 18 deletions samples/uptime/src/uptime_service.cpp
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
Expand All @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit ec8b3c6

Please sign in to comment.