1 # -*- coding: utf-8 -*- 2 # The LLVM Compiler Infrastructure 3 # 4 # This file is distributed under the University of Illinois Open Source 5 # License. See LICENSE.TXT for details. 6 7 import libear 8 import unittest 9 10 import os.path 11 import subprocess 12 import json 13 14 15 def run(source_dir, target_dir): 16 def execute(cmd): 17 return subprocess.check_call(cmd, 18 cwd=target_dir, 19 stdout=subprocess.PIPE, 20 stderr=subprocess.STDOUT) 21 22 execute(['cmake', source_dir]) 23 execute(['make']) 24 25 result_file = os.path.join(target_dir, 'result.json') 26 expected_file = os.path.join(target_dir, 'expected.json') 27 execute(['intercept-build', '--cdb', result_file, './exec', 28 expected_file]) 29 return (expected_file, result_file) 30 31 32 class ExecAnatomyTest(unittest.TestCase): 33 def assertEqualJson(self, expected, result): 34 def read_json(filename): 35 with open(filename) as handler: 36 return json.load(handler) 37 38 lhs = read_json(expected) 39 rhs = read_json(result) 40 for item in lhs: 41 self.assertTrue(rhs.count(item)) 42 for item in rhs: 43 self.assertTrue(lhs.count(item)) 44 45 def test_all_exec_calls(self): 46 this_dir, _ = os.path.split(__file__) 47 source_dir = os.path.normpath(os.path.join(this_dir, '..', 'exec')) 48 with libear.TemporaryDirectory() as tmp_dir: 49 expected, result = run(source_dir, tmp_dir) 50 self.assertEqualJson(expected, result) 51