NEURON
unit_test.cpp
Go to the documentation of this file.
1 #define CATCH_CONFIG_RUNNER
2 
3 #include <catch2/catch.hpp>
4 
5 #include <ocfunc.h>
6 #include <code.h>
7 #include <section.h>
8 #include <neuron.h>
9 
10 extern void nrn_threads_create(int, int);
11 extern void nrn_threads_free();
12 extern int ivocmain_session(int, const char**, const char**, int);
13 
14 extern int nrn_main_launch;
15 extern int nrn_nobanner_;
16 
17 /// Needed for compilation
18 void modl_reg() {}
19 extern int nrn_nthread;
20 extern NrnThread* nrn_threads;
21 
22 extern int nrn_use_fast_imem;
23 extern int use_cachevec;
24 
25 int main(int argc, char* argv[]) {
26  // global setup...
27  nrn_main_launch = 2;
28  int argc_nompi = 2;
29  const char* argv_nompi[] = {"NEURON", "-nogui", nullptr};
30  nrn_nobanner_ = 1;
31 
32  ivocmain_session(argc_nompi, argv_nompi, NULL, 0);
33 #undef run
34  int result = Catch::Session().run(argc, argv);
35 #define run hoc_run
36  // global clean-up...
37 
38  return result;
39 }
40 
41 
42 SCENARIO("Test fast_imem calculation", "[Neuron][fast_imem]") {
43  GIVEN("A section") {
44  hoc_oc("create s\n");
45 
46  WHEN("fast_imem and cachevec is allocated") {
47  nrn_use_fast_imem = true;
48  use_cachevec = 1;
50  THEN("nrn_fast_imem should not be nullptr") {
51  for (int it = 0; it < nrn_nthread; ++it) {
52  NrnThread* nt = &nrn_threads[it];
53  REQUIRE(nt->_nrn_fast_imem != nullptr);
54  }
55  }
56  }
57 
58  WHEN("fast_imem is created") {
59  hoc_oc(
60  "objref cvode\n"
61  "cvode = new CVode()\n"
62  "cvode.use_fast_imem(1)\n");
63  WHEN("iinitialize and run nrn_calc_fast_imem") {
64  hoc_oc("finitialize(-65)\n");
65  for (NrnThread* nt = nrn_threads; nt < nrn_threads + nrn_nthread; ++nt) {
67  }
68  THEN("The current in this section is 0") {
69  for (NrnThread* nt = nrn_threads; nt < nrn_threads + nrn_nthread; ++nt) {
70  for (int i = 0; i < nt->end; ++i) {
71  REQUIRE(nt->_nrn_fast_imem->_nrn_sav_rhs[i] == 0.0);
72  }
73  }
74  }
75  }
76  }
77 
78  hoc_oc("delete_section()");
79  }
80 }
81 
82 TEST_CASE("Test return code of execerror", "[NEURON][execerror]") {
83  REQUIRE(hoc_oc("execerror(\"test error\")") > 0);
84 }
85 
86 // AddressSanitizer seems to intercept the mallinfo[2]() system calls and return
87 // null values from them.
88 #ifndef NRN_ASAN_ENABLED
89 TEST_CASE("Test nrn_mallinfo returns non-zero", "[NEURON][nrn_mallinfo]") {
90  SECTION("HOC") {
91  REQUIRE(
92  hoc_oc(
93  "if (nrn_mallinfo(0) <= 0) { execerror(\"nrn_mallinfo returned <= 0 in HOC\") }") ==
94  0);
95  }
96  SECTION("C++") {
97  REQUIRE(nrn_mallinfo(0) > 0);
98  }
99 }
100 #endif
void nrn_calc_fast_imem(NrnThread *_nt)
Definition: fadvance.cpp:653
size_t nrn_mallinfo(int item)
Definition: symbol.cpp:407
int hoc_oc(const char *buf)
Definition: hoc.cpp:1471
static int argc
Definition: inithoc.cpp:53
static char ** argv
Definition: inithoc.cpp:54
#define Session
Definition: ivocmain.cpp:7
#define i
Definition: md1redef.h:12
void nrn_fast_imem_alloc()
Definition: multicore.cpp:629
#define NULL
Definition: sptree.h:16
Represent main neuron object computed by single thread.
Definition: multicore.h:58
_nrn_Fast_Imem * _nrn_fast_imem
Definition: multicore.h:82
TEST_CASE("Test return code of execerror", "[NEURON][execerror]")
Definition: unit_test.cpp:82
int main(int argc, char *argv[])
Definition: unit_test.cpp:25
void nrn_threads_free()
Definition: multicore.cpp:641
void modl_reg()
Needed for compilation.
Definition: unit_test.cpp:18
int nrn_nthread
Definition: multicore.cpp:46
int nrn_nobanner_
Definition: hoc.cpp:146
int use_cachevec
Definition: treeset.cpp:63
SCENARIO("Test fast_imem calculation", "[Neuron][fast_imem]")
Definition: unit_test.cpp:42
NrnThread * nrn_threads
Definition: multicore.cpp:47
int nrn_main_launch
Definition: hoc_init.cpp:528
void nrn_threads_create(int, int)
Definition: multicore.cpp:504
int ivocmain_session(int, const char **, const char **, int)
This used to be ivocmain, the main entrypoint to the HOC interpreter.
Definition: ivocmain.cpp:434
int nrn_use_fast_imem
Definition: fadvance.cpp:167