1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-07-03 01:46:12 +02:00
qmckl/org/test_qmckl.org

110 lines
3.0 KiB
Org Mode

#+TITLE: Testing
#+SETUPFILE: ../tools/theme.setup
* QMCkl test :noexport:
This file is the main program of the unit tests. The tests rely on the
$\mu$unit framework, which is provided as a git submodule.
First, we use a script to find the list of all the generated test files:
#+NAME: test-files
#+begin_src sh :exports none
FILES=$(cat table_of_contents)
grep begin_src $FILES \
| grep c_test \
| cut -d '.' -f 1 \
| uniq
#+end_src
#+RESULTS: test-files
| qmckl_error |
| qmckl_context |
| qmckl_memory |
| qmckl_electron |
| qmckl_ao |
| qmckl_distance |
We generate the function headers
#+begin_src sh :var files=test-files :exports output :results drawer
echo "#+NAME: headers"
echo "#+begin_src c :tangle no"
for file in $files
do
routine=test_${file%.c}
echo "MunitResult ${routine}();"
done
echo "#+end_src"
#+end_src
#+RESULTS:
:results:
#+NAME: headers
#+begin_src c :tangle no
MunitResult test_qmckl_error();
MunitResult test_qmckl_context();
MunitResult test_qmckl_memory();
MunitResult test_qmckl_electron();
MunitResult test_qmckl_ao();
MunitResult test_qmckl_distance();
#+end_src
:end:
and the required function calls:
#+begin_src sh :var files=test-files :exports output :results drawer
echo "#+NAME: calls"
echo "#+begin_src c :tangle no"
for file in $files
do
routine=test_${file%.c}
echo " { (char*) \"${routine}\", ${routine}, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},"
done
echo "#+end_src"
#+end_src
#+RESULTS:
:results:
#+NAME: calls
#+begin_src c :tangle no
{ (char*) "test_qmckl_error", test_qmckl_error, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
{ (char*) "test_qmckl_context", test_qmckl_context, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
{ (char*) "test_qmckl_memory", test_qmckl_memory, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
{ (char*) "test_qmckl_electron", test_qmckl_electron, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
{ (char*) "test_qmckl_ao", test_qmckl_ao, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
{ (char*) "test_qmckl_distance", test_qmckl_distance, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
#+end_src
:end:
We include the =mcheck.h= header to enable the debugging of
allocations with ~mtrace~. Memory allocations will be traced in the
file specified by the ~MALLOC_TRACE~ environment variable.
#+begin_src c :comments link :noweb yes :tangle test_qmckl.c
#include "qmckl.h"
#include "munit.h"
#include "mcheck.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
<<headers>>
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
mtrace();
static MunitTest test_suite_tests[] =
{
<<calls>>
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
static const MunitSuite test_suite =
{
(char*) "", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
};
int result = munit_suite_main(&test_suite, (void*) "µnit", argc, argv);
muntrace();
return result;
}
#+end_src