NEURON
basic.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include "code.h"
3 #include "neuron.h"
4 #include "ocfunc.h"
5 #include "section.h"
6 #if HAVE_IV
7 #include "ivoc.h"
8 #endif
9 
10 #include <catch2/catch_test_macros.hpp>
11 
12 SCENARIO("Test fast_imem calculation", "[Neuron][fast_imem]") {
13  GIVEN("A section") {
14  REQUIRE(hoc_oc("create s\n") == 0);
15  WHEN("fast_imem is allocated") {
16  nrn_use_fast_imem = true;
18  THEN("nrn_fast_imem should not be nullptr") {
19  for (int it = 0; it < nrn_nthread; ++it) {
20  REQUIRE(nrn_threads[it].node_sav_d_storage());
21  REQUIRE(nrn_threads[it].node_sav_rhs_storage());
22  }
23  }
24  }
25 
26  WHEN("fast_imem is created") {
27  REQUIRE(hoc_oc("objref cvode\n"
28  "cvode = new CVode()\n"
29  "cvode.use_fast_imem(1)\n") == 0);
30  WHEN("iinitialize and run nrn_calc_fast_imem") {
31  REQUIRE(hoc_oc("finitialize(-65)\n") == 0);
32  for (NrnThread* nt = nrn_threads; nt < nrn_threads + nrn_nthread; ++nt) {
34  }
35  THEN("The current in this section is 0") {
36  for (NrnThread* nt = nrn_threads; nt < nrn_threads + nrn_nthread; ++nt) {
37  auto const vec_sav_rhs = nt->node_sav_rhs_storage();
38  for (int i = 0; i < nt->end; ++i) {
39  REQUIRE(vec_sav_rhs[i] == 0.0);
40  }
41  }
42  }
43  }
44  }
45 
46  REQUIRE(hoc_oc("delete_section()") == 0);
47  }
48 }
49 
50 TEST_CASE("Test return code of execerror", "[NEURON][execerror]") {
51  REQUIRE(hoc_oc("execerror(\"test error\")") > 0);
52 }
53 
54 #if HAVE_IV
55 TEST_CASE("Test Oc::run(cmd)", "[NEURON]") {
56  Oc oc;
57  REQUIRE(oc.run("foo", 1) == 1);
58  REQUIRE(oc.run("foo", 0) == 1);
59 }
60 #endif
61 
62 // AddressSanitizer seems to intercept the mallinfo[2]() system calls and return
63 // null values from them. ThreadSanitizer seems to do the same.
64 #if !defined(NRN_ASAN_ENABLED) && !defined(NRN_TSAN_ENABLED)
65 TEST_CASE("Test nrn_mallinfo returns non-zero", "[NEURON][nrn_mallinfo]") {
66  SECTION("HOC") {
67  REQUIRE(
68  hoc_oc(
69  "if (nrn_mallinfo(0) <= 0) { execerror(\"nrn_mallinfo returned <= 0 in HOC\") }") ==
70  0);
71  }
72  SECTION("C++") {
73  REQUIRE(nrn_mallinfo(0) > 0);
74  }
75 }
76 #endif
TEST_CASE("Test return code of execerror", "[NEURON][execerror]")
Definition: basic.cpp:50
SCENARIO("Test fast_imem calculation", "[Neuron][fast_imem]")
Definition: basic.cpp:12
Definition: ivoc.h:36
int run(int argc, const char **argv)
#define i
Definition: md1redef.h:19
int hoc_oc(const char *buf)
Definition: hoc.cpp:1314
NrnThread * nrn_threads
Definition: multicore.cpp:56
double nrn_mallinfo(void)
Returns current memory usage in KBs.
int nrn_nthread
Definition: multicore.cpp:55
void nrn_fast_imem_alloc()
Definition: fast_imem.cpp:32
void nrn_calc_fast_imem(NrnThread *nt)
Definition: fast_imem.cpp:44
bool nrn_use_fast_imem
Definition: fast_imem.cpp:19
Represent main neuron object computed by single thread.
Definition: multicore.h:58