From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 6417A6DE0F76 for ; Tue, 25 Jun 2019 14:05:17 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.414 X-Spam-Level: X-Spam-Status: No, score=0.414 tagged_above=-999 required=5 tests=[AWL=-0.238, SPF_NEUTRAL=0.652] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nDg7NkFxpcRl for ; Tue, 25 Jun 2019 14:05:16 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by arlo.cworth.org (Postfix) with ESMTP id 8F8216DE0F66 for ; Tue, 25 Jun 2019 14:05:14 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 8240310019F; Wed, 26 Jun 2019 00:05:09 +0300 (EEST) From: Tomi Ollila To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH 1/2] test: provide machinery to make and use test_shims In-Reply-To: <20190526130854.8348-2-david@tethera.net> References: <20190526130854.8348-1-david@tethera.net> <20190526130854.8348-2-david@tethera.net> User-Agent: Notmuch/0.28.3+84~g41389bb (https://notmuchmail.org) Emacs/25.2.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2019 21:05:17 -0000 On Sun, May 26 2019, David Bremner wrote: > These can be used e.g. to override return values for functions, in > place of the existing scripting of gdb. > --- > test/test-lib.sh | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/test/test-lib.sh b/test/test-lib.sh > index ff18fae6..a423b7f4 100644 > --- a/test/test-lib.sh > +++ b/test/test-lib.sh > @@ -95,6 +95,8 @@ TEST_EMACSCLIENT=${TEST_EMACSCLIENT:-emacsclient} > TEST_GDB=${TEST_GDB:-gdb} > TEST_CC=${TEST_CC:-cc} > TEST_CFLAGS=${TEST_CFLAGS:-"-g -O0"} > +TEST_SHIM_CFLAGS=${TEST_SHIM_CFLAGS:-"-fpic -shared"} > +TEST_SHIM_LDFLAGS=${TEST_SHIM_LDFLAGS:-"-ldl"} > > # Protect ourselves from common misconfiguration to export > # CDPATH into the environment > @@ -1032,6 +1034,20 @@ test_C () { > notmuch_dir_sanitize OUTPUT.stdout OUTPUT.stderr > OUTPUT > } > > +make_shim () { > + base_name="$1" > + test_file="${base_name}.c" > + shim_file="${base_name}.so" > + cat > ${test_file} > + ${TEST_CC} ${TEST_CFLAGS} ${TEST_SHIM_CFLAGS} -I${NOTMUCH_SRCDIR}/test -I${NOTMUCH_SRCDIR}/lib -o ${shim_file} ${test_file} ${TEST_SHIM_LDFLAGS} > +} > + > +notmuch_with_shim () { > + base_name="$1" > + shift > + shim_file="${base_name}.so" > + LD_PRELOAD=./${shim_file} notmuch-shared "$@" LD_PRELOAD=./${shim_file}${LD_PRELOAD:+:$LD_PRELOAD} notmuch-shared "$@" So that if LD_PRELOAD is already set and is non-empty then ':' and its old value is appended to new value of LD_PRELOAD before this notmuch-shared invocation. Also I'm "insisting" that your patch 2/2 is updated based on id:8736kipe9f.fsf@fifthhorseman.net -- dkg had good opening how to improve robustness in `eval` executions, but since there are quite a few similar problems in code (i.e. and there are quite a few ways to improve it) IMO maintaining status quo we can this feature improved incrementally and choose how to fix *all* related problems... > +} --- above comment for this message -- below more on the test robustness --- part -- I was not supposed to write so long (and should have gone --- sleep an hour ago -- anyway if you read it all shout your opinion. One option, which is relatively easy to start using (when needed) while writing code is to use ${parameter@Q} transformation; from bash (4.4+) documentation: Q The expansion is a string that is the value of parameter quoted in a format that can be reused as input. ( that transforms e.g. foo'bar to 'foo'\''bar' ) Like hinted above, this would require that minimum bash version supported is 4.4. I did some linux distribution comparison and took gmime 3 along with it. Debian 9 (Stretch) has bash 4.4 -- and gmime 3.x Debian 8 (Jessie) as bash 4.3 -- but (only) gmime 2.6 (and if I used packages.debian.org correctly there is no backports either...) Ubuntu 18.04 (bionic) has bash 4.4 -- and gmime 3.x likewise, Ubuntu 16.04 (xenial) has neither (not even in backports) SO, in above cases, to compile current notmuch, gmime 3 has to be compiled separately. Then such user could also build newer bash... (and if there are 3rd party package repositories those can provide both...) I'd guess the situation is pretty much the same with other long-term supported distributions (centos 7 has bash 4.2, gmime 2.6 -- rhel/centos8 probably gmime30 3.2 and bash 4.4) Latest short-term, like Fedora -- and rolling release distributions, if those provide gmime 3.x those most probably have at least bash 4.4, if not 5.0, provided). I personally would like to use this feature; it is easy to add into scripts and pretty lean learning curve. I tried to do the same with bash syntax ${param//\'/\'\\\'\'}, but that looks more complicated -- and even more complicated to get it working right on bash 4.1 where the feature is a bit buggy when included inside double quotes ;( The downside could be that we get less testing due to some users not wanting to build newer bash (have to test whether it is hard so cannot say whether the time is right... BTW: tested ${var:q} on decade-old zsh (4.3.12 -- 2009-06-01), does the same. According to zsh changes file perhaps even version from 2001-06-01 has this feature.... And from https://mywiki.wooledge.org/BashFAQ/061 (which seems pretty good page to dig for features): ${var@spec} / 4.4 (2016) / mksh (2012) for the syntax, zsh (1990s) for the feature the feature could have been there even when I start using that shell ;D Tomi