LingaoM opened a new pull request, #20108:
URL: https://github.com/apache/nuttx/pull/20108
## Summary
This PR improves the Linux `sim` target for host-side Bluetooth testing.
It adds optional BabbleSim discrete-time support to `arch/sim`. When
`CONFIG_SIM_BSIM_TIME` is enabled, the simulator joins a BabbleSim PHY as a
device and uses the BabbleSim PHY wait protocol as the monotonic time
source.
`host_sleepuntil()` advances through `PB_MSG_WAIT` requests instead of
Linux
wall-time sleeps, so NuttX SIM applications can run in the same
discrete-time
domain as other BabbleSim devices.
The PR also fixes the simulated HCI socket watchdog lifetime. The receive
watchdog is now started only after the host HCI socket has been opened
successfully, and is canceled on close/free. This keeps the polling
lifetime
tied to the actual host socket lifetime and avoids polling an invalid host
fd.
Finally, it adds a runtime HCI socket target option. `--bt-dev=hciN`
overrides
`CONFIG_SIM_HCISOCKET_DEVID` for the BlueZ HCI user channel, while
`--bt-dev=/path/to/socket` connects the simulator to an H:4 stream over a
Unix
domain socket. Omitting `--bt-dev` keeps the existing configured default
behavior.
## Impact
- `CONFIG_SIM_BSIM_TIME` is disabled by default.
- Existing `sim` builds keep their current wall-time behavior unless
`CONFIG_SIM_BSIM_TIME` is enabled.
- BabbleSim time support is limited to Linux host SIM,
`CONFIG_SIM_WALLTIME_SLEEP`,
and non-SMP builds.
- Building with `CONFIG_SIM_BSIM_TIME=y` requires:
- `BSIM_COMPONENTS_PATH` for BabbleSim headers.
- `BSIM_OUT_PATH` or `BSIM_LIBS_DIR` for BabbleSim libraries.
- The BabbleSim PHY process must be started externally by the test runner
before
launching the NuttX SIM binary.
- RTC/realtime reads still use the host realtime clock. BabbleSim is used
only
for monotonic time after the simulator joins the PHY.
- `--bt-dev=hciN` keeps the BlueZ user-channel path and still requires the
normal host permissions/capabilities for BlueZ HCI access.
- `--bt-dev=/path/to/socket` allows use of a Unix-socket HCI transport,
which can
connect to another host process or a UART-to-Unix-socket bridge without
requiring BlueZ raw HCI privileges for the NuttX process.
- The HCI watchdog change only affects the simulated HCI socket driver
lifetime
handling and does not change the HCI packet format or public Bluetooth
APIs.
## Testing
Host machine:
- Ubuntu 22.04 x86_64
Style checks:
```console
$ git diff --check HEAD~2..HEAD
$ PATH=/home/mi/bsim-auto-test/.venv/bin:$PATH \
./tools/checkpatch.sh -c -u -m -g HEAD~2..HEAD
Default SIM smoke test:
$ ./tools/configure.sh -l -a ../nuttx-apps sim:nsh
$ make -j16
$ printf 'help\npoweroff\n' | timeout 20s ./nuttx
BabbleSim-enabled build:
$ kconfig-tweak --file .config \
-e SIM_WALLTIME_SLEEP \
-d SIM_WALLTIME_SIGNAL \
-e SIM_BSIM_TIME
$ make olddefconfig
$ BSIM_OUT_PATH=/tmp/bsworld/build/babblesim/bsim \
BSIM_COMPONENTS_PATH=/tmp/bsworld/build/babblesim/bsim/components \
make -j16
BabbleSim time smoke test without a controller:
$ bs_2G4_phy_v1 -s=<sid> -D=1 -defmodem=BLE_simple -nodump
$ printf 'usleep 1000000\npoweroff\n' | \
./nuttx --sim-bsim-sid=<sid> \
--sim-bsim-pid=2G4 \
--sim-bsim-dev=0
Observed result:
The 1 second simulated sleep completed in 19 ms wall time when no handbrake
device was present.
BabbleSim handbrake verification:
$ bs_2G4_phy_v1 -s=<sid> -D=2 -defmodem=BLE_simple -nodump
$ bs_device_handbrake -s=<sid> -p=2G4 -d=1 -pp=50000 -r=1
$ printf 'usleep 1000000\npoweroff\n' | \
./nuttx --sim-bsim-sid=<sid> \
--sim-bsim-pid=2G4 \
--sim-bsim-dev=0
Observed result:
The same 1 second simulated sleep completed in 985 ms wall time with the
handbrake device registered.
A shorter 200 ms check completed in 27 ms without handbrake and 172 ms with
handbrake.
This verifies that NuttX SIM monotonic time advances through the BabbleSim
PHY
and that the BabbleSim handbrake affects the NuttX SIM device.
Verified cleanup still works after enabling CONFIG_SIM_BSIM_TIME and
without
exporting BabbleSim environment variables:
$ make distclean
HCI socket watchdog and runtime target tests:
Board/config:
- sim:bthcisock
Clean build:
$ make distclean
$ ./tools/configure.sh -l -a ../../nuttx-apps sim:bthcisock
$ kconfig-tweak --file .config --set-val STACK_USAGE_WARNING 0
$ make olddefconfig
$ make -j16
Default startup smoke test:
$ printf 'poweroff\n' | timeout 10s ./nuttx
Observed result:
The simulator reached NSH and powered off cleanly. When no host HCI
controller
was available through the default BlueZ target, the board reported
sim_bthcisock_register() failure and continued booting without an
invalid-fd
watchdog crash.
Invalid runtime argument smoke test:
$ ./nuttx --bt-dev=invalid
Observed result:
The command exited with status 1 and reported the invalid target without
crashing before nx_start().
Unix socket HCI smoke test:
$ socat -d -d UNIX-LISTEN:/tmp/hci.sock,fork,reuseaddr \
/dev/ttyACM2,b1000000,raw,echo=0,crtscts=1
$ printf 'ifconfig\nbt bnep0 info\npoweroff\n' | \
timeout 20s ./nuttx --bt-dev=/tmp/hci.sock
Observed result:
The simulator registered the Bluetooth network device as bnep0, and
bt bnep0 info read controller state through the Unix-socket HCI path,
including
BDAddr aa:bb:cc:dd:ee:ff from the attached controller.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]