Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Nov 13, 2024
1 parent 34ddd3c commit b549a0c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/usecases/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(NMODL_USECASE_DIRS
point_process
pointer
procedure
protect
random
solve
state
Expand Down
17 changes: 17 additions & 0 deletions test/usecases/protect/shared_counter.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
NEURON {
SUFFIX shared_counter
GLOBAL g_cnt
}

ASSIGNED {
g_cnt
}


INITIAL {
PROTECT g_cnt = 0
}

BREAKPOINT {
PROTECT g_cnt = g_cnt + 1
}
30 changes: 30 additions & 0 deletions test/usecases/protect/test_shared_counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from neuron import h, gui


def test_shared_counter():
nthreads = 32
nseg = 10
nsteps = 100

sections = [h.Section() for _ in range(nthreads)]
for s in sections:
s.insert("shared_counter")
s.nseg = nseg

pc = h.ParallelContext()

pc.nthread(nthreads)
for k, s in enumerate(sections):
pc.partition(k, h.SectionList([s]))

h.finitialize()
for _ in range(nsteps):
h.step()

expected = nthreads * nseg * nsteps
g_cnt = h.g_cnt_shared_counter
assert h.g_cnt_shared_counter == expected, f"{g_cnt}"


if __name__ == "__main__":
test_shared_counter()

0 comments on commit b549a0c

Please sign in to comment.