Skip to contentSkip to conversation

unit: Add test for sdp_xml_parse_record()

PATCH Superseded Bastien Nocera 3 participants 4 messages Aug 5 – Aug 6

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 unit: Add test for sdp_xml_parse_record()

This adds 2 example XML files from other repositories, under a fair use license exception.
---
Changes since v1:
- Added an "expected result" field, so expected failures can also pass tests.

 Makefile.am                               |  10 ++
 unit/sdp-xml/Bluetooth_HID-sdp_record.xml | 123 ++++++++++++++++++++++
 unit/sdp-xml/qt-SerialPortSDPRecord.xml   |  57 ++++++++++
 unit/test-sdp-xml.c                       |  81 ++++++++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 unit/sdp-xml/Bluetooth_HID-sdp_record.xml
 create mode 100644 unit/sdp-xml/qt-SerialPortSDPRecord.xml
 create mode 100644 unit/test-sdp-xml.c
Makefile.am +10 -0
index 19c468d3a504..1c62ee66bdce 100644
@@ -637,6 +637,16 @@ unit_test_sdp_SOURCES = unit/test-sdp.c \
 unit_test_sdp_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-glib.la $(GLIB_LIBS)
 
+unit_tests += unit/test-sdp-xml
+
+unit_test_sdp_xml_SOURCES = unit/test-sdp-xml.c \
+				src/sdp-xml.c src/sdp-xml.h \
+				src/log.h src/log.c
+unit_test_sdp_xml_LDADD = lib/libbluetooth-internal.la \
+				src/libshared-glib.la $(GLIB_LIBS)
+unit_test_sdp_xml_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) -DTOP_SRCDIR=\""$(srcdir)"\"
+unit_test_sdp_xml_CPPFLAGS = -I$(srcdir)/lib
+
 unit_tests += unit/test-avdtp
 
 unit_test_avdtp_SOURCES = unit/test-avdtp.c \
unit/sdp-xml/Bluetooth_HID-sdp_record.xml new file +123 -0

123 lines not on this page · raw message

unit/sdp-xml/qt-SerialPortSDPRecord.xml new file +57 -0

57 lines not on this page · raw message

unit/test-sdp-xml.c new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
2.55.0
#1 lore raw

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/project/bluetooth/list/?series=1140873

---Test result---

Test Summary:

CheckPatch                    FAIL      1.01 seconds
GitLint                       PASS      0.35 seconds
BuildEll                      PASS      20.94 seconds
BluezMake                     PASS      565.15 seconds
MakeCheck                     PASS      18.82 seconds
MakeDistcheck                 FAIL      137.78 seconds
CheckValgrind                 PASS      224.92 seconds
CheckSmatch                   PASS      300.38 seconds
bluezmakeextell               PASS      97.26 seconds
IncrementalBuild              PASS      589.94 seconds
ScanBuild                     PASS      882.87 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v2] unit: Add test for sdp_xml_parse_record() WARNING:LONG_LINE: line length of 82 exceeds 80 columns #338: FILE: unit/test-sdp-xml.c:54:
+ path = g_build_filename(TOP_SRCDIR, "unit", "sdp-xml", t->filename, NULL);

WARNING:LONG_LINE: line length of 81 exceeds 80 columns #350: FILE: unit/test-sdp-xml.c:66:
+#define DEFINE_TEST(fname, res) \

WARNING:TRAILING_SEMICOLON: macros should not use a trailing semicolon #350: FILE: unit/test-sdp-xml.c:66:
+#define DEFINE_TEST(fname, res) \
+ data.expected_result = res; \
+ data.filename = fname; \
+ tester_add("/" fname, &data, NULL, parse_xml_for_filename, NULL);

WARNING:LONG_LINE: line length of 81 exceeds 80 columns #351: FILE: unit/test-sdp-xml.c:67:
+ data.expected_result = res; \

WARNING:LONG_LINE: line length of 81 exceeds 80 columns #352: FILE: unit/test-sdp-xml.c:68:
+ data.filename = fname; \

/github/workspace/src/patch/14732555.patch total: 0 errors, 5 warnings, 277 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.

/github/workspace/src/patch/14732555.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: MakeDistcheck - FAIL
Desc: Run Bluez Make Distcheck
Output:

../../test-driver: line 107: 53128 Aborted (core dumped) "$@" > $log_file 2>&1
make[4]: *** [Makefile:10329: test-suite.log] Error 1 make[3]: *** [Makefile:10437: check-TESTS] Error 2 make[2]: *** [Makefile:10915: check-am] Error 2 make[1]: *** [Makefile:10917: check] Error 2
make: *** [Makefile:10838: distcheck] Error 1

https://github.com/bluez/bluez/pull/2379

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Bastien Nocera

Hi Bastien,

Quoted 8 lines · Bastien Nocera

This adds 2 example XML files from other repositories, under a fair use license exception.
---
Changes since v1:
- Added an "expected result" field, so expected failures can also pass tests.

Quoted 8 lines
 Makefile.am                               |  10 ++
 unit/sdp-xml/Bluetooth_HID-sdp_record.xml | 123 ++++++++++++++++++++++
 unit/sdp-xml/qt-SerialPortSDPRecord.xml   |  57 ++++++++++
 unit/test-sdp-xml.c                       |  81 ++++++++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 unit/sdp-xml/Bluetooth_HID-sdp_record.xml
 create mode 100644 unit/sdp-xml/qt-SerialPortSDPRecord.xml
 create mode 100644 unit/test-sdp-xml.c

Why no reuse test-sdp?

Quoted 304 lines
Makefile.am +10 -0
index 19c468d3a504..1c62ee66bdce 100644
@@ -637,6 +637,16 @@ unit_test_sdp_SOURCES = unit/test-sdp.c \
 unit_test_sdp_LDADD = lib/libbluetooth-internal.la \
                                src/libshared-glib.la $(GLIB_LIBS)
 
+unit_tests += unit/test-sdp-xml
+
+unit_test_sdp_xml_SOURCES = unit/test-sdp-xml.c \
+                               src/sdp-xml.c src/sdp-xml.h \
+                               src/log.h src/log.c
+unit_test_sdp_xml_LDADD = lib/libbluetooth-internal.la \
+                               src/libshared-glib.la $(GLIB_LIBS)
+unit_test_sdp_xml_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) -DTOP_SRCDIR=\""$(srcdir)"\"
+unit_test_sdp_xml_CPPFLAGS = -I$(srcdir)/lib
+
 unit_tests += unit/test-avdtp
 
 unit_test_avdtp_SOURCES = unit/test-avdtp.c \
unit/sdp-xml/Bluetooth_HID-sdp_record.xml new file +123 -0
new file mode 100644
index 000000000000..687b0b15b520
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+
+ From: https://github.com/AnesBenmerzoug/Bluetooth_HID/blob/master/sdp_record.xml
+ A description of these fields can be found in the following links:
+ http://www.bluecove.org/bluecove/apidocs/javax/bluetooth/ServiceRecord.html
+ https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
+
+ -->
+
+<record>
+       <attribute id="0x0001"> <!-- Service Class ID List -->
+               <sequence>
+                       <uuid value="0x1124" /> <!-- Human Interface Device -->
+               </sequence>
+       </attribute>
+       <attribute id="0x0004"> <!-- Protocol Descriptor List -->
+               <sequence>
+                       <sequence>
+                               <uuid value="0x0100" /> <!-- L2CAP -->
+                               <uint16 value="0x0011" /> <!-- HIDP -->
+                       </sequence>
+                       <sequence>
+                               <uuid value="0x0011" /> <!-- HIDP -->
+                       </sequence>
+               </sequence>
+       </attribute>
+       <attribute id="0x0005"> <!-- Browse Group List -->
+               <sequence>
+                       <uuid value="0x1002" />
+               </sequence>
+       </attribute>
+       <attribute id="0x0006"> <!-- Language Based Attribute ID List -->
+               <sequence>
+                       <uint16 value="0x656e" /> <!-- code_ISO639 -->
+                       <uint16 value="0x006a" /> <!-- encoding -->
+                       <uint16 value="0x0100" /> <!-- base_offset -->
+               </sequence>
+       </attribute>
+       <attribute id="0x0009"> <!-- Bluetooth Profile Descriptor List -->
+               <sequence>
+                       <sequence>
+                               <uuid value="0x1124" /> <!-- Human Interface Device -->
+                               <uint16 value="0x0100" /> <!-- L2CAP -->
+                       </sequence>
+               </sequence>
+       </attribute>
+       <attribute id="0x000d"> <!-- Additional Protocol Descriptor Lists -->
+               <sequence>
+                       <sequence>
+                               <sequence>
+                                       <uuid value="0x0100" /> <!-- L2CAP -->
+                                       <uint16 value="0x0013" />
+                               </sequence>
+                               <sequence>
+                                       <uuid value="0x0011" /> <!-- HIDP -->
+                               </sequence>
+                       </sequence>
+               </sequence>
+       </attribute>
+       <attribute id="0x0100">
+               <text value="Bluetooth_Keyboard/Mouse" />
+       </attribute>
+       <attribute id="0x0101">
+               <text value="USB > BT Keyboard/Mouse" />
+       </attribute>
+       <attribute id="0x0102">
+               <text value="Raspberry Pi 3" />
+       </attribute>
+       <attribute id="0x0200">
+               <uint16 value="0x0100" />
+       </attribute>
+       <attribute id="0x0201">
+               <uint16 value="0x0111" />
+       </attribute>
+       <attribute id="0x0202">
+               <uint8 value="0x40" />
+       </attribute>
+       <attribute id="0x0203">
+               <uint8 value="0x00" />
+       </attribute>
+       <attribute id="0x0204">
+               <boolean value="false" />
+       </attribute>
+       <attribute id="0x0205">
+               <boolean value="false" />
+       </attribute>
+       <attribute id="0x0206">
+               <sequence>
+                       <sequence>
+                               <uint8 value="0x22" />
+                               <text encoding="hex" value="05010906A1018501A100050719E029E71500250175019508810295017508810195087508150025650507190029658100C0C005010902A10185020901A1000509190129031500250175019503810275059501810105010930093109381581257F750895038106C0C0"/>
+                       </sequence>
+               </sequence>
+       </attribute>
+       <attribute id="0x0207">
+               <sequence>
+                       <sequence>
+                               <uint16 value="0x0409" />
+                               <uint16 value="0x0100" />
+                       </sequence>
+               </sequence>
+       </attribute>
+       <attribute id="0x020b">
+               <uint16 value="0x0100" />
+       </attribute>
+       <attribute id="0x020c">
+               <uint16 value="0x0c80" />
+       </attribute>
+       <attribute id="0x020d">
+               <boolean value="true" />
+       </attribute>
+       <attribute id="0x020e">
+               <boolean value="false" />
+       </attribute>
+       <attribute id="0x020f">
+               <uint16 value="0x0640" />
+       </attribute>
+       <attribute id="0x0210">
+               <uint16 value="0x0320" />
+       </attribute>
+</record>
unit/sdp-xml/qt-SerialPortSDPRecord.xml new file +57 -0
new file mode 100644
index 000000000000..1f62ccf11a41
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ This is an XML file describing an SDP service record for a Serial Port
+ service.
+
+ You can use the linux sdptool command to create a file like this for
+ publishing your Bluetooth services. See the "Creating a Bluetooth service"
+ tutorial for more details.
+
+ From: https://radekp.github.io/qtmoko/api/bluetooth-bluetoothservice-serialportsdprecord-xml.html
+-->
+
+ <record>
+         <attribute id="0x0001">
+                 <sequence>
+                         <uuid value="0x1101" />
+                 </sequence>
+         </attribute>
+         <attribute id="0x0004">
+                 <sequence>
+                         <sequence>
+                                 <uuid value="0x0100" />
+                         </sequence>
+                         <sequence>
+                                 <uuid value="0x0003" />
+                                 <uint8 value="0x05" />
+                         </sequence>
+                 </sequence>
+         </attribute>
+         <attribute id="0x0005">
+                 <sequence>
+                         <uuid value="0x1002" />
+                 </sequence>
+         </attribute>
+         <attribute id="0x0006">
+                 <sequence>
+                         <uint16 value="0x656e" />
+                         <uint16 value="0x006a" />
+                         <uint16 value="0x0100" />
+                 </sequence>
+         </attribute>
+         <attribute id="0x0009">
+                 <sequence>
+                         <sequence>
+                                 <uuid value="0x1101" />
+                                 <uint16 value="0x0100" />
+                         </sequence>
+                 </sequence>
+         </attribute>
+         <attribute id="0x0100">
+                 <text value="Serial Port" />
+         </attribute>
+         <attribute id="0x0101">
+                 <text value="COM Port" />
+         </attribute>
+ </record>
unit/test-sdp-xml.c new file +81 -1
new file mode 100644
index 000000000000..aef22b280498
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2026  Intel Corporation. All rights reserved.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+
+#include "bluetooth/sdp.h"
+#include "bluetooth/sdp_lib.h"
+
+#include "src/shared/util.h"
+#include "src/shared/tester.h"
+#include "src/log.h"
+#include "src/sdp-xml.h"
+
+struct test_data {
+       GString *s;
+       char *filename;
+       gboolean expected_result;
+};
+
+static void parse_xml(gconstpointer data, gsize len, gboolean expected_result)
+{
+       sdp_record_t *rec = NULL;
+       gboolean ret;
+
+       rec = sdp_xml_parse_record(data, len);
+       ret = rec ? TRUE : FALSE;
+       if (ret == expected_result)
+               tester_test_passed();
+       else
+               tester_test_failed();
+       if (rec)
+               sdp_record_free(rec);
+}
+
+static void parse_xml_for_filename(gconstpointer data)
+{
+       struct test_data *t = (struct test_data *) data;
+       char *path = NULL;
+       GError *error = NULL;
+       char *contents = NULL;
+       gsize len;
+
+       path = g_build_filename(TOP_SRCDIR, "unit", "sdp-xml", t->filename, NULL);
+       if (!g_file_get_contents(path, &contents, &len, &error)) {
+               g_warning("Can't load file '%s': %s", path, error->message);
+               g_free(path);
+               g_error_free(error);
+               tester_test_failed();
+       }
+       parse_xml(contents, len, t->expected_result);
+       g_free(contents);
+       g_free(path);
+}
+
+#define DEFINE_TEST(fname, res)                                                        \
+       data.expected_result = res;                                             \
+       data.filename = fname;                                                  \
+       tester_add("/" fname, &data, NULL, parse_xml_for_filename, NULL);
+
+int main(int argc, char *argv[])
+{
+       struct test_data data;
+
+       tester_init(&argc, &argv);
+
+       DEFINE_TEST("Bluetooth_HID-sdp_record.xml", TRUE);
+       DEFINE_TEST("qt-SerialPortSDPRecord.xml", TRUE);
+
+       return tester_run();
+}
--

2.55.0

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw
Quoted 24 lines · Luiz Augusto von Dentz

Hi Bastien,

Quoted 15 lines · Bastien Nocera

This adds 2 example XML files from other repositories, under a fair use
license exception.
---
Changes since v1:
- Added an "expected result" field, so expected failures can also pass
  tests.

 Makefile.am                               |  10 ++ unit/sdp-xml/Bluetooth_HID-sdp_record.xml | 123
++++++++++++++++++++++
 unit/sdp-xml/qt-SerialPortSDPRecord.xml   |  57 ++++++++++ unit/test-sdp-xml.c                       |  81 ++++++++++++++

Quoted 4 lines
 4 files changed, 271 insertions(+)

 create mode 100644 unit/sdp-xml/Bluetooth_HID-sdp_record.xml create mode 100644 unit/sdp-xml/qt-SerialPortSDPRecord.xml create mode 100644 unit/test-sdp-xml.c

Quoted 1 line

Why no reuse test-sdp?

Because I did not want to add XML parsing tests to something that didn't link against it, and separate test binaries can run in parallel (at least they can in meson), making running loads of small tests faster than running larger tests.

Note that this patch is just the scaffolding for many other tests I have locally, so let me know quickly if folding this code into unit/sdp-xml.c is a requirement to getting it merged.

Cheers