Skip to content

Commit a108b2a

Browse files
committed
Fix sanitizer CI for IDA init/source-current hoctests
UBSan aborted LinearMechanism construction: NrnDAE bound references to optional-null elayer and y0 Vectors. Defer those dereferences until the pointers are known non-null. macOS ASan/TSan aborted isolated python -c children because SIP drops DYLD_INSERT_LIBRARIES. Re-apply NRN_SANITIZER_PRELOAD_* (same pattern as test_basic.py) so interceptors load before dlopen of libnrniv.
1 parent a15e968 commit a108b2a

3 files changed

Lines changed: 37 additions & 15 deletions

File tree

src/nrniv/nrndae.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,13 @@ NrnDAE::NrnDAE(Matrix* cmat,
187187
cmat = assumed_identity_;
188188
}
189189
c_ = new MatrixMap(cmat);
190-
Vect& elay = *elayer;
191190
nnode_ = nnode;
192191
nodes_ = nodes;
193192
if (nnode_ > 0) {
194193
elayer_ = new int[nnode_];
195194
if (elayer) {
196195
for (int i = 0; i < nnode_; ++i) {
197-
elayer_[i] = int(elay[i]);
196+
elayer_[i] = int((*elayer)[i]);
198197
}
199198
} else {
200199
for (int i = 0; i < nnode_; ++i) {
@@ -260,20 +259,17 @@ void NrnDAE::update() {
260259
void NrnDAE::init() {
261260
// printf("NrnDAE::init %lx\n", (long)this);
262261
// printf("init size_=%d %d %d %d\n", size_, y_->size(), y0_->size(), b_->size());
263-
Vect& y0 = *y0_;
264262

265263
v2y();
266264
if (f_init_) {
267265
f_init_(data_);
266+
} else if (y0_) {
267+
for (int i = nnode_; i < size_; ++i) {
268+
y_[i] = (*y0_)[i];
269+
}
268270
} else {
269-
if (y0_) {
270-
for (int i = nnode_; i < size_; ++i) {
271-
y_[i] = y0[i];
272-
}
273-
} else {
274-
for (int i = nnode_; i < size_; ++i) {
275-
y_[i] = 0.;
276-
}
271+
for (int i = nnode_; i < size_; ++i) {
272+
y_[i] = 0.;
277273
}
278274
}
279275
// for (i=0; i < nnode_; ++i) printf(" i=%d y[i]=%g\n", i, y[i]);

test/hoctests/tests/test_ida_init_mode.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,23 @@ def test_dae_init_stats_api():
7272
assert "ok" in _run_isolated(code)
7373

7474

75+
def _sanitizer_child_env(env=None):
76+
"""Re-apply sanitizer preload for macOS SIP (see NeuronTestHelper.cmake)."""
77+
env = os.environ.copy() if env is None else env
78+
try:
79+
env[os.environ["NRN_SANITIZER_PRELOAD_VAR"]] = os.environ[
80+
"NRN_SANITIZER_PRELOAD_VAL"
81+
]
82+
except KeyError:
83+
pass
84+
return env
85+
86+
7587
def _run_isolated(code: str):
76-
env = os.environ.copy()
88+
env = _sanitizer_child_env()
89+
exe = os.environ.get("NRN_PYTHON_EXECUTABLE", sys.executable)
7790
r = subprocess.run(
78-
[sys.executable, "-c", code],
91+
[exe, "-c", code],
7992
env=env,
8093
capture_output=True,
8194
text=True,

test/hoctests/tests/test_ida_source_current.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,31 @@ def _build_pwlclamp_mech_dir() -> str:
9898
return arch
9999

100100

101+
def _sanitizer_child_env(env=None):
102+
"""Re-apply sanitizer preload for macOS SIP (see NeuronTestHelper.cmake)."""
103+
env = os.environ.copy() if env is None else env
104+
try:
105+
env[os.environ["NRN_SANITIZER_PRELOAD_VAR"]] = os.environ[
106+
"NRN_SANITIZER_PRELOAD_VAL"
107+
]
108+
except KeyError:
109+
pass
110+
return env
111+
112+
101113
def _run_isolated(code: str, timeout: float = 120.0) -> str:
102114
"""Run code in a subprocess with the same interpreter/env; return stdout."""
103-
env = os.environ.copy()
115+
env = _sanitizer_child_env()
104116
# Point children at a ready PWLClamp mechanism directory
105117
try:
106118
env["NRN_PWLCLAMP_MECH"] = _build_pwlclamp_mech_dir()
107119
except Exception as e:
108120
# IClamp-only tests do not need the mech
109121
env.pop("NRN_PWLCLAMP_MECH", None)
110122
env["NRN_PWLCLAMP_BUILD_ERR"] = str(e)
123+
exe = os.environ.get("NRN_PYTHON_EXECUTABLE", sys.executable)
111124
proc = subprocess.run(
112-
[sys.executable, "-c", code],
125+
[exe, "-c", code],
113126
capture_output=True,
114127
text=True,
115128
timeout=timeout,

0 commit comments

Comments
 (0)