File indexing completed on 2024-05-05 05:41:37
0001 #!/usr/bin/env python2 0002 0003 import sys, os, json, argparse 0004 0005 JSON_CONFIG_FILENAME = os.path.dirname(sys.argv[0]) + '/conf.json' 0006 MAKEFLAGS = "-j12" 0007 BRANCH = 'master' 0008 BUILD_SCRIPT = '/root/clazy/tests/docker/build-clazy.sh' 0009 0010 class DockerTest: 0011 def __init__(self, name, url): 0012 self.name = name 0013 self.url = url 0014 self.ignore_checks = 'none' 0015 self.llvm_root = 'none' 0016 self.extra_cmake_args = 'none' 0017 0018 def read_json_config(): 0019 dockerTests = [] 0020 0021 if not os.path.exists(JSON_CONFIG_FILENAME): 0022 print "File doesn't exist %s" % (JSON_CONFIG_FILENAME) 0023 return [] 0024 0025 f = open(JSON_CONFIG_FILENAME, 'r') 0026 contents = f.read() 0027 f.close() 0028 decoded = json.loads(contents) 0029 if 'tests' in decoded: 0030 tests = decoded['tests'] 0031 for test in tests: 0032 if 'name' in test and 'url' in test: 0033 dockerTest = DockerTest(test['name'], test['url']) 0034 if 'llvm_root' in test: 0035 dockerTest.llvm_root = test['llvm_root'] 0036 if 'extra_cmake_args' in test: 0037 dockerTest.extra_cmake_args = test['extra_cmake_args'] 0038 if 'ignore_checks' in test: 0039 dockerTest.ignore_checks = test['ignore_checks'] 0040 0041 dockerTests.append(dockerTest) 0042 return dockerTests 0043 0044 0045 0046 def run_test(dockerTest): 0047 cmd = 'docker run -i -t %s sh %s %s %s %s %s %s' % (dockerTest.url, BUILD_SCRIPT, BRANCH, MAKEFLAGS, dockerTest.ignore_checks, dockerTest.llvm_root, dockerTest.extra_cmake_args) 0048 print cmd 0049 return os.system(cmd) == 0 0050 0051 0052 dockerTests = read_json_config() 0053 0054 0055 parser = argparse.ArgumentParser() 0056 parser.add_argument("-b", "--branch") 0057 parser.add_argument("docker_names", nargs='*', help="Names of the containers to run. Defaults to running all docker containers.") 0058 0059 args = parser.parse_args() 0060 0061 if args.branch is None: 0062 BRANCH = 'master' 0063 else: 0064 BRANCH = args.branch 0065 0066 results = {} 0067 success = True 0068 for test in dockerTests: 0069 if args.docker_names and test.name not in args.docker_names: 0070 continue 0071 0072 results[test.name] = run_test(test) 0073 success = success and results[test.name] 0074 0075 if success: 0076 print "Success!" 0077 else: 0078 for testname in results.keys(): 0079 if not results[testname]: 0080 print "Test %s failed!" % testname 0081 0082 sys.exit(0 if success else 1)