1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-11-19 20:42:50 +01:00
qmckl/src/test_qmckl.org

110 lines
3.0 KiB
Org Mode
Raw Normal View History

2021-03-09 01:16:23 +01:00
#+TITLE: Testing
2021-04-30 01:26:19 +02:00
#+SETUPFILE: ../tools/theme.setup
2021-03-09 01:16:23 +01:00
2020-11-05 15:34:58 +01:00
* QMCkl test :noexport:
2020-10-21 19:50:18 +02:00
2020-11-05 15:34:58 +01:00
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.
2020-10-22 01:24:14 +02:00
2021-03-09 01:16:23 +01:00
First, we use a script to find the list of all the generated test files:
2020-11-05 15:34:58 +01:00
#+NAME: test-files
2021-04-30 01:26:19 +02:00
#+begin_src sh :exports none
2021-03-18 18:02:06 +01:00
FILES=$(cat table_of_contents)
grep begin_src $FILES \
| grep c_test \
| cut -d '.' -f 1 \
| uniq
2021-03-09 01:16:23 +01:00
#+end_src
2020-10-21 19:50:18 +02:00
2020-11-05 15:34:58 +01:00
#+RESULTS: test-files
2021-03-18 18:02:06 +01:00
| qmckl_error |
| qmckl_context |
| qmckl_memory |
2021-04-21 01:56:47 +02:00
| qmckl_electron |
2021-03-18 18:02:06 +01:00
| qmckl_ao |
2021-04-21 01:56:47 +02:00
| qmckl_distance |
2020-10-21 19:50:18 +02:00
2020-11-05 15:34:58 +01:00
We generate the function headers
2021-03-18 18:02:06 +01:00
#+begin_src sh :var files=test-files :exports output :results drawer
2020-10-21 19:50:18 +02:00
echo "#+NAME: headers"
2021-03-09 01:16:23 +01:00
echo "#+begin_src c :tangle no"
2020-10-21 19:50:18 +02:00
for file in $files
do
2021-03-18 18:02:06 +01:00
routine=test_${file%.c}
2020-11-05 15:34:58 +01:00
echo "MunitResult ${routine}();"
2020-10-21 19:50:18 +02:00
done
2021-03-09 01:16:23 +01:00
echo "#+end_src"
#+end_src
2020-10-21 19:50:18 +02:00
2020-11-05 15:34:58 +01:00
#+RESULTS:
2021-03-18 18:02:06 +01:00
:results:
2020-11-05 15:34:58 +01:00
#+NAME: headers
2021-03-09 01:16:23 +01:00
#+begin_src c :tangle no
2021-03-18 18:02:06 +01:00
MunitResult test_qmckl_error();
MunitResult test_qmckl_context();
MunitResult test_qmckl_memory();
2021-04-21 01:56:47 +02:00
MunitResult test_qmckl_electron();
2021-03-18 18:02:06 +01:00
MunitResult test_qmckl_ao();
2021-04-21 01:56:47 +02:00
MunitResult test_qmckl_distance();
2021-03-09 01:16:23 +01:00
#+end_src
2021-03-18 18:02:06 +01:00
:end:
2021-04-30 01:26:19 +02:00
2020-11-05 15:34:58 +01:00
and the required function calls:
2021-03-18 18:02:06 +01:00
#+begin_src sh :var files=test-files :exports output :results drawer
2020-10-21 19:50:18 +02:00
echo "#+NAME: calls"
2021-03-09 01:16:23 +01:00
echo "#+begin_src c :tangle no"
2020-10-21 19:50:18 +02:00
for file in $files
do
2021-03-18 18:02:06 +01:00
routine=test_${file%.c}
2021-03-29 01:22:54 +02:00
echo " { (char*) \"${routine}\", ${routine}, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},"
2020-10-21 19:50:18 +02:00
done
2021-03-09 01:16:23 +01:00
echo "#+end_src"
#+end_src
2021-04-30 01:26:19 +02:00
2020-11-05 15:34:58 +01:00
#+RESULTS:
2021-03-18 18:02:06 +01:00
:results:
2020-11-05 15:34:58 +01:00
#+NAME: calls
2021-03-09 01:16:23 +01:00
#+begin_src c :tangle no
2021-03-29 01:22:54 +02:00
{ (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},
2021-04-21 01:56:47 +02:00
{ (char*) "test_qmckl_electron", test_qmckl_electron, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
2021-03-29 01:22:54 +02:00
{ (char*) "test_qmckl_ao", test_qmckl_ao, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
2021-04-21 01:56:47 +02:00
{ (char*) "test_qmckl_distance", test_qmckl_distance, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL},
2021-03-09 01:16:23 +01:00
#+end_src
2021-03-18 18:02:06 +01:00
: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.
2020-10-21 19:50:18 +02:00
2021-04-30 01:26:19 +02:00
#+begin_src c :comments link :noweb yes :tangle test_qmckl.c
2020-10-21 19:50:18 +02:00
#include "qmckl.h"
#include "munit.h"
2021-03-18 18:02:06 +01:00
#include "mcheck.h"
2021-05-10 10:05:50 +02:00
#ifdef HAVE_CONFIG_H
2021-05-09 02:12:38 +02:00
#include <config.h>
#endif
2020-10-21 19:50:18 +02:00
<<headers>>
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
2021-03-18 18:02:06 +01:00
mtrace();
2020-10-21 19:50:18 +02:00
static MunitTest test_suite_tests[] =
{
2020-11-05 15:34:58 +01:00
<<calls>>
2020-10-21 19:50:18 +02:00
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
2020-11-05 15:34:58 +01:00
static const MunitSuite test_suite =
2020-10-21 19:50:18 +02:00
{
2021-03-29 01:22:54 +02:00
(char*) "", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
2020-10-21 19:50:18 +02:00
};
2021-04-30 01:26:19 +02:00
2021-03-29 01:22:54 +02:00
int result = munit_suite_main(&test_suite, (void*) "µnit", argc, argv);
2021-03-18 18:02:06 +01:00
muntrace();
return result;
2020-11-05 15:34:58 +01:00
}
2021-03-09 01:16:23 +01:00
#+end_src
2021-04-30 01:26:19 +02:00