diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index a9f046c9d86c1..5370009596338 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -173,6 +173,19 @@ lit_config.note("\tUnset " + var) llvm_config.with_environment(var, "") + +# Temporarily modify environment to be the same that we use when running tests +class test_env: + def __enter__(self): + self.old_environ = dict(os.environ) + os.environ.clear() + os.environ.update(config.environment) + + def __exit__(self, exc_type, exc_value, exc_traceback): + os.environ.clear() + os.environ.update(self.old_environ) + + config.substitutions.append(("%sycl_libs_dir", config.sycl_libs_dir)) if platform.system() == "Windows": config.substitutions.append( @@ -263,10 +276,11 @@ def open_check_file(file_name): # check if compiler supports CL command line options cl_options = False -sp = subprocess.getstatusoutput(config.dpcpp_compiler + " /help") -if sp[0] == 0: - cl_options = True - config.available_features.add("cl_options") +with test_env(): + sp = subprocess.getstatusoutput(config.dpcpp_compiler + " /help") + if sp[0] == 0: + cl_options = True + config.available_features.add("cl_options") # check if the compiler was built in NDEBUG configuration has_ndebug = False @@ -321,14 +335,15 @@ def open_check_file(file_name): config.substitutions.append(("%level_zero_options", level_zero_options)) -sp = subprocess.getstatusoutput( - config.dpcpp_compiler + " -fsycl " + check_l0_file + level_zero_options -) -if sp[0] == 0: - config.available_features.add("level_zero_dev_kit") - config.substitutions.append(("%level_zero_options", level_zero_options)) -else: - config.substitutions.append(("%level_zero_options", "")) +with test_env(): + sp = subprocess.getstatusoutput( + config.dpcpp_compiler + " -fsycl " + check_l0_file + level_zero_options + ) + if sp[0] == 0: + config.available_features.add("level_zero_dev_kit") + config.substitutions.append(("%level_zero_options", level_zero_options)) + else: + config.substitutions.append(("%level_zero_options", "")) if lit_config.params.get("test-preview-mode", False): config.available_features.add("preview-mode") @@ -349,13 +364,14 @@ def open_check_file(file_name): file=fp, ) - sp = subprocess.getstatusoutput( - config.dpcpp_compiler - + " -fsycl -fpreview-breaking-changes " - + check_preview_breaking_changes_file - ) - if sp[0] == 0: - config.available_features.add("preview-breaking-changes-supported") + with test_env(): + sp = subprocess.getstatusoutput( + config.dpcpp_compiler + + " -fsycl -fpreview-breaking-changes " + + check_preview_breaking_changes_file + ) + if sp[0] == 0: + config.available_features.add("preview-breaking-changes-supported") # Check if clang is built with ZSTD and compression support. fPIC_opt = "-fPIC" if platform.system() != "Windows" else "" @@ -418,14 +434,15 @@ def open_check_file(file_name): config.substitutions.append(("%cuda_options", cuda_options)) -sp = subprocess.getstatusoutput( - config.dpcpp_compiler + " -fsycl " + check_cuda_file + cuda_options -) -if sp[0] == 0: - config.available_features.add("cuda_dev_kit") - config.substitutions.append(("%cuda_options", cuda_options)) -else: - config.substitutions.append(("%cuda_options", "")) +with test_env(): + sp = subprocess.getstatusoutput( + config.dpcpp_compiler + " -fsycl " + check_cuda_file + cuda_options + ) + if sp[0] == 0: + config.available_features.add("cuda_dev_kit") + config.substitutions.append(("%cuda_options", cuda_options)) + else: + config.substitutions.append(("%cuda_options", "")) # Check for OpenCL ICD if config.opencl_libs_dir: