Bug 507897

Summary: Allow for patching LTP sources
Product: [Developer tools] valgrind Reporter: mcermak
Component: generalAssignee: mcermak
Status: RESOLVED FIXED    
Severity: normal CC: mark
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: proposed patch
proposed patch
proposed patch
proposed patch

Description mcermak 2025-08-05 11:31:37 UTC
Created attachment 183802 [details]
proposed patch

Sometimes there's an upstream LTP patch that we need for testing valgrind, but it's not yet part of the released LTP tarball.  In such cases it's helpful to be able to conveniently patch the LTP sources as part of the valgrind test process.  Attached patch allows for that.
Comment 1 Mark Wielaard 2025-08-05 15:06:59 UTC
That should work, except if there are no patches, then:

+for i in *.patch; do
+    patch -d "$LTP_SRC_DIR"  -p1 < "$i"
+done

will not match anything and you end up with i being literally "*.patch" which causes the patch < "*.patch" to fail.

Since applypatches.sh is a bash script you could do:

if compgen -G "*.patch"; then
  for i in *.patch; do
     patch -d "$LTP_SRC_DIR"  -p1 < "$i"
  done
fi

Which should also work when there aren't any *patch files around.
Comment 2 Mark Wielaard 2025-08-05 15:11:34 UTC
O, and I think this:

@@ -199,6 +199,7 @@ $(LTP_SRC_DIR): $(LTP_TAR)
 	echo "$(LTP_SHA256_SUM)  $(LTP_TAR)" | @SHA256SUM@ --check -
 	(cd $(AUX_CHECK_DIR) && \
 	 tar Jxf $(LTP_TAR_NAME) && \
+	 ../ltp-patches/apply-patches.sh $(LTP_SRC_DIR) && \
 	 cd $(LTP_SRC_DIR) && \
 	 ./configure CC="${CC}" CXX="${CXX}" CFLAGS="$(LTP_CFLAGS)" && \
 	 ${MAKE} -j $(nproc) -C testcases/kernel/syscalls)

Should be:

+    $(abs_top_srcdir)/auxprogs/ltp-patches/apply-patches.sh $(LTP_SRC_DIR) && \

In case you are building with srcdir != builddir

(untested)
Comment 3 mcermak 2025-08-05 16:09:54 UTC
Created attachment 183810 [details]
proposed patch

Thank you for your review!  I'm attaching an updated patch.  Please check.
Comment 4 Mark Wielaard 2025-08-05 18:10:38 UTC
(In reply to mcermak from comment #3)
> Created attachment 183810 [details]
> proposed patch
> 
> Thank you for your review!  I'm attaching an updated patch.  Please check.

> +if test -f ltp-patches/*.patch; then

That won't work when there are multiple patches:

$ touch 1.patch 2.patch; if test -f *.patch; then echo yes; else echo no; fi
bash: test: 1.patch: binary operator expected
no

Which is why I would recommend using if compgen -G "*.patch";
Comment 5 mcermak 2025-08-05 21:11:07 UTC
Created attachment 183818 [details]
proposed patch

Apologies.  I've updated the patch using compgen now.  Please check.
Comment 6 mcermak 2025-08-06 05:01:07 UTC
Created attachment 183822 [details]
proposed patch

Improve README and commit message.
Comment 7 Mark Wielaard 2025-08-06 14:45:41 UTC
(In reply to mcermak from comment #6)
> Created attachment 183822 [details]
> proposed patch
> 
> Improve README and commit message.

Looks good. Pushed as:

commit 03ea5d11d3832fb83a434408a5ea7049392fd4bd
Author: Martin Cermak <mcermak@redhat.com>
Date:   Tue Aug 5 18:06:08 2025 +0200

    Allow for patching LTP sources
    
    Sometimes there's an upstream LTP patch that helps testing
    valgrind, but it's not yet part of the official LTP tarball.
    In such cases it's helpful to be able to patch the LTP sources.
    Attached patch allows for that.  It comes with a real life
    example patch: LTP commit b62b831cf.


Also updated the buildbot to clean the ltpchecks so patches are applied on next run:
https://sourceware.org/cgit/builder/commit/?id=a98c6cf9414073a1f44ae77f17f8220be1642914