bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27532: getprogname: support for qemu


From: Assaf Gordon
Subject: bug#27532: getprogname: support for qemu
Date: Thu, 29 Jun 2017 12:50:11 -0400

Hello Bruno and all,

> On Jun 29, 2017, at 12:26, Bruno Haible <address@hidden> wrote:
> 
> When running the testsuite of grep-3.0 with qemu user mode, some tests fail.
> [...]
> *** 1 ****
> ! grep: g:4: Unmatched [...
> --- 1 ----
> ! /tmp/grep-3.0/build-arm64/src/grep: g:4: Unmatched [...
> [...]
>     argv[0] = absolute file name of qemu-aarch64
>     argv[1] = absolute file name of grep (it must be absolute, since it's not
>               qemu's job to search for 'grep' in $PATH).

Luckily, many GNU test scripts already use "$prog" perl variable
for the program's name in error message, so perhaps it would be possible
to accomodate qemu without code changes.

I've encountered the same for my program (datamash).
and as an ugly hack added an undocumented option to print the program's name
to set '$prog' accordingly:
https://git.savannah.gnu.org/cgit/datamash.git/tree/tests/datamash-tests.pl#n37
  ## Cross-Compiling portability hack:
  ##  under qemu/binfmt, argv[0] (which is used to report errors) will contain
  ##  the full path of the binary, if the binary is on the $PATH.
  ##  So we try to detect what is the actual returned value of the program
  ##  in case of an error.
  my $prog = `$prog_bin ---print-progname`;
  $prog = $prog_bin unless $prog;


But this hack can be avoided, if we just run 'grep' with invalid
arguments, triggering an error, then extracting the program name from STDERR.

E.g. for 
https://git.savannah.gnu.org/cgit/grep.git/tree/tests/filename-lineno.pl
change the following on line 26 from:
    my $prog = 'grep';
to
    my $prog = 'grep';
    my $full_prog_name = `$prog --invalid-option-for-testing 2>&1 | head -n1 | 
cut -f1 -d:`;
    $prog = $full_prog_name if $full_prog_name;

This is untested code, but should work more-or-less.
Once "$prog" is updated, all the tests should pass.

Hope this helps,
regards,
 - assaf










reply via email to

[Prev in Thread] Current Thread [Next in Thread]