1#!/usr/bin/python3 2 3import argparse 4import os 5import stat 6import subprocess 7import yaml 8import requests 9import time 10 11URL_RUNS="https://api.github.com/repos/{repo}/actions/runs?head-sha={head_sha}&head-branch={head_branch}&per_page=2" 12URL_RUN="https://api.github.com/repos/{repo}/actions/runs/{run_id}" 13 14def run_fluster(codec, test_suite, skips, single_thread): 15 print(f" {codec} -> {test_suite} (skip: {skips})") 16 cmd = ['python3', '/usr/bin/fluster_parser.py', '-ts', test_suite, '-d', f"ccdec-{codec}", '-t' '300'] 17 18 if single_thread: 19 cmd.extend(['-j', '1']) 20 if skips: 21 for index, skip in enumerate(skips): 22 cmd.extend(['-sv', skip] if not index else [skip]) 23 24 print(cmd) 25 subprocess.run(cmd, check=False) 26 27def retrieve_ccdec_github(sha, branch, repo, token): 28 if os.path.exists("/opt/cros-codecs/ccdec"): 29 os.environ['PATH'] = os.environ['PATH'] + ":/opt/cros-codecs" 30 return True 31 32 runs = requests.get(URL_RUNS.format(head_sha=sha, head_branch=branch, repo=repo), headers={"Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", "Authorization": f"Bearer {token}"}).json() 33 34 found = False 35 36 for run in runs['workflow_runs']: 37 if run['name'] != 'Health check': 38 continue 39 40 artifacts = requests.get(run['artifacts_url'], headers={"Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", "Authorization": f"Bearer {token}"}).json() 41 42 if artifacts['total_count'] == 0: 43 break 44 45 for artifact in artifacts['artifacts']: 46 if artifact['name'] != 'ccdec-bin': 47 continue 48 49 r = requests.get(artifact['archive_download_url'], headers={"Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", "Authorization": f"Bearer {token}"}, stream=True) 50 51 if not os.path.exists("/opt/cros-codecs"): 52 os.mkdir("/opt/cros-codecs") 53 54 with open("/opt/cros-codecs/ccdec.zip", 'wb') as fd: 55 for chunk in r.iter_content(chunk_size=128): 56 fd.write(chunk) 57 58 subprocess.run(['unzip', '/opt/cros-codecs/ccdec.zip', '-d', '/opt/cros-codecs/']) 59 os.chmod("/opt/cros-codecs/ccdec", mode=(stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)) 60 os.environ['PATH'] = os.environ['PATH'] + ":/opt/cros-codecs" 61 62 found = True 63 64 break 65 66 break 67 68 return found 69 70def retrieve_ccdec(run_id, repo, token): 71 # Retrieve built sha and branch 72 run = requests.get(URL_RUN.format(run_id=run_id, repo=repo), headers={"Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", "Authorization": f"Bearer {token}"}).json() 73 sha = run['head_sha'] 74 branch = run['head_branch'] 75 76 # Retrieve the artifact 77 for i in range(30): 78 try: 79 if retrieve_ccdec_github(sha, branch, repo, token): 80 break 81 time.sleep(10) 82 except Exception as e: 83 print(e) 84 85 86argparser = argparse.ArgumentParser() 87argparser.add_argument('--arch', choices=['amd', 'intel'], help='Architecture', required=True) 88argparser.add_argument('--config-file', help='Configuration file', required=True) 89argparser.add_argument('--ccdec-build-id', help='ccded binary build id', required=True) 90argparser.add_argument('--token', help='Github read token', required=True) 91argparser.add_argument('--repo', help='Github git repository', required=True) 92argparser.add_argument('--single', help='Run in a single thread', action='store_true') 93args = argparser.parse_args() 94 95retrieve_ccdec(args.ccdec_build_id, args.repo, args.token) 96 97with open(args.config_file, "r") as stream: 98 try: 99 config = yaml.safe_load(stream) 100 for arch, arch_info in config.items(): 101 if arch != args.arch: 102 continue 103 device_type=arch_info['device_type'] 104 for c in arch_info['codecs']: 105 for codec, test_suites in c.items(): 106 for ts in test_suites['test-suites']: 107 for test_suite in ts: 108 skips=ts[test_suite]["skip-vectors"] 109 run_fluster(codec, test_suite, skips, args.single) 110 break 111 except yaml.YAMLError as exc: 112 print(exc) 113