brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · b4c1b92 Raw
41 lines · python
1import os2import configparser3 4import lit.formats5import lit.Test6 7 8class DummyFormat(lit.formats.FileBasedTest):9    def execute(self, test, lit_config):10        # In this dummy format, expect that each test file is actually just a11        # .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        # Load additional metrics.24        for key, value_str in cfg.items("results"):25            value = eval(value_str)26            metric = lit.Test.toMetricValue(value)27            if isinstance(value, int):28                assert isinstance(metric, lit.Test.IntMetricValue)29                assert metric.format() == lit.Test.IntMetricValue(value).format()30            elif isinstance(value, float):31                assert isinstance(metric, lit.Test.RealMetricValue)32                assert metric.format() == lit.Test.RealMetricValue(value).format()33            elif isinstance(value, str):34                assert isinstance(metric, lit.Test.JSONMetricValue)35                assert metric.format() == lit.Test.JSONMetricValue(value).format()36            else:37                raise RuntimeError("unsupported result type")38            result.addMetric(key, metric)39 40        return result41