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