git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How do I run tests under Valgrind?

From
Stefano Lattarini <stefano.lattarini@gmail.com>
Date
Sep 22, 2012, 13:03 UTC
Message-ID
<505DB73E.2020108@gmail.com>
In-Reply-To
<20120921204907.GA22977@sigill.intra.peff.net>
On 09/21/2012 10:49 PM, Jeff King wrote:
Show 6 quoted lines
>
> Oh. It sounds like setting $SHELL to zsh is really the problem, then. If
> it is not Bourne-compatible when called as "zsh", then it really should
> be called in a way that turns on compatibility mode (bash will do this
> when called as "sh", but you can also do it with "bash --posix").
>

AFAIK, if Zsh is called as "sh", it too will run in Bourne compatibility mode; not sure how to force this compatibility from the command line though (albeit I'd guess there is some way to do so).

As further reference, here is the trick autoconf uses to (try to) put Zsh in Bourne compatibility mode after it has been invoked:

    if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
       emulate sh
       NULLCMD=:
       # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
       # is contrary to our usage.  Disable this feature.
       alias -g '${1+"$@"}'='"$@"'
       setopt NO_GLOB_SUBST
    fi

You might think to use something like that in 't/test-lib.sh' (and other "shell libraries" of the testsuite), but sadly that would not be enough; this excerpt from the Automake suite shows why:

   # If Zsh is not started directly in POSIX-compatibility mode, it has some
   # incompatibilities in the handling of $0 that conflict with our usage;
   # i.e., $0 inside a file sourced with the '.' builtin is temporarily set
   # to the name of the sourced file.  Work around that.  The apparently
   # useless 'eval' here is needed by at least dash 0.5.2, to prevent it
   # from bailing out with an error like "Syntax error: Bad substitution".
   # Note that a bug in some versions of Zsh prevents us from resetting $0
   # in a sourced script, so the use of $argv0.  For more info see:
   #  <http://www.zsh.org/mla/workers/2009/msg01140.html>
   eval 'argv0=${functrace[-1]%:*}' && test -f "$argv0" || {
     echo "Cannot determine the path of running test script." >&2
     echo "Your Zsh (version $ZSH_VERSION) is probably too old." >&2
     exit 99
   }

Since I see that '$0' is used in (at least) 't/perf/perf-lib.sh' and 't/test-lib.sh', you'd need to copy the snippet above (or write an equivalent one) in those files, and change them to use '$argv0' instead of '$0' in few (but not all) places. Not sure whether it's worth it though -- given that you seems to have solved the issue already with a simpler change, I'd say it's not.

Regards,
  Stefano
Previous: Jeff KingNext: Jeff King
Message 17 of 37 in “How do I run tests under Valgrind?”
  1. Ramkumar RamachandraSep 17, 2012
  2. Jeff KingSep 17, 2012
  3. Ramkumar RamachandraSep 17, 2012
  4. Jeff KingSep 17, 2012
  5. Ramkumar RamachandraSep 17, 2012
  6. Jeff KingSep 17, 2012
  7. Johannes SixtSep 17, 2012
  8. Jeff KingSep 17, 2012
  9. Ramkumar RamachandraSep 17, 2012
  10. Jeff KingSep 17, 2012
  11. Ramkumar RamachandraSep 21, 2012
  12. Ramkumar RamachandraSep 21, 2012
  13. Stefano LattariniSep 21, 2012
  14. Ramkumar RamachandraSep 21, 2012
  15. Ramkumar RamachandraSep 21, 2012
  16. Jeff KingSep 21, 2012
  17. Stefano LattariniSep 22, 2012
  18. Jeff KingSep 22, 2012
  19. Stefano LattariniSep 22, 2012
  20. Junio C HamanoSep 22, 2012
  21. t/test-lib.sh: do not trust $SHELLRamkumar Ramachandra, Sep 21, 2012
  22. Jeff KingSep 21, 2012
  23. Ramkumar RamachandraSep 21, 2012
  24. Jeff KingSep 21, 2012
  25. Ramkumar RamachandraSep 21, 2012
  26. Andreas SchwabSep 21, 2012
  27. Junio C HamanoSep 21, 2012
  28. Ramkumar RamachandraSep 22, 2012
  29. Junio C HamanoSep 22, 2012
  30. Ramkumar RamachandraSep 22, 2012
  31. Ramkumar RamachandraSep 22, 2012
  32. Junio C HamanoSep 22, 2012
  33. Ramkumar RamachandraSep 26, 2012
  34. Junio C HamanoSep 21, 2012
  35. Jeff KingSep 21, 2012
  36. Andreas SchwabSep 21, 2012
  37. Jeff KingSep 21, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.