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 
45  hoc_oc("create s\n");
46 
47  WHEN("fast_imem and cachevec is allocated") {
48  nrn_use_fast_imem = true;
49  use_cachevec = 1;
51  THEN("nrn_fast_imem should not be nullptr") {
52  for(int it = 0; it < nrn_nthread; ++it) {
53  NrnThread *nt = &nrn_threads[it];
54  REQUIRE(nt->_nrn_fast_imem != nullptr);
55  }
56  }
57  }
58 
59  WHEN("fast_imem is created") {
60  hoc_oc("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 }
int nrn_nobanner_
Definition: hoc.cpp:146
Represent main neuron object computed by single thread.
Definition: multicore.h:58
int nrn_main_launch
Definition: hoc_init.cpp:396
int nrn_nthread
Definition: multicore.cpp:44
int ivocmain_session(int, const char **, const char **, int)
This used to be ivocmain, the main entrypoint to the HOC interpreter.
Definition: ivocmain.cpp:446
_nrn_Fast_Imem * _nrn_fast_imem
Definition: multicore.h:82
void nrn_threads_free()
Definition: multicore.cpp:626
void nrn_threads_create(int, int)
Definition: multicore.cpp:490
SCENARIO("Test fast_imem calculation", "[Neuron][fast_imem]")
Definition: unit_test.cpp:42
int hoc_oc(const char *buf)
Definition: hoc.cpp:1491
void nrn_fast_imem_alloc()
Definition: multicore.cpp:614
void nrn_calc_fast_imem(NrnThread *_nt)
Definition: fadvance.cpp:623
NrnThread * nrn_threads
Definition: multicore.cpp:45
int main(int argc, char *argv[])
Definition: unit_test.cpp:25
int nrn_use_fast_imem
Definition: fadvance.cpp:162
int use_cachevec
Definition: treeset.cpp:61
#define i
Definition: md1redef.h:12
static int argc
Definition: inithoc.cpp:53
#define Session
Definition: ivocmain.cpp:7
return NULL
Definition: cabcode.cpp:461
void modl_reg()
Needed for compilation.
Definition: unit_test.cpp:18
static char ** argv
Definition: inithoc.cpp:54