Skip to content

Commit d05ca21

Browse files
committed
pbio/test: Update for Bluetooth and tasks.
1 parent 023d6f6 commit d05ca21

File tree

4 files changed

+27
-119
lines changed

4 files changed

+27
-119
lines changed

lib/pbio/test/drv/test_bluetooth.c renamed to lib/pbio/test/drv/test_bluetooth_btstack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include <test-pbio.h>
1717

18-
#include "../../drv/bluetooth/bluetooth_btstack_run_loop_contiki.h"
1918
#include "../../drv/bluetooth/bluetooth_btstack.h"
2019
#include "../../drv/clock/clock_test.h"
2120

@@ -790,7 +789,7 @@ static PT_THREAD(test_btstack_run_loop_contiki_poll(struct pt *pt)) {
790789
PT_END(pt);
791790
}
792791

793-
struct testcase_t pbdrv_bluetooth_tests[] = {
792+
struct testcase_t pbdrv_bluetooth_btstack_tests[] = {
794793
PBIO_PT_THREAD_TEST(test_btstack_run_loop_contiki_timer),
795794
PBIO_PT_THREAD_TEST(test_btstack_run_loop_contiki_poll),
796795
END_OF_TESTCASES

lib/pbio/test/src/test_task.c

Lines changed: 0 additions & 74 deletions
This file was deleted.

lib/pbio/test/sys/test_bluetooth.c

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,74 @@
55
#include <stdio.h>
66

77
#include <btstack.h>
8-
#include <contiki.h>
8+
99
#include <tinytest_macros.h>
1010
#include <tinytest.h>
1111

1212
#include <pbdrv/bluetooth.h>
1313

14+
#include <pbio/os.h>
1415
#include <pbio/util.h>
1516
#include <pbsys/host.h>
1617
#include <pbsys/main.h>
1718
#include <pbsys/status.h>
1819
#include <test-pbio.h>
1920

20-
#include "../drv/clock/clock_test.h"
21+
static pbio_error_t test_bluetooth(pbio_os_state_t *state, void *context) {
22+
23+
static pbio_os_state_t sub;
2124

22-
static PT_THREAD(test_bluetooth(struct pt *pt)) {
23-
PT_BEGIN(pt);
25+
PBIO_OS_ASYNC_BEGIN(state);
2426

2527
pbsys_host_init();
2628

2729
// power should be initialized to off
2830
tt_want_uint_op(pbio_test_bluetooth_get_control_state(), ==, PBIO_TEST_BLUETOOTH_STATE_OFF);
2931

30-
pbdrv_bluetooth_power_on(true);
32+
PBIO_OS_AWAIT(state, &sub, pbdrv_bluetooth_power_on(&sub, false));
33+
PBIO_OS_AWAIT(state, &sub, pbdrv_bluetooth_power_on(&sub, true));
3134

32-
// wait for the power on delay
33-
PT_WAIT_UNTIL(pt, ({
34-
pbio_test_clock_tick(1);
35-
pbio_test_bluetooth_get_control_state() == PBIO_TEST_BLUETOOTH_STATE_ON;
36-
}));
35+
tt_want_uint_op(pbio_test_bluetooth_get_control_state(), ==, PBIO_TEST_BLUETOOTH_STATE_ON);
3736

38-
pbdrv_bluetooth_start_advertising();
37+
pbdrv_bluetooth_start_advertising(true);
38+
PBIO_OS_AWAIT(state, &sub, pbdrv_bluetooth_await_advertise_or_scan_command(&sub, NULL));
3939

40-
PT_WAIT_UNTIL(pt, ({
41-
pbio_test_clock_tick(1);
42-
pbio_test_bluetooth_is_advertising_enabled();
43-
}));
40+
tt_want(pbio_test_bluetooth_is_advertising_enabled());
4441

4542
pbio_test_bluetooth_connect();
4643

47-
PT_WAIT_UNTIL(pt, ({
48-
pbio_test_clock_tick(1);
49-
pbio_test_bluetooth_is_connected();
50-
}));
44+
PBIO_OS_AWAIT_UNTIL(state, pbio_test_bluetooth_is_connected());
5145

5246
// TODO: enable pybricks service notifications and do concurrent pybricks service and uart service calls
5347

5448
pbio_test_bluetooth_enable_pybricks_service_notifications();
5549

5650
static const char *test_data_1 = "test\n";
5751
static const char *test_data_2 = "test2\n";
58-
uint32_t size;
52+
static uint32_t size;
5953

60-
PT_WAIT_UNTIL(pt, ({
61-
pbio_test_clock_tick(1);
54+
PBIO_OS_AWAIT_UNTIL(state, ({
6255
size = strlen(test_data_1);
6356
pbdrv_bluetooth_tx((const uint8_t *)test_data_1, &size) == PBIO_SUCCESS;
6457
}));
6558

6659
tt_want_uint_op(size, ==, strlen(test_data_1));
6760

68-
// yielding here should allow the pbsys bluetooth process to run and queue
69-
// the data in the uart buffer
70-
PT_YIELD(pt);
71-
72-
// this next data should get pushed in the UART buffer but wait until the
73-
// previous request is finished before sending
74-
PT_WAIT_UNTIL(pt, ({
75-
pbio_test_clock_tick(1);
61+
// this next data should get pushed in the buffer too
62+
PBIO_OS_AWAIT_UNTIL(state, ({
7663
size = strlen(test_data_2);
7764
pbdrv_bluetooth_tx((const uint8_t *)test_data_2, &size) == PBIO_SUCCESS;
7865
}));
7966

8067
tt_want_uint_op(size, ==, strlen(test_data_2));
8168

82-
PT_YIELD(pt);
83-
8469
static const char *test_data_3 = "\x06test3\n";
8570
size = strlen(test_data_3);
8671
pbio_test_bluetooth_send_pybricks_command((const uint8_t *)test_data_3, size);
8772

8873
static uint8_t rx_data[20];
8974

90-
PT_WAIT_UNTIL(pt, ({
91-
pbio_test_clock_tick(1);
75+
PBIO_OS_AWAIT_UNTIL(state, ({
9276
size = PBIO_ARRAY_SIZE(rx_data);
9377
pbsys_host_stdin_read(rx_data, &size) == PBIO_SUCCESS;
9478
}));
@@ -104,15 +88,14 @@ static PT_THREAD(test_bluetooth(struct pt *pt)) {
10488
static uint32_t count;
10589
count = pbio_test_bluetooth_get_pybricks_service_notification_count();
10690

107-
PT_WAIT_UNTIL(pt, ({
108-
pbio_test_clock_tick(1);
91+
PBIO_OS_AWAIT_UNTIL(state, ({
10992
pbio_test_bluetooth_get_pybricks_service_notification_count() != count;
11093
}));
11194

112-
PT_END(pt);
95+
PBIO_OS_ASYNC_END(PBIO_SUCCESS);
11396
}
11497

11598
struct testcase_t pbdrv_bluetooth_tests[] = {
116-
PBIO_PT_THREAD_TEST(test_bluetooth),
99+
PBIO_PT_THREAD_TEST_WITH_PBIO_OS(test_bluetooth),
117100
END_OF_TESTCASES
118101
};

lib/pbio/test/test-pbio.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <tinytest_macros.h>
1313

1414
#include "../drv/motor_driver/motor_driver_virtual_simulation.h"
15+
#include "../drv/clock/clock_test.h"
1516

1617
#include <pbdrv/core.h>
1718

@@ -120,7 +121,8 @@ void pbio_test_run_thread_with_pbio_os_processes(void *env) {
120121
clock_gettime(CLOCK_MONOTONIC, &start_time);
121122

122123
while ((test_thread(&state, NULL)) == PBIO_ERROR_AGAIN) {
123-
pbio_os_run_processes_once();
124+
pbio_os_run_processes_and_wait_for_event();
125+
pbio_test_clock_tick(1);
124126
if (timeout > 0) {
125127
clock_gettime(CLOCK_MONOTONIC, &now_time);
126128
if (difftime(now_time.tv_sec, start_time.tv_sec) > timeout) {
@@ -147,7 +149,7 @@ struct testcase_setup_t pbio_test_setup = {
147149
.cleanup_fn = cleanup,
148150
};
149151

150-
extern struct testcase_t pbdrv_bluetooth_tests[];
152+
extern struct testcase_t pbdrv_bluetooth_btstack_tests[];
151153
extern struct testcase_t pbdrv_pwm_tests[];
152154
extern struct testcase_t pbio_angle_tests[];
153155
extern struct testcase_t pbio_battery_tests[];
@@ -160,13 +162,12 @@ extern struct testcase_t pbio_light_matrix_tests[];
160162
extern struct testcase_t pbio_int_math_tests[];
161163
extern struct testcase_t pbio_port_lump_tests[];
162164
extern struct testcase_t pbio_servo_tests[];
163-
extern struct testcase_t pbio_task_tests[];
164165
extern struct testcase_t pbio_trajectory_tests[];
165166
extern struct testcase_t pbio_util_tests[];
166167
extern struct testcase_t pbdrv_bluetooth_tests[];
167168
extern struct testcase_t pbsys_status_tests[];
168169
static struct testgroup_t test_groups[] = {
169-
{ "drv/bluetooth/", pbdrv_bluetooth_tests },
170+
{ "drv/bluetooth/", pbdrv_bluetooth_btstack_tests },
170171
{ "drv/pwm/", pbdrv_pwm_tests },
171172
{ "src/angle/", pbio_angle_tests },
172173
{ "src/battery/", pbio_battery_tests },
@@ -179,7 +180,6 @@ static struct testgroup_t test_groups[] = {
179180
{ "src/math/", pbio_int_math_tests },
180181
{ "src/port_lump/", pbio_port_lump_tests },
181182
{ "src/servo/", pbio_servo_tests },
182-
{ "src/task/", pbio_task_tests, },
183183
{ "src/trajectory/", pbio_trajectory_tests },
184184
{ "src/util/", pbio_util_tests, },
185185
{ "sys/bluetooth/", pbdrv_bluetooth_tests, },

0 commit comments

Comments
 (0)