diff mbox series

[nft,01/12] tests: shell: export DIFF to use it from feature scripts

Message ID 20231109162304.119506-2-pablo@netfilter.org
State Changes Requested
Headers show
Series update tests/shell for 5.4 kernels | expand

Commit Message

Pablo Neira Ayuso Nov. 9, 2023, 4:22 p.m. UTC
export DIFF so it can be used from feature scripts to probe the kernel.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 tests/shell/run-tests.sh | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Thomas Haller Nov. 9, 2023, 5:49 p.m. UTC | #1
On Thu, 2023-11-09 at 17:22 +0100, Pablo Neira Ayuso wrote:
> export DIFF so it can be used from feature scripts to probe the
> kernel.
> 
> +DIFF="$(which diff)"
> +if [ ! -x "$DIFF" ] ; then
> +	DIFF=true
> +fi
> +export DIFF


what is the purpose of having $DIFF variable at all?
Why not require to have `diff` installed?


Maybe that justification is somewhere in the history of the project. If
so, could you drop one line in the commit message what the point is?


Thomas
Pablo Neira Ayuso Nov. 9, 2023, 7:14 p.m. UTC | #2
On Thu, Nov 09, 2023 at 06:49:21PM +0100, Thomas Haller wrote:
> On Thu, 2023-11-09 at 17:22 +0100, Pablo Neira Ayuso wrote:
> > export DIFF so it can be used from feature scripts to probe the
> > kernel.
> > 
> > +DIFF="$(which diff)"
> > +if [ ! -x "$DIFF" ] ; then
> > +	DIFF=true
> > +fi
> > +export DIFF
> 
> 
> what is the purpose of having $DIFF variable at all?
> Why not require to have `diff` installed?
> 
> Maybe that justification is somewhere in the history of the project. If
> so, could you drop one line in the commit message what the point is?

It is all available in git annotate:

68310ba0f9c2 ("tests: shell: Search diff tool once and for all")
7d93e2c2fbc7 ("tests: shell: autogenerate dump verification")

I just need to move it around so I can use it from feature scripts.
If you prefer I can just use 'diff' instead from the feature scripts.
Thomas Haller Nov. 9, 2023, 8:35 p.m. UTC | #3
On Thu, 2023-11-09 at 20:14 +0100, Pablo Neira Ayuso wrote:
> On Thu, Nov 09, 2023 at 06:49:21PM +0100, Thomas Haller wrote:
> > On Thu, 2023-11-09 at 17:22 +0100, Pablo Neira Ayuso wrote:
> > > export DIFF so it can be used from feature scripts to probe the
> > > kernel.
> > > 
> > > +DIFF="$(which diff)"
> > > +if [ ! -x "$DIFF" ] ; then
> > > +	DIFF=true
> > > +fi
> > > +export DIFF
> > 
> > 
> > what is the purpose of having $DIFF variable at all?
> > Why not require to have `diff` installed?
> > 
> > Maybe that justification is somewhere in the history of the
> > project. If
> > so, could you drop one line in the commit message what the point
> > is?
> 
> It is all available in git annotate:
> 
> 68310ba0f9c2 ("tests: shell: Search diff tool once and for all")
> 7d93e2c2fbc7 ("tests: shell: autogenerate dump verification")

First use of $DIFF comes from 

  3fb3bb603374 ('tests/listing: add some listing tests')

which says:

    In order to ease debug in case of failure, if the diff tool is in the system,
    then a textual diff is printed.


With the `true` fallback, checks are skipped. It would be possible, to
use a fallback that still checks for equality (albeit without fancy
diff output).

But really. Just require everybody to install a diff program.


> 
> I just need to move it around so I can use it from feature scripts.
> If you prefer I can just use 'diff' instead from the feature scripts.

Sure. The patch is fine.


I think one day,

   sed 's/\$DIFF\>/diff/g' -i $(git grep -l DIFF tests/shell/)

should be done.



Thomas
Florian Westphal Nov. 9, 2023, 11:21 p.m. UTC | #4
Thomas Haller <thaller@redhat.com> wrote:
> I think one day,
> 
>    sed 's/\$DIFF\>/diff/g' -i $(git grep -l DIFF tests/shell/)
> 
> should be done.

FWIW I agree with this.
Florian Westphal Nov. 9, 2023, 11:25 p.m. UTC | #5
Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> I just need to move it around so I can use it from feature scripts.
> If you prefer I can just use 'diff' instead from the feature scripts.

Seems better to just use 'diff'.
diff mbox series

Patch

diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index 27a0ec43042a..e51d51c9539b 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -572,6 +572,12 @@  feature_probe()
 	return 1
 }
 
+DIFF="$(which diff)"
+if [ ! -x "$DIFF" ] ; then
+	DIFF=true
+fi
+export DIFF
+
 for feat in "${_HAVE_OPTS[@]}" ; do
 	var="NFT_TEST_HAVE_$feat"
 	if [ -z "${!var+x}" ] ; then
@@ -590,11 +596,6 @@  if [ "$NFT_TEST_JOBS" -eq 0 ] ; then
 	fi
 fi
 
-DIFF="$(which diff)"
-if [ ! -x "$DIFF" ] ; then
-	DIFF=true
-fi
-
 declare -A JOBS_PIDLIST
 
 _NFT_TEST_VALGRIND_VGDB_PREFIX=