Debian Codegraph @

llvm/utils/lit/tests/Inputs/xunit-output/dummy_format.py

raw
1 import os
2 import configparser
3
4 import lit.formats
5 import lit.Test
6
7
8 class DummyFormat(lit.formats.FileBasedTest):
9 def execute(self, test, lit_config):
10 # In this dummy format, expect that each test file is actually just a
11 # .ini format dump of the results to report.
12
13 source_path = test.getSourcePath()
14
15 cfg = configparser.ConfigParser()
16 cfg.read(source_path)
17
18 # Create the basic test result.
19 result_code = cfg.get("global", "result_code")
20 result_output = cfg.get("global", "result_output")
21 result = lit.Test.Result(getattr(lit.Test, result_code), result_output)
22
23 if cfg.has_option("global", "required_feature"):
24 required_feature = cfg.get("global", "required_feature")
25 if required_feature:
26 test.requires.append(required_feature)
27
28 # Load additional metrics.
29 for key, value_str in cfg.items("results"):
30 value = eval(value_str)
31 if isinstance(value, int):
32 metric = lit.Test.IntMetricValue(value)
33 elif isinstance(value, float):
34 metric = lit.Test.RealMetricValue(value)
35 else:
36 raise RuntimeError("unsupported result type")
37 result.addMetric(key, metric)
38
39 return result