summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Daniil Riazanovskiy <riazanovskiy@google.com> 2020-10-05 15:07:15 +0000
committer Nicolas Geoffray <ngeoffray@google.com> 2020-10-12 08:23:13 +0000
commitbfe8fc80767511676eae739e0924377dfc6c6089 (patch)
tree266db200bfb812ebe6b5ed9ab3ab9accb67081fe
parent7e9fc9d6d1622192f118bab771784eedfb66c60e (diff)
Restore cfg file printing in Checker as an option
Test: run checker with test that is expected to fail Change-Id: I14ca5e6bed38e2677cdf4b2eb4b79a6594af6f13
-rwxr-xr-xtest/run-test1
-rwxr-xr-xtools/checker/checker.py17
-rw-r--r--tools/checker/file_format/c1visualizer/parser.py10
-rw-r--r--tools/checker/file_format/c1visualizer/struct.py7
-rw-r--r--tools/checker/match/file.py21
5 files changed, 36 insertions, 20 deletions
diff --git a/test/run-test b/test/run-test
index 86d30d526f..72218324a5 100755
--- a/test/run-test
+++ b/test/run-test
@@ -928,6 +928,7 @@ if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
fi
run_args+=(-Xcompiler-option "--dump-cfg=$cfg_output_dir/$cfg_output" -Xcompiler-option -j1)
+ checker_args="$checker_args --print-cfg"
fi
fi
fi
diff --git a/tools/checker/checker.py b/tools/checker/checker.py
index 65b01a7f15..ad4cdd2e5f 100755
--- a/tools/checker/checker.py
+++ b/tools/checker/checker.py
@@ -39,19 +39,23 @@ def ParseArguments():
help="Run tests for the specified target architecture.")
parser.add_argument("--debuggable", action="store_true",
help="Run tests for debuggable code.")
+ parser.add_argument("--print-cfg", action="store_true", default="True", dest="print_cfg",
+ help="Print the whole cfg file in case of test failure (default)")
+ parser.add_argument("--no-print-cfg", action="store_false", default="True", dest="print_cfg",
+ help="Don't print the whole cfg file in case of test failure")
parser.add_argument("-q", "--quiet", action="store_true",
help="print only errors")
return parser.parse_args()
def ListPasses(outputFilename):
- c1File = ParseC1visualizerStream(os.path.basename(outputFilename), open(outputFilename, "r"))
+ c1File = ParseC1visualizerStream(outputFilename, open(outputFilename, "r"))
for compiler_pass in c1File.passes:
Logger.log(compiler_pass.name)
def DumpPass(outputFilename, passName):
- c1File = ParseC1visualizerStream(os.path.basename(outputFilename), open(outputFilename, "r"))
+ c1File = ParseC1visualizerStream(outputFilename, open(outputFilename, "r"))
compiler_pass = c1File.findPass(passName)
if compiler_pass:
maxLineNo = compiler_pass.startLineNo + len(compiler_pass.body)
@@ -85,14 +89,14 @@ def FindCheckerFiles(path):
Logger.fail("Source path \"" + path + "\" not found")
-def RunTests(checkPrefix, checkPath, outputFilename, targetArch, debuggableMode):
- c1File = ParseC1visualizerStream(os.path.basename(outputFilename), open(outputFilename, "r"))
+def RunTests(checkPrefix, checkPath, outputFilename, targetArch, debuggableMode, printCfg):
+ c1File = ParseC1visualizerStream(outputFilename, open(outputFilename, "r"))
for checkFilename in FindCheckerFiles(checkPath):
checkerFile = ParseCheckerStream(os.path.basename(checkFilename),
checkPrefix,
open(checkFilename, "r"),
targetArch)
- MatchFiles(checkerFile, c1File, targetArch, debuggableMode)
+ MatchFiles(checkerFile, c1File, targetArch, debuggableMode, printCfg)
if __name__ == "__main__":
@@ -106,4 +110,5 @@ if __name__ == "__main__":
elif args.dump_pass:
DumpPass(args.tested_file, args.dump_pass)
else:
- RunTests(args.check_prefix, args.source_path, args.tested_file, args.arch, args.debuggable)
+ RunTests(args.check_prefix, args.source_path, args.tested_file, args.arch, args.debuggable,
+ args.print_cfg)
diff --git a/tools/checker/file_format/c1visualizer/parser.py b/tools/checker/file_format/c1visualizer/parser.py
index a31bc565e6..b25d2b2f92 100644
--- a/tools/checker/file_format/c1visualizer/parser.py
+++ b/tools/checker/file_format/c1visualizer/parser.py
@@ -96,12 +96,16 @@ def __parseC1Line(c1File, line, lineNo, state, fileName):
else:
Logger.fail("C1visualizer line not inside a group", fileName, lineNo)
+
def ParseC1visualizerStream(fileName, stream):
c1File = C1visualizerFile(fileName)
state = C1ParserState()
- fnProcessLine = lambda line, lineNo: __parseC1Line(c1File, line, lineNo, state, fileName)
- fnLineOutsideChunk = lambda line, lineNo: \
- Logger.fail("C1visualizer line not inside a group", fileName, lineNo)
+
+ def fnProcessLine(line, lineNo):
+ return __parseC1Line(c1File, line, lineNo, state, c1File.baseFileName)
+
+ def fnLineOutsideChunk(line, lineNo):
+ Logger.fail("C1visualizer line not inside a group", c1File.baseFileName, lineNo)
for passName, passLines, startLineNo, testArch in \
SplitStream(stream, fnProcessLine, fnLineOutsideChunk):
C1visualizerPass(c1File, passName, passLines, startLineNo + 1)
diff --git a/tools/checker/file_format/c1visualizer/struct.py b/tools/checker/file_format/c1visualizer/struct.py
index 21036da213..5925da96c5 100644
--- a/tools/checker/file_format/c1visualizer/struct.py
+++ b/tools/checker/file_format/c1visualizer/struct.py
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import os
+
from common.immutables import ImmutableDict
from common.logger import Logger
from common.mixins import PrintableMixin
@@ -19,7 +21,8 @@ from common.mixins import PrintableMixin
class C1visualizerFile(PrintableMixin):
def __init__(self, fileName):
- self.fileName = fileName
+ self.baseFileName = os.path.basename(fileName)
+ self.fullFileName = fileName
self.passes = []
self.instructionSetFeatures = ImmutableDict()
@@ -58,7 +61,7 @@ class C1visualizerPass(PrintableMixin):
@property
def fileName(self):
- return self.parent.fileName
+ return self.parent.baseFileName
def __eq__(self, other):
return isinstance(other, self.__class__) \
diff --git a/tools/checker/match/file.py b/tools/checker/match/file.py
index 4a0923caec..1f686667ac 100644
--- a/tools/checker/match/file.py
+++ b/tools/checker/match/file.py
@@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from collections import namedtuple
-from common.immutables import ImmutableDict
-from common.logger import Logger
-from file_format.c1visualizer.struct import C1visualizerFile, C1visualizerPass
-from file_format.checker.struct import CheckerFile, TestCase, TestStatement
-from match.line import MatchLines, EvaluateLine
+from collections import namedtuple
+
+from common.immutables import ImmutableDict
+from common.logger import Logger
+from file_format.checker.struct import TestStatement
+from match.line import MatchLines, EvaluateLine
MatchScope = namedtuple("MatchScope", ["start", "end"])
MatchInfo = namedtuple("MatchInfo", ["scope", "variables"])
@@ -324,7 +324,7 @@ def MatchTestCase(testCase, c1Pass, instructionSetFeatures):
for statement in testStatements:
state.handle(statement)
-def MatchFiles(checkerFile, c1File, targetArch, debuggableMode):
+def MatchFiles(checkerFile, c1File, targetArch, debuggableMode, printCfg):
for testCase in checkerFile.testCases:
if testCase.testArch not in [None, targetArch]:
continue
@@ -336,10 +336,10 @@ def MatchFiles(checkerFile, c1File, targetArch, debuggableMode):
# match a check group against the first output group of the same name.
c1Pass = c1File.findPass(testCase.name)
if c1Pass is None:
- with file(c1File.fileName) as cfgFile:
+ with file(c1File.fullFileName) as cfgFile:
Logger.log(''.join(cfgFile), Logger.Level.Error)
Logger.fail("Test case not found in the CFG file",
- testCase.fileName, testCase.startLineNo, testCase.name)
+ testCase.fullFileName, testCase.startLineNo, testCase.name)
Logger.startTest(testCase.name)
try:
@@ -352,4 +352,7 @@ def MatchFiles(checkerFile, c1File, targetArch, debuggableMode):
else:
msg = "Statement could not be matched starting from line {}"
msg = msg.format(lineNo)
+ if printCfg:
+ with file(c1File.fullFileName) as cfgFile:
+ Logger.log(''.join(cfgFile), Logger.Level.Error)
Logger.testFailed(msg, e.statement, e.variables)