Skip to content

Commit 9baf18b

Browse files
committed
Document foreign ctest and test-install in install/CMake docs
Expand NRN_ENABLE_TESTS (in-tree vs test-install), wheel testing via test/foreign, and cross-links from install instructions, developer index, coverage, and GPU testing pages.
1 parent 814fdf5 commit 9baf18b

6 files changed

Lines changed: 195 additions & 41 deletions

File tree

docs/cmake_doc/options.rst

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -533,27 +533,98 @@ Readline_ROOT_DIR:PATH=/usr
533533

534534
NRN_ENABLE_TESTS:BOOL=OFF
535535
-------------------------
536-
Enable unit tests
537-
538-
Clones the submodule catch2 from https://github.com/catchorg/Catch2.git and after a build using
539-
``make`` can run the tests with ``make test``.
540-
May also need to ``pip install pytest``.
541-
``make test`` is quite terse. To get the same verbose output that is
542-
seen with the CI tests, use ``ctest -VV`` (executed in the
543-
build folder) or an individual test with ``ctest -VV -R name_of_the_test``.
544-
One can also run individual test files
545-
with ``python3 -m pytest -s <testfile.py>`` or all the test files in that
546-
folder with ``python3 -m pytest -s``. (The ``-s`` shows all output on
547-
the terminal.) Note: It is helpful to ``make test``
548-
first to ensure any mod files needed are available to the tests. If
549-
running a test outside the folder where the test is located, it may be
550-
necessary to add the folder to PYTHONPATH. Note: The last python
551-
mentioned in the ``-DNRN_PYTHON_DYNAMIC=...`` (if the semicolon separated
552-
list is non-empty and ``-DNRN_ENABLE_PYTHON_DYNAMIC=ON``)
553-
is the one used for ``make test`` and ``ctest -VV``. Otherwise the
554-
value specified by ``PYTHON_EXECUTABLE`` is used.
555-
556-
Example
536+
Enable the NEURON test suite (build-tree and install checks).
537+
538+
When ``ON``:
539+
540+
* Clones the Catch2 submodule (https://github.com/catchorg/Catch2.git) for
541+
C++ unit tests.
542+
* Registers the full in-tree CTest suite under the main CMake binary
543+
directory (unit tests, HOC/Python integration, RxD, optional MPI and
544+
CoreNEURON paths, and so on).
545+
* Adds a convenience target ``test-install`` that runs the **portable**
546+
foreign test harness against ``CMAKE_INSTALL_PREFIX`` (see
547+
:ref:`cmake-nrn-test-install` below).
548+
549+
You typically need ``pip install pytest`` (and, for RxD plots, packages
550+
such as ``matplotlib`` / ``plotly`` / ``anywidget`` as required by
551+
individual tests).
552+
553+
In-tree tests (build directory)
554+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
555+
556+
After configuring and building, run tests from the **main build**
557+
directory. ``make test`` / ``ninja test`` is terse; prefer ``ctest`` for
558+
the same verbose style as CI:
559+
560+
.. code-block:: shell
561+
562+
mkdir build && cd build
563+
cmake .. -G Ninja -DNRN_ENABLE_TESTS=ON -DCMAKE_INSTALL_PREFIX=install ...
564+
ninja # or: cmake --build . -j
565+
ctest --output-on-failure -j8
566+
ctest -VV -R parallel_tests
567+
568+
It is helpful to complete a full ``ctest`` (or at least build the test
569+
targets) once so that ``nrnivmodl`` has produced any mod-file libraries
570+
the scripts expect.
571+
572+
One can also run individual Python test files with
573+
``python3 -m pytest -s <testfile.py>`` or all tests in a folder with
574+
``python3 -m pytest -s`` (``-s`` sends output to the terminal). If
575+
running a test outside the folder where it lives, you may need that
576+
folder on ``PYTHONPATH``.
577+
578+
Note: the last Python listed in ``-DNRN_PYTHON_DYNAMIC=...`` (when
579+
non-empty and ``-DNRN_ENABLE_PYTHON_DYNAMIC=ON``) is used for
580+
``make test`` / default ``ctest``. Otherwise the value of
581+
``PYTHON_EXECUTABLE`` / the default discovered Python is used.
582+
583+
.. _cmake-nrn-test-install:
584+
585+
Install check (``test-install`` / foreign ctest)
586+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
587+
588+
Linked C++ unit tests require the build tree. To validate a **prefix
589+
install** (or a pip wheel), NEURON also provides a standalone project
590+
under ``test/foreign`` that discovers an installed NEURON and runs the
591+
portable subset of the suite (no rebuild of ``libnrniv``).
592+
593+
With ``NRN_ENABLE_TESTS=ON``, the main build defines a target
594+
``test-install``. After installing into ``CMAKE_INSTALL_PREFIX``:
595+
596+
.. code-block:: shell
597+
598+
ninja install # or: cmake --build . --target install
599+
ninja test-install # or: cmake --build . --target test-install
600+
601+
That target:
602+
603+
1. Configures ``test/foreign`` into ``${CMAKE_BINARY_DIR}/build-ctest``
604+
(for example ``build/build-ctest``), using the same CMake generator as
605+
the main build (for example Ninja).
606+
2. Points foreign discovery at the install prefix
607+
(``NRN_FOREIGN_ROOT``) and the build’s default Python.
608+
3. Builds mechanisms for the portable tests and runs a default
609+
``ctest -L serial`` install check.
610+
4. Prints how to re-run ``ctest`` with other filters against that
611+
foreign binary directory.
612+
613+
Afterwards you can use ordinary CTest options against the foreign dir:
614+
615+
.. code-block:: shell
616+
617+
ctest --test-dir build-ctest --output-on-failure
618+
ctest --test-dir build-ctest -L mpi -j2
619+
ctest --test-dir build-ctest -L coreneuron -j2
620+
ctest --test-dir build-ctest -R 'pytest::' --rerun-failed
621+
622+
You can also configure the foreign project yourself (wheels, custom
623+
prefixes, or a different binary dir). See ``test/foreign/README.md``
624+
and ``test/foreign/INVENTORY.md`` (what runs under foreign mode vs
625+
build-only).
626+
627+
Example (in-tree tests only, classic workflow)
557628

558629
.. code-block:: shell
559630
@@ -562,9 +633,6 @@ NRN_ENABLE_TESTS:BOOL=OFF
562633
make -j
563634
make test
564635
ctest -VV -R parallel_tests
565-
cd ../test/pynrn
566-
python3 -m pytest
567-
python3 -m pytest test_currents.py
568636
569637
NRN_ENABLE_COVERAGE:BOOL=OFF
570638
----------------------------

docs/dev/gpu-testing.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ If you have configured NEURON with CoreNEURON, CoreNEURON GPU support and tests
5757
5858
$ ctest --output-on-failure
5959
60-
in your CMake build directory will execute a large number of tests, many of them including GPU execution.
60+
in your **main** CMake build directory will execute a large number of tests, many of them including GPU execution.
61+
(That is the in-tree suite. The separate ``test-install`` / ``test/foreign`` path
62+
validates an install or wheel and is CPU-oriented; GPU install checks are not
63+
the focus of that harness yet.)
6164
You can filter which tests are run by name using the ``-R`` option to CTest, for example:
6265

6366
.. code-block:: console

docs/install/code_coverage.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ and ``make cover_html``. See [Simplified Workflow](#simplified-workflow) below.
2424

2525
In addition to the COVERAGE_FLAGS use whatever cmake options you desire.
2626
But you will generally want ```-DNRN_ENABLE_TESTS=ON``` to see what
27-
effect your new tests have on coverage.
27+
effect your new tests have on coverage. Use in-tree `ctest` in the main
28+
build directory for coverage (not the foreign install/wheel
29+
`test-install` suite, which exercises an installed tree).
2830
```
2931
COVERAGE_FLAGS="--coverage -O0 -fno-inline -g"
3032
cmake .. -DCMAKE_INSTALL_PREFIX=install -DCMAKE_C_FLAGS="${COVERAGE_FLAGS}" -DCMAKE_CXX_FLAGS="${COVERAGE_FLAGS}" -DNRN_ENABLE_TESTS=ON

docs/install/developer.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
Developer Builds
2-
============
2+
================
33

44
Developer builds for creating Binary and Python wheel distributions, tests, documentation, code coverage.
55
Each aspect generally has extra dependencies and special instructions.
66

7+
**Tests overview**
8+
9+
* In-tree CTest (build directory): enable with
10+
:ref:`-DNRN_ENABLE_TESTS=ON <cmake-nrn-enable-tests-option>`, then
11+
``ctest`` from the main build directory.
12+
* Install / wheel portable suite: target ``test-install`` (same option), or
13+
configure ``test/foreign`` directly — see that option page and
14+
``test/foreign/README.md``.
15+
* Wheel smoke script: ``packaging/python/test_wheels.sh`` (documented under
16+
:doc:`python_wheels`).
17+
* Coverage workflow: :doc:`code_coverage`.
18+
* Sanitizers / debugging: :doc:`debug`.
19+
720

821
.. toctree::
922
:maxdepth: 2

docs/install/install_instructions.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,29 +330,47 @@ step method. You can find detailed instructions [here](../coreneuron/index.rst)
330330

331331
#### Run integrated tests
332332

333-
**NEURON** includes also some unit and integration tests. To enable you need to set the `CMake` flag **-DNRN\_ENABLE\_TESTS=ON**.
334-
The tests lie in the `test` directory and cover various aspects of **NEURON**:
335-
* **CoreNEURON** integration (if enabled in build step)
336-
* Functionality and result regression test for [ringtest](https://github.com/neuronsimulator/ringtest) and [testcorenrn](https://github.com/neuronsimulator/testcorenrn)
337-
* HOC interpreter tests
338-
* Python interpreter tests
339-
* Parallel Context tests
333+
**NEURON** includes unit and integration tests. Enable them with the CMake
334+
flag **-DNRN\_ENABLE\_TESTS=ON**. Sources live under `test/` and cover
335+
(among other areas):
336+
* **CoreNEURON** integration (if enabled at configure time)
337+
* Functionality and result regression tests for [ringtest](https://github.com/neuronsimulator/ringtest) and [testcorenrn](https://github.com/neuronsimulator/testcorenrn)
338+
* HOC and Python interpreter tests
339+
* Parallel Context / MPI tests
340340
* Rx3d tests
341-
* Unit tests
342-
* GapJunction tests
341+
* C++ unit tests (Catch2)
342+
* Gap junction tests
343+
344+
**In-tree tests** (against the build directory; includes linked unit tests):
343345

344-
To run the tests it's needed to:
345346
```bash
346347
cd nrn/build
347348
cmake .. \
349+
-G Ninja \
350+
-DNRN_ENABLE_TESTS=ON \
348351
-DNRN_ENABLE_INTERVIEWS=OFF \
349352
-DNRN_ENABLE_MPI=OFF \
350353
-DNRN_ENABLE_RX3D=OFF \
351354
-DCMAKE_INSTALL_PREFIX=/path/to/install/directory
352355
cmake --build . --parallel 8
353-
ctest # use --parallel for speed, -R to run specific tests
356+
ctest --output-on-failure -j8 # -R to select tests by name
357+
```
358+
359+
**Install check** (portable suite against the install prefix; no rebuild of
360+
`libnrniv`). After the same configure with `-DNRN_ENABLE_TESTS=ON`:
361+
362+
```bash
363+
cmake --build . --target install
364+
cmake --build . --target test-install
365+
# creates build/build-ctest and runs a default serial foreign ctest
366+
ctest --test-dir build-ctest -L mpi --output-on-failure # optional filters
354367
```
355368

369+
Details, labels (`serial`, `mpi`, `coreneuron`), and wheel testing are
370+
documented under the CMake option `NRN_ENABLE_TESTS` and in
371+
`test/foreign/README.md`. For a short smoke test of a built wheel, see
372+
also `packaging/python/test_wheels.sh` in [Building Python Wheels](python_wheels.md).
373+
356374
### FAQs
357375

358376
* **I am getting link errors "undefined reference to 'tgoto, tgetent, tputs'".**

docs/install/python_wheels.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ Change the pretend version to whatever is relevant for your case.
148148

149149
## Testing the wheels
150150

151-
To test the generated wheels, you can do:
151+
There are two complementary approaches: a **smoke script** that ships with
152+
the packaging tree, and the **foreign CTest harness** that reuses a large
153+
portable subset of the developer suite against an installed wheel.
154+
155+
### Smoke tests (`test_wheels.sh`)
156+
157+
Quick health check after building a wheel (or against TestPyPI):
152158

153159
```
154160
# first arg is a python exe and second arg is the corresponding wheel
@@ -158,11 +164,55 @@ bash packaging/python/test_wheels.sh python3.9 wheelhouse/NEURON-7.8.0.236-cp39-
158164
bash packaging/python/test_wheels.sh python3.9 "-i https://test.pypi.org/simple/NEURON==7.8.11.2"
159165
```
160166

167+
This covers import/`neuron.test()`, basic `nrnivmodl`, and a few MPI /
168+
CoreNEURON paths when available. It is intentionally smaller than a full
169+
developer `ctest` run.
170+
171+
### Foreign CTest against a wheel (portable suite)
172+
173+
For broader coverage without rebuilding NEURON, configure the standalone
174+
project under `test/foreign` against a venv that has the wheel installed:
175+
176+
```bash
177+
python3 -m venv .venv && source .venv/bin/activate
178+
pip install -U pip pytest
179+
# local wheel, or e.g. neuron-nightly from PyPI:
180+
pip install path/to/NEURON-*.whl
181+
# pip install neuron-nightly
182+
183+
# From the NEURON source tree (same revision as the wheel when possible):
184+
cmake -S test/foreign -B build-ctest \
185+
-DNRN_FOREIGN_PYTHON="$(which python)" \
186+
-DNRN_FOREIGN_ALLOW_SKEW=ON # only if source tip ≠ wheel revision
187+
188+
cmake --build build-ctest --target test-install -j
189+
# default: build mechanisms + ctest -L serial
190+
191+
# Full ctest control against the foreign binary dir:
192+
ctest --test-dir build-ctest -L mpi --output-on-failure -j2
193+
ctest --test-dir build-ctest -L coreneuron --output-on-failure -j2
194+
```
195+
196+
Notes:
197+
198+
* Version policy defaults to a hard match between the wheel’s git identity
199+
and this source tree; use `-DNRN_FOREIGN_ALLOW_SKEW=ON` for exploratory
200+
runs (for example `neuron-nightly` vs a feature branch).
201+
* MPI tests register only if the wheel was built with MPI **and** `mpiexec`
202+
is on `PATH` at foreign configure time.
203+
* See `test/foreign/README.md` and `test/foreign/INVENTORY.md` for
204+
labels, dependencies (e.g. RxD plot packages), and what remains
205+
build-only (Catch2 unit tests, NMODL unit binaries, …).
206+
207+
The same foreign harness is used after a **prefix install** via the main
208+
build target `test-install` when `NRN_ENABLE_TESTS=ON` (see the CMake
209+
option documentation for `NRN_ENABLE_TESTS`).
210+
161211
### MacOS considerations
162212

163213
On MacOS, launching `nrniv -python` or `special -python` can fail to load `neuron` module due to security restrictions.
164-
For this specific purpose, please `export SKIP_EMBEDED_PYTHON_TEST=true` before launching the tests.
165-
214+
For this specific purpose, please `export SKIP_EMBEDED_PYTHON_TEST=true` before launching the tests
215+
(for `test_wheels.sh`).
166216
## Publishing the wheels on Pypi via Azure
167217

168218
### Variables that drive PyPI upload

0 commit comments

Comments
 (0)