From 7bca5a12b22b23b9082a28c8e66bccf08b9bfe08 Mon Sep 17 00:00:00 2001 From: yunhanw Date: Mon, 14 Sep 2020 12:13:47 -0700 Subject: [PATCH] Enable TestInetEndPoint and TestInetLayerDNS Problem Missing TestInetEndPoint and TestInetLayerDNS for Inet layer Summary of Changes Add TestInetEndPoint and TestInetLayerDNS Add priviledge and host network to enable IPv6 in docker Fix #329 --- .github/workflows/build.yaml | 1 + src/inet/tests/BUILD.gn | 2 + src/inet/tests/TestInetEndPoint.cpp | 38 ++++++++-------- src/inet/tests/TestInetEndPointDriver.cpp | 36 +++++++++++++++ src/inet/tests/TestInetLayer.h | 3 +- src/inet/tests/TestInetLayerDNS.cpp | 53 ++++++++++++----------- src/inet/tests/TestInetLayerDNSDriver.cpp | 36 +++++++++++++++ 7 files changed, 124 insertions(+), 45 deletions(-) create mode 100644 src/inet/tests/TestInetEndPointDriver.cpp create mode 100644 src/inet/tests/TestInetLayerDNSDriver.cpp diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6834b2e45e16c0..19615522fb71ba 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -37,6 +37,7 @@ jobs: image: connectedhomeip/chip-build:0.4.6 volumes: - "/tmp/log_output:/tmp/test_logs" + options: --privileged steps: - name: Checkout diff --git a/src/inet/tests/BUILD.gn b/src/inet/tests/BUILD.gn index fe968dbea03dde..bb5bc1b7fd9614 100644 --- a/src/inet/tests/BUILD.gn +++ b/src/inet/tests/BUILD.gn @@ -53,5 +53,7 @@ chip_test_suite("tests") { tests = [ "TestInetAddress", "TestInetErrorStr", + "TestInetEndPoint", + "TestInetLayerDNS" ] } diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp index 156561ea7a4bab..22356aa42e9528 100644 --- a/src/inet/tests/TestInetEndPoint.cpp +++ b/src/inet/tests/TestInetEndPoint.cpp @@ -28,6 +28,8 @@ #define __STDC_LIMIT_MACROS #endif +#include "TestInetLayer.h" + #include #include #include @@ -55,10 +57,10 @@ using namespace chip::System; #define TOOL_NAME "TestInetEndPoint" -static ArgParser::HelpOptions gHelpOptions(TOOL_NAME, "Usage: " TOOL_NAME " []\n", +ArgParser::HelpOptions gHelpOptions(TOOL_NAME, "Usage: " TOOL_NAME " []\n", CHIP_VERSION_STRING "\n" CHIP_TOOL_COPYRIGHT); -static ArgParser::OptionSet * gToolOptionSets[] = { &gNetworkOptions, &gFaultInjectionOptions, &gHelpOptions, NULL }; +ArgParser::OptionSet * gToolOptionSets[] = { &gNetworkOptions, &gFaultInjectionOptions, &gHelpOptions, NULL }; bool callbackHandlerCalled = false; @@ -82,7 +84,7 @@ void HandleTimer(Layer * aLayer, void * aAppState, Error aError) } // Test before init network, Inet is not initialized -static void TestInetPre(nlTestSuite * inSuite, void * inContext) +void TestInetPre(nlTestSuite * inSuite, void * inContext) { #if INET_CONFIG_ENABLE_RAW_ENDPOINT RawEndPoint * testRawEP = NULL; @@ -127,9 +129,9 @@ static void TestInetPre(nlTestSuite * inSuite, void * inContext) #if INET_CONFIG_ENABLE_DNS_RESOLVER // Test Inet ResolveHostAddress functionality -static void TestResolveHostAddress(nlTestSuite * inSuite, void * inContext) +void TestResolveHostAddress(nlTestSuite * inSuite, void * inContext) { - char testHostName1[20] = "www.nest.com"; + char testHostName1[20] = "www.google.com"; char testHostName2[20] = "127.0.0.1"; char testHostName3[20] = ""; char testHostName4[260]; @@ -188,10 +190,10 @@ static void TestResolveHostAddress(nlTestSuite * inSuite, void * inContext) #endif // INET_CONFIG_ENABLE_DNS_RESOLVER // Test Inet ParseHostPortAndInterface -static void TestParseHost(nlTestSuite * inSuite, void * inContext) +void TestParseHost(nlTestSuite * inSuite, void * inContext) { char correctHostName[7][30] = { - "10.0.0.1", "10.0.0.1:3000", "www.nest.com", "www.nest.com:3000", "[fd00:0:1:1::1]:3000", "[fd00:0:1:1::1]:300%wpan0", + "10.0.0.1", "10.0.0.1:3000", "www.google.com", "www.google.com:3000", "[fd00:0:1:1::1]:3000", "[fd00:0:1:1::1]:300%wpan0", "%wpan0" }; char invalidHostName[4][30] = { "[fd00::1]5", "[fd00:0:1:1::1:3000", "10.0.0.1:1234567", "10.0.0.1:er31" }; @@ -214,7 +216,7 @@ static void TestParseHost(nlTestSuite * inSuite, void * inContext) } } -static void TestInetError(nlTestSuite * inSuite, void * inContext) +void TestInetError(nlTestSuite * inSuite, void * inContext) { INET_ERROR err = INET_NO_ERROR; @@ -223,7 +225,7 @@ static void TestInetError(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, IsErrorPOSIX(err)); } -static void TestInetInterface(nlTestSuite * inSuite, void * inContext) +void TestInetInterface(nlTestSuite * inSuite, void * inContext) { InterfaceIterator intIterator; InterfaceAddressIterator addrIterator; @@ -296,7 +298,7 @@ static void TestInetInterface(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, !addrIterator.HasBroadcastAddress()); } -static void TestInetEndPoint(nlTestSuite * inSuite, void * inContext) +void TestInetEndPointFunct(nlTestSuite * inSuite, void * inContext) { INET_ERROR err; IPAddress addr_any = IPAddress::Any; @@ -478,7 +480,7 @@ static void TestInetEndPoint(nlTestSuite * inSuite, void * inContext) } // Test the InetLayer resource limitation -static void TestInetEndPointLimit(nlTestSuite * inSuite, void * inContext) +void TestInetEndPointLimit(nlTestSuite * inSuite, void * inContext) { RawEndPoint * testRawEP = NULL; UDPEndPoint * testUDPEP = NULL; @@ -525,7 +527,7 @@ static const nlTest sTests[] = { NL_TEST_DEF("InetEndPoint::PreTest", TestInetPr NL_TEST_DEF("InetEndPoint::TestParseHost", TestParseHost), NL_TEST_DEF("InetEndPoint::TestInetError", TestInetError), NL_TEST_DEF("InetEndPoint::TestInetInterface", TestInetInterface), - NL_TEST_DEF("InetEndPoint::TestInetEndPoint", TestInetEndPoint), + NL_TEST_DEF("InetEndPoint::TestInetEndPoint", TestInetEndPointFunct), NL_TEST_DEF("InetEndPoint::TestEndPointLimit", TestInetEndPointLimit), NL_TEST_SENTINEL() }; @@ -535,7 +537,7 @@ static const nlTest sTests[] = { NL_TEST_DEF("InetEndPoint::PreTest", TestInetPr * This is a work-around to initiate PacketBuffer protected class instance's * data and set it to a known state, before an instance is created. */ -static int TestSetup(void * inContext) +int TestSetup(void * inContext) { return (SUCCESS); } @@ -544,13 +546,13 @@ static int TestSetup(void * inContext) * Tear down the test suite. * Free memory reserved at TestSetup. */ -static int TestTeardown(void * inContext) +int TestTeardown(void * inContext) { return (SUCCESS); } #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS -int TestInetEndPoint(void) +int TestInetEndPointFunct(void) { #if CHIP_SYSTEM_CONFIG_USE_SOCKETS // clang-format off @@ -574,10 +576,10 @@ int TestInetEndPoint(void) static void __attribute__((constructor)) TestCHIPInetEndpointCtor(void) { - VerifyOrDie(RegisterUnitTests(&TestInetEndPoint) == CHIP_NO_ERROR); + VerifyOrDie(RegisterUnitTests(&TestInetEndPointFunct) == CHIP_NO_ERROR); } -int main(int argc, char * argv[]) +int TestInetEndPoint(int argc, char * argv[]) { SetSIGUSR1Handler(); @@ -589,5 +591,5 @@ int main(int argc, char * argv[]) // Generate machine-readable, comma-separated value (CSV) output. nlTestSetOutputStyle(OUTPUT_CSV); - return (TestInetEndPoint()); + return (TestInetEndPointFunct()); } diff --git a/src/inet/tests/TestInetEndPointDriver.cpp b/src/inet/tests/TestInetEndPointDriver.cpp new file mode 100644 index 00000000000000..b63a1c201c164e --- /dev/null +++ b/src/inet/tests/TestInetEndPointDriver.cpp @@ -0,0 +1,36 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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 standalone/native program executable + * test driver for the CHIP Internet (inet) library address unit + * tests. + * + */ + +#include "TestInetLayer.h" + +#include + +int main(int argc, char * argv[]) +{ + // Generate machine-readable, comma-separated value (CSV) output. + nlTestSetOutputStyle(OUTPUT_CSV); + + return (TestInetEndPoint(argc, argv)); +} diff --git a/src/inet/tests/TestInetLayer.h b/src/inet/tests/TestInetLayer.h index 60823ca35835f0..cc8e572ded165c 100644 --- a/src/inet/tests/TestInetLayer.h +++ b/src/inet/tests/TestInetLayer.h @@ -33,7 +33,8 @@ int TestInetAddress(void); int TestInetBuffer(void); int TestInetErrorStr(void); int TestInetTimer(void); - +int TestInetEndPoint(int argc, char * argv[]); +int TestInetLayerDNS(int argc, char * argv[]); #ifdef __cplusplus } #endif diff --git a/src/inet/tests/TestInetLayerDNS.cpp b/src/inet/tests/TestInetLayerDNS.cpp index a7cfa1c35ee1c5..44c8351a2144bd 100644 --- a/src/inet/tests/TestInetLayerDNS.cpp +++ b/src/inet/tests/TestInetLayerDNS.cpp @@ -27,6 +27,8 @@ #define __STDC_LIMIT_MACROS #endif +#include "TestInetLayer.h" + #include #include #include @@ -76,18 +78,18 @@ struct DNSResolutionTestContext IPAddress resultsBuf[kMaxResults]; }; -static void RunTestCase(nlTestSuite * testSuite, const DNSResolutionTestCase & testCase); -static void StartTestCase(DNSResolutionTestContext & testContext); -static void HandleResolutionComplete(void * appState, INET_ERROR err, uint8_t addrCount, IPAddress * addrArray); -static void ServiceNetworkUntilDone(uint32_t timeoutMS); -static void HandleSIGUSR1(int sig); +void RunTestCase(nlTestSuite * testSuite, const DNSResolutionTestCase & testCase); +void StartTestCase(DNSResolutionTestContext & testContext); +void HandleResolutionComplete(void * appState, INET_ERROR err, uint8_t addrCount, IPAddress * addrArray); +void ServiceNetworkUntilDone(uint32_t timeoutMS); +void HandleSIGUSR1(int sig); // clang-format off -static ArgParser::HelpOptions gHelpOptions(TOOL_NAME, +ArgParser::HelpOptions gHelpOptions(TOOL_NAME, "Usage: " TOOL_NAME " []\n", CHIP_VERSION_STRING "\n" CHIP_TOOL_COPYRIGHT); -static ArgParser::OptionSet * gToolOptionSets[] = +ArgParser::OptionSet * gToolOptionSets[] = { &gNetworkOptions, &gFaultInjectionOptions, @@ -99,7 +101,7 @@ static ArgParser::OptionSet * gToolOptionSets[] = /** * Test basic name resolution functionality. */ -static void TestDNSResolution_Basic(nlTestSuite * testSuite, void * testContext) +void TestDNSResolution_Basic(nlTestSuite * testSuite, void * testContext) { // clang-format off @@ -147,7 +149,7 @@ static void TestDNSResolution_Basic(nlTestSuite * testSuite, void * testContext) /** * Test resolving a name using various address type options. */ -static void TestDNSResolution_AddressTypeOption(nlTestSuite * testSuite, void * testContext) +void TestDNSResolution_AddressTypeOption(nlTestSuite * testSuite, void * testContext) { // clang-format off @@ -212,7 +214,7 @@ static void TestDNSResolution_AddressTypeOption(nlTestSuite * testSuite, void * /** * Test resolving a name with a limited number of results. */ -static void TestDNSResolution_RestrictedResults(nlTestSuite * testSuite, void * testContext) +void TestDNSResolution_RestrictedResults(nlTestSuite * testSuite, void * testContext) { // clang-format off @@ -279,7 +281,7 @@ static void TestDNSResolution_RestrictedResults(nlTestSuite * testSuite, void * /** * Test resolving a non-existant name. */ -static void TestDNSResolution_NoRecord(nlTestSuite * testSuite, void * testContext) +void TestDNSResolution_NoRecord(nlTestSuite * testSuite, void * testContext) { // clang-format off RunTestCase(testSuite, @@ -299,7 +301,7 @@ static void TestDNSResolution_NoRecord(nlTestSuite * testSuite, void * testConte /** * Test resolving a name where the resultant DNS entry lacks an A or AAAA record. */ -static void TestDNSResolution_NoHostRecord(nlTestSuite * testSuite, void * testContext) +void TestDNSResolution_NoHostRecord(nlTestSuite * testSuite, void * testContext) { // clang-format off @@ -349,7 +351,7 @@ static void TestDNSResolution_NoHostRecord(nlTestSuite * testSuite, void * testC /** * Test resolving text form IP addresses. */ -static void TestDNSResolution_TextForm(nlTestSuite * testSuite, void * testContext) +void TestDNSResolution_TextForm(nlTestSuite * testSuite, void * testContext) { // clang-format off RunTestCase(testSuite, @@ -405,7 +407,7 @@ static void TestDNSResolution_TextForm(nlTestSuite * testSuite, void * testConte // clang-format on } -static void TestDNSResolution_Cancel(nlTestSuite * testSuite, void * inContext) +void TestDNSResolution_Cancel(nlTestSuite * testSuite, void * inContext) { DNSResolutionTestContext testContext{ testSuite, DNSResolutionTestCase{ "www.google.com", kDNSOption_Default, kMaxResults, INET_NO_ERROR, true, false } @@ -433,7 +435,7 @@ static void TestDNSResolution_Cancel(nlTestSuite * testSuite, void * inContext) sNumResInProgress = 0; } -static void TestDNSResolution_Simultaneous(nlTestSuite * testSuite, void * inContext) +void TestDNSResolution_Simultaneous(nlTestSuite * testSuite, void * inContext) { // clang-format off DNSResolutionTestContext tests[] = @@ -505,7 +507,7 @@ static void TestDNSResolution_Simultaneous(nlTestSuite * testSuite, void * inCon NL_TEST_ASSERT(testSuite, sNumResInProgress == 0); } -static void RunTestCase(nlTestSuite * testSuite, const DNSResolutionTestCase & testCase) +void RunTestCase(nlTestSuite * testSuite, const DNSResolutionTestCase & testCase) { DNSResolutionTestContext testContext{ testSuite, testCase }; @@ -522,7 +524,7 @@ static void RunTestCase(nlTestSuite * testSuite, const DNSResolutionTestCase & t NL_TEST_ASSERT(testSuite, sNumResInProgress == 0); } -static void StartTestCase(DNSResolutionTestContext & testContext) +void StartTestCase(DNSResolutionTestContext & testContext) { INET_ERROR err = INET_NO_ERROR; DNSResolutionTestCase & testCase = testContext.testCase; @@ -553,7 +555,7 @@ static void StartTestCase(DNSResolutionTestContext & testContext) } } -static void HandleResolutionComplete(void * appState, INET_ERROR err, uint8_t addrCount, IPAddress * addrArray) +void HandleResolutionComplete(void * appState, INET_ERROR err, uint8_t addrCount, IPAddress * addrArray) { DNSResolutionTestContext & testContext = *static_cast(appState); DNSResolutionTestCase & testCase = testContext.testCase; @@ -653,7 +655,7 @@ static void HandleResolutionComplete(void * appState, INET_ERROR err, uint8_t ad } } -static void ServiceNetworkUntilDone(uint32_t timeoutMS) +void ServiceNetworkUntilDone(uint32_t timeoutMS) { uint64_t timeoutTimeMS = System::Layer::GetClock_MonotonicMS() + timeoutMS; struct timeval sleepTime; @@ -671,14 +673,14 @@ static void ServiceNetworkUntilDone(uint32_t timeoutMS) } } -static void HandleSIGUSR1(int sig) +void HandleSIGUSR1(int sig) { gInet.Shutdown(); exit(0); } -int TestInetLayerDNS(void) +int TestInetLayerDNSFunct(void) { // clang-format off const nlTest DNSTests[] = @@ -719,12 +721,11 @@ int TestInetLayerDNS(void) static void __attribute__((constructor)) TestCHIPInetLayerDNSCtor(void) { - VerifyOrDie(RegisterUnitTests(&TestInetLayerDNS) == CHIP_NO_ERROR); + VerifyOrDie(RegisterUnitTests(&TestInetLayerDNSFunct) == CHIP_NO_ERROR); } - #else // !INET_CONFIG_ENABLE_DNS_RESOLVER -int TestInetLayerDNS(void) +int TestInetLayerDNSFunct(void) { fprintf(stderr, "Please assert INET_CONFIG_ENABLE_DNS_RESOLVER to use this test.\n"); @@ -733,7 +734,7 @@ int TestInetLayerDNS(void) #endif // !INET_CONFIG_ENABLE_DNS_RESOLVER -int main(int argc, char * argv[]) +int TestInetLayerDNS(int argc, char * argv[]) { SetupFaultInjectionContext(argc, argv); @@ -747,5 +748,5 @@ int main(int argc, char * argv[]) nlTestSetOutputStyle(OUTPUT_CSV); - return (TestInetLayerDNS()); + return (TestInetLayerDNSFunct()); } diff --git a/src/inet/tests/TestInetLayerDNSDriver.cpp b/src/inet/tests/TestInetLayerDNSDriver.cpp new file mode 100644 index 00000000000000..a3485b940d0b3f --- /dev/null +++ b/src/inet/tests/TestInetLayerDNSDriver.cpp @@ -0,0 +1,36 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * 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 standalone/native program executable + * test driver for the CHIP Internet (inet) library address unit + * tests. + * + */ + +#include "TestInetLayer.h" + +#include + +int main(int argc, char * argv[]) +{ + // Generate machine-readable, comma-separated value (CSV) output. + nlTestSetOutputStyle(OUTPUT_CSV); + + return (TestInetLayerDNS(argc, argv)); +}