From 5d6cd0568e211d4f13f8db3b058d0cd9d5b64702 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Sat, 15 Feb 2025 00:19:27 +0100 Subject: [PATCH] [#3729] Began perfdhcp UTs --- src/bin/d2/meson.build | 1 + src/bin/d2/tests/d2_process_tests.sh.in | 0 .../tests/meson-test_callout_libraries.h.in | 24 +++++ .../meson-test_configured_libraries.h.in | 26 +++++ src/bin/d2/tests/meson.build | 94 +++++++++++++++---- src/bin/perfdhcp/meson.build | 1 + src/bin/perfdhcp/tests/meson.build | 6 +- 7 files changed, 132 insertions(+), 20 deletions(-) mode change 100644 => 100755 src/bin/d2/tests/d2_process_tests.sh.in create mode 100644 src/bin/d2/tests/meson-test_callout_libraries.h.in create mode 100644 src/bin/d2/tests/meson-test_configured_libraries.h.in diff --git a/src/bin/d2/meson.build b/src/bin/d2/meson.build index e08d9d7bf9..b5abd2f79a 100644 --- a/src/bin/d2/meson.build +++ b/src/bin/d2/meson.build @@ -27,3 +27,4 @@ executable( install_dir: 'sbin', link_with: [d2_lib] + LIBS_BUILT_SO_FAR, ) +subdir('tests') diff --git a/src/bin/d2/tests/d2_process_tests.sh.in b/src/bin/d2/tests/d2_process_tests.sh.in old mode 100644 new mode 100755 diff --git a/src/bin/d2/tests/meson-test_callout_libraries.h.in b/src/bin/d2/tests/meson-test_callout_libraries.h.in new file mode 100644 index 0000000000..5f04b3ee7d --- /dev/null +++ b/src/bin/d2/tests/meson-test_callout_libraries.h.in @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef D2_TEST_CALLOUT_LIBRARIES_H +#define D2_TEST_CALLOUT_LIBRARIES_H + +#include + +namespace { + +// Names of the libraries used in these tests. These libraries are built using +// libtool, so we need to look in the hidden ".libs" directory to locate the +// .so file. Note that we access the .so file - libtool creates this as a +// like to the real shared library. + +// Basic callout library with context_create and three "standard" callouts. +static const char* CALLOUT_LIBRARY = "@abs_builddir@/libcallout.so"; + +} // anonymous namespace + +#endif // D2_TEST_CALLOUT_LIBRARIES_H diff --git a/src/bin/d2/tests/meson-test_configured_libraries.h.in b/src/bin/d2/tests/meson-test_configured_libraries.h.in new file mode 100644 index 0000000000..cd2fa47fd2 --- /dev/null +++ b/src/bin/d2/tests/meson-test_configured_libraries.h.in @@ -0,0 +1,26 @@ +// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef D2_TEST_CONFIGURED_LIBRARIES_H +#define D2_TEST_CONFIGURED_LIBRARIES_H + +#include + +namespace { + +// Names of the libraries used in these tests. These libraries are built using +// libtool, so we need to look in the hidden ".libs" directory to locate the +// .so file. Note that we access the .so file - libtool creates this as a +// like to the real shared library. + +// Configured library with d2_srv_configured testing: if there is a toplevel +// user context with an error entry the returned status is DROP with the +// content of the error entry. +static const char* CONFIGURED_LIBRARY = "@abs_builddir@/libconfigured.so"; + +} // anonymous namespace + +#endif // D2_TEST_CONFIGURED_LIBRARIES_H diff --git a/src/bin/d2/tests/meson.build b/src/bin/d2/tests/meson.build index 0ad9c90376..d5f8f95b1b 100644 --- a/src/bin/d2/tests/meson.build +++ b/src/bin/d2/tests/meson.build @@ -3,33 +3,91 @@ if not gtest.found() endif current_build_dir = meson.current_build_dir() +kea_d2_tests_data = configuration_data() +kea_d2_tests_data.set('abs_top_builddir', TOP_BUILD_DIR) +kea_d2_tests_data.set('abs_top_srcdir', TOP_SOURCE_DIR) +kea_d2_tests_data.set('abs_builddir', current_build_dir) +d2_process_tests = configure_file( + input: 'd2_process_tests.sh.in', + output: 'd2_process_tests.sh', + configuration: kea_d2_tests_data, +) +test( + 'd2_process_tests.sh', + d2_process_tests, + workdir: current_build_dir, + is_parallel: false, + priority: -1, +) +configure_file( + input: 'meson-test_callout_libraries.h.in', + output: 'test_callout_libraries.h', + configuration: kea_d2_tests_data, +) +configure_file( + input: 'test_data_files_config.h.in', + output: 'test_data_files_config.h', + configuration: kea_d2_tests_data, +) +configure_file( + input: 'meson-test_configured_libraries.h.in', + output: 'test_configured_libraries.h', + configuration: kea_d2_tests_data, +) +current_source_dir = meson.current_source_dir() +kea_d2_tests_libs = [ + kea_d2srv_testutils_lib, + kea_process_testutils_lib, + kea_testutils_lib, + kea_asiolink_testutils_lib, +] kea_d2_tests = executable( 'kea-d2-tests', - 'check_exists_add.cc', - 'check_exists_remove.cc', - 'd2_controller.cc', - 'd2_lexer.cc', - 'd2_parser.cc', - 'd2_process.cc', - 'd2_queue_mgr.cc', - 'd2_update_mgr.cc', - 'main.cc', - 'nc_add.cc', - 'nc_remove.cc', - 'parser_context.cc', - 'simple_add.cc', - 'simple_add_without_dhcid.cc', - 'simple_remove.cc', - 'simple_remove_without_dhcid.cc', + 'check_exists_add_unittests.cc', + 'check_exists_remove_unittests.cc', + 'd2_cfg_mgr_unittests.cc', + 'd2_command_unittest.cc', + 'd2_controller_unittests.cc', + 'd2_http_command_unittest.cc', + 'd2_process_unittests.cc', + 'd2_queue_mgr_unittests.cc', + 'd2_simple_parser_unittest.cc', + 'd2_unittests.cc', + 'd2_update_mgr_unittests.cc', + 'get_config_unittest.cc', + 'nc_add_unittests.cc', + 'nc_remove_unittests.cc', + 'parser_unittest.cc', + 'simple_add_unittests.cc', + 'simple_add_without_dhcid_unittests.cc', + 'simple_remove_unittests.cc', + 'simple_remove_without_dhcid_unittests.cc', cpp_args: [ + f'-DTEST_DATA_BUILDDIR="@current_build_dir@"', f'-DCFG_EXAMPLES="@TOP_SOURCE_DIR@/doc/examples/ddns"', f'-DSYNTAX_FILE="@current_source_dir@/../d2_parser.yy"', f'-DTEST_CA_DIR="@TEST_CA_DIR@"', - f'-DTEST_DATA_BUILDDIR="@current_build_dir@"', ], dependencies: [gtest], include_directories: [include_directories('.')] + INCLUDES, - link_with: [d2_lib] + LIBS_BUILT_SO_FAR, + link_with: [d2_lib] + kea_d2_tests_libs + LIBS_BUILT_SO_FAR, ) test('kea-d2-tests', kea_d2_tests, protocol: 'gtest') + +shared_library( + 'callout', + 'callout_library.cc', + include_directories: [include_directories('.')] + INCLUDES, + link_with: LIBS_BUILT_SO_FAR, + build_rpath: '/nowhere', + name_suffix: 'so', +) +shared_library( + 'configured', + 'configured_library.cc', + include_directories: [include_directories('.')] + INCLUDES, + link_with: LIBS_BUILT_SO_FAR, + build_rpath: '/nowhere', + name_suffix: 'so', +) diff --git a/src/bin/perfdhcp/meson.build b/src/bin/perfdhcp/meson.build index 6a52e2e86b..36c8353d9e 100644 --- a/src/bin/perfdhcp/meson.build +++ b/src/bin/perfdhcp/meson.build @@ -21,3 +21,4 @@ executable( install_dir: 'sbin', link_with: [perfdhcp_lib] + LIBS_BUILT_SO_FAR, ) +subdir('tests') diff --git a/src/bin/perfdhcp/tests/meson.build b/src/bin/perfdhcp/tests/meson.build index 8d02b2b469..96bd4b9a01 100644 --- a/src/bin/perfdhcp/tests/meson.build +++ b/src/bin/perfdhcp/tests/meson.build @@ -2,6 +2,7 @@ if not gtest.found() subdir_done() endif +current_source_dir = meson.current_source_dir() perfdhcp_tests = executable( 'perfdhcp-tests', 'avalanche_scen_unittest.cc', @@ -17,8 +18,9 @@ perfdhcp_tests = executable( 'run_unittests.cc', 'stats_mgr_unittest.cc', 'test_control_unittest.cc', + cpp_args: [f'-DTEST_DATA_DIR="@current_source_dir@/testdata"'], dependencies: [gtest], - include_directories: [include_directories('.')] + INCLUDES, - link_with: LIBS_BUILT_SO_FAR, + include_directories: [include_directories('.'), include_directories('..')] + INCLUDES, + link_with: [perfdhcp_lib, kea_util_unittests_lib] + LIBS_BUILT_SO_FAR, ) test('perfdhcp-tests', perfdhcp_tests, protocol: 'gtest') -- 2.47.3