[llvm] r272021 - [lit] Improve logging with file redirection.
Michael Spencer via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 7 12:56:36 PDT 2016
On Tue, Jun 7, 2016 at 9:13 AM, Daniel Dunbar via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: ddunbar
> Date: Tue Jun 7 11:13:40 2016
> New Revision: 272021
>
> URL: http://llvm.org/viewvc/llvm-project?rev=272021&view=rev
> Log:
> [lit] Improve logging with file redirection.
>
> - This will cause lit to automatically include the first 1K of data in
> redirected output files when a command fails (previously if the command
> failed, but the main point of the test was, say, a `FileCheck` later on, then
> the log wasn't helpful in showing why the command failed).
>
> Modified:
> llvm/trunk/utils/lit/lit/TestRunner.py
> llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt
> llvm/trunk/utils/lit/tests/shtest-output-printing.py
> llvm/trunk/utils/lit/tests/shtest-shell.py
>
> Modified: llvm/trunk/utils/lit/lit/TestRunner.py
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=272021&r1=272020&r2=272021&view=diff
> ==============================================================================
> --- llvm/trunk/utils/lit/lit/TestRunner.py (original)
> +++ llvm/trunk/utils/lit/lit/TestRunner.py Tue Jun 7 11:13:40 2016
> @@ -113,12 +113,14 @@ class TimeoutHelper(object):
> class ShellCommandResult(object):
> """Captures the result of an individual command."""
>
> - def __init__(self, command, stdout, stderr, exitCode, timeoutReached):
> + def __init__(self, command, stdout, stderr, exitCode, timeoutReached,
> + outputFiles = []):
> self.command = command
> self.stdout = stdout
> self.stderr = stderr
> self.exitCode = exitCode
> self.timeoutReached = timeoutReached
> + self.outputFiles = list(outputFiles)
>
> def executeShCmd(cmd, shenv, results, timeout=0):
> """
> @@ -268,7 +270,7 @@ def _executeShCmd(cmd, shenv, results, t
> # FIXME: Actually, this is probably an instance of PR6753.
> if r[1] == 'a':
> r[2].seek(0, 2)
> - opened_files.append(r[2])
> + opened_files.append(tuple(r) + (redir_filename,))
> result = r[2]
> final_redirects.append(result)
>
> @@ -342,7 +344,7 @@ def _executeShCmd(cmd, shenv, results, t
> # need to release any handles we may have on the temporary files (important
> # on Win32, for example). Since we have already spawned the subprocess, our
> # handles have already been transferred so we do not need them anymore.
> - for f in opened_files:
> + for (name, mode, f, path) in opened_files:
> f.close()
>
> # FIXME: There is probably still deadlock potential here. Yawn.
> @@ -393,8 +395,21 @@ def _executeShCmd(cmd, shenv, results, t
> except:
> err = str(err)
>
> + # Gather the redirected output files.
> + output_files = []
> + for (name, mode, f, path) in sorted(opened_files):
> + if mode in ('w', 'a'):
> + try:
> + with open(path) as f:
> + data = f.read()
> + except:
> + data = None
> + if data != None:
> + output_files.append((name, path, data))
> +
> results.append(ShellCommandResult(
> - cmd.commands[i], out, err, res, timeoutHelper.timeoutReached()))
> + cmd.commands[i], out, err, res, timeoutHelper.timeoutReached(),
> + output_files))
> if cmd.pipe_err:
> # Python treats the exit code as a signed char.
> if exitCode is None:
> @@ -455,6 +470,19 @@ def executeScriptInternal(test, litConfi
> continue
>
> # Otherwise, something failed or was printed, show it.
> +
> + # Add the command output, if redirected.
> + for (name, path, data) in result.outputFiles:
> + if data.strip():
> + out += "# redirected output from %r:\n" % (name,)
> + data = to_string(data.decode('utf-8'))
> + if len(data) > 1024:
> + out += data[:1024] + "\n...\n"
> + out += "note: data was truncated\n"
> + else:
> + out += data
> + out += "\n"
> +
> if result.stdout.strip():
> out += '# command output:\n%s\n' % (result.stdout,)
> if result.stderr.strip():
>
> Modified: llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt?rev=272021&r1=272020&r2=272021&view=diff
> ==============================================================================
> --- llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt (original)
> +++ llvm/trunk/utils/lit/tests/Inputs/shtest-output-printing/basic.txt Tue Jun 7 11:13:40 2016
> @@ -1,3 +1,3 @@
> # RUN: true
> # RUN: echo hi
> -# RUN: false
> +# RUN: wc missing-file &> %t.out
>
> Modified: llvm/trunk/utils/lit/tests/shtest-output-printing.py
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/shtest-output-printing.py?rev=272021&r1=272020&r2=272021&view=diff
> ==============================================================================
> --- llvm/trunk/utils/lit/tests/shtest-output-printing.py (original)
> +++ llvm/trunk/utils/lit/tests/shtest-output-printing.py Tue Jun 7 11:13:40 2016
> @@ -1,7 +1,7 @@
> # Check the various features of the ShTest format.
> #
> # RUN: not %{lit} -j 1 -v %{inputs}/shtest-output-printing > %t.out
> -# RUN: FileCheck < %t.out %s
> +# RUN: FileCheck --input-file %t.out %s
> #
> # END.
>
> @@ -21,6 +21,8 @@
> # CHECK-NEXT: # command output:
> # CHECK-NEXT: hi
> #
> -# CHECK: $ "false"
> -# CHECK-NEXT: note: command had no output on stdout or stderr
> +# CHECK: $ "wc" "missing-file"
> +# CHECK-NEXT: # redirected output from '{{.*}}/basic.txt.tmp.out':
> +# CHECK-NEXT: missing-file{{.*}} No such file or directory
> +# CHECK: note: command had no output on stdout or stderr
> # CHECK-NEXT: error: command failed with exit status: 1
>
> Modified: llvm/trunk/utils/lit/tests/shtest-shell.py
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/shtest-shell.py?rev=272021&r1=272020&r2=272021&view=diff
> ==============================================================================
> --- llvm/trunk/utils/lit/tests/shtest-shell.py (original)
> +++ llvm/trunk/utils/lit/tests/shtest-shell.py Tue Jun 7 11:13:40 2016
> @@ -1,7 +1,7 @@
> # Check the internal shell handling component of the ShTest format.
> #
> # RUN: not %{lit} -j 1 -v %{inputs}/shtest-shell > %t.out
> -# RUN: FileCheck < %t.out %s
> +# RUN: FileCheck --input-file %t.out %s
> #
> # END.
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
This breaks for me for some tests with:
UnboundLocalError: local variable 'redir_filename' referenced before assignment
Python 2.7.10
Unresolved Tests (70):
Clang :: Analysis/inline-unique-reports.c
Clang :: CodeGenCXX/microsoft-abi-alignment-fail.cpp
Clang :: CodeGenCXX/microsoft-abi-non-virtual-base-ordering.cpp
Clang :: CodeGenCXX/microsoft-abi-rtti.cpp
Clang :: CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-vtordisps.cpp
Clang :: Driver/msc-version.c
Clang :: Format/multiple-inputs-error.cpp
Clang :: Frontend/optimization-remark.c
Clang :: Frontend/profile-sample-use-loc-tracking.c
Clang :: Frontend/stdin.c
Clang :: Integration/cocoa-pch.m
Clang :: Layout/itanium-union-bitfield.cpp
Clang :: Layout/ms-x86-alias-avoidance-padding.cpp
Clang :: Layout/ms-x86-aligned-tail-padding.cpp
Clang :: Layout/ms-x86-basic-layout.cpp
Clang :: Layout/ms-x86-bitfields-vbases.cpp
Clang :: Layout/ms-x86-declspec-empty_bases.cpp
Clang :: Layout/ms-x86-empty-base-after-base-with-vbptr.cpp
Clang :: Layout/ms-x86-empty-layout.c
Clang :: Layout/ms-x86-empty-nonvirtual-bases.cpp
Clang :: Layout/ms-x86-empty-virtual-base.cpp
Clang :: Layout/ms-x86-lazy-empty-nonvirtual-base.cpp
Clang :: Layout/ms-x86-misalignedarray.cpp
Clang :: Layout/ms-x86-pack-and-align.cpp
Clang :: Layout/ms-x86-primary-bases.cpp
Clang :: Layout/ms-x86-size-alignment-fail.cpp
Clang :: Layout/ms-x86-vfvb-alignment.cpp
Clang :: Layout/ms-x86-vfvb-sharing.cpp
Clang :: Layout/ms-x86-vtordisp.cpp
Clang :: Layout/ms_struct-bitfields.c
Clang :: Misc/serialized-diags-frontend.c
Clang :: Misc/serialized-diags-no-category.c
Clang :: Misc/serialized-diags-stable.c
Clang :: Misc/serialized-diags.c
Clang :: Misc/serialized-diags.m
Clang :: Modules/serialized-diags.m
Clang :: Preprocessor/include-directive1.c
Clang :: Preprocessor/include-directive3.c
Clang :: Preprocessor/init-v7k-compat.c
Clang :: Preprocessor/init.c
Clang :: Sema/ms_bitfield_layout.c
Clang :: Sema/ms_class_layout.cpp
LLVM :: Assembler/align-inst-alloca.ll
LLVM :: Assembler/align-inst-load.ll
LLVM :: Assembler/align-inst-store.ll
LLVM :: Bindings/llvm-c/add_named_metadata_operand.ll
LLVM :: Bindings/llvm-c/objectfile.ll
LLVM :: Bindings/llvm-c/set_metadata.ll
LLVM :: FileCheck/check-empty.txt
LLVM :: Linker/2002-07-17-LinkTest2.ll
LLVM :: Linker/2002-08-20-ConstantExpr.ll
LLVM :: Linker/2009-09-03-mdnode.ll
LLVM :: MC/AArch64/arm64-v128_lo-diagnostics.s
LLVM :: MC/AsmParser/floating-literals.s
LLVM :: MC/Mips/elf_eflags_micromips.s
LLVM :: Other/2009-09-14-function-elements.ll
LLVM :: Other/ResponseFile.ll
LLVM :: TableGen/BitsInitOverflow.td
LLVM :: tools/llvm-objdump/eh_frame-arm64.test
LLVM :: tools/llvm-objdump/eh_frame_zero_cie.test
LLVM :: tools/llvm-objdump/macho-exports-trie.test
LLVM :: tools/llvm-objdump/macho-unwind-info-arm64.test
LLVM :: tools/llvm-objdump/macho-unwind-info-no-relocs.test
LLVM :: tools/llvm-objdump/macho-unwind-info-x86_64.test
lld :: ELF/default-output.s
lld :: ELF/linkerscript-ouputformat.s
lld :: ELF/linkerscript-outputarch.s
lld :: ELF/warn-common.s
lld :: mach-o/image-base.yaml
lld :: mach-o/stack-size.yaml
- Michael Spencer
More information about the llvm-commits
mailing list