Devicetree Compiler
 help / color / mirror / Atom feed
From: Herve Codina <herve.codina@bootlin.com>
To: Simon Glass <sjg@chromium.org>
Cc: Devicetree Compiler <devicetree-compiler@vger.kernel.org>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH v2 3/4] fdtput: Suggest -p when a node is missing
Date: Wed, 28 Oct 2026 22:08:54 +0100	[thread overview]
Message-ID: <20261028220854.5f7edb4e@bootlin.com> (raw)
In-Reply-To: <20261028073440.3327687-4-sjg@chromium.org>

Hi Simon,

On Wed, 28 Oct 2026 01:34:19 -0600
Simon Glass <sjg@chromium.org> wrote:

> When the node being written to does not exist, fdtput just prints
> FDT_ERR_NOTFOUND - nothing points to -p, which creates missing nodes, so
> it is easy to conclude that fdtput cannot add nodes at all.
> 
> When creating a node with -c, the error also names the full path, even
> though it is the parent which is missing.
> 
> Add a hint to use -p when a node is missing, both when writing a
> property and when creating a node. Report the parent path when it is
> the parent which is missing.
> 
> Add tests that writing a property or creating a node fails when a parent
> node is missing and -p is not given, and that the error suggests -p.
> Add a run_wrap_error_msg_test() helper for this, which checks the
> output as well as the return code.

Nice idea!

> 
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> Changes in v2:
> - Check that the error suggests -p, using a new helper
> - Drop David's Reviewed-by, since the tests have changed
> 
>  fdtput.c           | 20 ++++++++++++++++++--
>  tests/run_tests.sh | 37 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 55 insertions(+), 2 deletions(-)
> 
> diff --git a/fdtput.c b/fdtput.c
> index 3c6cc98..b8d5081 100644
> --- a/fdtput.c
> +++ b/fdtput.c

...

I am ok with the implementation in fdtput.c.


> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index b3d3f3a..cf978ee 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -181,6 +181,37 @@ run_wrap_error_test () {
>      base_run_test wrap_error "$@"
>  }
>  
> +# Run a command, checking that it fails and that its output has $1 in it
> +wrap_error_msg () {
> +    (
> +	msg="$1"
> +	shift
> +	log=tmp.log.$$
> +	trap "rm -f $log" 0
> +	verbose_run_log "$log" "$@"
> +	ret="$?"
> +	FAIL_IF_SIGNAL $ret
> +	if [ "$ret" -eq 0 ]; then
> +	    FAIL "Expected non-zero return code"
> +	fi
> +	if ! grep -qF -- "$msg" "$log"; then
> +	    FAIL "Expected message '$msg'"
> +	fi
> +	PASS
> +    )
> +}
> +
> +# Check that a command fails and prints a message
> +# $1: message to look for in the output
> +# $2...: command to run
> +run_wrap_error_msg_test () {
> +    msg="$1"
> +    shift
> +    shorten_echo "$@"
> +    printf " {!= 0, \"%s\"}:	" "$msg"
> +    base_run_test wrap_error_msg "$msg" "$@"
> +}
> +

Right, you introduce this wrapper and I think they can be useful for other
cases.

You also sent the series "dtc: Fix deletes within a section and before a
redefinition" [1].

The patch "tests: Allow dtc-fatal.sh to check the error message" [2]
available in the series plays also with error messages, adding a "-m" option
to tests/dtc-fatal.sh.

At some point, could all tests use the same uniform method (probably the
wrappers added here)?

Could dtc-fatal.sh script be replaced by an existing wrapper?

Again, I think wrappers you added here are nice. I would like to have your
opinion related to dtc-fatal.sh and a way to avoid the '-m' option in order
to have uniform features.

[1]: https://lore.kernel.org/devicetree-compiler/20261028093620.3705074-1-sjg@chromium.org/
[2]: https://lore.kernel.org/devicetree-compiler/20261028093620.3705074-5-sjg@chromium.org/

>  # $1: dtb file
>  # $2: align base
>  check_align () {
> @@ -962,6 +993,12 @@ fdtput_tests () {
>      run_wrap_error_test $DTPUT $dtb -c /chosen
>      run_wrap_error_test $DTPUT $dtb -c /chosen/son
>  
> +    # Writing below a missing node fails without -p, suggesting -p
> +    run_wrap_error_msg_test "Use -p to create missing nodes" \
> +	$DTPUT $dtb -c /blackadder/the-second
> +    run_wrap_error_msg_test "Use -p to create missing nodes" \
> +	$DTPUT $dtb /blackadder/the-second cost -ts high
> +
>      # Automatic node creation
>      run_wrap_test $DTPUT $dtb -cp /blackadder/the-second/turnip \
>  	/blackadder/the-second/potato

Best regards,
Hervé

  reply	other threads:[~2026-10-28 21:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28  7:34 [PATCH v2 0/4] fdtput: Make it clearer how to create nodes Simon Glass
2026-10-28  7:34 ` [PATCH v2 1/4] fdtput: Require a leading '/' with -p Simon Glass
2026-10-28 20:14   ` Herve Codina
2026-10-29  2:07     ` David Gibson
2026-10-29  6:44       ` Simon Glass
2026-10-28  7:34 ` [PATCH v2 2/4] fdtput: Follow an alias when creating nodes " Simon Glass
2026-10-28 20:34   ` Herve Codina
2026-10-28  7:34 ` [PATCH v2 3/4] fdtput: Suggest -p when a node is missing Simon Glass
2026-10-28 21:08   ` Herve Codina [this message]
2026-10-29  2:02     ` David Gibson
2026-10-28  7:34 ` [PATCH v2 4/4] fdtput: Name the property when it cannot be deleted Simon Glass
2026-10-28 21:18   ` Herve Codina
2026-10-29  2:06 ` [PATCH v2 0/4] fdtput: Make it clearer how to create nodes David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028220854.5f7edb4e@bootlin.com \
    --to=herve.codina@bootlin.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=devicetree-compiler@vger.kernel.org \
    --cc=sjg@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox