Run the testers under User Mode Linux with time travel
Subsystems (2)
Luiz Augusto von Dentz
maintainercover Run the testers under User Mode Linux with time travel
From: Luiz Augusto von Dentz <[email protected]>
This makes test-runner run the kernel testers in a User Mode Linux guest as well as with QEMU/KVM, and with -T on a simulated clock: btvirt is the guest's time travel calendar, so timers and timeouts take no real time and timing is the same on every run. btvirt can also serve controllers to UML guests as vhost-user virtio devices sharing the calendar, e.g. for firmware simulators.
Time travel made test races and busy loops visible, fixed first in the series, and showed that GLib's main loop reads the clock for every source on every iteration, a system call through the host under UML, so the testers now run on the mainloop instead.
Wall clock time in seconds, same kernel version and machine, all tests passing, single runs:
tester tests KVM UML UML -T UML -T
(GLib) (mainloop)
mgmt-tester 514 78.2 94.0 42.6 20.3 l2cap-tester 111 9.2 10.2 10.2 5.6 iso-tester 141 8.1 11.7 16.3 7.6 sco-tester 30 4.6 3.1 3.6 2.0 rfcomm-tester 11 3.6 1.5 2.6 1.5 smp-tester 8 3.6 1.5 1.5 1.0 ioctl-tester 28 4.1 2.1 3.1 1.5 userchan-tester 4 2.6 1.0 1.5 1.0 bnep-tester 1 2.6 1.0 1.0 1.0
doc/tester.config is split into tester.kvm.config and tester.uml.config, both building every Bluetooth driver, so a single UML kernel can verify the drivers and run the testers.
Usage, with a UML kernel built from doc/tester.uml.config:
tools/test-runner -T -k <linux>/linux -- tools/mgmt-tester
Luiz Augusto von Dentz (27):
tools/test-runner: Do not report filesystems already mounted shared/tester: Time out teardown
mgmt-tester: Wait for LL Privacy setup to complete
iso-tester: Fix leaking socket watches
l2cap-tester: Fix race in LE Client - Close socket 2
iso-tester: Fix busy waiting in PAST tests
doc: Enable IPv6 in tester.config
6lowpan-tester: Find the interface of the controller
emulator: Remove -T option from btvirt
doc: Add btvirt documentation
emulator: Add vhost-user backend
emulator: Add vhost-user virtio server to btvirt
emulator: Add time travel calendar to btvirt
emulator: Add virtio console and time travel client to btvirt tools/test-runner: Add User Mode Linux support
doc: Add virtio documentation
shared/mainloop: Add idle callbacks
shared/timeout: Run timeouts of 0 once idle shared/tester: Remove GLib dependency emulator/hciemu: Remove GLib dependency
tools: Build testers that do not need GLib with the mainloop shared/mainloop: Add deferred callbacks
tools: Add socket watches for testers without GLib
tools: Run sco-tester, rfcomm-tester and 6lowpan-tester on the
mainloop
tools: Run l2cap-tester and iso-tester on the mainloop doc/virtio: Update measurements of the testers
doc: Split tester.config for QEMU and User Mode Linux
Makefile.am | 5 +- Makefile.tools | 47 +- doc/btvirt.rst | 189 ++++++ doc/test-functional.rst | 4 +- doc/test-runner.rst | 150 ++++- doc/tester.config | 118 +--- doc/tester.kvm.config | 144 +++++ doc/tester.uml.config | 120 ++++ doc/virtio.rst | 412 +++++++++++++ emulator/hciemu.c | 122 ++-- emulator/main.c | 116 +++- emulator/timeout.c | 102 ++++ emulator/timetravel.c | 743 ++++++++++++++++++++++++ emulator/timetravel.h | 55 ++ emulator/ttclient.c | 313 ++++++++++ emulator/ttclient.h | 50 ++ emulator/vconsole.c | 701 +++++++++++++++++++++++ emulator/vconsole.h | 26 + emulator/vhost.c | 1018 +++++++++++++++++++++++++++++++++ emulator/vhost.h | 67 +++ emulator/virtio.c | 356 ++++++++++++ emulator/virtio.h | 20 + src/shared/mainloop-ell.c | 12 + src/shared/mainloop-glib.c | 12 + src/shared/mainloop.c | 177 +++++- src/shared/mainloop.h | 4 + src/shared/tester.c | 306 +++++++--- src/shared/timeout-glib.c | 10 +- src/shared/timeout-mainloop.c | 9 +- tools/6lowpan-tester.c | 111 +++- tools/bnep-tester.c | 7 - tools/ioctl-tester.c | 6 +- tools/iso-tester.c | 358 +++++++----- tools/l2cap-tester.c | 347 +++++------ tools/mesh-tester.c | 1 - tools/mgmt-tester.c | 204 ++++++- tools/rfcomm-tester.c | 105 ++-- tools/sco-tester.c | 108 ++-- tools/smp-tester.c | 30 +- tools/test-runner.c | 404 ++++++++++++- tools/tester-io.c | 400 +++++++++++++ tools/tester-io.h | 52 ++ tools/tester.h | 8 +- tools/userchan-tester.c | 1 - 44 files changed, 6721 insertions(+), 829 deletions(-) create mode 100644 doc/btvirt.rst mode change 100644 => 120000 doc/tester.config create mode 100644 doc/tester.kvm.config create mode 100644 doc/tester.uml.config create mode 100644 doc/virtio.rst create mode 100644 emulator/timeout.c create mode 100644 emulator/timetravel.c create mode 100644 emulator/timetravel.h create mode 100644 emulator/ttclient.c create mode 100644 emulator/ttclient.h create mode 100644 emulator/vconsole.c create mode 100644 emulator/vconsole.h create mode 100644 emulator/vhost.c create mode 100644 emulator/vhost.h create mode 100644 emulator/virtio.c create mode 100644 emulator/virtio.h create mode 100644 tools/tester-io.c create mode 100644 tools/tester-io.h
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 1/27 tools/test-runner: Do not report filesystems already mounted
From: Luiz Augusto von Dentz <[email protected]>
With CONFIG_DEVTMPFS_MOUNT the kernel mounts devtmpfs itself, so mounting it again fails with EBUSY, reported as an error on every run:
Mounting devtmpfs to /dev
Failed to mount filesystem: Device or resource busy
Only report other failures.
--- tools/test-runner.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/test-runner.c +4 -1
@@ -254,11 +254,14 @@ static void prepare_sandbox(void)printf ("Mounting %s to %s\n" , mount_table[i].fstype, mount_table[i].target); +/* The kernel may have mounted it already, e.g. devtmpfs +* with CONFIG_DEVTMPFS_MOUNT. +*/ if (mount (mount_table[i].fstype, mount_table[i].target, mount_table[i].fstype, mount_table[i].flags, - mount_table[i].options) <0 ) + mount_table[i].options) <0 && errno !=EBUSY )perror ("Failed to mount filesystem" ); }
Signature · 1 line
2.56.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1191414/
---Test result---
Test Summary:
CheckPatch FAIL 18.23 seconds GitLint FAIL 9.50 seconds BuildEll PASS 19.55 seconds BluezMake PASS 301.82 seconds MakeCheck PASS 14.53 seconds MakeDistcheck PASS 144.54 seconds CheckValgrind PASS 237.04 seconds CheckSmatch WARNING 298.70 seconds bluezmakeextell PASS 96.09 seconds TestFunctional PASS 1154.77 seconds IncrementalBuild PASS 635.83 seconds ScanBuild PASS 1186.64 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v1,11/27] emulator: Add vhost-user backend WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #258: FILE: emulator/vhost.c:87:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #263: FILE: emulator/vhost.c:92:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #272: FILE: emulator/vhost.c:101:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #279: FILE: emulator/vhost.c:108:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #285: FILE: emulator/vhost.c:114:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #292: FILE: emulator/vhost.c:121:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #303: FILE: emulator/vhost.c:132:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #310: FILE: emulator/vhost.c:139:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #316: FILE: emulator/vhost.c:145:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #321: FILE: emulator/vhost.c:150:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #327: FILE: emulator/vhost.c:156:
+} __attribute__((packed));
/home/runner/work/bluez/bluez/src/patch/14908110.patch total: 0 errors, 11 warnings, 1094 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluez/bluez/src/patch/14908110.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v1,12/27] emulator: Add vhost-user virtio server to btvirt WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #368: FILE: emulator/virtio.c:48:
+} __attribute__((packed));
/home/runner/work/bluez/bluez/src/patch/14908117.patch total: 0 errors, 1 warnings, 491 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluez/bluez/src/patch/14908117.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v1,13/27] emulator: Add time travel calendar to btvirt WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #474: FILE: emulator/timetravel.c:54:
+} __attribute__((packed));
/home/runner/work/bluez/bluez/src/patch/14908111.patch total: 0 errors, 1 warnings, 1088 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluez/bluez/src/patch/14908111.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v1,14/27] emulator: Add virtio console and time travel client to btvirt WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #345: FILE: emulator/ttclient.c:43:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #737: FILE: emulator/vconsole.c:60:
+} __attribute__((packed));
WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __packed over __attribute__((packed)) #743: FILE: emulator/vconsole.c:66:
+} __attribute__((packed));
/home/runner/work/bluez/bluez/src/patch/14908112.patch total: 0 errors, 3 warnings, 1221 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluez/bluez/src/patch/14908112.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[BlueZ,v1,24/27] tools: Run sco-tester, rfcomm-tester and 6lowpan-tester on the mainloop
1: T1 Title exceeds max length (88>80): "[BlueZ,v1,24/27] tools: Run sco-tester, rfcomm-tester and 6lowpan-tester on the mainloop"
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:tools/sco-tester.c: note: in included file:./lib/bluetooth/bluetooth.h:232:15: warning: array of flexible structures./lib/bluetooth/bluetooth.h:237:31: warning: array of flexible structures
https://github.com/bluez/bluez/pull/2701
---
Regards,
Linux Bluetooth
This is an automated email and please do not reply to this email.
Dear Submitter,
This series was picked up by the CI more than 2 weeks ago and the pull request created for it is still open, which means the series was never applied to the tree.
Series: Run the testers under User Mode Linux with time travel
Pull Request: https://github.com/bluez/bluez/pull/2701
Created: 2026-10-22 18:51:57+00:00
The pull request has been closed and no further action is taken on this series.
If the change should still be considered, it must be resent to the Linux Bluetooth mailing list ([email protected]) so that it is picked up again.
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerPATCH 2/27 shared/tester: Time out teardown
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
A teardown with no timeout blocks every following test if what it waits for never happens, e.g. mgmt-tester waiting for the removal of an index the kernel never added since the controller failed to initialize:
Set Low Energy on 6.2 - SCI Setting - test timed out Set Low Energy on 6.2 - SCI Setting - teardown
Give teardown the timeout of the test, but at least 30 seconds, as it may have to wait for the kernel to time out commands still sent to a controller being removed, 2 seconds each. When it expires report the test as timed out and do not run the remaining tests: the callbacks of the test may still complete later, and would be taken for those of the test running then.
--- src/shared/tester.c | 66 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-)
src/shared/tester.c +62 -4
@@ -423,6 +423,55 @@ static int tester_summarize(void)return failed; } +static gboolean done_callback (gpointer user_data); + +static bool teardown_timeout (gpointer user_data) +{ +struct test_case *test = user_data; + + test->timeout_id =0 ; + +if (!test_current || test_current->data != test) +return FALSE; + +/* Give up waiting, e.g. for an index that was never added to be +* removed, rather than blocking for good. Its callbacks may still +* complete later, and would be taken for those of the test running +* then, so do not run the remaining tests. +*/ + test->result =TEST_RESULT_TIMED_OUT ; + test->stage =TEST_STAGE_INVALID ; + +print_progress (test->name,COLOR_RED ,"teardown timed out" ); +tester_warn ("Not running the remaining tests" ); + +while (test_current->next) + test_current = test_current->next; + +g_idle_add (done_callback, test); + +return FALSE; +} + +/* Teardown may have to wait for the kernel to time out commands still sent +* to a controller being removed, 2 seconds each, so only give up on a +* teardown that clearly does not complete. +*/ +#define TEARDOWN_TIMEOUT 30 + +static void teardown_timeout_start (struct test_case *test) +{ +if (test->timeout_id >0 ) { +timeout_remove (test->timeout_id); + test->timeout_id =0 ; + } + +if (test->timeout >0 ) + test->timeout_id =timeout_add_seconds ( +MAX (test->timeout,TEARDOWN_TIMEOUT ), + teardown_timeout, test,NULL ); +} +static gboolean teardown_callback (gpointer user_data) {struct test_case *test = user_data;
@@ -430,6 +479,8 @@ static gboolean teardown_callback(gpointer user_data) test->teardown_id =0 ; test->stage =TEST_STAGE_TEARDOWN ; +teardown_timeout_start (test); +print_progress (test->name,COLOR_MAGENTA ,"teardown" ); test->teardown_func (test->test_data);
@@ -629,10 +680,7 @@ void tester_setup_failed(void) test->result =TEST_RESULT_FAILED ; test->stage =TEST_STAGE_POST_TEARDOWN ; -if (test->timeout_id >0 ) { -timeout_remove (test->timeout_id); - test->timeout_id =0 ; - } +teardown_timeout_start (test);print_progress (test->name,COLOR_RED ,"setup failed" );print_progress (test->name,COLOR_MAGENTA ,"teardown" );
@@ -745,6 +793,11 @@ void tester_post_teardown_complete(void)if (test->stage !=TEST_STAGE_POST_TEARDOWN )return ; +if (test->timeout_id >0 ) { +timeout_remove (test->timeout_id); + test->timeout_id =0 ; + } +print_progress (test->name,COLOR_MAGENTA ,"teardown complete" );g_idle_add (done_callback, test);
@@ -762,6 +815,11 @@ void tester_post_teardown_failed(void)if (test->stage !=TEST_STAGE_POST_TEARDOWN )return ; +if (test->timeout_id >0 ) { +timeout_remove (test->timeout_id); + test->timeout_id =0 ; + } +print_progress (test->name,COLOR_RED ,"teardown failed" );g_idle_add (done_callback, test);
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 3/27 mgmt-tester: Wait for LL Privacy setup to complete
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The LL Privacy setups send Power On, Add Device, Set Device Flags and Add Advertising without waiting for their replies, so setup may complete while they are still pending, even twice, and the test then gets their events, e.g. the Device Flags Changed of Add Device instead of the one of Set Device Flags.
Make each of them a setup condition, and once all are met wait for the controller to settle, i.e. no HCI command for 100 ms, as the kernel keeps programming the accept and resolving lists after replying, which a test may otherwise take for its own commands.
This shows with time travel, where computing takes no time:
LL Privacy, before: 13/27 passed
LL Privacy, after: 27/27 passed
--- tools/mgmt-tester.c | 201 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 190 insertions(+), 11 deletions(-)
tools/mgmt-tester.c +190 -11
@@ -76,6 +76,8 @@ struct test_data {struct queue *expect_hci_q;int unmet_conditions;int unmet_setup_conditions; +bool setup_settle; +unsigned int settle_id;int sk;struct simult_discovery simult; };
@@ -119,6 +121,11 @@ static void test_post_teardown(const void *test_data)simult_discovery_cleanup (data); +if (data->settle_id) { +timeout_remove (data->settle_id); + data->settle_id =0 ; + } +if (data->sk >=0 )close (data->sk);
@@ -554,6 +561,50 @@ static void test_add_setup_condition(struct test_data *data) data->unmet_setup_conditions); } +/* Time without HCI commands after which the controller is considered +* settled, see test_setup_settle(). +*/ +#define SETTLE_TIMEOUT 100 + +static bool settle_timeout (void *user_data) +{ +struct test_data *data = user_data; + + data->settle_id =0 ; +hciemu_clear_central_post_command_hooks (data->hciemu); + +tester_print ("Controller settled" ); +tester_setup_complete (); + +return false; +} + +static void settle_command (uint16_t opcode,const void *param, +uint8_t length,void *user_data) +{ +struct test_data *data = user_data; + +if (data->settle_id) +timeout_remove (data->settle_id); + + data->settle_id =timeout_add (SETTLE_TIMEOUT , settle_timeout, data, +NULL ); +} + +/* The kernel may still program the controller, e.g. its accept and +* resolving lists, after replying to the setup commands, so wait for the +* controller to be idle for a while, or a test may see the setup commands +* instead of its own. +*/ +static void test_setup_settle (struct test_data *data) +{ +tester_print ("Waiting for the controller to settle" ); + +hciemu_add_central_post_command_hook (data->hciemu, settle_command, + data); +settle_command (0 ,NULL ,0 , data); +} +static void test_setup_condition_complete (struct test_data *data) { data->unmet_setup_conditions--;
@@ -564,6 +615,11 @@ static void test_setup_condition_complete(struct test_data *data)if (data->unmet_setup_conditions >0 )return ; +if (data->setup_settle) { +test_setup_settle (data); +return ; + } +tester_setup_complete (); }
@@ -6624,6 +6680,18 @@ static void setup_powered_callback(uint8_t status, uint16_t length,setup_bthost (); } +/* Powered on as one of several setup commands, which completes once all +* of them are, not just the client setup started from here. +*/ +static void setup_powered_condition_callback (uint8_t status,uint16_t length, +const void *param,void *user_data) +{ +setup_powered_callback (status, length, param, user_data); + +if (status ==MGMT_STATUS_SUCCESS ) +test_setup_condition_complete (tester_get_data ()); +} +static void setup_class (const void *test_data) {struct test_data *data =tester_get_data ();
@@ -11526,6 +11594,8 @@ static void setup_add_device_callback(uint8_t status, uint16_t length, }tester_print ("New Device is Added" ); + +test_setup_condition_complete (tester_get_data ()); } static void setup_remove_device_callback(uint8_t status, uint16_t length,
@@ -11559,6 +11629,17 @@ static void setup_add_adv_callback(uint8_t status, uint16_t length, rp->instance); } +/* Last of several setup commands, see setup_powered_condition_callback() */ +static void setup_add_advertising_condition_callback (uint8_t status, +uint16_t length,const void *param, +void *user_data) +{ +setup_add_advertising_callback (status, length, param, user_data); + +if (status ==MGMT_STATUS_SUCCESS ) +test_setup_condition_complete (tester_get_data ()); +} +static void setup_add_adv_callback_adv (uint8_t status,uint16_t length,const void *param,void *user_data) {
@@ -11582,7 +11663,7 @@ static void setup_add_adv_callback_adv(uint8_t status, uint16_t length,mgmt_send (data->mgmt,MGMT_OP_ADD_ADVERTISING , data->mgmt_index,sizeof (adv_param), adv_param, - setup_add_advertising_callback, + setup_add_advertising_condition_callback,NULL ,NULL ); }
@@ -11591,17 +11672,22 @@ static void setup_ll_privacy_set_flags_1(const void *test_data)struct test_data *data =tester_get_data ();unsigned char param[] = {0x01 }; + data->setup_settle = true; +mgmt_send (data->mgmt,MGMT_OP_LOAD_IRKS , data->mgmt_index,sizeof (load_irks_le_public_param_1), load_irks_le_public_param_1, setup_load_irks_callback,NULL ,NULL );/* Set Powered On */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL );/* Add Device 1 */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_ADD_DEVICE, data->mgmt_index, sizeof(add_device_le_public_param_1), add_device_le_public_param_1,
@@ -11617,6 +11703,8 @@ static void setup_set_device_flags_callback(uint8_t status, uint16_t length, }tester_print ("Device Flags are set" ); + +test_setup_condition_complete (tester_get_data ()); }static void setup_ll_privacy_add_2 (const void *test_data)
@@ -11624,6 +11712,8 @@ static void setup_ll_privacy_add_2(const void *test_data)struct test_data *data =tester_get_data ();unsigned char param[] = {0x01 }; + data->setup_settle = true; +/* Add IRKs of Device1 and Device2 */ mgmt_send(data->mgmt, MGMT_OP_LOAD_IRKS, data->mgmt_index, sizeof(load_irks_2_devices_param),
@@ -11631,16 +11721,20 @@ static void setup_ll_privacy_add_2(const void *test_data) setup_load_irks_callback, NULL, NULL);/* Set Powered On */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL );/* Add Device 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_1), add_device_le_public_param_1, setup_add_device_callback,NULL ,NULL );/* Device 1 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_1), set_device_flags_param_1,
@@ -11653,6 +11747,8 @@ static void setup_ll_privacy_set_flags_3(const void *test_data)struct test_data *data =tester_get_data ();unsigned char param[] = {0x01 }; + data->setup_settle = true; +/* Add IRKs of Device1 and Device2 */ mgmt_send(data->mgmt, MGMT_OP_LOAD_IRKS, data->mgmt_index, sizeof(load_irks_2_devices_param),
@@ -11660,17 +11756,21 @@ static void setup_ll_privacy_set_flags_3(const void *test_data) setup_load_irks_callback, NULL, NULL);/* Set Powered On */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL );/* Add Device 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_1), add_device_le_public_param_1, setup_add_device_callback,NULL ,NULL );/* Device 1 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_1), set_device_flags_param_1,
@@ -11678,6 +11778,7 @@ static void setup_ll_privacy_set_flags_3(const void *test_data) NULL);/* Add Device 2 */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_ADD_DEVICE, data->mgmt_index, sizeof(add_device_le_public_param_2), add_device_le_public_param_2,
@@ -11698,6 +11799,8 @@ static void setup_ll_privacy_3_devices(const void *test_data)struct test_data *data =tester_get_data ();unsigned char param[] = {0x01 }; + data->setup_settle = true; +/* Add IRKs of 4 Devices */ mgmt_send(data->mgmt, MGMT_OP_LOAD_IRKS, data->mgmt_index, sizeof(load_irks_4_devices_param),
@@ -11705,12 +11808,14 @@ static void setup_ll_privacy_3_devices(const void *test_data) setup_load_irks_callback, NULL, NULL);/* Add Device 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_1), add_device_le_public_param_1, setup_add_device_callback,NULL ,NULL );/* Device 1 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_1), set_device_flags_param_1,
@@ -11718,12 +11823,14 @@ static void setup_ll_privacy_3_devices(const void *test_data) NULL);/* Add Device 2 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_2), add_device_le_public_param_2, setup_add_device_callback,NULL ,NULL );/* Device 2 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_2), set_device_flags_param_2,
@@ -11731,21 +11838,25 @@ static void setup_ll_privacy_3_devices(const void *test_data) NULL);/* Add Device 3 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_3), add_device_le_public_param_3, setup_add_device_callback,NULL ,NULL );/* Device 3 Flags */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_DEVICE_FLAGS , data->mgmt_index,sizeof (set_device_flags_param_3), set_device_flags_param_3, setup_set_device_flags_callback,NULL ,NULL ); +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL ); }static void setup_ll_privacy_set_flags_4 (const void *test_data)
@@ -11753,6 +11864,8 @@ static void setup_ll_privacy_set_flags_4(const void *test_data)struct test_data *data =tester_get_data ();unsigned char param[] = {0x01 }; + data->setup_settle = true; +hciemu_set_central_le_rl_len (data->hciemu,4 );/* Add IRKs of 4 Devices */
@@ -11762,12 +11875,14 @@ static void setup_ll_privacy_set_flags_4(const void *test_data) setup_load_irks_callback, NULL, NULL);/* Add Device 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_1), add_device_le_public_param_1, setup_add_device_callback,NULL ,NULL );/* Device 1 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_1), set_device_flags_param_1,
@@ -11775,12 +11890,14 @@ static void setup_ll_privacy_set_flags_4(const void *test_data) NULL);/* Add Device 2 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_2), add_device_le_public_param_2, setup_add_device_callback,NULL ,NULL );/* Device 2 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_2), set_device_flags_param_2,
@@ -11788,12 +11905,14 @@ static void setup_ll_privacy_set_flags_4(const void *test_data) NULL);/* Add Device 3 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_3), add_device_le_public_param_3, setup_add_device_callback,NULL ,NULL );/* Device 3 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_3), set_device_flags_param_3,
@@ -11801,14 +11920,17 @@ static void setup_ll_privacy_set_flags_4(const void *test_data) NULL);/* Add Device 4 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_4), add_device_le_public_param_4, setup_add_device_callback,NULL ,NULL ); +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL ); }static void setup_ll_privacy_add_3 (const void *test_data)
@@ -11816,6 +11938,8 @@ static void setup_ll_privacy_add_3(const void *test_data)struct test_data *data =tester_get_data ();unsigned char param[] = {0x01 }; + data->setup_settle = true; +hciemu_set_central_le_al_len (data->hciemu,2 );/* Add IRKs of 3 Devices */
@@ -11825,17 +11949,21 @@ static void setup_ll_privacy_add_3(const void *test_data) setup_load_irks_callback, NULL, NULL);/* Set Powered On */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL );/* Add Device 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_1), add_device_le_public_param_1, setup_add_device_callback,NULL ,NULL );/* Device 1 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_1), set_device_flags_param_1,
@@ -11843,12 +11971,14 @@ static void setup_ll_privacy_add_3(const void *test_data) NULL);/* Add Device 2 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_2), add_device_le_public_param_2, setup_add_device_callback,NULL ,NULL );/* Device 2 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_2), set_device_flags_param_2,
@@ -11863,9 +11993,13 @@ static void setup_ll_privacy_device2_discovry(const void *test_data)unsigned char param[] = {0x01 };uint8_t disc_param[] = {0x06 }; + data->setup_settle = true; + +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL );/* Load IRKs */ mgmt_send(data->mgmt, MGMT_OP_LOAD_IRKS, data->mgmt_index, sizeof(load_irks_2_devices_param),
@@ -11873,11 +12007,13 @@ static void setup_ll_privacy_device2_discovry(const void *test_data) setup_load_irks_callback, NULL, NULL);/* Load Device1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_1), add_device_le_public_param_1, setup_add_device_callback,NULL ,NULL ); +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_ADD_DEVICE, data->mgmt_index, sizeof(add_device_le_public_param_2), add_device_le_public_param_2,
@@ -11906,6 +12042,8 @@ static void setup_ll_privacy_add_4(const void *test_data)unsigned char param[] = {0x01 };unsigned char adv_param[sizeof (*cp) +TESTER_ADD_ADV_DATA_LEN ]; + data->setup_settle = true; + cp = (struct mgmt_cp_add_advertising *) adv_param;setup_add_adv_param (cp,1 );
@@ -11926,6 +12064,8 @@ static void setup_ll_privacy_set_flags_5(const void *test_data)unsigned char param[] = {0x01 };unsigned char adv_param[sizeof (*cp) +TESTER_ADD_ADV_DATA_LEN ]; + data->setup_settle = true; + cp = (struct mgmt_cp_add_advertising *) adv_param;setup_add_adv_param (cp,1 );
@@ -11941,11 +12081,13 @@ static void setup_ll_privacy_set_flags_5(const void *test_data) NULL, NULL, NULL);/* Add Advertising Instance */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_ADVERTISING , data->mgmt_index,sizeof (adv_param), adv_param, setup_add_adv_callback_adv,NULL ,NULL );/* Add Device 1 */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_ADD_DEVICE, data->mgmt_index, sizeof(add_device_le_public_param_1), add_device_le_public_param_1,
@@ -11959,6 +12101,8 @@ static void setup_ll_privacy_set_flags_6(const void *test_data)unsigned char param[] = {0x01 };unsigned char adv_param[sizeof (*cp) +TESTER_ADD_ADV_DATA_LEN ]; + data->setup_settle = true; + cp = (struct mgmt_cp_add_advertising *) adv_param;setup_add_adv_param (cp,1 );
@@ -11974,17 +12118,20 @@ static void setup_ll_privacy_set_flags_6(const void *test_data) NULL, NULL, NULL);/* Add Advertising Instance 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_ADVERTISING , data->mgmt_index,sizeof (adv_param), adv_param, setup_add_adv_callback_adv,NULL ,NULL );/* Add Device 2 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_2), add_device_le_public_param_2, setup_add_device_callback,NULL ,NULL );/* Device 2 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_2), set_device_flags_param_2,
@@ -11992,6 +12139,7 @@ static void setup_ll_privacy_set_flags_6(const void *test_data) NULL);/* Add Device 1 */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_ADD_DEVICE, data->mgmt_index, sizeof(add_device_le_public_param_1), add_device_le_public_param_1,
@@ -12005,6 +12153,8 @@ static void setup_ll_privacy_adv_3_devices(const void *test_data)unsigned char param[] = {0x01 };unsigned char adv_param[sizeof (*cp) +TESTER_ADD_ADV_DATA_LEN ]; + data->setup_settle = true; + cp = (struct mgmt_cp_add_advertising *) adv_param;setup_add_adv_param (cp,1 );
@@ -12019,12 +12169,14 @@ static void setup_ll_privacy_adv_3_devices(const void *test_data) setup_load_irks_callback, NULL, NULL);/* Add Device 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_1), add_device_le_public_param_1, setup_add_device_callback,NULL ,NULL );/* Device 1 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_1), set_device_flags_param_1,
@@ -12032,12 +12184,14 @@ static void setup_ll_privacy_adv_3_devices(const void *test_data) NULL);/* Add Device 2 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_2), add_device_le_public_param_2, setup_add_device_callback,NULL ,NULL );/* Device 2 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_2), set_device_flags_param_2,
@@ -12045,21 +12199,25 @@ static void setup_ll_privacy_adv_3_devices(const void *test_data) NULL);/* Add Device 3 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_3), add_device_le_public_param_3, setup_add_device_callback,NULL ,NULL );/* Device 3 Flags */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_DEVICE_FLAGS , data->mgmt_index,sizeof (set_device_flags_param_3), set_device_flags_param_3, setup_set_device_flags_callback,NULL ,NULL ); +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL ); }static void setup_ll_privacy_adv_1_device_2_advs (const void *test_data)
@@ -12069,6 +12227,8 @@ static void setup_ll_privacy_adv_1_device_2_advs(const void *test_data)unsigned char param[] = {0x01 };unsigned char adv_param[sizeof (*cp) +TESTER_ADD_ADV_DATA_LEN ]; + data->setup_settle = true; + cp = (struct mgmt_cp_add_advertising *) adv_param;setup_add_adv_param (cp,1 );
@@ -12083,12 +12243,14 @@ static void setup_ll_privacy_adv_1_device_2_advs(const void *test_data) NULL, NULL, NULL);/* Add Device 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_1), add_device_le_public_param_1, setup_add_device_callback,NULL ,NULL );/* Device 1 Flags */ +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_SET_DEVICE_FLAGS, data->mgmt_index, sizeof(set_device_flags_param_1), set_device_flags_param_1,
@@ -12096,18 +12258,21 @@ static void setup_ll_privacy_adv_1_device_2_advs(const void *test_data) NULL);/* Add Device 2 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_le_public_param_2), add_device_le_public_param_2, setup_add_device_callback,NULL ,NULL );/* Device 2 Flags */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_DEVICE_FLAGS , data->mgmt_index,sizeof (set_device_flags_param_2), set_device_flags_param_2, setup_set_device_flags_callback,NULL ,NULL ); +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_ADVERTISING , data->mgmt_index,sizeof (adv_param), adv_param, setup_add_adv_callback_adv,NULL ,NULL );
@@ -12133,6 +12298,7 @@ static void setup_add_2_advertisings(const void *test_data)sizeof (param), param, NULL, NULL, NULL); +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_ADD_ADVERTISING, data->mgmt_index, sizeof(adv_param), adv_param, setup_add_adv_callback_adv,
@@ -12155,6 +12321,7 @@ static void setup_add_2_advertisings_no_power(const void *test_data)sizeof (param), ¶m, NULL, NULL, NULL); +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_ADD_ADVERTISING, data->mgmt_index, sizeof(adv_param), adv_param, setup_add_adv_callback_adv,
@@ -12167,6 +12334,8 @@ static void setup_ll_privacy_enable_powered(const void *test_data)unsigned char param[] = {0x01 };struct bthost *bthost; + data->setup_settle = true; + bthost =hciemu_client_get_host (data->hciemu);bthost_set_scan_params (bthost,0x01 ,0x00 ,0x00 );bthost_set_scan_enable (bthost,0x01 );
@@ -12184,6 +12353,8 @@ static void setup_ll_privacy_add_adv(const void *test_data)unsigned char set_adv_param[] = {0x02 };struct bthost *bthost; + data->setup_settle = true; +/* Setup bthost to enable the scan */ bthost =hciemu_client_get_host (data->hciemu);bthost_set_scan_params (bthost,0x01 ,0x00 ,0x00 );
@@ -12216,15 +12387,20 @@ static void setup_ll_privacy_add_device(const void *test_data)struct test_data *data =tester_get_data ();unsigned char param[] = {0x01 }; + data->setup_settle = true; +mgmt_send (data->mgmt,MGMT_OP_LOAD_IRKS , data->mgmt_index,sizeof (load_irks_le_public_param_1), load_irks_le_public_param_1, setup_load_irks_callback,NULL ,NULL ); +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL ); +test_add_setup_condition (data); mgmt_send(data->mgmt, MGMT_OP_ADD_DEVICE, data->mgmt_index, sizeof(add_device_le_public_param_1), add_device_le_public_param_1,
@@ -13583,15 +13759,18 @@ static void setup_suspend_resume_success_3(const void *test_data)unsigned char param[] = {0x01 };/* Add Device 1 */ +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_ADD_DEVICE , data->mgmt_index,sizeof (add_device_success_param_3), add_device_success_param_3, setup_add_device_callback,NULL ,NULL ); +test_add_setup_condition (data);mgmt_send (data->mgmt,MGMT_OP_SET_POWERED , data->mgmt_index,sizeof (param), param, - setup_powered_callback,NULL ,NULL ); + setup_powered_condition_callback, +NULL ,NULL ); }static void test_suspend_resume_success_3 (const void *test_data)
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 4/27 iso-tester: Fix leaking socket watches
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
iso_recv_data() clears io_id[0] on entry, but returns TRUE to keep its watch while more data is expected, so the watch can no longer be removed, and the watches with ids are only removed when the test data is freed at exit. Either way the watched socket stays open past the test, and once it hangs up, as the controller is removed, it wakes up the main loop over and over for every following test, as G_IO_IN does not include G_IO_HUP.
Keep the id while the watch is kept and remove the watches on post teardown. This busy loop is costly under User Mode Linux time travel, where computing takes no simulated time, e.g. the PAST Receiver tests took about 7 seconds each, with -T:
iso-tester before 49.2 s
after 16.3 s
--- tools/iso-tester.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
tools/iso-tester.c +16 -2
@@ -707,10 +707,22 @@ static void io_free(void *data)static void test_post_teardown (const void *test_data) {struct test_data *data =tester_get_data (); +unsigned int i;if (data->io_queue)queue_remove_all (data->io_queue,NULL ,NULL , io_free); +/* Remove the watches with the test, as the sockets they keep open +* hang up once the controller is removed, which would wake up the +* main loop over and over for the following tests. +*/ +for (i =0 ; i <ARRAY_SIZE (data->io_id); ++i) { +if (data->io_id[i] >0 ) { +g_source_remove (data->io_id[i]); + data->io_id[i] =0 ; + } + } +mgmt_send (data->mgmt,MGMT_OP_SET_EXP_FEATURE ,MGMT_INDEX_NONE ,sizeof (reset_iso_socket_param), reset_iso_socket_param,NULL ,NULL ,NULL );
@@ -2542,9 +2554,11 @@ static gboolean iso_recv_data(GIOChannel *io, GIOCondition cond,if (memcmp (buf, isodata->recv->iov_base, ret))tester_test_failed (); -else if (data->step) +else if (data->step) { +/* Keep the watch, and its id so teardown can remove it */ + data->io_id[0 ] =g_source_get_id (g_main_current_source ());return TRUE; -else if (isodata->disconnect) + }else if (isodata->disconnect)iso_shutdown (data, io);else if (isodata->terminate)iso_terminate (data, io);
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 5/27 l2cap-tester: Fix race in LE Client - Close socket 2
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The test closes the socket once the scan is disabled, expecting the kernel to cancel the connection attempt with LE Create Connection Cancel, but the kernel only sends LE Create Connection after disabling the scan, so whether there is an attempt to cancel depends on which runs first. Close the socket once LE Create Connection was sent instead.
This shows under User Mode Linux time travel, where the test always closed the socket too early.
--- tools/l2cap-tester.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
tools/l2cap-tester.c +13 -1
@@ -2769,7 +2769,17 @@ static void test_close_socket_scan_disabled(void)if (l2data == &le_client_close_socket_test_1)g_idle_add (test_close_socket_1_part_3,NULL ); -else if (l2data == &le_client_close_socket_test_2) +} + +/* The kernel creates the connection once the scan is disabled, close the +* socket only then, so it has a connection attempt to cancel. +*/ +static void test_close_socket_create_conn (void ) +{ +struct test_data *data =tester_get_data (); +const struct l2cap_data *l2data = data->test_data; + +if (l2data == &le_client_close_socket_test_2)g_idle_add (test_close_socket_2_part_3,NULL ); }
@@ -2793,6 +2803,8 @@ static void test_close_socket_router(uint16_t opcode, const void *param,test_close_socket_scan_enabled (); elsetest_close_socket_scan_disabled (); + }else if (opcode ==BT_HCI_CMD_LE_CREATE_CONN ) { +test_close_socket_create_conn (); }else if (opcode ==BT_HCI_CMD_LE_CREATE_CONN_CANCEL ) {test_close_socket_conn_cancel (); }
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 6/27 iso-tester: Fix busy waiting in PAST tests
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
iso_pollout() kept its watch while the connection to the PAST receiver was missing, but the socket is writable all along, so the main loop was woken up until the connection was established. Under User Mode Linux time travel, where computing takes no simulated time, the PAST Info tests took about 400 seconds each.
Drop the watch instead and send from iso_new_conn() once the connection is there.
--- tools/iso-tester.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
tools/iso-tester.c +22 -3
@@ -471,6 +471,7 @@ struct test_data {uint16_t handle;uint16_t acl_handle;struct queue *io_queue; +GIOChannel *past_io;unsigned int io_id[4 ];uint8_t client_num;int step;
@@ -712,6 +713,11 @@ static void test_post_teardown(const void *test_data)if (data->io_queue)queue_remove_all (data->io_queue,NULL ,NULL , io_free); +if (data->past_io) { +g_io_channel_unref (data->past_io); + data->past_io =NULL ; + } +/* Remove the watches with the test, as the sockets they keep open * hang up once the controller is removed, which would wake up the * main loop over and over for the following tests.
@@ -1716,6 +1722,8 @@ static void bthost_iso_disconnected(void *user_data) data->handle =0x0000 ; } +static void iso_send (struct test_data *data,GIOChannel *io); +static void iso_new_conn (uint16_t handle,void *user_data) {struct test_data *data = user_data;
@@ -1727,6 +1735,12 @@ static void iso_new_conn(uint16_t handle, void *user_data) data->handle = handle; +if (data->past_io) { +iso_send (data, data->past_io); +g_io_channel_unref (data->past_io); + data->past_io =NULL ; + } + host =hciemu_client_get_host (data->hciemu);bthost_add_iso_hook (host, data->handle, bthost_recv_data, data, bthost_iso_disconnected);
@@ -2703,11 +2717,16 @@ static gboolean iso_pollout(GIOChannel *io, GIOCondition cond,const struct iso_client_data *isodata = data->test_data;unsigned int count; -if (isodata->past && !data->handle) -return TRUE; - data->io_id[0 ] =0 ; +/* Send once the connection to the PAST receiver is there, see +* iso_new_conn(), rather than waking up for good until then. +*/ +if (isodata->past && !data->handle) { + data->past_io =g_io_channel_ref (io); +return FALSE; + } +tester_print ("POLLOUT event received" );for (count =0 ; count < isodata->repeat_send_pre_ts; ++count)
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 7/27 doc: Enable IPv6 in tester.config
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
6LoWPAN over Bluetooth needs IPv6, which tester.config relied on the default configuration for: without it 6lowpan_enable does not show up in debugfs and every 6lowpan-tester test fails, as with the User Mode Linux defconfig.
--- doc/tester.config | 1 + 1 file changed, 1 insertion(+)
doc/tester.config +1 -0
@@ -15,6 +15,7 @@ CONFIG_PTP_1588_CLOCK_VMCLOCK=y CONFIG_NET=y CONFIG_INET=y +CONFIG_IPV6=y CONFIG_NET_9P=y CONFIG_NET_9P_VIRTIO=y
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 8/27 6lowpan-tester: Find the interface of the controller
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The tests open bt0, but the interface of a previous test may still be there, removed by the kernel from a work, in which case the interface of the current test gets another name and the test waits for packets on the wrong one. Use the most recent interface of the controller of the test.
This shows under User Mode Linux time travel, where the receive tests always got the interface of the previous test.
--- tools/6lowpan-tester.c | 62 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-)
tools/6lowpan-tester.c +61 -1
@@ -22,6 +22,7 @@#include <net/if.h> #include <linux/if_packet.h> #include <sys/ioctl.h> +#include <dirent.h> #include <glib.h>
@@ -590,14 +591,73 @@ done:return FALSE; } +/* Find the interface of the controller of this test, the most recent one, +* as the interface of a previous test may still be there, which can also +* make the name of this one other than bt0. +*/ +static bool find_iface (struct test_data *data,char *ifname,size_t len) +{ +char path[PATH_MAX ], link[PATH_MAX ], hci[16 ]; +struct dirent *entry; +int best =-1 ; +DIR *dir; + +snprintf (hci,sizeof (hci),"hci%u" , data->mgmt_index); + + dir =opendir ("/sys/class/net" ); +if (!dir) +return false; + +while ((entry =readdir (dir))) { +const char *name; +ssize_t n; +int index; + +if (strncmp (entry->d_name,"bt" ,2 )) +continue ; + +snprintf (path,sizeof (path),"/sys/class/net/%s/device" , + entry->d_name); + + n =readlink (path, link,sizeof (link) -1 ); +if (n <0 ) +continue ; + + link[n] ='\0' ; + name =strrchr (link,'/' ); + name = name ? name +1 : link; + +if (strcmp (name, hci)) +continue ; + +if (strlen (entry->d_name) >= len) +continue ; + + index =if_nametoindex (entry->d_name); +if (index > best) { + best = index; +memcpy (ifname, entry->d_name, +strlen (entry->d_name) +1 ); + } + } + +closedir (dir); + +return best >=0 ; +} +static gboolean client_open_iface (gpointer user_data) {struct test_data *data = user_data;const struct client_data *cdata = data->test_data; +char ifname[IFNAMSIZ ]; data->io_id =0 ; - data->packet_fd =open_iface ("bt0" , cdata->sk_type); + data->packet_fd =-1 ; + +if (find_iface (data, ifname,sizeof (ifname))) + data->packet_fd =open_iface (ifname, cdata->sk_type);if (data->packet_fd <0 ) {tester_print ("Wait for interface..." ); data->io_id =g_timeout_add (500 , client_open_iface, data);
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 9/27 emulator: Remove -T option from btvirt
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The AMP test controllers were removed, but -T was left in the help text and the getopt string without a handler, so btvirt -T exits with an error.
--- emulator/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
emulator/main.c +1 -2
@@ -58,7 +58,6 @@ static void usage(void)"\t BR/EDR/LE controllers created with\n" "\t -l, -s and -t:\n" "\t 5.0, 5.2, 6.0 or 6.2 (default)\n" -"\t-T[num] Number of test AMP controllers\n" "\t-h, --help Show help options\n"); }
@@ -141,7 +140,7 @@ int main(int argc, char *argv[])for (;;) {int opt; - opt =getopt_long (argc, argv,"dSs::t::l::LBAC:U::T::vh" , + opt =getopt_long (argc, argv,"dSs::t::l::LBAC:U::vh" , main_options,NULL );if (opt <0 )break ;
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 10/27 doc: Add btvirt documentation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Document the btvirt options, the ways it exposes the emulated controllers and which of them share the emulated air interface.
--- Makefile.am | 1 + doc/btvirt.rst | 153 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 doc/btvirt.rst
Makefile.am +1 -0
@@ -494,6 +494,7 @@ EXTRA_DIST += SECURITY.md EXTRA_DIST += doc/assigned-numbers.rst doc/supported-features.txt \ doc/test-coverage.txt \ doc/test-runner.rst \ + doc/btvirt.rst \ doc/test-functional.rst \ doc/functional-testing.rst \ doc/functional-a2dp.rst \
doc/btvirt.rst new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 11/27 emulator: Add vhost-user backend
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add a vhost-user back-end on top of the mainloop, so emulated devices can be provided to virtual machines as virtio devices. It supports the split virtqueue layout, the configuration space and kick/call file descriptors.
Offer VHOST_USER_PROTOCOL_F_SLAVE_REQ and VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS, so the guest sends kicks as VHOST_USER_VRING_KICK messages and is notified with VHOST_USER_SLAVE_VRING_CALL requests. User Mode Linux with external time travel requires this, as it does not handle call file descriptors while it waits for the time controller. The front-end only acknowledges a notification after the time controller answered it, so a wait callback lets the user serve it in the meantime.
Messages are read without blocking and may arrive in several parts, so one connection cannot hold up the others or the calendar, and vhost_process() handles them for a time travel calendar before it advances time; a nested call for a connection already being processed returns right away, so only the outer one removes it on failure. A can_notify callback holds notifications to the driver back until vhost_flush_notify(), for a back-end that may only notify while the calendar lets it run.
--- Makefile.tools | 3 +- emulator/vhost.c | 1018 ++++++++++++++++++++++++++++++++++++++++++++++ emulator/vhost.h | 67 +++ 3 files changed, 1087 insertions(+), 1 deletion(-) create mode 100644 emulator/vhost.c create mode 100644 emulator/vhost.h
Makefile.tools +2 -1
@@ -102,7 +102,8 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c \ emulator/phy.h emulator/phy.c \ - emulator/le.h emulator/le.c + emulator/le.h emulator/le.c \ + emulator/vhost.h emulator/vhost.c emulator_btvirt_LDADD = lib/libbluetooth-internal.la src/libshared-mainloop.la emulator_b1ee_SOURCES = emulator/b1ee.c
emulator/vhost.c new file +1018 -0
1,018 lines not on this page · raw message
emulator/vhost.h new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 12/27 emulator: Add vhost-user virtio server to btvirt
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add the -V option, which creates a vhost-user server socket on which each connection gets a new controller, provided to the guest as a virtio Bluetooth device. This is how User Mode Linux guests, which can only attach external devices through vhost-user, get emulated controllers.
Packets for the driver are queued until it posts receive buffers, since the Linux driver keeps only one posted.
--- Makefile.tools | 3 +- doc/btvirt.rst | 26 +++- emulator/main.c | 27 +++- emulator/virtio.c | 323 ++++++++++++++++++++++++++++++++++++++++++++++ emulator/virtio.h | 20 +++ 5 files changed, 391 insertions(+), 8 deletions(-) create mode 100644 emulator/virtio.c create mode 100644 emulator/virtio.h
Makefile.tools +2 -1
@@ -103,7 +103,8 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \ emulator/smp.c \ emulator/phy.h emulator/phy.c \ emulator/le.h emulator/le.c \ - emulator/vhost.h emulator/vhost.c + emulator/vhost.h emulator/vhost.c \ + emulator/virtio.h emulator/virtio.c emulator_btvirt_LDADD = lib/libbluetooth-internal.la src/libshared-mainloop.la emulator_b1ee_SOURCES = emulator/b1ee.c
doc/btvirt.rst +22 -4
@@ -32,6 +32,8 @@ and speak HCI. They can be exposed to a Bluetooth stack in several ways: appear as ``hciN`` on the machine running btvirt; - as H:4 streams on Unix socket servers (**-s**) or a TCP server (**-t**), one controller per client connection; +- as virtio Bluetooth devices on a vhost-user server (**-V**), one + controller per connection, for virtual machines; - as an H:4 stream on a pseudo terminal (**-S**). All controllers created by one btvirt process share an emulated air
@@ -45,7 +47,8 @@ btvirt runs until it receives **SIGINT** or **SIGTERM**. OPTIONS ======= -At least one of **-l**, **-s**, **-t**, **-S** or **-U** must be given. +At least one of **-l**, **-s**, **-t**, **-V**, **-S** or **-U** must be +given. Optional arguments must be attached to the option, as in **-l2**, **-t45551** or **--server=/tmp/bt**.
@@ -78,6 +81,14 @@ Optional arguments must be attached to the option, as in **-l2**, attached as an H:4 stream. The server listens on 127.0.0.1 only. +-V[path], --vhost[=path] Create a vhost-user server socket + ``bt-vhost-bredrle`` in the directory *path* + (default: ``/tmp``). Each connection gets a new + BR/EDR/LE controller, of the version given with + **-C**, provided to the guest as a virtio + Bluetooth device. See **virtio** for how to + attach it to QEMU or User Mode Linux guests. + -S, --serial Create a pseudo terminal with a BR/EDR/LE controller attached as an H:4 stream. The path of the terminal is printed on startup; attach it
@@ -99,12 +110,12 @@ Optional arguments must be attached to the option, as in **-l2**, -C version, --core=version Core Specification version of the BR/EDR/LE controllers created with **-l**, **-s** (on - ``bt-server-bredrle``) and **-t**. Supported + ``bt-server-bredrle``), **-t** and **-V**. Supported values are ``5.0``, ``5.2``, ``6.0`` and ``6.2`` (default). --d, --debug Enable debug output for the **-l** and **-s** - controllers. +-d, --debug Enable debug output for the **-l**, **-s** and + **-V** controllers. -v, --version Show version.
@@ -133,6 +144,13 @@ Serve controllers to virtual machines, one per connecting VM, the way $ btvirt --server=/tmp/bt $ test-runner -u/tmp/bt/bt-server-bredrle -k bzImage -- ... +Provide controllers to User Mode Linux guests as virtio Bluetooth +devices, two from the same socket:: + + $ btvirt -V/tmp/bt + $ linux ... virtio_uml.device=/tmp/bt/bt-vhost-bredrle:40 \ + virtio_uml.device=/tmp/bt/bt-vhost-bredrle:40 + Emulate a Bluetooth 5.2 controller over TCP:: $ btvirt -C 5.2 -t
emulator/main.c +24 -3
@@ -27,6 +27,7 @@#include "btdev.h" #include "server.h" #include "vhci.h" +#include "virtio.h" #include "le.h" static void signal_callback (int signum,void *user_data)
@@ -49,6 +50,8 @@ static void usage(void)"\t-S Create local serial port\n" "\t-s[path=/tmp] Create local server sockets\n" "\t-t[port=45550] Create a TCP server\n" +"\t-V[path=/tmp] Create local vhost-user virtio\n" +"\t server socket\n" "\t-l[num] Number of local controllers\n" "\t-L Create LE only controller\n" "\t-U[num] Number of test LE controllers\n"
@@ -56,7 +59,7 @@ static void usage(void)"\t-A Create AMP controller\n" "\t-C, --core=<version> Core Specification version of the\n" "\t BR/EDR/LE controllers created with\n" -"\t -l, -s and -t:\n" +"\t -l, -s, -t and -V:\n" "\t 5.0, 5.2, 6.0 or 6.2 (default)\n" "\t-h, --help Show help options\n"); }
@@ -66,6 +69,7 @@ static const struct option main_options[] = { { "serial", no_argument, NULL, 'S' }, { "server", optional_argument, NULL, 's' }, { "tcp", optional_argument, NULL, 't' }, + { "vhost", optional_argument, NULL, 'V' }, { "local", optional_argument, NULL, 'l' }, { "le", no_argument, NULL, 'L' }, { "bredr", no_argument, NULL, 'B' },
@@ -126,6 +130,7 @@ int main(int argc, char *argv[])bool server_enabled = false;const char *server_path ="/tmp" ;uint16_t tcp_port =0 ; +const char *vhost_path =NULL ;bool serial_enabled = false;int letest_count =0 ;int vhci_count =0 ;
@@ -140,7 +145,7 @@ int main(int argc, char *argv[])for (;;) {int opt; - opt =getopt_long (argc, argv,"dSs::t::l::LBAC:U::vh" , + opt =getopt_long (argc, argv,"dSs::t::V::l::LBAC:U::vh" , main_options,NULL );if (opt <0 )break ;
@@ -163,6 +168,9 @@ int main(int argc, char *argv[])else tcp_port =45550 ;break ; +case 'V' : + vhost_path = optarg ? optarg :"/tmp" ; +break ;case 'l' :if (optarg) vhci_count =atoi (optarg);
@@ -209,7 +217,7 @@ int main(int argc, char *argv[]) type = bredrle_type;if (letest_count <1 && vhci_count <1 && !server_enabled && - !tcp_port && !serial_enabled) { + !tcp_port && !serial_enabled && !vhost_path) {fprintf (stderr,"No emulator specified\n" );return EXIT_FAILURE ; }
@@ -306,5 +314,18 @@ int main(int argc, char *argv[])fprintf (stderr,"Listening TCP on 127.0.0.1:%d\n" , tcp_port); } +if (vhost_path) { +struct vtio *vtio; +char path[PATH_MAX ]; + +snprintf (path,sizeof (path),"%s/%s" , vhost_path, +"bt-vhost-bredrle" ); + vtio =vtio_open (bredrle_type, path); +if (!vtio) +fprintf (stderr,"Failed to open vhost-user server\n" ); +else if (debug_enabled) +vtio_set_debug (vtio, server_debug,"vhost" ); + } +return mainloop_run_with_signal (signal_callback,NULL ); }
emulator/virtio.c new file +323 -0
323 lines not on this page · raw message
emulator/virtio.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2026 Intel Corporation +* +* +*/ + +#include <stdbool.h> + +struct vtio ; + +struct vtio *vtio_open (enum btdev_type type,const char *path); +void vtio_close (struct vtio *vtio); + +typedef void (*vtio_debug_func_t )(const char *str,void *user_data); +bool vtio_set_debug (struct vtio *vtio, +vtio_debug_func_t callback,void *user_data);
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 13/27 emulator: Add time travel calendar to btvirt
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add the --time option, which makes btvirt the time travel calendar of User Mode Linux guests started with time-travel=ext, so they share a simulated clock with btvirt without an external time controller. Time only advances when every guest waits, and the timers of the emulated controllers run on the simulated clock. A guest runs exactly at the time it requested, and GET answers with the current time, which a guest takes as the time of an interrupt.
The calendar only uses messages. UML uses the file descriptors of the START acknowledgment without checking how many it received, so send a shared memory it rejects and /dev/null.
In lock-step, send FREE_UNTIL with the next event of any other client or timer before RUN, so a guest does not ask before each of its own events, about four round trips each, and lower it when an earlier event shows up. A guest sends UPDATE before each virtio notification, but does not wait for it to be handled, so take its time from UPDATE and stop it there before acknowledging: it may not run ahead of what the notification causes, such as an interrupt from the device.
Add tt_set_skew() to let time advance up to a skew beyond the earliest running guest, and a hold callback for pacing: while held, time advances no faster than real time, and no FREE_UNTIL is given so pacing can stop a guest.
--- Makefile.tools | 4 +- doc/btvirt.rst | 22 +- emulator/main.c | 27 +- emulator/timeout.c | 102 ++++++ emulator/timetravel.c | 743 ++++++++++++++++++++++++++++++++++++++++++ emulator/timetravel.h | 55 ++++ emulator/virtio.c | 33 ++ 7 files changed, 981 insertions(+), 5 deletions(-) create mode 100644 emulator/timeout.c create mode 100644 emulator/timetravel.c create mode 100644 emulator/timetravel.h
Makefile.tools +3 -1
@@ -104,7 +104,9 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \ emulator/phy.h emulator/phy.c \ emulator/le.h emulator/le.c \ emulator/vhost.h emulator/vhost.c \ - emulator/virtio.h emulator/virtio.c + emulator/virtio.h emulator/virtio.c \ + emulator/timetravel.h emulator/timetravel.c \ + emulator/timeout.c emulator_btvirt_LDADD = lib/libbluetooth-internal.la src/libshared-mainloop.la emulator_b1ee_SOURCES = emulator/b1ee.c
doc/btvirt.rst +20 -2
@@ -47,8 +47,8 @@ btvirt runs until it receives **SIGINT** or **SIGTERM**. OPTIONS ======= -At least one of **-l**, **-s**, **-t**, **-V**, **-S** or **-U** must be -given. +At least one of **-l**, **-s**, **-t**, **-V**, **-S**, **-U** or +**--time** must be given. Optional arguments must be attached to the option, as in **-l2**, **-t45551** or **--server=/tmp/bt**.
@@ -89,6 +89,17 @@ Optional arguments must be attached to the option, as in **-l2**, Bluetooth device. See **virtio** for how to attach it to QEMU or User Mode Linux guests. +--time[=path] Create a time travel calendar socket ``bt-time`` + in the directory *path* (default: ``/tmp``) for + User Mode Linux guests started with + ``time-travel=ext:<path>/bt-time``. The guests + and btvirt then share a simulated clock: time + only advances when every guest waits, and the + timers of the emulated controllers run on it. + Notifications of **-V** controllers are + exchanged in-band, so they are ordered with + the guests' clocks. + -S, --serial Create a pseudo terminal with a BR/EDR/LE controller attached as an H:4 stream. The path of the terminal is printed on startup; attach it
@@ -151,6 +162,13 @@ devices, two from the same socket:: $ linux ... virtio_uml.device=/tmp/bt/bt-vhost-bredrle:40 \ virtio_uml.device=/tmp/bt/bt-vhost-bredrle:40 +Run the same guests on a simulated clock shared with btvirt:: + + $ btvirt --time=/tmp/bt -V/tmp/bt + $ linux ... time-travel=ext:/tmp/bt/bt-time \ + virtio_uml.device=/tmp/bt/bt-vhost-bredrle:40 \ + virtio_uml.device=/tmp/bt/bt-vhost-bredrle:40 + Emulate a Bluetooth 5.2 controller over TCP:: $ btvirt -C 5.2 -t
emulator/main.c +25 -2
@@ -28,6 +28,7 @@#include "server.h" #include "vhci.h" #include "virtio.h" +#include "timetravel.h" #include "le.h" static void signal_callback (int signum,void *user_data)
@@ -52,6 +53,8 @@ static void usage(void)"\t-t[port=45550] Create a TCP server\n" "\t-V[path=/tmp] Create local vhost-user virtio\n" "\t server socket\n" +"\t--time[=path=/tmp] Create time travel calendar socket\n" +"\t for User Mode Linux guests\n" "\t-l[num] Number of local controllers\n" "\t-L Create LE only controller\n" "\t-U[num] Number of test LE controllers\n"
@@ -70,6 +73,7 @@ static const struct option main_options[] = { { "server", optional_argument, NULL, 's' }, { "tcp", optional_argument, NULL, 't' }, { "vhost", optional_argument, NULL, 'V' }, + { "time", optional_argument, NULL, 'I' }, { "local", optional_argument, NULL, 'l' }, { "le", no_argument, NULL, 'L' }, { "bredr", no_argument, NULL, 'B' },
@@ -131,6 +135,7 @@ int main(int argc, char *argv[])const char *server_path ="/tmp" ;uint16_t tcp_port =0 ;const char *vhost_path =NULL ; +const char *time_path =NULL ;bool serial_enabled = false;int letest_count =0 ;int vhci_count =0 ;
@@ -145,7 +150,7 @@ int main(int argc, char *argv[])for (;;) {int opt; - opt =getopt_long (argc, argv,"dSs::t::V::l::LBAC:U::vh" , + opt =getopt_long (argc, argv,"dSs::t::V::I::l::LBAC:U::vh" , main_options,NULL );if (opt <0 )break ;
@@ -168,6 +173,9 @@ int main(int argc, char *argv[])else tcp_port =45550 ;break ; +case 'I' : + time_path = optarg ? optarg :"/tmp" ; +break ;case 'V' : vhost_path = optarg ? optarg :"/tmp" ;break ;
@@ -217,13 +225,28 @@ int main(int argc, char *argv[]) type = bredrle_type;if (letest_count <1 && vhci_count <1 && !server_enabled && - !tcp_port && !serial_enabled && !vhost_path) { + !tcp_port && !serial_enabled && !vhost_path && + !time_path) {fprintf (stderr,"No emulator specified\n" );return EXIT_FAILURE ; }printf ("Bluetooth emulator ver %s\n" ,VERSION ); +/* Before any controller, so their timers use the simulated clock */ +if (time_path) { +char path[PATH_MAX ]; + +snprintf (path,sizeof (path),"%s/%s" , time_path,"bt-time" ); +if (!tt_open (path)) { +fprintf (stderr,"Failed to open time travel socket\n" ); +return EXIT_FAILURE ; + } + +if (debug_enabled) +tt_set_debug (server_debug,"time" ); + } +for (i =0 ; i < letest_count; i++) {struct bt_le *le;
emulator/timeout.c new file +102 -0
102 lines not on this page · raw message
emulator/timetravel.c new file +743 -0
743 lines not on this page · raw message
emulator/timetravel.h new file +55 -0
55 lines not on this page · raw message
emulator/virtio.c +33 -0
@@ -27,6 +27,7 @@#include "btdev.h" #include "vhost.h" +#include "timetravel.h" #include "virtio.h" /* Virtio device ID 40, see include/uapi/linux/virtio_bt.h in Linux */
@@ -160,6 +161,34 @@ static void queue_notify(struct vhost *vu, unsigned int index,flush_pending (client);break ; } + +/* The guest may wait for the calendar now */ +tt_schedule (); +} + +/* The guest acknowledges in-band notifications only after its calendar +* requests are answered, so keep serving the calendar meanwhile. +*/ +static void vhost_wait (struct vhost *vu,void *user_data) +{ +tt_process (); +} + +static void flush_client (void *data,void *user_data) +{ +struct client *client = data; + +vhost_process (client->vu); +} + +/* Process guest notifications sent before the guest waited, so time does +* not advance past them. +*/ +static void flush (void *user_data) +{ +struct vtio *vtio = user_data; + +queue_foreach (vtio->clients, flush_client,NULL ); }static void disconnect (struct vhost *vu,void *user_data)
@@ -182,6 +211,7 @@ static const struct vhost_ops vhost_ops = { .config_len = sizeof(config), .queue_notify = queue_notify, .disconnect = disconnect, + .wait = vhost_wait, };static void vu_debug (const char *str,void *user_data)
@@ -247,6 +277,7 @@ static void vtio_destroy(void *user_data) {struct vtio *vtio = user_data; +tt_remove_flush (flush, vtio);queue_destroy (vtio->clients, detach_client);close (vtio->fd);free (vtio);
@@ -292,6 +323,8 @@ struct vtio *vtio_open(enum btdev_type type, const char *path) vtio_destroy) < 0) goto fail; +tt_add_flush (flush, vtio); +return vtio; fail:
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 14/27 emulator: Add virtio console and time travel client to btvirt
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add --console, a vhost-user virtio console with named ports, each relayed to a Unix socket <path>-<name>, so a test driver outside the guest, such as pytest-bluezenv, can reach User Mode Linux guests the way it uses virtio-serial ports under QEMU. While the driver has no request outstanding on a sync port, time is paced to real time so guests do not run ahead of it.
Add --time-client, so the console relay takes part in an external time travel calendar, e.g. one simulating the controllers: it keeps a request one quantum (100 us) ahead and only injects input while the calendar lets it run, as guests may run ahead of the calendar's current time with FREE_UNTIL. Add --time-skew for btvirt's own calendar.
--- Makefile.tools | 2 + emulator/main.c | 69 ++++- emulator/ttclient.c | 313 ++++++++++++++++++++ emulator/ttclient.h | 50 ++++ emulator/vconsole.c | 701 ++++++++++++++++++++++++++++++++++++++++++++ emulator/vconsole.h | 26 ++ 6 files changed, 1158 insertions(+), 3 deletions(-) create mode 100644 emulator/ttclient.c create mode 100644 emulator/ttclient.h create mode 100644 emulator/vconsole.c create mode 100644 emulator/vconsole.h
Makefile.tools +2 -0
@@ -106,6 +106,8 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \ emulator/vhost.h emulator/vhost.c \ emulator/virtio.h emulator/virtio.c \ emulator/timetravel.h emulator/timetravel.c \ + emulator/vconsole.h emulator/vconsole.c \ + emulator/ttclient.h emulator/ttclient.c \ emulator/timeout.c emulator_btvirt_LDADD = lib/libbluetooth-internal.la src/libshared-mainloop.la
emulator/main.c +66 -3
123 lines not on this page · raw message
emulator/ttclient.c new file +313 -0
313 lines not on this page · raw message
emulator/ttclient.h new file +50 -0
50 lines not on this page · raw message
emulator/vconsole.c new file +701 -0
701 lines not on this page · raw message
emulator/vconsole.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2026 Intel Corporation +* +* +*/ + +#include <stdbool.h> + +struct vcon ; + +/* Serve a virtio console with named ports on the vhost-user socket path. +* Each port is relayed to a Unix socket "<path>-<name>" for a peer outside +* the guest. spec is "<path>:<name>[=sync]:<name>[=sync]...", a sync port +* carries requests from the peer: time is held while the peer has none +* outstanding on any sync port. +*/ +struct vcon *vcon_open (const char *spec); +void vcon_close (struct vcon *vcon); + +typedef void (*vcon_debug_func_t )(const char *str,void *user_data); +bool vcon_set_debug (struct vcon *vcon,vcon_debug_func_t callback, +void *user_data);
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 15/27 tools/test-runner: Add User Mode Linux support
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Accept a User Mode Linux kernel with -k, detected by its .uml.setup.init section, and run it directly with the host filesystem as root and test-runner as init, as is done with QEMU. Options given with -o are passed as kernel parameters, e.g. virtio_uml.device=<socket>:<id> for devices served from the host. The guest powers off at the end, as rebooting User Mode Linux starts it again, and mounts the coverage directory with hostfs instead of 9p.
Add -T, --time-travel, which starts btvirt --time as time travel calendar and joins the guest to it, so the same kernel runs with or without simulated time by adding -T. The calendar is stopped when the guest exits. The kernel needs CONFIG_UML_TIME_TRAVEL_SUPPORT, checked with its --help, which only lists time-travel=ext with it.
Wall clock time of the testers, all tests passing, same kernel version and machine, User Mode Linux with seccomp:
tester tests KVM UML UML -T
mgmt-tester 514 83.6 111.6 42.6 l2cap-tester 111 9.6 13.7 10.2 iso-tester 141 13.7 24.3 16.3 sco-tester 30 5.1 4.1 3.6 rfcomm-tester 11 3.6 2.0 2.6 smp-tester 8 4.1 1.5 1.5 ioctl-tester 28 4.1 2.6 3.1 userchan-tester 4 2.6 1.5 1.5 bnep-tester 1 2.6 1.0 1.0
--- doc/test-runner.rst | 46 ++++- tools/test-runner.c | 399 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 431 insertions(+), 14 deletions(-)
doc/test-runner.rst +44 -2
@@ -26,9 +26,12 @@ OPTIONS :-P/--pcie=<qemu_args>: Provide PCIe device :-q/--qemu=<path>: QEMU binary :-H/--qemu-host-cpu: Use host CPU (requires KVM support) -:-k/--kernel=<image>: Kernel image (bzImage) +:-k/--kernel=<image>: Kernel image (bzImage) or User Mode Linux binary :-F/--virtiofs[=<path>]: Path to virtiofsd, or no to disable virtio-fs -:-o/--option=<opt>: Additional argument passed to QEMU +:-T/--time-travel: Run a User Mode Linux kernel on simulated time, with + btvirt as time travel calendar +:-o/--option=<opt>: Additional argument passed to QEMU, or kernel + parameter with User Mode Linux :-h/--help: Show help options ARCHITECTURE
@@ -134,6 +137,28 @@ additional channels between the launcher and the guest are added, for example by **test-functional(1)**, which attaches its own virtio-serial ports and a writable shared directory this way. +User Mode Linux +--------------- + +When ``-k`` is a User Mode Linux (UML) binary, recognized by its +``.uml.setup.init`` section, test-runner runs it directly instead of QEMU, +with the host filesystem mounted as root through hostfs, and powers it off +at the end since rebooting UML starts it again. The kernel needs +``CONFIG_HOSTFS``, and ``CONFIG_VIRTIO_UML`` for virtio devices. + +``-o`` then adds kernel parameters, which is how UML attaches devices served +from the host, e.g. ``virtio_uml.device=<socket>:40`` for a virtio +Bluetooth controller, or joins an external simulated clock with +``time-travel=ext:<socket>``. See `virtio.rst <virtio.rst>`_. ``-u``, +``-U``, ``-P``, ``-q`` and ``-H`` need QEMU. + +With ``-T``, test-runner starts **btvirt(1)** ``--time`` as time travel +calendar and runs the guest on its simulated clock: time only advances when +the guest waits, so it skips idle time and timeouts take no real time, while +the guest sees the same timings on every run. This needs a kernel with +``CONFIG_UML_TIME_TRAVEL_SUPPORT``, which test-runner checks; without +``-T`` the same kernel runs on real time. + Kernel ======
@@ -385,3 +410,20 @@ exits. Note that unlike the other modes, PCIe-passthrough boots the guest with ACPI and APIC enabled, as these are required for device enumeration and MSI interrupt delivery. + +Running mgmt-tester under User Mode Linux +----------------------------------------- + +.. code-block:: + + $ make ARCH=um defconfig + $ scripts/kconfig/merge_config.sh -m .config <bluez>/doc/tester.config + $ make ARCH=um olddefconfig linux + $ tools/test-runner -k <linux>/linux -- tools/mgmt-tester + +On simulated time, with a kernel that also has +``CONFIG_UML_TIME_TRAVEL_SUPPORT=y``: + +.. code-block:: + + $ tools/test-runner -T -k <linux>/linux -- tools/mgmt-tester
tools/test-runner.c +387 -12
487 lines not on this page · raw message
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 16/27 doc: Add virtio documentation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Document the virtio Bluetooth device as implemented by the Linux driver and what a vhost-user backend has to provide to serve controllers to virtual machines, including User Mode Linux guests with time travel.
Explain how time travel works, with diagrams of the two clocks, the calendar protocol, lock-step scheduling, FREE_UNTIL and how a virtio notification ends it, and why busy-waiting is costly under it, and compare KVM and User Mode Linux with the wall clock time of the kernel testers with and without test-runner -T.
--- Makefile.am | 1 + doc/virtio.rst | 406 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 407 insertions(+) create mode 100644 doc/virtio.rst
Makefile.am +1 -0
@@ -495,6 +495,7 @@ EXTRA_DIST += doc/assigned-numbers.rst doc/supported-features.txt \ doc/test-coverage.txt \ doc/test-runner.rst \ doc/btvirt.rst \ + doc/virtio.rst \ doc/test-functional.rst \ doc/functional-testing.rst \ doc/functional-a2dp.rst \
doc/virtio.rst new file +406 -0
406 lines not on this page · raw message
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 17/27 shared/mainloop: Add idle callbacks
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add mainloop_add_idle(), whose callback runs once no file descriptor is ready, after everything pending was handled, as GLib's idle sources do. It is armed again with mainloop_modify_timeout() with 0 and removed with mainloop_remove_timeout(), its id being above the file descriptors.
A timeout of 0 cannot be used for this: mainloop_add_timeout() leaves it disarmed, and a short timer would run before pending events.
--- src/shared/mainloop-ell.c | 6 ++ src/shared/mainloop-glib.c | 6 ++ src/shared/mainloop.c | 156 ++++++++++++++++++++++++++++++++++++- src/shared/mainloop.h | 2 + 4 files changed, 169 insertions(+), 1 deletion(-)
src/shared/mainloop-ell.c +6 -0
@@ -100,6 +100,12 @@ int mainloop_add_timeout(unsigned int msec, mainloop_timeout_func callback,return -ENOSYS ; } +int mainloop_add_idle (mainloop_timeout_func callback,void *user_data, +mainloop_destroy_func destroy) +{ +return -EOPNOTSUPP ; +} +int mainloop_modify_timeout (int fd,unsigned int msec) {return -ENOSYS ;
src/shared/mainloop-glib.c +6 -0
@@ -94,6 +94,12 @@ int mainloop_add_timeout(unsigned int msec, mainloop_timeout_func callback,return -ENOSYS ; } +int mainloop_add_idle (mainloop_timeout_func callback,void *user_data, +mainloop_destroy_func destroy) +{ +return -EOPNOTSUPP ; +} +int mainloop_modify_timeout (int fd,unsigned int msec) {return -ENOSYS ;
src/shared/mainloop.c +155 -1
196 lines not on this page · raw message
src/shared/mainloop.h +2 -0
@@ -33,6 +33,8 @@ int mainloop_remove_fd(int fd);int mainloop_add_timeout (unsigned int msec,mainloop_timeout_func callback,void *user_data,mainloop_destroy_func destroy);int mainloop_modify_timeout (int fd,unsigned int msec); +int mainloop_add_idle (mainloop_timeout_func callback,void *user_data, +mainloop_destroy_func destroy);int mainloop_remove_timeout (int id); int mainloop_set_signal(sigset_t *mask, mainloop_signal_func callback,
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 18/27 shared/timeout: Run timeouts of 0 once idle
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
With the mainloop backend timeout_add() with 0 never runs, as a timer of 0 is disarmed, e.g. bt_hci's deferred event filter update. Use an idle callback for it instead.
With GLib it runs at default priority, before pending events, so run it at idle priority, as with the mainloop backend, which is what deferring to the next iteration means.
--- src/shared/timeout-glib.c | 10 +++++++++- src/shared/timeout-mainloop.c | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-)
src/shared/timeout-glib.c +9 -1
@@ -52,7 +52,15 @@ unsigned int timeout_add(unsigned int timeout, timeout_func_t func, data->destroy = destroy; data->user_data = user_data; - id =g_timeout_add_full (G_PRIORITY_DEFAULT , timeout, timeout_callback, +/* A timeout of 0 runs once nothing else is pending, as with the +* mainloop backend. +*/ +if (timeout) + id =g_timeout_add_full (G_PRIORITY_DEFAULT , timeout, + timeout_callback, data, + timeout_destroy); +else + id =g_idle_add_full (G_PRIORITY_DEFAULT_IDLE , timeout_callback, data, timeout_destroy);if (!id)g_free (data);
src/shared/timeout-mainloop.c +8 -1
@@ -54,7 +54,14 @@ unsigned int timeout_add(unsigned int timeout, timeout_func_t func, data->timeout = timeout; data->destroy = destroy; - data->id =mainloop_add_timeout (timeout, timeout_callback, data, +/* A timeout of 0 runs as soon as the mainloop gets to it, as with the +* other backends, while mainloop_add_timeout() leaves it disarmed. +*/ +if (timeout) + data->id =mainloop_add_timeout (timeout, timeout_callback, data, + timeout_destroy); +else + data->id =mainloop_add_idle (timeout_callback, data, timeout_destroy);if (data->id <0 ) {free (data);
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 19/27 shared/tester: Remove GLib dependency
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Use timeout_add() with 0 for the idle callbacks, struct queue for the tests, CLOCK_MONOTONIC for the execution times and getopt_long() for the options, and build it into libshared-mainloop as well, so testers can run on the mainloop instead of GLib.
GLib's main loop reads the clock for every source on every iteration, which under User Mode Linux is a system call through the host, about 6 us each: it was 78% of the system calls of mgmt-tester, 1.2 million in one run.
--- Makefile.am | 3 +- src/shared/tester.c | 250 +++++++++++++++++++++++++++----------------- 2 files changed, 156 insertions(+), 97 deletions(-)
Makefile.am +2 -1
@@ -272,7 +272,8 @@ src_libshared_mainloop_la_SOURCES = $(shared_sources) \ src/shared/timeout-mainloop.c \ src/shared/mainloop.h src/shared/mainloop.c \ src/shared/mainloop-notify.h \ - src/shared/mainloop-notify.c + src/shared/mainloop-notify.c \ + src/shared/tester.c src_libshared_mainloop_la_LDFLAGS = $(AM_LDFLAGS) src_libshared_mainloop_la_CFLAGS = $(AM_CFLAGS)
src/shared/tester.c +154 -96
538 lines not on this page · raw message
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 20/27 emulator/hciemu: Remove GLib dependency
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Use struct io for the sockets between the emulated controllers and hosts, and timeout_add() with 0 for the deferred host start and the flushing of client events, so hciemu works with any mainloop backend.
--- emulator/hciemu.c | 122 +++++++++++++++++----------------------------- 1 file changed, 45 insertions(+), 77 deletions(-)
emulator/hciemu.c +45 -77
@@ -24,8 +24,6 @@#include <sys/socket.h> #include <sys/ioctl.h> -#include <glib.h> -#include "bluetooth/bluetooth.h" #include "bluetooth/hci.h"
@@ -35,14 +33,16 @@#include "emulator/bthost.h" #include "src/shared/util.h" #include "src/shared/queue.h" +#include "src/shared/io.h" +#include "src/shared/timeout.h" #include "emulator/hciemu.h" struct hciemu_client {struct bthost *host;struct btdev *dev; -guint start_source; -guint host_source; -guint source; +unsigned int start_source; +struct io *host_io; +struct io *io;int sock[2 ]; };
@@ -124,11 +124,11 @@ static void client_command_callback(uint16_t opcode,static void writev_callback (const struct iovec *iov,int iovlen,void *user_data) { -GIOChannel *channel = user_data; +struct io *io = user_data;ssize_t written;int fd; - fd =g_io_channel_unix_get_fd (channel); + fd =io_get_fd (io); written =writev (fd, iov, iovlen);if (written <0 ) {
@@ -162,99 +162,69 @@ static void writev_callback(const struct iovec *iov, int iovlen, } } -static gboolean receive_bthost (GIOChannel *channel,GIOCondition condition, -gpointer user_data) +static bool receive_bthost (struct io *io,void *user_data) {struct bthost *bthost = user_data;unsigned char buf[4096 ];ssize_t len; -int fd; -if (condition & (G_IO_NVAL |G_IO_ERR |G_IO_HUP )) -return FALSE; - - fd =g_io_channel_unix_get_fd (channel); - - len =read (fd, buf,sizeof (buf)); + len =read (io_get_fd (io), buf,sizeof (buf));if (len <0 ) -return FALSE; +return false;bthost_receive_h4 (bthost, buf, len); -return TRUE; +return true; } -static guint create_source_bthost (int fd,struct bthost *bthost) +static struct io *create_io_bthost (int fd,struct bthost *bthost) { -GIOChannel *channel; -guint source; +struct io *io; - channel =g_io_channel_unix_new (fd); + io =io_new (fd); +io_set_close_on_destroy (io, true); -g_io_channel_set_close_on_unref (channel, TRUE); -g_io_channel_set_encoding (channel,NULL ,NULL ); -g_io_channel_set_buffered (channel, FALSE); +bthost_set_send_handler (bthost, writev_callback, io); -bthost_set_send_handler (bthost, writev_callback, channel); +io_set_read_handler (io, receive_bthost, bthost,NULL ); - source =g_io_add_watch_full (channel,G_PRIORITY_DEFAULT , -G_IO_IN |G_IO_HUP |G_IO_ERR |G_IO_NVAL , - receive_bthost, bthost,NULL ); - -g_io_channel_unref (channel); - -return source; +return io; } -static gboolean receive_btdev (GIOChannel *channel,GIOCondition condition, -gpointer user_data) +static bool receive_btdev (struct io *io,void *user_data) {struct btdev *btdev = user_data;unsigned char buf[4096 ];ssize_t len; -int fd; -if (condition & (G_IO_NVAL |G_IO_ERR |G_IO_HUP )) -return FALSE; - - fd =g_io_channel_unix_get_fd (channel); - - len =read (fd, buf,sizeof (buf)); + len =read (io_get_fd (io), buf,sizeof (buf));if (len <0 ) {if (errno ==EAGAIN || errno ==EINTR ) -return TRUE; +return true; -return FALSE; +return false; }if (len <1 ) -return FALSE; +return false;btdev_receive_h4 (btdev, buf, len); -return TRUE; +return true; } -static guint create_source_btdev (int fd,struct btdev *btdev) +static struct io *create_io_btdev (int fd,struct btdev *btdev) { -GIOChannel *channel; -guint source; +struct io *io; - channel =g_io_channel_unix_new (fd); + io =io_new (fd); +io_set_close_on_destroy (io, true); -g_io_channel_set_close_on_unref (channel, TRUE); -g_io_channel_set_encoding (channel,NULL ,NULL ); -g_io_channel_set_buffered (channel, FALSE); +btdev_set_send_handler (btdev, writev_callback, io); -btdev_set_send_handler (btdev, writev_callback, channel); +io_set_read_handler (io, receive_btdev, btdev,NULL ); - source =g_io_add_watch_full (channel,G_PRIORITY_DEFAULT , -G_IO_IN |G_IO_HUP |G_IO_ERR |G_IO_NVAL , - receive_btdev, btdev,NULL ); - -g_io_channel_unref (channel); - -return source; +return io; }static bool create_vhci (struct hciemu *hciemu)
@@ -318,7 +288,7 @@ struct bthost *hciemu_client_get_host(struct hciemu *hciemu)return hciemu_client_host (client); } -static gboolean start_host (gpointer user_data) +static bool start_host (void *user_data) {struct hciemu_client *client = user_data;
@@ -326,18 +296,17 @@ static gboolean start_host(gpointer user_data)bthost_start (client->host); -return FALSE; +return false; }static void hciemu_client_destroy (void *data) {struct hciemu_client *client = data; -if (client->start_source) -g_source_remove (client->start_source); +timeout_remove (client->start_source); -g_source_remove (client->host_source); -g_source_remove (client->source); +io_destroy (client->host_io); +io_destroy (client->io);bthost_destroy (client->host);btdev_destroy (client->dev);
@@ -385,9 +354,9 @@ static struct hciemu_client *hciemu_client_new(struct hciemu *hciemu, client->sock[0 ] = sv[0 ]; client->sock[1 ] = sv[1 ]; - client->source =create_source_btdev (sv[0 ], client->dev); - client->host_source =create_source_bthost (sv[1 ], client->host); - client->start_source =g_idle_add (start_host, client); + client->io =create_io_btdev (sv[0 ], client->dev); + client->host_io =create_io_bthost (sv[1 ], client->host); + client->start_source =timeout_add (0 , start_host, client,NULL );btdev_get_mtu (client->dev, &acl_mtu,NULL , &iso_mtu);bthost_set_acl_mtu (client->host, acl_mtu);
@@ -512,8 +481,7 @@ void hciemu_unref(struct hciemu *hciemu)queue_destroy (hciemu->post_command_hooks, destroy_command_hook);queue_destroy (hciemu->clients, hciemu_client_destroy); -if (hciemu->flush_id) -g_source_remove (hciemu->flush_id); +timeout_remove (hciemu->flush_id);vhci_close (hciemu->vhci);
@@ -853,7 +821,7 @@ static bool client_is_pending(const void *data, const void *match_data)struct hciemu_client *client = (struct hciemu_client *)data;int used, i; -if (!client->source || !client->host_source) +if (!client->io || !client->host_io)return false;for (i =0 ; i <2 ; ++i) {
@@ -866,12 +834,12 @@ static bool client_is_pending(const void *data, const void *match_data)return false; } -static gboolean flush_client_events (gpointer user_data) +static bool flush_client_events (void *user_data) {struct hciemu *hciemu = user_data;if (queue_find (hciemu->clients, client_is_pending,NULL )) -return TRUE; +return true; hciemu->flush_id =0 ;
@@ -879,7 +847,7 @@ static gboolean flush_client_events(gpointer user_data)if (hciemu->vhci)vhci_pause_input (hciemu->vhci, false); -return FALSE; +return false; }void hciemu_flush_client_events (struct hciemu *hciemu)
@@ -889,5 +857,5 @@ void hciemu_flush_client_events(struct hciemu *hciemu)util_debug (hciemu->debug_callback, hciemu->debug_data,"vhci: pause" );vhci_pause_input (hciemu->vhci, true); - hciemu->flush_id =g_idle_add (flush_client_events, hciemu); + hciemu->flush_id =timeout_add (0 , flush_client_events, hciemu,NULL ); }
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 21/27 tools: Build testers that do not need GLib with the mainloop
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Remove the remaining GLib uses of mgmt-tester, smp-tester, bnep-tester, ioctl-tester, userchan-tester, mesh-tester and hci-tester, unused watch ids and g_assert() mostly, and link them with libshared-mainloop, which does not read the clock on every iteration.
mgmt-tester under User Mode Linux with test-runner -T:
GLib 42.6 s
mainloop 20.3 s
--- Makefile.tools | 14 +++++++------- tools/bnep-tester.c | 7 ------- tools/ioctl-tester.c | 6 ++---- tools/mesh-tester.c | 1 - tools/mgmt-tester.c | 3 +-- tools/smp-tester.c | 30 +++++++++++++----------------- tools/tester.h | 8 ++++---- tools/userchan-tester.c | 1 - 8 files changed, 27 insertions(+), 43 deletions(-)
Makefile.tools +7 -7
@@ -136,7 +136,7 @@ tools_mgmt_tester_SOURCES = tools/mgmt-tester.c monitor/bt.h \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_mgmt_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_mesh_tester_SOURCES = tools/mesh-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
@@ -145,7 +145,7 @@ tools_mesh_tester_SOURCES = tools/mesh-tester.c monitor/bt.h \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_mesh_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_l2cap_tester_SOURCES = tools/l2cap-tester.c tools/tester.h monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
@@ -172,7 +172,7 @@ tools_bnep_tester_SOURCES = tools/bnep-tester.c monitor/bt.h \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_bnep_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_smp_tester_SOURCES = tools/smp-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
@@ -181,7 +181,7 @@ tools_smp_tester_SOURCES = tools/smp-tester.c monitor/bt.h \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_smp_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_gap_tester_SOURCES = tools/gap-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
@@ -204,7 +204,7 @@ tools_sco_tester_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la $(GLIB_LIBS) tools_hci_tester_SOURCES = tools/hci-tester.c monitor/bt.h -tools_hci_tester_LDADD = src/libshared-glib.la $(GLIB_LIBS) +tools_hci_tester_LDADD = src/libshared-mainloop.la tools_userchan_tester_SOURCES = tools/userchan-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
@@ -213,7 +213,7 @@ tools_userchan_tester_SOURCES = tools/userchan-tester.c monitor/bt.h \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_userchan_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_iso_tester_SOURCES = tools/iso-tester.c tools/tester.h monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
@@ -231,7 +231,7 @@ tools_ioctl_tester_SOURCES = tools/ioctl-tester.c monitor/bt.h \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_ioctl_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_6lowpan_tester_SOURCES = tools/6lowpan-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
tools/bnep-tester.c +0 -7
@@ -18,7 +18,6 @@#include <errno.h> #include <stdbool.h> -#include <glib.h> #include "bluetooth/bluetooth.h" #include "bluetooth/bnep.h"
@@ -37,7 +36,6 @@ struct test_data {struct hciemu *hciemu;enum hciemu_type hciemu_type;const void *test_data; -unsigned int io_id;uint16_t conn_handle; };
@@ -198,10 +196,6 @@ static void test_post_teardown(const void *test_data) {struct test_data *data =tester_get_data (); -if (data->io_id >0 ) { -g_source_remove (data->io_id); - data->io_id =0 ; - }hciemu_unref (data->hciemu); data->hciemu =NULL ;
@@ -288,7 +282,6 @@ static void test_basic(const void *test_data)break ; \ user->hciemu_type =HCIEMU_TYPE_BREDR ; \ user->test_data = data; \ - user->io_id =0 ; \tester_add_full (name, data, \ test_pre_setup, setup, func,NULL , \ test_post_teardown,2 , user, test_data_free); \
tools/ioctl-tester.c +2 -4
@@ -20,7 +20,7 @@#include <sys/ioctl.h> #include <sys/socket.h> -#include <glib.h> +#include <assert.h> #include "bluetooth/bluetooth.h" #include "bluetooth/mgmt.h"
@@ -50,8 +50,6 @@ struct test_data {uint16_t handle;uint16_t acl_handle; -GIOChannel *io; -unsigned int io_id[2 ];int step;bool reconnect;
@@ -782,7 +780,7 @@ static void test_ioctl_common(const void *test_data) } }else {if (ioctl_data->param_len) { -g_assert (req_len >= ioctl_data->param_len); +assert (req_len >= ioctl_data->param_len); req_len = ioctl_data->param_len; }memcpy (req, ioctl_data->param, req_len);
tools/mesh-tester.c +0 -1
@@ -21,7 +21,6 @@#include <errno.h> #include <unistd.h> -#include <glib.h> #include "bluetooth/bluetooth.h" #include "bluetooth/hci.h"
tools/mgmt-tester.c +1 -2
@@ -22,7 +22,6 @@#include <errno.h> #include <unistd.h> -#include <glib.h> #include "bluetooth/bluetooth.h" #include "bluetooth/hci.h"
@@ -12599,7 +12598,7 @@ static void test_remove_device(const void *test_data)static bool hook_delay_cmd (const void *data,uint16_t len,void *user_data) {tester_print ("Delaying emulator response..." ); -g_usleep (250000 ); +usleep (250000 );tester_print ("Delaying emulator response... Done." );return true; }
tools/smp-tester.c +13 -17
@@ -18,7 +18,7 @@#include <stdbool.h> #include <sys/socket.h> -#include <glib.h> +#include <assert.h> #include "bluetooth/bluetooth.h" #include "bluetooth/hci.h"
@@ -31,6 +31,7 @@#include "src/shared/crypto.h" #include "src/shared/ecc.h" #include "src/shared/tester.h" +#include "src/shared/util.h" #include "src/shared/mgmt.h" #define SMP_CID 0x0006
@@ -41,7 +42,6 @@ struct test_data {uint16_t mgmt_index;struct hciemu *hciemu;enum hciemu_type hciemu_type; -unsigned int io_id;uint8_t ia[6 ];uint8_t ia_type;uint8_t ra[6 ];
@@ -229,10 +229,6 @@ static void test_post_teardown(const void *test_data) {struct test_data *data =tester_get_data (); -if (data->io_id >0 ) { -g_source_remove (data->io_id); - data->io_id =0 ; - }if (data->crypto) {bt_crypto_unref (data->crypto);
@@ -293,7 +289,7 @@ static const struct smp_req_rsp nval_req_1[] = {static const struct smp_data smp_server_nval_req_1_test = { .req = nval_req_1, - .req_count =G_N_ELEMENTS (nval_req_1), + .req_count =ARRAY_SIZE (nval_req_1), };static const uint8_t smp_nval_req_2[7 ] = {0x01 };
@@ -306,7 +302,7 @@ static const struct smp_req_rsp srv_nval_req_1[] = {static const struct smp_data smp_server_nval_req_2_test = { .req = srv_nval_req_1, - .req_count =G_N_ELEMENTS (srv_nval_req_1), + .req_count =ARRAY_SIZE (srv_nval_req_1), };static const uint8_t smp_nval_req_3[] = {0x01 ,0xff };
@@ -319,7 +315,7 @@ static const struct smp_req_rsp srv_nval_req_2[] = {static const struct smp_data smp_server_nval_req_3_test = { .req = srv_nval_req_2, - .req_count =G_N_ELEMENTS (srv_nval_req_2), + .req_count =ARRAY_SIZE (srv_nval_req_2), };static const uint8_t smp_basic_req_1[] = {0x01 ,/* Pairing Request */
@@ -353,7 +349,7 @@ static const struct smp_req_rsp srv_basic_req_1[] = {static const struct smp_data smp_server_basic_req_1_test = { .req = srv_basic_req_1, - .req_count =G_N_ELEMENTS (srv_basic_req_1), + .req_count =ARRAY_SIZE (srv_basic_req_1), };static const struct smp_req_rsp cli_basic_req_1[] = {
@@ -367,7 +363,7 @@ static const struct smp_req_rsp cli_basic_req_1[] = {static const struct smp_data smp_client_basic_req_1_test = { .req = cli_basic_req_1, - .req_count =G_N_ELEMENTS (cli_basic_req_1), + .req_count =ARRAY_SIZE (cli_basic_req_1), };static const uint8_t smp_basic_req_2[] = {0x01 ,/* Pairing Request */
@@ -390,7 +386,7 @@ static const struct smp_req_rsp cli_basic_req_2[] = {static const struct smp_data smp_client_basic_req_2_test = { .req = cli_basic_req_2, - .req_count =G_N_ELEMENTS (cli_basic_req_1), + .req_count =ARRAY_SIZE (cli_basic_req_1), .mitm = true, };
@@ -429,7 +425,7 @@ static const struct smp_req_rsp cli_sc_req_1[] = {static const struct smp_data smp_client_sc_req_1_test = { .req = cli_sc_req_1, - .req_count =G_N_ELEMENTS (cli_sc_req_1), + .req_count =ARRAY_SIZE (cli_sc_req_1), .sc = true, };
@@ -455,7 +451,7 @@ static const struct smp_req_rsp cli_sc_req_2[] = {static const struct smp_data smp_client_sc_req_2_test = { .req = cli_sc_req_2, - .req_count =G_N_ELEMENTS (cli_sc_req_2), + .req_count =ARRAY_SIZE (cli_sc_req_2), .sc = true, };
@@ -549,16 +545,16 @@ static const void *get_pdu(const uint8_t *pdu, size_t len)uint8_t opcode = pdu[0 ];static uint8_t buf[65 ]; -g_assert (len >0 ); +assert (len >0 );switch (opcode) {case 0x01 :/* Pairing Request */ -g_assert (len <=sizeof (data->preq)); +assert (len <=sizeof (data->preq));memset (data->preq,0 ,sizeof (data->preq));memcpy (data->preq, pdu, len);break ;case 0x02 :/* Pairing Response */ -g_assert (len <=sizeof (data->prsp)); +assert (len <=sizeof (data->prsp));memset (data->prsp,0 ,sizeof (data->prsp));memcpy (data->prsp, pdu, len);break ;
tools/tester.h +4 -4
@@ -20,7 +20,7 @@#include <net/if.h> #include <sys/ioctl.h> -#include <glib.h> +#include <assert.h> #define SEC_NSEC (_t) ((_t) * 1000000000LL)#define TS_NSEC (_ts) (SEC_NSEC((_ts)->tv_sec) + (_ts)->tv_nsec)
@@ -65,21 +65,21 @@ static inline int tx_tstamp_expect(struct tx_tstamp_data *data, size_t len) data->sent += len -1 ;if (data->so_timestamping &SOF_TIMESTAMPING_TX_SCHED ) { -g_assert (pos <ARRAY_SIZE (data->expect)); +assert (pos <ARRAY_SIZE (data->expect)); data->expect[pos].type =SCM_TSTAMP_SCHED ; data->expect[pos].id = data->sent; pos++; }if (data->so_timestamping &SOF_TIMESTAMPING_TX_SOFTWARE ) { -g_assert (pos <ARRAY_SIZE (data->expect)); +assert (pos <ARRAY_SIZE (data->expect)); data->expect[pos].type =SCM_TSTAMP_SND ; data->expect[pos].id = data->sent; pos++; }if (data->so_timestamping &SOF_TIMESTAMPING_TX_COMPLETION ) { -g_assert (pos <ARRAY_SIZE (data->expect)); +assert (pos <ARRAY_SIZE (data->expect)); data->expect[pos].type =SCM_TSTAMP_COMPLETION ; data->expect[pos].id = data->sent; pos++;
tools/userchan-tester.c +0 -1
@@ -18,7 +18,6 @@#include <errno.h> #include <stdbool.h> -#include <glib.h> #include "bluetooth/bluetooth.h" #include "bluetooth/hci.h"
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 22/27 shared/mainloop: Add deferred callbacks
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add mainloop_add_deferred(), whose callback runs once the descriptors ready at the time were handled, before the idle callbacks, like a GLib source of default priority dispatched after those added before it.
--- src/shared/mainloop-ell.c | 6 ++++++ src/shared/mainloop-glib.c | 6 ++++++ src/shared/mainloop.c | 41 ++++++++++++++++++++++++++++---------- src/shared/mainloop.h | 2 ++ 4 files changed, 45 insertions(+), 10 deletions(-)
src/shared/mainloop-ell.c +6 -0
@@ -106,6 +106,12 @@ int mainloop_add_idle(mainloop_timeout_func callback, void *user_data,return -EOPNOTSUPP ; } +int mainloop_add_deferred (mainloop_timeout_func callback,void *user_data, +mainloop_destroy_func destroy) +{ +return -EOPNOTSUPP ; +} +int mainloop_modify_timeout (int fd,unsigned int msec) {return -ENOSYS ;
src/shared/mainloop-glib.c +6 -0
@@ -100,6 +100,12 @@ int mainloop_add_idle(mainloop_timeout_func callback, void *user_data,return -EOPNOTSUPP ; } +int mainloop_add_deferred (mainloop_timeout_func callback,void *user_data, +mainloop_destroy_func destroy) +{ +return -EOPNOTSUPP ; +} +int mainloop_modify_timeout (int fd,unsigned int msec) {return -ENOSYS ;
src/shared/mainloop.c +31 -10
94 lines not on this page · raw message
src/shared/mainloop.h +2 -0
@@ -35,6 +35,8 @@ int mainloop_add_timeout(unsigned int msec, mainloop_timeout_func callback,int mainloop_modify_timeout (int fd,unsigned int msec);int mainloop_add_idle (mainloop_timeout_func callback,void *user_data,mainloop_destroy_func destroy); +int mainloop_add_deferred (mainloop_timeout_func callback,void *user_data, +mainloop_destroy_func destroy);int mainloop_remove_timeout (int id); int mainloop_set_signal(sigset_t *mask, mainloop_signal_func callback,
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 23/27 tools: Add socket watches for testers without GLib
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add tester_io, watches on file descriptors on top of the mainloop for the testers using GIOChannel watches, keeping their semantics: several watches per descriptor holding a reference to it, the descriptor closed with the last reference if requested, tester_io_close() reported as TESTER_IO_NVAL, and the watches called after the other ready descriptors in the order they were added, which the testers rely on to see the events of the emulated controllers first.
Unlike GLib, a hang up nobody watches for drops the watches instead of waking up the mainloop for good, and an error nobody watches for, e.g. a connection attempt timing out, is polled again after a millisecond, which also lets time advance under User Mode Linux time travel.
--- tools/tester-io.c | 400 ++++++++++++++++++++++++++++++++++++++++++++++ tools/tester-io.h | 52 ++++++ 2 files changed, 452 insertions(+) create mode 100644 tools/tester-io.c create mode 100644 tools/tester-io.h
tools/tester-io.c new file +400 -0
@@ -0,0 +1,400 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2026 Intel Corporation +* +* +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdlib.h> +#include <unistd.h> + +#include "src/shared/util.h" +#include "src/shared/queue.h" +#include "src/shared/mainloop.h" +#include "src/shared/timeout.h" +#include "tools/tester-io.h" + +/* Watch ids have the high bit set, so tester_remove_source() can tell them +* from timeout ids. +*/ +#define WATCH_ID_BIT 0x80000000u + +struct tester_io { +int ref_count; +int fd; +bool close_on_unref; +bool registered; +bool dispatching; +bool scheduled; +unsigned int backoff_id; +uint32_t pending; +struct queue *watches; +}; + +struct watch { +unsigned int id; +struct tester_io *io; +uint32_t cond; +tester_io_func_t func; +void *user_data; +bool removed; +}; + +/* The tester_io with watches, in the order of their first watch */ +static struct queue *ios; +static int dispatch_id; +static unsigned int next_id; +static unsigned int current_id; + +struct tester_io *tester_io_new (int fd) +{ +struct tester_io *io; + + io = new0(struct tester_io, 1); + io->ref_count =1 ; + io->fd = fd; + io->watches =queue_new (); + +return io; +} + +struct tester_io *tester_io_ref (struct tester_io *io) +{ +if (io) + io->ref_count++; + +return io; +} + +void tester_io_unref (struct tester_io *io) +{ +if (!io || --io->ref_count >0 ) +return ; + +queue_destroy (io->watches, free); + +if (io->close_on_unref && io->fd >=0 ) +close (io->fd); + +free (io); +} + +int tester_io_get_fd (struct tester_io *io) +{ +return io ? io->fd :-1 ; +} + +void tester_io_set_close_on_unref (struct tester_io *io,bool close_on_unref) +{ +if (io) + io->close_on_unref = close_on_unref; +} + +static void collect_cond (void *data,void *user_data) +{ +struct watch *watch = data; +uint32_t *events = user_data; + +if (!watch->removed) + *events |= watch->cond; +} + +static void io_event (int fd,uint32_t events,void *user_data); + +static bool match_registered_fd (const void *data,const void *match_data) +{ +const struct tester_io *io = data; + +return io->registered && io->fd ==PTR_TO_INT (match_data); +} + +static void unregister (struct tester_io *io) +{ +if (!io->registered) +return ; + + io->registered = false; +mainloop_remove_fd (io->fd); +} + +/* Poll for what the watches want, except while their callbacks are +* pending, and stop polling without any. +*/ +static void update_events (struct tester_io *io) +{ +uint32_t events =0 ; + +queue_foreach (io->watches, collect_cond, &events); + events &= ~TESTER_IO_NVAL ; + +if (queue_isempty (io->watches) || io->scheduled || io->backoff_id || + io->fd <0 ) { +unregister (io); +return ; + } + +if (!io->registered) { +if (mainloop_add_fd (io->fd, events, io_event, io,NULL ) <0 ) { +struct tester_io *stale; + +/* The descriptor of another io was closed directly, +* and the same number was given to this one. +*/ + stale =queue_find (ios, match_registered_fd, +INT_TO_PTR (io->fd)); +if (!stale || stale == io) +return ; + +unregister (stale); + +if (mainloop_add_fd (io->fd, events, io_event, io, +NULL ) <0 ) +return ; + } + + io->registered = true; +return ; + } + +mainloop_modify_fd (io->fd, events); +} + +static bool match_removed (const void *data,const void *match_data) +{ +const struct watch *watch = data; + +return watch->removed; +} + +/* Drops the removed watches and their references to io. The caller holds +* a reference of its own, so io is freed by the caller's unref at most. +*/ +static void cleanup (struct tester_io *io) +{ +struct watch *watch; + +while ((watch =queue_remove_if (io->watches, match_removed,NULL ))) { +free (watch); + io->ref_count--; + } + +if (queue_isempty (io->watches)) { + io->scheduled = false; + io->pending =0 ; +timeout_remove (io->backoff_id); + io->backoff_id =0 ; +queue_remove (ios, io); + } + +update_events (io); +} + +static bool backoff_done (void *user_data) +{ +struct tester_io *io = user_data; + + io->backoff_id =0 ; +update_events (io); + +return false; +} + +static void remove_watch (void *data,void *user_data) +{ +struct watch *watch = data; + + watch->removed = true; +} + +static void dispatch (struct tester_io *io) +{ +const struct queue_entry *entry; +unsigned int last = next_id; +uint32_t events = io->pending; +uint32_t wanted =0 ; + + io->scheduled = false; + io->pending =0 ; + +tester_io_ref (io); + io->dispatching = true; + +queue_foreach (io->watches, collect_cond, &wanted); + +/* Watches added by a callback wait for the next event */ +for (entry =queue_get_entries (io->watches); entry; + entry = entry->next) { +struct watch *watch = entry->data; + +if (watch->removed || (watch->id & ~WATCH_ID_BIT ) > last || + !(events & watch->cond)) +continue ; + + current_id = watch->id; + +if (!watch->func (io, events & watch->cond, watch->user_data)) + watch->removed = true; + + current_id =0 ; + } + +/* A hang up nobody watches for would be reported over and over, +* waking up the mainloop for good: drop the watches instead, as with +* a closed descriptor. An error may be transient, e.g. a connection +* attempt timing out, so keep watching after one, as GLib does. +*/ +if (events & (TESTER_IO_HUP |TESTER_IO_NVAL ) & ~wanted) +queue_foreach (io->watches, remove_watch,NULL ); +else if (events &TESTER_IO_ERR & ~wanted && !io->backoff_id) +/* Polling would report the error right away again, so look +* again a bit later, which lets simulated time advance too. +*/ + io->backoff_id =timeout_add (1 , backoff_done, io,NULL ); + +if (io->fd <0 ) +queue_foreach (io->watches, remove_watch,NULL ); + + io->dispatching = false; +cleanup (io); +tester_io_unref (io); +} + +static bool match_scheduled (const void *data,const void *match_data) +{ +const struct tester_io *io = data; + +return io->scheduled; +} + +static void dispatch_all (int id,void *user_data) +{ +struct tester_io *io; + +mainloop_remove_timeout (id); + dispatch_id =0 ; + +while ((io =queue_find (ios, match_scheduled,NULL ))) +dispatch (io); +} + +/* Like GLib, which dispatches the ready sources in the order they were +* added, call the watches after the other descriptors ready at the same +* time, e.g. those of the emulated controllers, were handled, in the order +* of the first watch of each descriptor, and before idle callbacks: stop +* polling and dispatch once the ready descriptors were handled. +*/ +static void schedule_dispatch (struct tester_io *io,uint32_t events) +{ + io->pending |= events; + +if (io->scheduled) +return ; + + io->scheduled = true; +unregister (io); + +if (!dispatch_id) + dispatch_id =mainloop_add_deferred (dispatch_all,NULL ,NULL ); +} + +static void io_event (int fd,uint32_t events,void *user_data) +{ +struct tester_io *io = user_data; + +schedule_dispatch (io, events); +} + +unsigned int tester_io_add_watch (struct tester_io *io,uint32_t cond, +tester_io_func_t func,void *user_data) +{ +struct watch *watch; + +if (!io || !func) +return 0 ; + +if (!ios) + ios =queue_new (); + + watch = new0(struct watch, 1); + watch->id = ++next_id |WATCH_ID_BIT ; + watch->io =tester_io_ref (io); + watch->cond = cond; + watch->func = func; + watch->user_data = user_data; + +if (queue_isempty (io->watches)) +queue_push_tail (ios, io); + +queue_push_tail (io->watches, watch); +update_events (io); + +return watch->id; +} + +void tester_io_close (struct tester_io *io) +{ +if (!io || io->fd <0 ) +return ; + +unregister (io); +close (io->fd); + io->fd =-1 ; + +if (!queue_isempty (io->watches)) +schedule_dispatch (io,TESTER_IO_NVAL ); +} + +static bool match_watch_id (const void *data,const void *match_data) +{ +const struct watch *watch = data; + +return watch->id ==PTR_TO_UINT (match_data) && !watch->removed; +} + +static bool match_io_watch (const void *data,const void *match_data) +{ +const struct tester_io *io = data; + +return queue_find (io->watches, match_watch_id, match_data); +} + +unsigned int tester_current_source (void ) +{ +return current_id; +} + +void tester_remove_source (unsigned int id) +{ +struct tester_io *io; +struct watch *watch; + +if (!id) +return ; + +if (!(id &WATCH_ID_BIT )) { +timeout_remove (id); +return ; + } + + io =queue_find (ios, match_io_watch,UINT_TO_PTR (id)); +if (!io) +return ; + + watch =queue_find (io->watches, match_watch_id,UINT_TO_PTR (id)); + watch->removed = true; + +/* Cleaned up once the callbacks are done */ +if (io->dispatching) +return ; + +tester_io_ref (io); +cleanup (io); +tester_io_unref (io); +}
tools/tester-io.h new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 24/27 tools: Run sco-tester, rfcomm-tester and 6lowpan-tester on the mainloop
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Replace their GIOChannel watches with tester_io and GLib timeouts with timeout_add(), and link them with libshared-mainloop. rfcomm-tester closes its socket with tester_io_close(), as the mainloop cannot tell that a descriptor was closed.
--- Makefile.tools | 15 +++--- tools/6lowpan-tester.c | 51 ++++++++++--------- tools/rfcomm-tester.c | 105 ++++++++++++++++++++------------------- tools/sco-tester.c | 108 +++++++++++++++++++++-------------------- 4 files changed, 148 insertions(+), 131 deletions(-)
Makefile.tools +9 -6
@@ -156,14 +156,15 @@ tools_l2cap_tester_SOURCES = tools/l2cap-tester.c tools/tester.h monitor/bt.h \ tools_l2cap_tester_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la $(GLIB_LIBS) -tools_rfcomm_tester_SOURCES = tools/rfcomm-tester.c monitor/bt.h \ +tools_rfcomm_tester_SOURCES = tools/rfcomm-tester.c \ + tools/tester-io.h tools/tester-io.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \ emulator/vhci.h emulator/vhci.c \ emulator/btdev.h emulator/btdev.c \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_rfcomm_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_bnep_tester_SOURCES = tools/bnep-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
@@ -194,14 +195,15 @@ tools_gap_tester_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la \ $(GLIB_LIBS) $(DBUS_LIBS) -tools_sco_tester_SOURCES = tools/sco-tester.c tools/tester.h monitor/bt.h \ +tools_sco_tester_SOURCES = tools/sco-tester.c \ + tools/tester-io.h tools/tester-io.c tools/tester.h monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \ emulator/vhci.h emulator/vhci.c \ emulator/btdev.h emulator/btdev.c \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_sco_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_hci_tester_SOURCES = tools/hci-tester.c monitor/bt.h tools_hci_tester_LDADD = src/libshared-mainloop.la
@@ -233,14 +235,15 @@ tools_ioctl_tester_SOURCES = tools/ioctl-tester.c monitor/bt.h \ tools_ioctl_tester_LDADD = lib/libbluetooth-internal.la \ src/libshared-mainloop.la -tools_6lowpan_tester_SOURCES = tools/6lowpan-tester.c monitor/bt.h \ +tools_6lowpan_tester_SOURCES = tools/6lowpan-tester.c \ + tools/tester-io.h tools/tester-io.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \ emulator/vhci.h emulator/vhci.c \ emulator/btdev.h emulator/btdev.c \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_6lowpan_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la endif if TOOLS
tools/6lowpan-tester.c +27 -24
137 lines not on this page · raw message
tools/rfcomm-tester.c +56 -49
259 lines not on this page · raw message
tools/sco-tester.c +56 -52
307 lines not on this page · raw message
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 25/27 tools: Run l2cap-tester and iso-tester on the mainloop
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Replace their GIOChannel watches with tester_io and GLib timeouts with timeout_add(), and link them with libshared-mainloop, which unlike GLib does not read the clock on every iteration.
Under User Mode Linux with test-runner -T:
l2cap-tester 10.2 s -> 5.6 s
iso-tester 16.3 s -> 7.6 s
--- Makefile.tools | 10 +- tools/iso-tester.c | 337 ++++++++++++++++++++++--------------------- tools/l2cap-tester.c | 333 ++++++++++++++++++++++-------------------- 3 files changed, 355 insertions(+), 325 deletions(-)
Makefile.tools +6 -4
@@ -147,14 +147,15 @@ tools_mesh_tester_SOURCES = tools/mesh-tester.c monitor/bt.h \ tools_mesh_tester_LDADD = lib/libbluetooth-internal.la \ src/libshared-mainloop.la -tools_l2cap_tester_SOURCES = tools/l2cap-tester.c tools/tester.h monitor/bt.h \ +tools_l2cap_tester_SOURCES = tools/l2cap-tester.c \ + tools/tester-io.h tools/tester-io.c tools/tester.h monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \ emulator/vhci.h emulator/vhci.c \ emulator/btdev.h emulator/btdev.c \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_l2cap_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_rfcomm_tester_SOURCES = tools/rfcomm-tester.c \ tools/tester-io.h tools/tester-io.c monitor/bt.h \
@@ -217,14 +218,15 @@ tools_userchan_tester_SOURCES = tools/userchan-tester.c monitor/bt.h \ tools_userchan_tester_LDADD = lib/libbluetooth-internal.la \ src/libshared-mainloop.la -tools_iso_tester_SOURCES = tools/iso-tester.c tools/tester.h monitor/bt.h \ +tools_iso_tester_SOURCES = tools/iso-tester.c \ + tools/tester-io.h tools/tester-io.c tools/tester.h monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \ emulator/vhci.h emulator/vhci.c \ emulator/btdev.h emulator/btdev.c \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_iso_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-mainloop.la tools_ioctl_tester_SOURCES = tools/ioctl-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \
tools/iso-tester.c +176 -161
936 lines not on this page · raw message
tools/l2cap-tester.c +173 -160
932 lines not on this page · raw message
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 26/27 doc/virtio: Update measurements of the testers
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Update the wall clock time of the kernel testers, now that they run on the mainloop, which unlike GLib does not read the clock, a system call through the host under User Mode Linux, on every iteration.
--- doc/virtio.rst | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
doc/virtio.rst +14 -8
@@ -375,14 +375,14 @@ version and machine, User Mode Linux with seccomp, with and without **-T**, all tests passing:: tester tests KVM UML UML -T - mgmt-tester 514 83.6 111.6 42.6 - l2cap-tester 111 9.6 13.7 10.2 - iso-tester 141 13.7 24.3 16.3 - sco-tester 30 5.1 4.1 3.6 - rfcomm-tester 11 3.6 2.0 2.6 - smp-tester 8 4.1 1.5 1.5 - ioctl-tester 28 4.1 2.6 3.1 - userchan-tester 4 2.6 1.5 1.5 + mgmt-tester 514 78.2 94.0 20.3 + l2cap-tester 111 9.2 10.2 5.6 + iso-tester 141 8.1 11.7 7.6 + sco-tester 30 4.6 3.1 2.0 + rfcomm-tester 11 3.6 1.5 1.5 + smp-tester 8 3.6 1.5 1.0 + ioctl-tester 28 4.1 2.1 1.5 + userchan-tester 4 2.6 1.0 1.0 bnep-tester 1 2.6 1.0 1.0 UML runs the guest's system calls and context switches considerably slower
@@ -391,6 +391,12 @@ small messages are slower without time travel. With it, tests that wait, like most of mgmt-tester, take no real time for timers and timeouts. Small testers are faster under UML, which starts in a fraction of a second. +Under UML, reading the clock is a system call through the host too, about +6 us against 0.02 us with KVM, where the vDSO answers it. GLib's main loop +reads it for every source on every iteration, so testers run on the +mainloop of ``src/shared/mainloop.c`` instead, which waits with +``epoll_wait()`` and one ``timerfd`` per timer and does not read the clock. + Time travel helps most when tests wait: timers, timeouts and idle time take no real time, and the timing is the same on every run. It also lets controllers outside the guests, such as btvirt's or a firmware simulation,
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 27/27 doc: Split tester.config for QEMU and User Mode Linux
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Rename tester.config to tester.kvm.config, keeping tester.config as a link to it for existing users, and add tester.uml.config for a User Mode Linux kernel, which uses hostfs and virtio_uml instead of the QEMU devices and needs time travel support for test-runner -T.
Both build every Bluetooth protocol and device driver, with the buses and subsystems they depend on and COMPILE_TEST, so a tester kernel also verifies that they all build, and a single User Mode Linux kernel can verify the drivers and run the testers. CONFIG_BT_HS, which no longer exists, is removed. CONFIG_BT_INTEL_PCIE depends on ACPI, which User Mode Linux does not have, unless built with COMPILE_TEST in kernels allowing it.
Document each configuration in test-runner.
--- doc/test-functional.rst | 4 +- doc/test-runner.rst | 118 +++++++++++++++++++++++++++----- doc/tester.config | 119 +-------------------------------- doc/tester.kvm.config | 144 ++++++++++++++++++++++++++++++++++++++++ doc/tester.uml.config | 120 +++++++++++++++++++++++++++++++++ 5 files changed, 370 insertions(+), 135 deletions(-) mode change 100644 => 120000 doc/tester.config create mode 100644 doc/tester.kvm.config create mode 100644 doc/tester.uml.config
doc/test-functional.rst +2 -2
@@ -90,7 +90,7 @@ The following additional options apply: ``--kernel=<image>`` Kernel image (or built Linux source tree root) to - use. See **test-runner(1)** and `tester.config` for required + use. See **test-runner(1)** and `tester.kvm.config` for required kernel config. If not provided, value from `FUNCTIONAL_TESTING_KERNEL`
@@ -300,7 +300,7 @@ Simplest setup is .. code-block:: - cp ../bluez/doc/tester.config .config + cp ../bluez/doc/tester.kvm.config .config make olddefconfig make -j8
doc/test-runner.rst +103 -15
162 lines not on this page · raw message
doc/tester.config deleted +0 -118
118 lines not on this page · raw message
doc/tester.config new file +1 -0
@@ -0,0 +1 @@ +tester.kvm.config
doc/tester.kvm.config new file +144 -0
144 lines not on this page · raw message
doc/tester.uml.config new file +120 -0
120 lines not on this page · raw message
Signature · 1 line
2.56.0
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 10 lines · On Thu, 22 Oct 2026 11:46:33 -0400 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
This makes test-runner run the kernel testers in a User Mode Linux guest as well as with QEMU/KVM, and with -T on a simulated clock: btvirt is the guest's time travel calendar, so timers and timeouts take no real time and timing is the same on every run. btvirt can also serve controllers to UML guests as vhost-user virtio devices sharing the calendar, e.g. for firmware simulators.
[...]
Here is the summary with links:
- [BlueZ,v1,01/27] tools/test-runner: Do not report filesystems already mounted
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=01a2794c5b5e - [BlueZ,v1,02/27] shared/tester: Time out teardown https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d32cf1e77713 - [BlueZ,v1,03/27] mgmt-tester: Wait for LL Privacy setup to complete https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a2b5b7c7b756 - [BlueZ,v1,04/27] iso-tester: Fix leaking socket watches https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9cd93aa69d97 - [BlueZ,v1,05/27] l2cap-tester: Fix race in LE Client - Close socket 2 https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a10a29556ce8 - [BlueZ,v1,06/27] iso-tester: Fix busy waiting in PAST tests https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9b3856a85336 - [BlueZ,v1,07/27] doc: Enable IPv6 in tester.config https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2362c4224ba9 - [BlueZ,v1,08/27] 6lowpan-tester: Find the interface of the controller https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6cc3ff01132d - [BlueZ,v1,09/27] emulator: Remove -T option from btvirt https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ba940f323890 - [BlueZ,v1,10/27] doc: Add btvirt documentation https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=703331bde0eb - [BlueZ,v1,11/27] emulator: Add vhost-user backend https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=1ce41b67dd13 - [BlueZ,v1,12/27] emulator: Add vhost-user virtio server to btvirt https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=11199825bfdc - [BlueZ,v1,13/27] emulator: Add time travel calendar to btvirt https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d7ef45305b15 - [BlueZ,v1,14/27] emulator: Add virtio console and time travel client to btvirt https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=faca01db81d6 - [BlueZ,v1,15/27] tools/test-runner: Add User Mode Linux support https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a7e9a42a791a - [BlueZ,v1,16/27] doc: Add virtio documentation https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=fe2d32320fba - [BlueZ,v1,17/27] shared/mainloop: Add idle callbacks https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=43593026bf84 - [BlueZ,v1,18/27] shared/timeout: Run timeouts of 0 once idle https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=3bce4ad01a01 - [BlueZ,v1,19/27] shared/tester: Remove GLib dependency https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=941e0a26f1f9 - [BlueZ,v1,20/27] emulator/hciemu: Remove GLib dependency https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=60eda0019a8b - [BlueZ,v1,21/27] tools: Build testers that do not need GLib with the mainloop (no matching commit) - [BlueZ,v1,22/27] shared/mainloop: Add deferred callbacks https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a2b4b1308069 - [BlueZ,v1,23/27] tools: Add socket watches for testers without GLib https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=b0c80a96d0a2 - [BlueZ,v1,24/27] tools: Run sco-tester, rfcomm-tester and 6lowpan-tester on the mainloop https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e37f17751c75 - [BlueZ,v1,25/27] tools: Run l2cap-tester and iso-tester on the mainloop https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=477642f6b5fa - [BlueZ,v1,26/27] doc/virtio: Update measurements of the testers https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=14bd6ab65f4a
- [BlueZ,v1,27/27] doc: Split tester.config for QEMU and User Mode Linux (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html