1import subprocess
2import lit.util
3
4if not ('X86' in config.root.targets):
5    # We need support for X86.
6    config.unsupported = True
7
8elif not ('x86_64' in config.root.host_triple):
9    # We need to be running on an X86 host.
10    config.unsupported = True
11
12else:
13    # We need libpfm to be installed and the host to be support LBR format with cycles.
14    llvm_exegesis_exe = lit.util.which('llvm-exegesis', config.llvm_tools_dir)
15    if not llvm_exegesis_exe:
16        print('llvm-exegesis not found')
17        config.unsupported = True
18    else:
19      try:
20          with open(os.devnull, 'w') as quiet:
21              check_llvm_exegesis_latency_result = subprocess.call(
22                [llvm_exegesis_exe, '-mode', 'latency', '-x86-lbr-sample-period', '123', '-repetition-mode', 'loop', '-snippets-file', '/dev/null'], stdout=quiet, stderr=quiet)
23      except OSError:
24          print('could not exec llvm-exegesis')
25          config.unsupported = True
26      if not check_llvm_exegesis_latency_result == 0:
27        config.unsupported = True
28