Linux bluetooth development
 help / color / mirror / Atom feed
* [BlueZ, v2] unit: Add test for sdp_xml_parse_record()
@ 2026-08-05 15:02 Bastien Nocera
  2026-08-05 16:13 ` [BlueZ,v2] " bluez.test.bot
  2026-08-05 16:37 ` [BlueZ, v2] " Luiz Augusto von Dentz
  0 siblings, 2 replies; 4+ messages in thread
From: Bastien Nocera @ 2026-08-05 15:02 UTC (permalink / raw)
  To: linux-bluetooth

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

diff --git a/Makefile.am b/Makefile.am
index 19c468d3a504..1c62ee66bdce 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 \
diff --git a/unit/sdp-xml/Bluetooth_HID-sdp_record.xml b/unit/sdp-xml/Bluetooth_HID-sdp_record.xml
new file mode 100644
index 000000000000..687b0b15b520
--- /dev/null
+++ b/unit/sdp-xml/Bluetooth_HID-sdp_record.xml
@@ -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>
diff --git a/unit/sdp-xml/qt-SerialPortSDPRecord.xml b/unit/sdp-xml/qt-SerialPortSDPRecord.xml
new file mode 100644
index 000000000000..1f62ccf11a41
--- /dev/null
+++ b/unit/sdp-xml/qt-SerialPortSDPRecord.xml
@@ -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>
diff --git a/unit/test-sdp-xml.c b/unit/test-sdp-xml.c
new file mode 100644
index 000000000000..aef22b280498
--- /dev/null
+++ b/unit/test-sdp-xml.c
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [BlueZ,v2] unit: Add test for sdp_xml_parse_record()
  2026-08-05 15:02 [BlueZ, v2] unit: Add test for sdp_xml_parse_record() Bastien Nocera
@ 2026-08-05 16:13 ` bluez.test.bot
  2026-08-05 16:37 ` [BlueZ, v2] " Luiz Augusto von Dentz
  1 sibling, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2026-08-05 16:13 UTC (permalink / raw)
  To: linux-bluetooth, hadess

[-- Attachment #1: Type: text/plain, Size: 3035 bytes --]

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BlueZ, v2] unit: Add test for sdp_xml_parse_record()
  2026-08-05 15:02 [BlueZ, v2] unit: Add test for sdp_xml_parse_record() Bastien Nocera
  2026-08-05 16:13 ` [BlueZ,v2] " bluez.test.bot
@ 2026-08-05 16:37 ` Luiz Augusto von Dentz
  2026-08-06  9:13   ` Bastien Nocera
  1 sibling, 1 reply; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2026-08-05 16:37 UTC (permalink / raw)
  To: Bastien Nocera; +Cc: linux-bluetooth

Hi Bastien,

On Wed, Aug 5, 2026 at 11:07 AM Bastien Nocera <hadess@hadess.net> wrote:
>
> 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

Why no reuse test-sdp?

> diff --git a/Makefile.am b/Makefile.am
> index 19c468d3a504..1c62ee66bdce 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -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 \
> diff --git a/unit/sdp-xml/Bluetooth_HID-sdp_record.xml b/unit/sdp-xml/Bluetooth_HID-sdp_record.xml
> new file mode 100644
> index 000000000000..687b0b15b520
> --- /dev/null
> +++ b/unit/sdp-xml/Bluetooth_HID-sdp_record.xml
> @@ -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>
> diff --git a/unit/sdp-xml/qt-SerialPortSDPRecord.xml b/unit/sdp-xml/qt-SerialPortSDPRecord.xml
> new file mode 100644
> index 000000000000..1f62ccf11a41
> --- /dev/null
> +++ b/unit/sdp-xml/qt-SerialPortSDPRecord.xml
> @@ -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>
> diff --git a/unit/test-sdp-xml.c b/unit/test-sdp-xml.c
> new file mode 100644
> index 000000000000..aef22b280498
> --- /dev/null
> +++ b/unit/test-sdp-xml.c
> @@ -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
>
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [BlueZ, v2] unit: Add test for sdp_xml_parse_record()
  2026-08-05 16:37 ` [BlueZ, v2] " Luiz Augusto von Dentz
@ 2026-08-06  9:13   ` Bastien Nocera
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien Nocera @ 2026-08-06  9:13 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

On Wed, 2026-08-05 at 12:37 -0400, Luiz Augusto von Dentz wrote:
> Hi Bastien,
> 
> On Wed, Aug 5, 2026 at 11:07 AM Bastien Nocera <hadess@hadess.net>
> wrote:
> > 
> > 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
> 
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-06  9:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 15:02 [BlueZ, v2] unit: Add test for sdp_xml_parse_record() Bastien Nocera
2026-08-05 16:13 ` [BlueZ,v2] " bluez.test.bot
2026-08-05 16:37 ` [BlueZ, v2] " Luiz Augusto von Dentz
2026-08-06  9:13   ` Bastien Nocera

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox