# -*- Python -*-

# Configuration file for the 'lit' test runner.

import os
import platform

import lit.formats
import lit.util

# name: The name of this test suite.
config.name = 'clang-taef'

# Check that the object root is known.
te = getattr(config, 'te', None)
if te is None:
    # Otherwise, we haven't loaded the site specific configuration (the user is
    # probably trying to run on a test file directly, and either the site
    # configuration hasn't been created by the build system, or we are in an
    # out-of-tree build situation).

    # Check for 'clang_taef_site_config' user parameter, and use that if available.
    site_cfg = lit_config.params.get('clang_taef_site_config', None)
    if site_cfg and os.path.exists(site_cfg):
        lit_config.load_config(config, site_cfg)
        raise SystemExit

# TAEF only runs on Windows
if platform.system() != 'Windows':
  config.unsupported = True
else:
  test_dll = os.path.join(config.llvm_obj_root, config.llvm_build_mode, 'bin', 'ClangHLSLTests.dll')

  hlsl_data_dir = os.path.join(config.llvm_src_root, 'tools', 'clang', 'test', 'HLSL')

  test_dir = os.path.join(config.llvm_obj_root, config.llvm_build_mode, 'test')

  param_hlsl_data_dir = str.format('/p:"HlslDataDir={}"', hlsl_data_dir)
  extra_params = [param_hlsl_data_dir]

  verbose = lit_config.params.get('verbose', None)
  if verbose == None:
      extra_params.append('/logOutput:"LowWithConsoleBuffering"')

  arch = getattr(config, 'taef_arch', None)
  arch_filter = str.format("@Architecture='{}'", arch)
  no_priority = lit_config.params.get('no_priority', None)
  if no_priority:
      select_filter = arch_filter
  else:
      priority_filter = "@Priority<1"
      select_filter = str.format("{} AND {}", priority_filter, arch_filter)

  config.test_format = lit.formats.TaefTest(config.te, test_dll, test_dir, select_filter, extra_params)
