Newshot

Show HN:BSWorld——AI 智能体现可在无硬件的情况下测试蓝牙代码

Translation(model translation, not the source's own text)

Show HN:BSWorld – AI 智能体现在无需硬件即可测试蓝牙代码

English | 简体中文

Release
Release
PyPI bscontroller
PyPI bscontroller
License
License

BSWorld 通过确定性仿真在 Linux 上测试蓝牙 Host 和应用程序。在 pytest 中定义拓扑和预期行为。Host 通过 H4 HCI 连接到 BSController,并通过共享的 BabbleSim 无线电进行通信。

  • 无需硬件,也无需修改源代码,即可测试开源 Host 协议栈。
  • 在一个仿真时钟上运行多个设备。使用 pytest-xdist 并行运行独立场景。
  • 设置路径衰减,注入干扰和 WLAN 活动,或回放录制的无线电信号。
  • 检查应用日志、HCI BTSnoop 捕获、每个 Controller 的无线电捕获以及共享的 Ellisys 跟踪。

快速开始

BSWorld 在 Linux/x86_64 上运行。

Docker

Docker 镜像附带 BabbleSim、32 位 UML 内核,以及包含 Host 可执行文件的 Guest 根文件系统。在装有 Docker Engine 的主机上,从仓库根目录运行集成测试。


        sudo docker pull ghcr.io/xiaomi/bsworld-linux:latest
mkdir -p .cache/docker-results
# The image runs as UID/GID 1000.
sudo chown 1000:1000 .cache/docker-results
sudo docker run --rm \
  --security-opt seccomp=docker/uml-seccomp.json \
  --mount "type=bind,src=$PWD/.cache/docker-results,dst=/output" \
  ghcr.io/xiaomi/bsworld-linux:latest
      

.cache/docker-results 中的结果包括 pytest.xml、进程日志、HCI 捕获和 RF 跟踪。有关测试套件选择、镜像版本和本地构建的信息,请参阅 Docker 指南。

本地 Linux

开发和测试需要 Python 3.12 或更新版本。在 Ubuntu 24.04 上安装这些工具。

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-ven

每个 Host 通过 H4 HCI 连接到自己的 BSController。各个 Controller、pytest 时钟以及任何已配置的干扰源共享一个 BabbleSim PHY。

Bumble 运行在 pytest 事件循环中。每个 UML Guest 运行在独立进程中,并通过自己的 time-travel socket 从该循环接收仿真时间。一个拓扑可以同时运行多个 Guest。

要设置每个 Controller 的选项(例如设备地址、缓冲区大小和 Bluetooth 版本),请参阅 BSController configuration。

在 Wireshark 中打开 hciN.snoop 和 radioN.pcapng,以检查 Controller 的 HCI 流量和无线电活动。共享的 babblesim/ellisys.bttrp 收集供 Ellisys 使用的 BSController 传输。有关捕获范围和文件位置,请参阅 Logs, traces, and captures。

离散时间调度

时间基准含义
仿真时间当所有 PHY 参与者同步时推进。它支配协议定时器、数据包时序、RF 事件、asyncio 等待和测试超时。
墙钟时间在主机上测量测试持续时间,并随 CPU 负载和 Linux 调度而变化。

启动后,标准 asyncio 等待和超时使用仿真时间。示例见 Async waiting and simulation time。

可重复性假设二进制文件和输入完全相同,并且随机源受控。外部网络、由墙钟时间驱动的服务以及其他未适配的 Host I/O 仍可能引入不确定性。

文档

  • 编写测试并配置 RF 场景
  • 分配并配置 BSController
  • 查找日志、跟踪和捕获
  • 运行单元测试、lint 检查和覆盖率
  • 构建或运行 Docker 测试镜像

社区

  • 贡献
  • 行为准则
  • 安全政策

许可证

BSWorld 在 Apache License 2.0 下许可。有关第三方许可证,请参阅 Third-Party Notices。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗