Skip to content
XiaoMiPublic

About

Hardware-free Bluetooth simulation framework for AI agents and CI. Runs Zephyr, NuttX, NimBLE, BlueZ, Bumble, and Trouble concurrently—with deterministic results and speeds up to hundreds of times faster than real time.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

16 stars

Watchers

1 watching

Forks

BSWorld

English | 简体中文

BSWorld is a deterministic simulation framework for testing Bluetooth Hosts and Applications on Linux. A pytest scenario defines the device topology and expected behavior; BSWorld runs the participants on a shared BabbleSim radio and simulation clock, then archives logs and protocol traces.

Use BSWorld to:

  • Test open-source Host stacks such as Zephyr, NuttX, BlueZ, NimBLE, Bumble, and TrouBLE without modifying their source code.
  • Run without hardware: Hosts connect over standard H4 HCI to virtual Controllers, or complete firmware joins the PHY with its own Controller and radio.
  • Keep Application logs, HCI BTSnoop captures, PHY logs, and Ellisys traces for debugging failures.
  • Simulate many devices in one scenario. Repeated runs of the same scenario produce consistent logs and timing, regardless of host load or scheduling.
  • Share one discrete simulation clock across all devices. Scenarios are isolated and run in parallel with pytest-xdist, up to 100 times faster than real time.
  • Inject attenuation, interference, WLAN activity, and recorded radio signals.

Quick Start

BSWorld runs on Linux/x86_64. The published Docker image includes Python, BSWorld, and the firmware required by the integration tests.

Docker (Recommended)

Install Docker Engine, then run the packaged integration tests:

sudo docker pull ghcr.io/xiaomi/bsworld:latest
mkdir -p .cache/docker-results
# The published image runs as UID/GID 1000.
sudo chown 1000:1000 .cache/docker-results
sudo docker run --rm \
  -e PYTHONPATH=/workspace \
  --mount "type=bind,src=$PWD/.cache/docker-results,dst=/output" \
  ghcr.io/xiaomi/bsworld:latest

Results are written to .cache/docker-results, including pytest.xml, process logs, HCI captures, and RF traces. See the Docker guide to run a selected suite, test the current checkout, choose an image version, or build an image.

Local Linux

Development and test commands require Python 3.12 or newer. On Ubuntu 24.04, install the required tools:

sudo apt-get update
sudo apt-get install -y \
  bash ca-certificates curl git repo file make binutils build-essential \
  python3.12 python3.12-dev python3.12-venv python3-pip \
  gcc-multilib g++-multilib coreutils findutils grep sed

Clone and install BSWorld:

git clone https://github.com/XiaoMi/bsworld.git
cd bsworld
export BSWORLD_ROOT="$PWD"
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install -e .

Run the development checks:

ruff check src tests
pytest tests/unit -q

Build and Test

Fetch the BabbleSim revisions selected by components/babblesim.xml:

mkdir -p "$BSWORLD_ROOT/.cache/babblesim"
cd "$BSWORLD_ROOT/.cache/babblesim"
repo init --standalone-manifest --depth=1 -u "file://$BSWORLD_ROOT/components/babblesim.xml"
repo sync -c --no-tags

Set the output paths and build every component:

export BSIM_OUT_PATH="$PWD/build"
export BSIM_COMPONENTS_PATH="$PWD/components"
export BSIM_BUILD_FAIL_ASAP=1
make -j"$(nproc)" everything

Run the Bumble scenarios on BSController, which need no other binaries:

cd "$BSWORLD_ROOT"
pytest tests/integration/bumble -n auto -k '[bscontroller]'

Test Controller Variants

Integration scenarios run with both the Zephyr Controller ([zephyr]) and Python BSController ([bscontroller]); [zephyr] cases are skipped when the Zephyr Controller is not built. See Virtual Controllers.

Select one implementation with its pytest parameter ID:

pytest tests/integration -n auto -v -k '[zephyr]'
pytest tests/integration -n auto -v -k '[bscontroller]'

Supported Integrations

Environment Validated behavior Guide
Zephyr Bluetooth shell Advertising and scanning, interference and recovery, connections and GATT, LL procedures, pairing and privacy, periodic advertising; complete firmware against Host-only shells on either Controller and against Bumble Zephyr tests
Bumble Python Host Advertising, scanning, connections, periodic advertising and synchronization Bumble tests
Linux and BlueZ under QEMU Controller setup, advertising, scanning, connection and disconnection through the Linux Bluetooth subsystem BlueZ tests
TrouBLE Rust Host Advertising, connection, Battery Service discovery, reads and notifications TrouBLE tests
NuttX BTSak Advertising, scanning, multiple advertisers, interference and recovery BTSak tests
Apache NimBLE Discovery, connection, GATT and subscription on NuttX; discovery and connection under QEMU NuttX tests · QEMU tests

Technical Architecture

BSWorld keeps each Application and Host stack on its native interface. Every Host connects through standard HCI to an independent Zephyr Controller process or Python BSController worker. Complete Zephyr firmware includes its own Controller and radio and joins the PHY directly; see Complete firmware. All Controllers, complete firmware and interference sources share the BabbleSim PHY and simulation clock.

BSWorld participants connected through independent virtual Controllers or as complete firmware to a shared BabbleSim PHY
Figure 1: BSWorld architecture

The virtual Controllers implement HCI commands, events, ACL data, Link Layer procedures, and radio transmission and reception. A topology can mix RTOS, Python, QEMU-based Linux and complete Zephyr participants with either Controller implementation. See Virtual Controllers to choose and configure them.

HCI traffic is saved as hciN.snoop for Wireshark or another BTSnoop-capable tool. Radio traffic is saved as babblesim/ellisys.bttrp for Ellisys. See Logs, traces, and captures for locations and a recommended investigation order.

Discrete-Time Scheduling

Time base Meaning
Simulation time Defines protocol timers, packet timing, RF events, asyncio waits, and test timeouts. It advances only after all participants synchronize.
Wall-clock time Measures how long the test takes on the host. CPU load and Linux scheduling affect this duration but not protocol timing.

BSWorld registers Applications, Controllers, interference devices, and pytest in the same simulation. A shared synchronization barrier keeps them on one timeline, so a protocol interval such as T_IFS = 150 μs remains 150 μs regardless of host load. After topology startup, standard asyncio waits and timeouts use simulation time; see Async waiting and simulation time.

Repeatability assumes identical binaries and inputs and controlled random sources. External networks, wall-clock-driven services, and other unadapted Host I/O can still introduce nondeterminism.

Documentation

Community

License

BSWorld is licensed under the Apache License 2.0. Third-party components retain their own licenses; see Third-Party Notices.

About

Hardware-free Bluetooth simulation framework for AI agents and CI. Runs Zephyr, NuttX, NimBLE, BlueZ, Bumble, and Trouble concurrently—with deterministic results and speeds up to hundreds of times faster than real time.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages