Skip to content

Commit f2786c2

Browse files
committed
bricks/virtualhub: Build on CI without libusb.
Also add local test scripts and launch configs.
1 parent f186107 commit f2786c2

6 files changed

Lines changed: 107 additions & 7 deletions

File tree

.vscode/launch.json

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"console":"integratedTerminal"
6262
},
6363
{
64-
"name": "virtualhub",
64+
"name": "virtualhub (no bluetooth)",
6565
"type": "cppdbg",
6666
"request": "launch",
6767
"program": "${workspaceFolder}/bricks/virtualhub/build-debug/firmware.elf",
@@ -70,6 +70,38 @@
7070
],
7171
"stopAtEntry": false,
7272
"cwd": "${workspaceFolder}",
73+
"environment": [
74+
{
75+
"name": "PBIO_TEST_CONNECT_SOCKET",
76+
"value": "true"
77+
},
78+
],
79+
"externalConsole": false,
80+
"MIMode": "gdb",
81+
"setupCommands": [
82+
{
83+
"description": "Enable pretty-printing for gdb",
84+
"text": "-enable-pretty-printing",
85+
"ignoreFailures": true
86+
},
87+
{
88+
"description": "Ignore timer signal",
89+
"text": "handle SIG34 noprint pass",
90+
"ignoreFailures": false
91+
}
92+
],
93+
"preLaunchTask": "build virtualhub (debug)"
94+
},
95+
{
96+
"name": "virtualhub (UB500_INDEX=0)",
97+
"type": "cppdbg",
98+
"request": "launch",
99+
"program": "${workspaceFolder}/bricks/virtualhub/build-debug/firmware.elf",
100+
"args": [
101+
"${workspaceFolder}/tests/bluetooth/virtual0.py",
102+
],
103+
"stopAtEntry": false,
104+
"cwd": "${workspaceFolder}",
73105
"environment": [
74106
{
75107
"name": "PBIO_TEST_CONNECT_SOCKET",
@@ -96,6 +128,42 @@
96128
],
97129
"preLaunchTask": "build virtualhub (debug)"
98130
},
131+
{
132+
"name": "virtualhub (UB500_INDEX=1)",
133+
"type": "cppdbg",
134+
"request": "launch",
135+
"program": "${workspaceFolder}/bricks/virtualhub/build-debug/firmware.elf",
136+
"args": [
137+
"${workspaceFolder}/tests/bluetooth/virtual1.py",
138+
],
139+
"stopAtEntry": false,
140+
"cwd": "${workspaceFolder}",
141+
"environment": [
142+
{
143+
"name": "PBIO_TEST_CONNECT_SOCKET",
144+
"value": "true"
145+
},
146+
{
147+
"name": "UB500_INDEX",
148+
"value": "1"
149+
}
150+
],
151+
"externalConsole": false,
152+
"MIMode": "gdb",
153+
"setupCommands": [
154+
{
155+
"description": "Enable pretty-printing for gdb",
156+
"text": "-enable-pretty-printing",
157+
"ignoreFailures": true
158+
},
159+
{
160+
"description": "Ignore timer signal",
161+
"text": "handle SIG34 noprint pass",
162+
"ignoreFailures": false
163+
}
164+
],
165+
"preLaunchTask": "build virtualhub (debug)"
166+
},
99167
{
100168
"name": "test-pbio",
101169
"type": "cppdbg",

bricks/_common/common.mk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ INC += -I$(PBTOP)/lib/btstack/chipset/bcm
134134
INC += -I$(PBTOP)/lib/btstack/chipset/intel
135135
INC += -I$(PBTOP)/lib/btstack/chipset/realtek
136136
INC += -I$(PBTOP)/lib/btstack/chipset/zephyr
137+
ifneq ($(CI_MODE),1)
137138
INC += $(shell pkg-config libusb-1.0 --cflags)
138139
endif
139140
endif
141+
endif
140142
ifeq ($(PB_LIB_LSM6DS3TR_C),1)
141143
INC += -I$(PBTOP)/lib/lsm6ds3tr_c_STdC/driver
142144
endif
@@ -167,6 +169,10 @@ TEXT0_ADDR ?= 0x08000000
167169
ifeq ($(PB_MCU_FAMILY),native)
168170
UNAME_S := $(shell uname -s)
169171
LD = $(CC)
172+
ifeq ($(CI_MODE),1)
173+
COPT = -DPBDRV_CONFIG_RUN_ON_CI
174+
else
175+
endif
170176
CFLAGS += $(INC) -Wall -Werror -Wdouble-promotion -Wfloat-conversion -std=gnu99 $(COPT) -D_GNU_SOURCE
171177
ifeq ($(UNAME_S),Linux)
172178
LDFLAGS += -Wl,-Map=$@.map,--cref -Wl,--gc-sections
@@ -175,8 +181,10 @@ LDFLAGS += -Wl,-map,$@.map -Wl,-dead_strip
175181
endif
176182
LIBS = -lm
177183
ifeq ($(PB_LIB_BTSTACK),lowenergy)
184+
ifneq ($(CI_MODE),1)
178185
LIBS += $(shell pkg-config libusb-1.0 --libs)
179186
endif
187+
endif
180188
else # end native, begin embedded
181189
CROSS_COMPILE ?= arm-none-eabi-
182190
ifeq ($(PB_MCU_FAMILY),STM32)
@@ -562,15 +570,19 @@ OBJ += $(addprefix $(BUILD)/, $(BLE5STACK_SRC_C:.c=.o))
562570
endif
563571

564572
ifeq ($(PB_LIB_BTSTACK),classic)
573+
ifneq ($(CI_MODE),1)
565574
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
566575
$(BUILD)/lib/btstack/%.o: CFLAGS += -Wno-error
567576
endif
577+
endif
568578

569579
ifeq ($(PB_LIB_BTSTACK),lowenergy)
580+
ifneq ($(CI_MODE),1)
570581
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
571582
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_BLE_SRC_C:.c=.o))
572583
$(BUILD)/lib/btstack/%.o: CFLAGS += -Wno-error
573584
endif
585+
endif
574586

575587
ifeq ($(PB_LIB_STM32_HAL),1)
576588
OBJ += $(addprefix $(BUILD)/, $(STM32_HAL_SRC_C:.c=.o))

test-virtualhub.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ BUILD_DIR="$BRICK_DIR/$BUILD_DIR_NAME"
2323
PBIO_DIR="$SCRIPT_DIR/lib/pbio"
2424

2525
make mpy-cross -j
26-
make -s -j $(nproc --all) -C "$BRICK_DIR" BUILD="$BUILD_DIR_NAME" COPT=-DPBDRV_CONFIG_RUN_ON_CI
26+
make -s -j $(nproc --all) -C "$BRICK_DIR" BUILD="$BUILD_DIR_NAME" CI_MODE=1
2727

2828
export MICROPY_MICROPYTHON="$BUILD_DIR/firmware.elf"
2929

tests/bluetooth/virtual0.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pybricks.hubs import VirtualHub
2+
from pybricks.tools import wait
3+
4+
hub = VirtualHub(broadcast_channel=123)
5+
6+
for i in range(99):
7+
hub.ble.broadcast(["Hello", i])
8+
wait(100)
9+
10+
hub.ble.broadcast(b"STOP")
11+
wait(500)

tests/bluetooth/virtual1.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pybricks.hubs import VirtualHub
2+
3+
hub = VirtualHub(observe_channels=[123])
4+
5+
data = ()
6+
7+
while data != b"STOP":
8+
new = hub.ble.observe(123)
9+
if new == data:
10+
continue
11+
12+
data = new
13+
print(data)

tests/virtualhub/basics/hello.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
from pybricks.tools import wait, AppData
2-
3-
app = AppData("<bb")
4-
5-
app.write_bytes(b"BOO")
1+
from pybricks.tools import wait
62

73
print("\nHello")
84
wait(1000)

0 commit comments

Comments
 (0)