Re: [RFC PATCH v2 10/74] tests: Add basic metadata tests

From: David Gibson

Date: Fri Oct 30 2026 - 01:25:27 EST


On Wed, Aug 26, 2026 at 11:48:39AM +0200, Herve Codina wrote:
> This first test is related to local phandle references used in
> properties (FDT_PROPDATA_PHANDLE dtb tag).
>
> The test pattern used is
> - Generate a dts (xxx.dts.dts) from an input dts
> - Check this generated dts against expected contents
> - Generate a dtb (xxx.dtb) from the same input dts
> - Check this generated dtb against expected contents
> - Generate a dts (xxx.dtb.dts) from the generated dtb
> - Check this generated dts against expected contents
> - Generate a dtb (xxx.dtb.dts.dtb) from the generated dts
> - Check this generated dtb, expect the same contents as for xxx.dtb
>
> Even if only one meta-data feature is currently tested in this tests
> introduction, use a loop in order to ease future addition consisting in
> adding new input dts as soon as new meta-data feature are supported.
>
> Signed-off-by: Herve Codina <herve.codina@xxxxxxxxxxx>

As noted elsewhere, I'd prefer to see new helper tools for comparing
metadata in binary rather than using text comparisons.

> ---
> tests/meson.build | 1 +
> ...data_propdata_phandle_local.dtb.dts.expect | 23 ++++++++++++++++
> ...metadata_propdata_phandle_local.dtb.expect | 20 ++++++++++++++
> tests/metadata_propdata_phandle_local.dts | 27 +++++++++++++++++++
> ...data_propdata_phandle_local.dts.dts.expect | 23 ++++++++++++++++
> tests/run_tests.sh | 25 ++++++++++++++++-
> 6 files changed, 118 insertions(+), 1 deletion(-)
> create mode 100644 tests/metadata_propdata_phandle_local.dtb.dts.expect
> create mode 100644 tests/metadata_propdata_phandle_local.dtb.expect
> create mode 100644 tests/metadata_propdata_phandle_local.dts
> create mode 100644 tests/metadata_propdata_phandle_local.dts.dts.expect
>
> diff --git a/tests/meson.build b/tests/meson.build
> index fcc73982..ec24f0af 100644
> --- a/tests/meson.build
> +++ b/tests/meson.build
> @@ -143,6 +143,7 @@ run_test_types = [
> 'fdtput',
> 'fdtdump',
> 'fdtoverlay',
> + 'metadata',
> ]
> run_test_deps = [
> dtc_tools, treegen_dtb, tests_exe,
> diff --git a/tests/metadata_propdata_phandle_local.dtb.dts.expect b/tests/metadata_propdata_phandle_local.dtb.dts.expect
> new file mode 100644
> index 00000000..076c17ae
> --- /dev/null
> +++ b/tests/metadata_propdata_phandle_local.dtb.dts.expect
> @@ -0,0 +1,23 @@
> +/dts-v1/;
> +
> +/ {
> +
> + node-a {
> +
> + subnode-a {
> + phandle = <0x01>;
> + };
> + };
> +
> + node-b {
> + phandle = <0x02>;
> + };
> +
> + node-c {
> + };
> +
> + node-d {
> + ref-subnode-a = <&{/node-a/subnode-a}>;
> + ref-node-b = <0x123 0x456 &{/node-b} 0x789>;
> + };
> +};
> diff --git a/tests/metadata_propdata_phandle_local.dtb.expect b/tests/metadata_propdata_phandle_local.dtb.expect
> new file mode 100644
> index 00000000..c923d2e2
> --- /dev/null
> +++ b/tests/metadata_propdata_phandle_local.dtb.expect
> @@ -0,0 +1,20 @@
> +/dts-v1/;
> +
> +/ {
> + node-a {
> + subnode-a {
> + phandle = <0x00000001>;
> + };
> + };
> + node-b {
> + phandle = <0x00000002>;
> + };
> + node-c {
> + };
> + node-d {
> + ref-subnode-a = <0x00000001>;
> + // [FDT_PROPDATA_PHANDLE] ref-subnode-a[0]
> + ref-node-b = <0x00000123 0x00000456 0x00000002 0x00000789>;
> + // [FDT_PROPDATA_PHANDLE] ref-node-b[8]
> + };
> +};
> diff --git a/tests/metadata_propdata_phandle_local.dts b/tests/metadata_propdata_phandle_local.dts
> new file mode 100644
> index 00000000..f04d24f9
> --- /dev/null
> +++ b/tests/metadata_propdata_phandle_local.dts
> @@ -0,0 +1,27 @@
> +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
> +/*
> + * Copyright (C) 2026 Bootlin
> + */
> +
> +/dts-v1/;
> +
> +/ {
> + node-a {
> + subnode_a: subnode-a {
> + };
> + };
> +
> + node_b: node-b {
> + };
> +
> + node-c {
> + };
> +
> + node_d: node-d {
> + ref-subnode-a = <&subnode_a>;
> + };
> +};
> +
> +&node_d {
> + ref-node-b = <0x123 0x456 &node_b 0x789>;
> +};
> diff --git a/tests/metadata_propdata_phandle_local.dts.dts.expect b/tests/metadata_propdata_phandle_local.dts.dts.expect
> new file mode 100644
> index 00000000..b72b545f
> --- /dev/null
> +++ b/tests/metadata_propdata_phandle_local.dts.dts.expect
> @@ -0,0 +1,23 @@
> +/dts-v1/;
> +
> +/ {
> +
> + node-a {
> +
> + subnode_a: subnode-a {
> + phandle = <0x01>;
> + };
> + };
> +
> + node_b: node-b {
> + phandle = <0x02>;
> + };
> +
> + node-c {
> + };
> +
> + node_d: node-d {
> + ref-subnode-a = <&subnode_a>;
> + ref-node-b = <0x123 0x456 &node_b 0x789>;
> + };
> +};
> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index 42b74e05..8c27b463 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -1239,6 +1239,26 @@ fdtoverlay_tests() {
> run_wrap_test test "$bd" = "$pd"
> }
>
> +metadata_tests() {
> + for dt in metadata_propdata_phandle_local; do
> + run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts"
> + base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect"
> + run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
> + base_run_test wrap_fdtdump $dt.dtb $dt.dtb.out
> + # Remove unneeded comments
> + sed -i '/^\/\/ /d' $dt.dtb.out
> + base_run_test check_diff $dt.dtb.out "$SRCDIR/$dt.dtb.expect"
> + run_test check_full $dt.dtb
> + run_dtc_test -I dtb -O dts -o $dt.dtb.dts $dt.dtb
> + base_run_test check_diff $dt.dtb.dts "$SRCDIR/$dt.dtb.dts.expect"
> + run_dtc_test -I dts -O dtb -o $dt.dtb.dts.dtb $dt.dtb.dts
> + base_run_test wrap_fdtdump $dt.dtb.dts.dtb $dt.dtb.dts.dtb.out
> + # Remove unneeded comments
> + sed -i '/^\/\/ /d' $dt.dtb.dts.dtb.out
> + base_run_test check_diff $dt.dtb.dts.dtb.out "$SRCDIR/$dt.dtb.expect"
> + done
> +}
> +
> pylibfdt_tests () {
> run_dtc_test -I dts -O dtb -o test_props.dtb "$SRCDIR/test_props.dts"
> TMP=/tmp/tests.stderr.$$
> @@ -1278,7 +1298,7 @@ while getopts "vt:me" ARG ; do
> done
>
> if [ -z "$TESTSETS" ]; then
> - TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtoverlay"
> + TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtoverlay metadata"
>
> # Test pylibfdt if the libfdt Python module is available.
> if ! $no_python; then
> @@ -1318,6 +1338,9 @@ for set in $TESTSETS; do
> "fdtoverlay")
> fdtoverlay_tests
> ;;
> + "metadata")
> + metadata_tests
> + ;;
> esac
> done
>
> --
> 2.55.0
>
>

--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson

Attachment: signature.asc
Description: PGP signature