Commit 5f4c3cd8 authored by Tomas Krizek's avatar Tomas Krizek

meson: unit tests - move test closer to code

parent e5c06568
......@@ -14,7 +14,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/generic/array.h"
knot_mm_t global_mm;
......
......@@ -19,7 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/generic/lru.h"
typedef lru_t(int) lru_int_t;
......
......@@ -19,7 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/generic/map.h"
/*
......
......@@ -14,7 +14,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/generic/pack.h"
#define U8(x) (const uint8_t *)(x)
......
......@@ -14,7 +14,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/generic/queue.h"
/* The main intention is to use queues with pointers, so we test the same-sized int. */
......
......@@ -9,7 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/generic/set.h"
#include "lib/utils.h"
......
......@@ -15,7 +15,7 @@
*/
#include "lib/generic/trie.h"
#include "tests/test.h"
#include "tests/unit/test.h"
static const char *dict[] = {
"catagmatic", "prevaricator", "statoscope", "workhand", "benzamide",
......
......@@ -55,6 +55,20 @@ libkres_headers = [
'zonecut.h',
]
unit_tests += [
['array', files('generic/test_array.c')],
['lru', files('generic/test_lru.c')],
['map', files('generic/test_map.c')],
['pack', files('generic/test_pack.c')],
['queue', files('generic/test_queue.c')],
['set', files('generic/test_set.c')],
['trie', files('generic/test_trie.c')],
['module', files('test_module.c')],
['rplan', files('test_rplan.c')],
['utils', files('test_utils.c')],
['zonecut', files('test_zonecut.c')],
]
libkres_inc = include_directories('..')
libkres_lib = library('kres',
......@@ -78,7 +92,6 @@ libkres_dep = declare_dependency(
link_with: libkres_lib
)
# TODO what dir structure does it create?
install_headers(
libkres_headers,
subdir: 'libkres',
......
......@@ -14,7 +14,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/module.h"
static void test_module_params(void **state)
......@@ -35,7 +35,7 @@ static void test_module_builtin(void **state)
static void test_module_c(void **state)
{
struct kr_module module;
assert_int_equal(kr_module_load(&module, "mock_cmodule", "tests"), 0);
assert_int_equal(kr_module_load(&module, "mock_cmodule", "tests/unit"), 0);
kr_module_unload(&module);
}
......
......@@ -14,7 +14,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/resolve.h"
#include "lib/rplan.h"
......
......@@ -18,7 +18,7 @@
#include <stdio.h>
#include <contrib/cleanup.h>
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/utils.h"
static void test_strcatdup(void **state)
......
......@@ -16,7 +16,7 @@
#include <netinet/in.h>
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/zonecut.h"
static void test_zonecut_params(void **state)
......
......@@ -65,6 +65,8 @@ add_global_arguments(
language: 'c',
)
unit_tests = [] # list of [test_name, files(test)]
# compile
subdir('contrib')
......
# Unit tests
unit_tests = [
'test_array',
#'test_cache', # TODO: re-consider how best to test cache
'test_lru',
'test_map',
'test_module',
'test_pack',
'test_queue',
'test_rplan',
'test_set',
'test_trie',
'test_utils',
'test_zonecut',
]
# dependency
cmocka = dependency('cmocka', required: false)
if cmocka.found()
# mock module for test_module
mock_cmodule_src = [
'mock_cmodule.c',
]
mock_cmodule_lib = library(
'mock_cmodule',
mock_cmodule_src,
name_prefix: '',
dependencies: libkres_dep,
)
mock_cmodule_dep = declare_dependency(
link_with: mock_cmodule_lib,
)
# executables with tests
foreach unit_test : unit_tests
exec_test = executable(
unit_test,
unit_test + '.c',
dependencies: [
contrib_dep,
libkres_dep,
cmocka,
lmdb,
],
)
test(
unit_test,
exec_test,
suite: 'unit',
)
endforeach
endif
subdir('unit')
......@@ -19,7 +19,7 @@
#include <dlfcn.h>
#include <ucw/mempool.h>
#include "tests/test.h"
#include "tests/unit/test.h"
#include "lib/cache.h"
#include "lib/cache/cdb_lmdb.h"
......@@ -50,7 +50,7 @@ int knot_rdataset_gather(knot_rdataset_t *dst, knot_rdata_t **src, uint16_t coun
if (original_knot_rdataset_gather == NULL) {
original_knot_rdataset_gather = dlsym(RTLD_NEXT,"knot_rdataset_gather");
assert_non_null (original_knot_rdataset_gather);
}
}
err = original_knot_rdataset_gather(dst, src, count, mm);
if (err_mock != 0)
err = err_mock;
......
# Unit tests
# dependency
cmocka = dependency('cmocka', required: false)
if cmocka.found()
# mock module for test_module
mock_cmodule_src = [
'mock_cmodule.c',
]
mock_cmodule_lib = library(
'mock_cmodule',
mock_cmodule_src,
name_prefix: '',
dependencies: libkres_dep,
)
mock_cmodule_dep = declare_dependency(
link_with: mock_cmodule_lib,
)
# executables with tests
foreach unit_test : unit_tests
exec_test = executable(
unit_test[0],
unit_test[1],
dependencies: [
contrib_dep,
libkres_dep,
cmocka,
lmdb,
],
)
test(
unit_test[0],
exec_test,
suite: 'unit',
)
endforeach
endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment