From d505187062d07791df73be8a4103d8ba3cc998c5 Mon Sep 17 00:00:00 2001
From: Simon Rose <simon.rose@ess.eu>
Date: Thu, 4 May 2023 14:39:43 +0200
Subject: [PATCH] Add test for debug architecture

---
 configure/E3/CONFIG_TEST |  2 ++
 tests/test_e3.py         | 23 +++++++++++++++++++++++
 tests/utils.py           |  5 +++--
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/configure/E3/CONFIG_TEST b/configure/E3/CONFIG_TEST
index e8494bcf..1836a92d 100644
--- a/configure/E3/CONFIG_TEST
+++ b/configure/E3/CONFIG_TEST
@@ -12,5 +12,7 @@ VARS_EXCLUDES+=TEMP_CELL_PATH
 
 ifneq (,$(findstring test,$(MAKECMDGOALS)))
   TEST_DEBUG_ARCH:=$(if $(and $(findstring debug,$(EPICS_HOST_ARCH)),$(wildcard $(EPICS_BASE)/bin/$(EPICS_HOST_ARCH)/softIocPVA)),$(EPICS_HOST_ARCH))
+  EXPORT_VARS+=TEST_DEBUG_ARCH
+
   E3_MODULES_PATH=$(TEMP_CELL_PATH)/$(notdir $(EPICS_BASE))/require-$(E3_REQUIRE_VERSION)
 endif
diff --git a/tests/test_e3.py b/tests/test_e3.py
index 54e1e079..b79327fd 100644
--- a/tests/test_e3.py
+++ b/tests/test_e3.py
@@ -1,3 +1,5 @@
+import pytest
+
 from .utils import Wrapper
 
 
@@ -49,3 +51,24 @@ def test_warning_if_building_from_sitemods(wrapper: Wrapper):
     assert (
         "It is ill-advised to build a module from the module install location." in errs
     )
+
+
+def test_debug_arch_is_not_used_when_unspecified(wrapper: Wrapper):
+    rc, _, errs = wrapper.run_make("test")
+    assert rc == 0
+
+    # Note that output from run-iocsh goes to stderr
+    assert f'EPICS_HOST_ARCH = "{wrapper.host_arch}"' in errs
+
+
+def test_debug_arch_is_used_when_specified(wrapper: Wrapper):
+    debug_arch = f"{wrapper.host_arch}-debug"
+    softioc_exec = wrapper.epics_base / "bin" / debug_arch / "softIocPVA"
+    if not softioc_exec.exists():
+        pytest.skip("No debug arch installed")
+
+    rc, _, errs = wrapper.run_make("test", EPICS_HOST_ARCH=debug_arch)
+    assert rc == 0
+
+    # Note that output from run-iocsh goes to stderr
+    assert f'EPICS_HOST_ARCH = "{debug_arch}"' in errs
diff --git a/tests/utils.py b/tests/utils.py
index b837ab55..7223776e 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -78,8 +78,6 @@ include $(REQUIRE_CONFIG)/RULES_SITEMODS
             module_makefile_contents = """
 where_am_I := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
 include $(E3_REQUIRE_TOOLS)/driver.makefile
-
-EXCLUDE_ARCHS+=debug
 """
             self.module_makefile.write_text(module_makefile_contents)
 
@@ -138,6 +136,9 @@ EXCLUDE_ARCHS+=debug
         args = list(args)
         if module_version:
             args.append(f"E3_MODULE_VERSION={module_version}")
+        if not ("TEST_DEBUG_ARCH" in env and not env["TEST_DEBUG_ARCH"]):
+            args.append("EXCLUDE_ARCHS=debug")
+
         if cell_path:
             self.write_dot_local_data("CONFIG_CELL", {"E3_CELL_PATH": cell_path})
         make_cmd = ["make", "-C", self.path, target] + args
-- 
GitLab