-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 BSIM based BLE tests #1875
Merged
petejohanson
merged 4 commits into
zmkfirmware:main
from
petejohanson:testing/add-bsim-ble-tests
Dec 3, 2023
Merged
Add BSIM based BLE tests #1875
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b5882d8
feat(bluetooth): Build on ARCH_POSIX.
petejohanson 2495257
feat(bluetooth): Initial nRF52 BSIM based test support.
petejohanson 0c427fe
chore: Ensure BSIM env. variables set in devcontainer.
petejohanson 7c430d8
feat(tests): Add ability to auto-accept test diff.
petejohanson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ | ||
name: BLE Tests | ||
|
||
on: | ||
push: | ||
paths: | ||
- ".github/workflows/ble-test.yml" | ||
- "app/tests/ble/**" | ||
- "app/src/**" | ||
- "app/run-ble-test.sh" | ||
pull_request: | ||
paths: | ||
- ".github/workflows/ble-test.yml" | ||
- "app/tests/ble/**" | ||
- "app/src/**" | ||
- "app/run-ble-test.sh" | ||
|
||
jobs: | ||
collect-tests: | ||
outputs: | ||
test-dirs: ${{ steps.test-dirs.outputs.test-dirs }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Find test directories | ||
id: test-dirs | ||
run: | | ||
cd app/tests/ble | ||
export TESTS=$(ls -d * | grep -v central | jq -R -s -c 'split("\n")[:-1]') | ||
echo "::set-output name=test-dirs::${TESTS}" | ||
run-tests: | ||
needs: collect-tests | ||
strategy: | ||
matrix: | ||
test: ${{ fromJSON(needs.collect-tests.outputs.test-dirs) }} | ||
runs-on: ubuntu-latest | ||
container: | ||
image: docker.io/zmkfirmware/zmk-build-arm:3.2 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Cache west modules | ||
uses: actions/[email protected] | ||
env: | ||
cache-name: cache-zephyr-modules | ||
with: | ||
path: | | ||
modules/ | ||
tools/ | ||
zephyr/ | ||
bootloader/ | ||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('app/west.yml') }} | ||
restore-keys: | | ||
${{ runner.os }}-build-${{ env.cache-name }}- | ||
${{ runner.os }}-build- | ||
${{ runner.os }}- | ||
timeout-minutes: 2 | ||
continue-on-error: true | ||
- name: Initialize workspace (west init) | ||
run: west init -l app | ||
- name: Enable babblesim group filter | ||
run: west config manifest.group-filter -- +babblesim | ||
- name: Update modules (west update) | ||
run: west update | ||
- name: Export Zephyr CMake package (west zephyr-export) | ||
run: west zephyr-export | ||
- name: Build BabbleSim components | ||
working-directory: tools/bsim | ||
run: make everything | ||
- name: Test ${{ matrix.test }} | ||
working-directory: app | ||
run: BSIM_COMPONENTS_PATH="${GITHUB_WORKSPACE}/tools/bsim/components/" BSIM_OUT_PATH="${GITHUB_WORKSPACE}/tools/bsim/" ./run-ble-test.sh tests/ble/${{ matrix.test }} | ||
- name: Archive artifacts | ||
if: ${{ always() }} | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: "log-files" | ||
path: app/build/**/*.log |
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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CONFIG_ZMK_BLE=y | ||
CONFIG_LOG=y | ||
CONFIG_LOG_BACKEND_SHOW_COLOR=n | ||
CONFIG_ZMK_LOG_LEVEL_DBG=y |
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,17 @@ | ||
#include <behaviors.dtsi> | ||
#include <dt-bindings/zmk/keys.h> | ||
#include <dt-bindings/zmk/kscan_mock.h> | ||
|
||
/ { | ||
chosen { | ||
zmk,kscan = &kscan; | ||
}; | ||
|
||
kscan: kscan { | ||
compatible = "zmk,kscan-mock"; | ||
label = "KSCAN_MOCK"; | ||
|
||
rows = <2>; | ||
columns = <2>; | ||
}; | ||
}; |
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,107 @@ | ||
#!/bin/bash | ||
petejohanson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Copyright (c) 2023 The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
if [ -z "$1" ]; then | ||
echo "Usage: ./run-ble-test.sh <path to testcase>" | ||
exit 1 | ||
fi | ||
|
||
path=$1 | ||
if [ "$path" = "all" ]; then | ||
path="tests" | ||
fi | ||
|
||
if [ -z "${BSIM_OUT_PATH}" ]; then | ||
echo "BSIM_OUT_PATH needs to be set before running this script." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$BLE_TESTS_NO_CENTRAL_BUILD" ]; then | ||
if ! [ -e build/tests/ble/central ]; then | ||
west build -d build/tests/ble/central -b nrf52_bsim tests/ble/central > /dev/null 2>&1 | ||
else | ||
west build -d build/tests/ble/central | ||
fi | ||
|
||
cp build/tests/ble/central/zephyr/zephyr.exe "${BSIM_OUT_PATH}/bin/ble_test_central.exe" | ||
caksoylar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if ! [ -e build/tests/ble/private_central ]; then | ||
west build -d build/tests/ble/private_central -b nrf52_bsim tests/ble/central -- -DCONFIG_BT_PRIVACY=y -DCONFIG_BT_SCAN_WITH_IDENTITY=n > /dev/null 2>&1 | ||
else | ||
west build -d build/tests/ble/private_central | ||
fi | ||
|
||
cp build/tests/ble/private_central/zephyr/zephyr.exe "${BSIM_OUT_PATH}/bin/ble_test_private_central.exe" | ||
fi | ||
|
||
testcases=$(find $path -name nrf52_bsim.keymap -exec dirname \{\} \;) | ||
num_cases=$(echo "$testcases" | wc -l) | ||
if [ $num_cases -gt 1 ] || [ "$testcases" != "${path%%/}" ]; then | ||
echo "$testcases" | ||
echo "" > ./build/tests/pass-fail.log | ||
echo "$testcases" | BLE_TESTS_QUIET_OUTPUT=y BLE_TESTS_NO_CENTRAL_BUILD=y xargs -L 1 -P ${J:-4} ./run-ble-test.sh | ||
err=$? | ||
sort -k2 ./build/tests/pass-fail.log | ||
exit $err | ||
fi | ||
|
||
testcase="$path" | ||
echo "Running $testcase:" | ||
|
||
west build -d build/$testcase -b nrf52_bsim -- -DZMK_CONFIG="$(pwd)/$testcase" > /dev/null 2>&1 | ||
if [ $? -gt 0 ]; then | ||
echo "FAILED: $testcase did not build" | tee -a ./build/tests/pass-fail.log | ||
exit 1 | ||
fi | ||
|
||
if [ -n "${BLE_TESTS_QUIET_OUTPUT}" ]; then | ||
output_dev="/dev/null" | ||
else | ||
output_dev="/dev/stdout" | ||
fi | ||
|
||
exe_name=${testcase//\//_} | ||
|
||
start_dir=$(pwd) | ||
cp build/$testcase/zephyr/zmk.exe "${BSIM_OUT_PATH}/bin/${exe_name}" | ||
pushd "${BSIM_OUT_PATH}/bin" > /dev/null 2>&1 | ||
if [ -e "${start_dir}/build/$testcase/output.log" ]; then | ||
rm "${start_dir}/build/$testcase/output.log" | ||
fi | ||
|
||
central_counts=$(wc -l ${start_dir}/${testcase}/centrals.txt | cut -d' ' -f1) | ||
./${exe_name} -d=0 -s=${exe_name} | tee -a "${start_dir}/build/$testcase/output.log" > "${output_dev}" & | ||
./bs_device_handbrake -s=${exe_name} -d=1 -r=10 > "${output_dev}" & | ||
|
||
cat "${start_dir}/${testcase}/centrals.txt" | | ||
while IFS= read -r line | ||
do | ||
${line} -s=${exe_name} | tee -a "${start_dir}/build/$testcase/output.log" > "${output_dev}" & | ||
done | ||
|
||
./bs_2G4_phy_v1 -s=${exe_name} -D=$(( 2 + central_counts )) -sim_length=50e6 > "${output_dev}" 2>&1 | ||
|
||
popd > /dev/null 2>&1 | ||
|
||
cat build/$testcase/output.log | sed -E -n -f $testcase/events.patterns > build/$testcase/filtered_output.log | ||
|
||
diff -auZ $testcase/snapshot.log build/$testcase/filtered_output.log | ||
if [ $? -gt 0 ]; then | ||
if [ -f $testcase/pending ]; then | ||
echo "PENDING: $testcase" | tee -a ./build/tests/pass-fail.log | ||
exit 0 | ||
fi | ||
|
||
if [ -n "${ZMK_TESTS_AUTO_ACCEPT}" ]; then | ||
echo "Auto-accepting failure for $testcase" | ||
cp build/$testcase/filtered_output.log $testcase/snapshot.log | ||
else | ||
echo "FAILED: $testcase" | tee -a ./build/tests/pass-fail.log | ||
exit 1 | ||
fi | ||
fi | ||
|
||
echo "PASS: $testcase" | tee -a ./build/tests/pass-fail.log | ||
exit 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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(ble_test_central) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) | ||
|
||
# zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth) |
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,9 @@ | ||
CONFIG_BT=y | ||
CONFIG_LOG=y | ||
CONFIG_BOOT_BANNER=n | ||
CONFIG_BT_LOG_LEVEL_WRN=y | ||
CONFIG_LOG_BACKEND_SHOW_COLOR=n | ||
CONFIG_BT_CENTRAL=y | ||
CONFIG_BT_SMP=y | ||
CONFIG_BT_SCAN_WITH_IDENTITY=y | ||
CONFIG_BT_GATT_CLIENT=y |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to not have the test cases and the test builds be sibling folders. If we ever need to add a "peripheral" build, then this command has to become more complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not sure it's worth the complexity trying to generalize it at this point.