llvm.org GIT mirror llvm / c2a684a
[lit] Report line number for failed RUN command When debugging test failures with -vv (or -v in the case of the internal shell), this makes it easier to locate the RUN line that failed. For example, clang's test/Driver/linux-ld.c has 892 total RUN lines, and clang's test/Driver/arm-cortex-cpus.c has 424 RUN lines after concatenation for line continuations. When reading the generated shell script, this also makes it easier to locate the RUN line that produced each command. To support reporting RUN line numbers in the case of the internal shell, this patch extends the internal shell to support the null command, ":", except pipelines are not supported. Reviewed By: asmith, delcypher Differential Revision: https://reviews.llvm.org/D44598 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330755 91177308-0d34-0410-b5e6-96231b3b80d8 Joel E. Denny 1 year, 5 months ago
16 changed file(s) with 155 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
8484 Echo all commands to stdout, as they are being executed.
8585 This can be valuable for debugging test failures, as the last echoed command
8686 will be the one which has failed.
87 To help you find the source RUN line, :program:`lit` inserts a no-op ``:``
88 command with argument ``'RUN: at line N'`` before each command pipeline.
8789 This option implies ``--verbose``.
8890
8991 .. option:: -a, --show-all
788788 results.append(cmdResult)
789789 return cmdResult.exitCode
790790
791 if cmd.commands[0].args[0] == ':':
792 if len(cmd.commands) != 1:
793 raise InternalShellError(cmd.commands[0], "Unsupported: ':' "
794 "cannot be part of a pipeline")
795 results.append(ShellCommandResult(cmd.commands[0], '', '', 0, False))
796 return 0;
797
791798 procs = []
792799 default_stdin = subprocess.PIPE
793800 stderrTempFiles = []
13171324 def parseLine(self, line_number, line):
13181325 try:
13191326 self.parsed_lines += [(line_number, line)]
1320 self.value = self.parser(line_number, line, self.value)
1327 self.value = self.parser(line_number, line, self.value,
1328 self.keyword)
13211329 except ValueError as e:
13221330 raise ValueError(str(e) + ("\nin %s directive on test line %d" %
13231331 (self.keyword, line_number)))
13261334 return self.value
13271335
13281336 @staticmethod
1329 def _handleTag(line_number, line, output):
1337 def _handleTag(line_number, line, output, keyword):
13301338 """A helper for parsing TAG type keywords"""
13311339 return (not line.strip() or output)
13321340
13331341 @staticmethod
1334 def _handleCommand(line_number, line, output):
1342 def _handleCommand(line_number, line, output, keyword):
13351343 """A helper for parsing COMMAND type keywords"""
13361344 # Trim trailing whitespace.
13371345 line = line.rstrip()
13501358 else:
13511359 if output is None:
13521360 output = []
1361 line = ": '{keyword} at line {line}'; {real_command}".format(
1362 keyword=keyword,
1363 line=line_number,
1364 real_command=line)
13531365 output.append(line)
13541366 return output
13551367
13561368 @staticmethod
1357 def _handleList(line_number, line, output):
1369 def _handleList(line_number, line, output, keyword):
13581370 """A parser for LIST type keywords"""
13591371 if output is None:
13601372 output = []
13621374 return output
13631375
13641376 @staticmethod
1365 def _handleBooleanExpr(line_number, line, output):
1377 def _handleBooleanExpr(line_number, line, output, keyword):
13661378 """A parser for BOOLEAN_EXPR type keywords"""
13671379 if output is None:
13681380 output = []
13751387 return output
13761388
13771389 @staticmethod
1378 def _handleRequiresAny(line_number, line, output):
1390 def _handleRequiresAny(line_number, line, output, keyword):
13791391 """A custom parser to transform REQUIRES-ANY: into REQUIRES:"""
13801392
13811393 # Extract the conditions specified in REQUIRES-ANY: as written.
13821394 conditions = []
1383 IntegratedTestKeywordParser._handleList(line_number, line, conditions)
1395 IntegratedTestKeywordParser._handleList(line_number, line, conditions,
1396 keyword)
13841397
13851398 # Output a `REQUIRES: a || b || c` expression in its place.
13861399 expression = ' || '.join(conditions)
1387 IntegratedTestKeywordParser._handleBooleanExpr(line_number,
1388 expression, output)
1400 IntegratedTestKeywordParser._handleBooleanExpr(line_number, expression,
1401 output, keyword)
13891402 return output
13901403
13911404 def parseIntegratedTestScript(test, additional_parsers=[],
0 # RUN: : first line continued \
1 # RUN: to second line
2 # RUN: echo 'foo bar' \
3 # RUN: | FileCheck %s
4 # RUN: echo \
5 # RUN: 'foo baz' \
6 # RUN: | FileCheck %s
7 # RUN: echo 'foo bar' \
8 # RUN: | FileCheck %s
9
10 # CHECK: foo bar
0 import lit.formats
1 config.test_format = lit.formats.ShTest(execute_external=True)
0 # RUN: : first line continued \
1 # RUN: to second line
2 # RUN: echo 'foo bar' \
3 # RUN: | FileCheck %s
4 # RUN: echo \
5 # RUN: 'foo baz' \
6 # RUN: | FileCheck %s
7 # RUN: echo 'foo bar' \
8 # RUN: | FileCheck %s
9
10 # CHECK: foo bar
0 import lit.formats
1 config.test_format = lit.formats.ShTest(execute_external=False)
0 import lit.formats
1 config.name = 'shtest-run-at-line'
2 config.suffixes = ['.txt']
0 # Check error on an unsupported ":". (cannot be part of a pipeline)
1 #
2 # RUN: : | echo "hello"
77 #
88 # END.
99
10 # CHECK: Failing Tests (26)
10 # CHECK: Failing Tests (27)
1111 # CHECK: Failing Tests (1)
1212 # CHECK: Failing Tests (2)
1313 # CHECK: error: Setting --max-failures to 0 does not have any effect.
3838 #
3939 # CHECK: Command Output (stdout):
4040 # CHECK-NEXT: --
41 # CHECK-NEXT: $ ":" "RUN: at line 1"
4142 # CHECK-NEXT: $ "printf"
4243 # CHECK-NEXT: # command output:
4344 # CHECK-NEXT: line 1: failed test output on stdout
1515 #
1616 # CHECK: Command Output
1717 # CHECK-NEXT: --
18 # CHECK-NEXT: $ ":" "RUN: at line 1"
1819 # CHECK-NEXT: $ "true"
20 # CHECK-NEXT: $ ":" "RUN: at line 2"
1921 # CHECK-NEXT: $ "echo" "hi"
2022 # CHECK-NEXT: # command output:
2123 # CHECK-NEXT: hi
2224 #
23 # CHECK: $ "wc" "missing-file"
25 # CHECK: $ ":" "RUN: at line 3"
26 # CHECK-NEXT: $ "wc" "missing-file"
2427 # CHECK-NEXT: # redirected output from '{{.*(/|\\\\)}}basic.txt.tmp.out':
2528 # CHECK-NEXT: missing-file{{.*}} No such file or directory
2629 # CHECK: note: command had no output on stdout or stderr
0 # Check that -vv makes the line number of the failing RUN command clear.
1 # (-v is actually sufficient in the case of the internal shell.)
2 #
3 # RUN: not %{lit} -j 1 -vv %{inputs}/shtest-run-at-line > %t.out
4 # RUN: FileCheck --input-file %t.out %s
5 #
6 # END.
7
8
9 # CHECK: Testing: 4 tests
10
11
12 # In the case of the external shell, we check for only RUN lines in stderr in
13 # case some shell implementations format "set -x" output differently.
14
15 # CHECK-LABEL: FAIL: shtest-run-at-line :: external-shell/basic.txt
16
17 # CHECK: Script:
18 # CHECK: : 'RUN: at line 1'; true
19 # CHECK-NEXT: : 'RUN: at line 2'; false
20 # CHECK-NEXT: : 'RUN: at line 3'; true
21
22 # CHECK: Command Output (stderr)
23 # CHECK: RUN: at line 1
24 # CHECK: RUN: at line 2
25 # CHECK-NOT: RUN
26
27 # CHECK-LABEL: FAIL: shtest-run-at-line :: external-shell/line-continuation.txt
28
29 # CHECK: Script:
30 # CHECK: : 'RUN: at line 1'; : first line continued to second line
31 # CHECK-NEXT: : 'RUN: at line 3'; echo 'foo bar' | FileCheck
32 # CHECK-NEXT: : 'RUN: at line 5'; echo 'foo baz' | FileCheck
33 # CHECK-NEXT: : 'RUN: at line 8'; echo 'foo bar' | FileCheck
34
35 # CHECK: Command Output (stderr)
36 # CHECK: RUN: at line 1
37 # CHECK: RUN: at line 3
38 # CHECK: RUN: at line 5
39 # CHECK-NOT: RUN
40
41
42 # CHECK-LABEL: FAIL: shtest-run-at-line :: internal-shell/basic.txt
43
44 # CHECK: Script:
45 # CHECK: : 'RUN: at line 1'; true
46 # CHECK-NEXT: : 'RUN: at line 2'; false
47 # CHECK-NEXT: : 'RUN: at line 3'; true
48
49 # CHECK: Command Output (stdout)
50 # CHECK: $ ":" "RUN: at line 1"
51 # CHECK-NEXT: $ "true"
52 # CHECK-NEXT: $ ":" "RUN: at line 2"
53 # CHECK-NEXT: $ "false"
54 # CHECK-NOT: RUN
55
56 # CHECK-LABEL: FAIL: shtest-run-at-line :: internal-shell/line-continuation.txt
57
58 # CHECK: Script:
59 # CHECK: : 'RUN: at line 1'; : first line continued to second line
60 # CHECK-NEXT: : 'RUN: at line 3'; echo 'foo bar' | FileCheck
61 # CHECK-NEXT: : 'RUN: at line 5'; echo 'foo baz' | FileCheck
62 # CHECK-NEXT: : 'RUN: at line 8'; echo 'foo bar' | FileCheck
63
64 # CHECK: Command Output (stdout)
65 # CHECK: $ ":" "RUN: at line 1"
66 # CHECK-NEXT: $ ":" "first" "line" "continued" "to" "second" "line"
67 # CHECK-NEXT: $ ":" "RUN: at line 3"
68 # CHECK-NEXT: $ "echo" "foo bar"
69 # CHECK-NEXT: $ "FileCheck" "{{.*}}"
70 # CHECK-NEXT: $ ":" "RUN: at line 5"
71 # CHECK-NEXT: $ "echo" "foo baz"
72 # CHECK-NEXT: $ "FileCheck" "{{.*}}"
73 # CHECK-NOT: RUN
2525 # CHECK: error: command failed with exit status: 1
2626 # CHECK: ***
2727
28 # CHECK: FAIL: shtest-shell :: colon-error.txt
29 # CHECK: *** TEST 'shtest-shell :: colon-error.txt' FAILED ***
30 # CHECK: $ ":"
31 # CHECK: # command stderr:
32 # CHECK: Unsupported: ':' cannot be part of a pipeline
33 # CHECK: error: command failed with exit status: 127
34 # CHECK: ***
35
2836 # CHECK: FAIL: shtest-shell :: diff-error-0.txt
2937 # CHECK: *** TEST 'shtest-shell :: diff-error-0.txt' FAILED ***
3038 # CHECK: $ "diff" "diff-error-0.txt" "diff-error-0.txt"
152160 #
153161 # CHECK: FAIL: shtest-shell :: error-1.txt
154162 # CHECK: *** TEST 'shtest-shell :: error-1.txt' FAILED ***
155 # CHECK: shell parser error on: 'echo "missing quote'
163 # CHECK: shell parser error on: ': \'RUN: at line 3\'; echo "missing quote'
156164 # CHECK: ***
157165
158166 # CHECK: FAIL: shtest-shell :: error-2.txt
218226 # CHECK: PASS: shtest-shell :: sequencing-0.txt
219227 # CHECK: XFAIL: shtest-shell :: sequencing-1.txt
220228 # CHECK: PASS: shtest-shell :: valid-shell.txt
221 # CHECK: Failing Tests (26)
229 # CHECK: Failing Tests (27)
4646
4747 @staticmethod
4848 def make_parsers():
49 def custom_parse(line_number, line, output):
49 def custom_parse(line_number, line, output, keyword):
5050 if output is None:
5151 output = []
5252 output += [part for part in line.split(' ') if part.strip()]
9898 cmd_parser = self.get_parser(parsers, 'MY_RUN:')
9999 value = cmd_parser.getValue()
100100 self.assertEqual(len(value), 2) # there are only two run lines
101 self.assertEqual(value[0].strip(), 'baz')
102 self.assertEqual(value[1].strip(), 'foo bar')
101 self.assertEqual(value[0].strip(), ": 'MY_RUN: at line 4'; baz")
102 self.assertEqual(value[1].strip(), ": 'MY_RUN: at line 7'; foo bar")
103103
104104 def test_custom(self):
105105 parsers = self.make_parsers()