From f2873d2da0ac9802e0b570e8e0b9e7e04a82bf55 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 4 Jul 2018 15:27:24 +0200 Subject: testrun.sh: Implement --tool=strace, --tool=valgrind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $(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 --- Makefile | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'Makefile') 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 -- cgit 1.4.1