From 95e644cc9703ad2efa20e645b3678bc8716e21ae Mon Sep 17 00:00:00 2001 From: Jakub Latusek Date: Thu, 16 Nov 2023 17:37:34 +0100 Subject: [PATCH] Use source_set in all tests fix TestLwiPDNS test --- build/chip/chip_test_group.gni | 2 +- build/chip/chip_test_suite.gni | 14 +--- build/chip/tests.gni | 5 -- src/inet/tests/BUILD.gn | 1 + src/inet/tests/TestLwIPDNS.cpp | 74 +---------------- src/inet/tests/TestLwIPDNS.h | 29 +++++++ src/inet/tests/TestLwIPDNSDriver.cpp | 115 +++++++++++++++++++++++++++ src/platform/tests/BUILD.gn | 5 +- 8 files changed, 152 insertions(+), 93 deletions(-) create mode 100644 src/inet/tests/TestLwIPDNS.h create mode 100644 src/inet/tests/TestLwIPDNSDriver.cpp diff --git a/build/chip/chip_test_group.gni b/build/chip/chip_test_group.gni index bc092c46ab6bcd..b5017cc358269b 100644 --- a/build/chip/chip_test_group.gni +++ b/build/chip/chip_test_group.gni @@ -46,7 +46,7 @@ template("chip_test_group") { deps += [ get_label_info(_test, "label_no_toolchain") + ".lib" ] } - if (_build_monolithic_library && chip_build_test_static_libraries) { + if (_build_monolithic_library) { complete_static_lib = true } } diff --git a/build/chip/chip_test_suite.gni b/build/chip/chip_test_suite.gni index 596642d5335241..f043534bf0129f 100644 --- a/build/chip/chip_test_suite.gni +++ b/build/chip/chip_test_suite.gni @@ -80,12 +80,7 @@ template("chip_test_suite") { invoker.sources += invoker.test_sources } - if (chip_build_test_static_libraries) { - _target_type = "static_library" - } else { - _target_type = "source_set" - } - target(_target_type, "${_suite_name}.lib") { + pw_source_set("${_suite_name}.lib") { forward_variables_from(invoker, "*", [ "tests" ]) output_dir = "${root_out_dir}/lib" @@ -178,12 +173,7 @@ template("chip_test_suite_using_nltest") { invoker.sources += invoker.test_sources } - if (chip_build_test_static_libraries) { - _target_type = "static_library" - } else { - _target_type = "source_set" - } - target(_target_type, "${_suite_name}.lib") { + target("source_set", "${_suite_name}.lib") { forward_variables_from(invoker, "*", [ "tests" ]) output_dir = "${root_out_dir}/lib" diff --git a/build/chip/tests.gni b/build/chip/tests.gni index 61a2ad3e685682..cbc3e02fe918f6 100644 --- a/build/chip/tests.gni +++ b/build/chip/tests.gni @@ -34,11 +34,6 @@ declare_args() { chip_pw_run_tests = chip_link_tests && current_os != "tizen" } -declare_args() { - # Use source_set instead of static_lib for tests. - chip_build_test_static_libraries = chip_device_platform != "efr32" -} - declare_args() { # Enable use of nlfaultinjection. chip_with_nlfaultinjection = chip_build_tests diff --git a/src/inet/tests/BUILD.gn b/src/inet/tests/BUILD.gn index df98b8ee30deb6..f03b1f499ca8fd 100644 --- a/src/inet/tests/BUILD.gn +++ b/src/inet/tests/BUILD.gn @@ -91,6 +91,7 @@ chip_test_suite_using_nltest("tests") { chip_device_platform != "ameba") { # TODO: This test does not seem executed sources += [ "TestLwIPDNS.cpp" ] + tests = [ "TestLwIPDNS" ] } cflags = [ "-Wconversion" ] diff --git a/src/inet/tests/TestLwIPDNS.cpp b/src/inet/tests/TestLwIPDNS.cpp index 8681f7b2e54328..85af47bb4ab8da 100644 --- a/src/inet/tests/TestLwIPDNS.cpp +++ b/src/inet/tests/TestLwIPDNS.cpp @@ -51,32 +51,11 @@ using namespace chip::Inet; #define TOOL_NAME "TestLwIPDNS" -static bool HandleNonOptionArgs(const char * progName, int argc, char * const argv[]); - -// Globals - #if CHIP_SYSTEM_CONFIG_USE_LWIP static uint8_t sNumIpAddrs = DNS_MAX_ADDRS_PER_NAME; static ip_addr_t sIpAddrs[DNS_MAX_ADDRS_PER_NAME]; #endif // CHIP_SYSTEM_CONFIG_USE_LWIP -static const char * sHostname = nullptr; -static const char * sDNSServerAddr = nullptr; - -// clang-format off -static ArgParser::HelpOptions gHelpOptions(TOOL_NAME, - "Usage: " TOOL_NAME " [] \n", - CHIP_VERSION_STRING "\n" CHIP_TOOL_COPYRIGHT); - -static ArgParser::OptionSet * gToolOptionSets[] = -{ - &gNetworkOptions, - &gFaultInjectionOptions, - &gHelpOptions, - nullptr -}; -// clang-format on - #if CHIP_SYSTEM_CONFIG_USE_LWIP static void found_multi(const char * aName, ip_addr_t * aIpAddrs, uint8_t aNumIpAddrs, void * callback_arg) { @@ -96,7 +75,7 @@ static void found_multi(const char * aName, ip_addr_t * aIpAddrs, uint8_t aNumIp Done = true; } -static void TestLwIPDNS(void) +static void TestLwIPDNS(const char *sDNSServerAddr) { uint8_t numdns = 1; ip_addr_t dnsserver[1]; @@ -207,54 +186,3 @@ static void TestLwIPDNS(void) } } #endif // CHIP_SYSTEM_CONFIG_USE_LWIP - -int main(int argc, char * argv[]) -{ - SetSIGUSR1Handler(); - - if (argc == 1) - { - gHelpOptions.PrintBriefUsage(stderr); - exit(EXIT_FAILURE); - } - - if (!ParseArgs(TOOL_NAME, argc, argv, gToolOptionSets, HandleNonOptionArgs)) - { - exit(EXIT_FAILURE); - } - - InitSystemLayer(); - - InitNetwork(); - -#if CHIP_SYSTEM_CONFIG_USE_LWIP - TestLwIPDNS(); -#else - fprintf(stderr, "Please assert CHIP_SYSTEM_CONFIG_USE_LWIP to use this test.\n"); -#endif // CHIP_SYSTEM_CONFIG_USE_LWIP - - ShutdownNetwork(); - - ShutdownSystemLayer(); - - return (EXIT_SUCCESS); -} - -static bool HandleNonOptionArgs(const char * progName, int argc, char * const argv[]) -{ - if (argc < 2) - { - printf("TestDNS: Missing %s argument\n", argc == 0 ? "" : ""); - return false; - } - - if (argc > 2) - { - printf("Unexpected argument: %s\n", argv[1]); - } - - sHostname = argv[0]; - sDNSServerAddr = argv[1]; - - return true; -} diff --git a/src/inet/tests/TestLwIPDNS.h b/src/inet/tests/TestLwIPDNS.h new file mode 100644 index 00000000000000..95da0688130995 --- /dev/null +++ b/src/inet/tests/TestLwIPDNS.h @@ -0,0 +1,29 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2023 Samsung + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file implements a process to effect a functional test for + * LwIP's Domain Name Service (DNS) interface. + * + */ + +#if CHIP_SYSTEM_CONFIG_USE_LWIP +static void TestLwIPDNS(const char * sDNSServerAddr); +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP diff --git a/src/inet/tests/TestLwIPDNSDriver.cpp b/src/inet/tests/TestLwIPDNSDriver.cpp new file mode 100644 index 00000000000000..b04d81f47a4fb1 --- /dev/null +++ b/src/inet/tests/TestLwIPDNSDriver.cpp @@ -0,0 +1,115 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2013-2017 Nest Labs, Inc. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file implements a process to effect a functional test for + * LwIP's Domain Name Service (DNS) interface. + * + */ + +#include +#include + +#include +#include + +#include + +#include + +#include + +#include "TestInetCommon.h" +#include "TestInetCommonOptions.h" +#include "TestSetupFaultInjection.h" +#include "TestSetupSignalling.h" + +using namespace chip; +using namespace chip::Inet; + +#define TOOL_NAME "TestLwIPDNS" + +static bool HandleNonOptionArgs(const char * progName, int argc, char * const argv[]); + +static const char * sDNSServerAddr = nullptr; + +// clang-format off +static ArgParser::HelpOptions gHelpOptions(TOOL_NAME, + "Usage: " TOOL_NAME " [] \n", + CHIP_VERSION_STRING "\n" CHIP_TOOL_COPYRIGHT); + +static ArgParser::OptionSet * gToolOptionSets[] = +{ + &gNetworkOptions, + &gFaultInjectionOptions, + &gHelpOptions, + nullptr +}; +// clang-format on + +int main(int argc, char * argv[]) +{ + SetSIGUSR1Handler(); + + if (argc == 1) + { + gHelpOptions.PrintBriefUsage(stderr); + exit(EXIT_FAILURE); + } + + if (!ParseArgs(TOOL_NAME, argc, argv, gToolOptionSets, HandleNonOptionArgs)) + { + exit(EXIT_FAILURE); + } + + InitSystemLayer(); + + InitNetwork(); + +#if CHIP_SYSTEM_CONFIG_USE_LWIP + TestLwIPDNS(sDNSServerAddr); +#else + fprintf(stderr, "Please assert CHIP_SYSTEM_CONFIG_USE_LWIP to use this test.\n"); +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP + + ShutdownNetwork(); + + ShutdownSystemLayer(); + + return (EXIT_SUCCESS); +} + +static bool HandleNonOptionArgs(const char * progName, int argc, char * const argv[]) +{ + if (argc < 2) + { + printf("TestDNS: Missing %s argument\n", argc == 0 ? "" : ""); + return false; + } + + if (argc > 2) + { + printf("Unexpected argument: %s\n", argv[1]); + } + + sDNSServerAddr = argv[1]; + + return true; +} diff --git a/src/platform/tests/BUILD.gn b/src/platform/tests/BUILD.gn index d5b4ebf1f60048..8a9e504a9cb061 100644 --- a/src/platform/tests/BUILD.gn +++ b/src/platform/tests/BUILD.gn @@ -80,9 +80,10 @@ if (chip_device_platform != "none" && chip_device_platform != "fake") { sources = [ "TestCHIPoBLEStackMgr.cpp", "TestCHIPoBLEStackMgr.h", - "TestCHIPoBLEStackMgrDriver.cpp", ] - tests = [ "TestCHIPoBLEStackMgr" ] + tests = [ + "TestCHIPoBLEStackMgr", + ] } if (current_os == "zephyr" || current_os == "android" ||