about summary refs log tree commit diff
path: root/Makefile
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2018-07-04 15:27:24 +0200
committerFlorian Weimer <fweimer@redhat.com>2018-07-04 15:30:45 +0200
commitf2873d2da0ac9802e0b570e8e0b9e7e04a82bf55 (patch)
tree5228718da2051a29c5d92d49d014114568f3cbce /Makefile
parenteb04c21373e2a2885f3d52ff192b0499afe3c672 (diff)
downloadglibc-f2873d2da0ac9802e0b570e8e0b9e7e04a82bf55.tar.gz
glibc-f2873d2da0ac9802e0b570e8e0b9e7e04a82bf55.tar.xz
glibc-f2873d2da0ac9802e0b570e8e0b9e7e04a82bf55.zip
testrun.sh: Implement --tool=strace, --tool=valgrind
$(file …) appears to be the only convenient way to create files
with newlines and make substitution variables.  This needs make 4.0
(released in 2013), so update the requirement to match.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile55
1 files changed, 49 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index bea4e27f8d..d3f25a525a 100644
--- a/Makefile
+++ b/Makefile
@@ -128,17 +128,60 @@ ifeq (yes,$(build-shared))
 lib: $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so
 endif # $(build-shared)
 
+# Used to build testrun.sh.
+define testrun-script
+#!/bin/bash
+builddir=`dirname "$$0"`
+GCONV_PATH="$${builddir}/iconvdata"
+
+usage () {
+  echo "usage: $$0 [--tool=strace] PROGRAM [ARGUMENTS...]" 2>&1
+  echo "       $$0 --tool=valgrind PROGRAM [ARGUMENTS...]" 2>&1
+}
+
+toolname=default
+while test $$# -gt 0 ; do
+  case "$$1" in
+    --tool=*)
+      toolname="$${1:7}"
+      shift
+      ;;
+    --*)
+      usage
+      ;;
+    *)
+      break
+      ;;
+  esac
+done
+
+if test $$# -eq 0 ; then
+  usage
+fi
+
+case "$$toolname" in
+  default)
+    exec $(subst $(common-objdir),"$${builddir}", $(test-program-prefix)) \
+      $${1+"$$@"}
+    ;;
+  strace)
+    exec strace $(patsubst %, -E%, $(run-program-env)) \
+      $(test-via-rtld-prefix) $${1+"$$@"}
+    ;;
+  valgrind)
+    exec env $(run-program-env) valgrind $(test-via-rtld-prefix) $${1+"$$@"}
+    ;;
+  *)
+    usage
+    ;;
+esac
+endef
 
 # This is a handy script for running any dynamically linked program against
 # the current libc build for testing.
 $(common-objpfx)testrun.sh: $(common-objpfx)config.make \
 			    $(..)Makeconfig $(..)Makefile
-	(echo '#!/bin/sh'; \
-	 echo 'builddir=`dirname "$$0"`'; \
-	 echo 'GCONV_PATH="$${builddir}/iconvdata" \'; \
-	 echo 'exec $(subst $(common-objdir),"$${builddir}",\
-			    $(test-program-prefix)) $${1+"$$@"}'; \
-	) > $@T
+	$(file >$@T, $(testrun-script))
 	chmod a+x $@T
 	mv -f $@T $@
 postclean-generated += testrun.sh