Re: [PATCH 3/9] ktest: Treat undefined self-reference as empty

From: Steven Rostedt

Date: Mon Mar 09 2026 - 10:43:01 EST


On Sat, 07 Mar 2026 19:07:58 -0300
Ricardo B. Marlière <rbm@xxxxxxxx> wrote:

> Config variables are expanded when they are assigned. A first-time append
> such as:
>
> VAR := ${VAR} foo
>
> leaves the literal ${VAR} in the stored value because VAR has not been
> defined yet. Later expansions then carry the self-reference forward instead
> of behaving like an empty prefix.
>
> Drop an unescaped self-reference when the variable has no current value,
> and trim the outer whitespace left behind. Keep escaped \${VAR} references
> unchanged so literal text still works.
>
> Signed-off-by: Ricardo B. Marlière <rbm@xxxxxxxx>
> ---
> tools/testing/ktest/ktest.pl | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
> index b7a1c8c617e0..b8fcdabffffe 100755
> --- a/tools/testing/ktest/ktest.pl
> +++ b/tools/testing/ktest/ktest.pl
> @@ -910,6 +910,14 @@ sub set_variable {
> if (defined($command_tmp_vars{$lvalue})) {
> return;
> }
> +
> + # If a variable is undefined, treat an unescaped self-reference as empty.
> + if (!defined($variable{$lvalue})) {
> + $rvalue =~ s/(?<!\\)\$\{\Q$lvalue\E\}//g;

So today I learned about "negative look behind" "?<!" ;-)

-- Steve

> + $rvalue =~ s/^\s+//;
> + $rvalue =~ s/\s+$//;
> + }
> +
> if ($rvalue =~ /^\s*$/) {
> delete $variable{$lvalue};
> } else {
>