brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · cdcbc1f Raw
48 lines · python
1# -*- coding: utf-8 -*-2# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3# See https://llvm.org/LICENSE.txt for license information.4# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5 6import libear7import unittest8 9import os.path10import subprocess11import json12 13 14def run(source_dir, target_dir):15    def execute(cmd):16        return subprocess.check_call(17            cmd, cwd=target_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT18        )19 20    execute(["cmake", source_dir])21    execute(["make"])22 23    result_file = os.path.join(target_dir, "result.json")24    expected_file = os.path.join(target_dir, "expected.json")25    execute(["intercept-build", "--cdb", result_file, "./exec", expected_file])26    return (expected_file, result_file)27 28 29class ExecAnatomyTest(unittest.TestCase):30    def assertEqualJson(self, expected, result):31        def read_json(filename):32            with open(filename) as handler:33                return json.load(handler)34 35        lhs = read_json(expected)36        rhs = read_json(result)37        for item in lhs:38            self.assertTrue(rhs.count(item))39        for item in rhs:40            self.assertTrue(lhs.count(item))41 42    def test_all_exec_calls(self):43        this_dir, _ = os.path.split(__file__)44        source_dir = os.path.abspath(os.path.join(this_dir, "..", "exec"))45        with libear.TemporaryDirectory() as tmp_dir:46            expected, result = run(source_dir, tmp_dir)47            self.assertEqualJson(expected, result)48