Skip to content

Commit

Permalink
Enable TestInetEndPoint and TestInetLayerDNS (#2644)
Browse files Browse the repository at this point in the history
Problem
Missing TestInetEndPoint and TestInetLayerDNS for Inet layer

Summary of Changes
Add TestInetEndPoint and TestInetLayerDNS
Add IPv6 support in docker

Fix #329
  • Loading branch information
yunhanw-google authored Sep 17, 2020
1 parent ec9744d commit 15b4c2d
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 49 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
image: connectedhomeip/chip-build:0.4.7
volumes:
- "/tmp/log_output:/tmp/test_logs"
options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1"

steps:
- name: Checkout
Expand Down
2 changes: 2 additions & 0 deletions src/inet/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ chip_test_suite("tests") {
tests = [
"TestInetAddress",
"TestInetErrorStr",
"TestInetEndPoint",
"TestInetLayerDNS",
]
}
9 changes: 7 additions & 2 deletions src/inet/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,20 @@ TestLwIPDNS_LDADD = libTestInetCommon.a $(CO
TestInetAddress_SOURCES = TestInetAddressDriver.cpp
TestInetAddress_LDADD = $(COMMON_LDADD)

TestInetEndPoint_SOURCES = TestInetEndPoint.cpp \
TestInetEndPoint_SOURCES = TestInetEndPointDriver.cpp \
TestInetEndPoint.cpp \
$(NULL)

TestInetEndPoint_LDADD = libTestInetCommon.a $(COMMON_LDADD)

TestInetErrorStr_SOURCES = TestInetErrorStrDriver.cpp \
$(NULL)
TestInetErrorStr_LDADD = $(COMMON_LDADD)

TestInetLayerDNS_SOURCES = TestInetLayerDNS.cpp
TestInetLayerDNS_SOURCES = TestInetLayerDNSDriver.cpp \
TestInetLayerDNS.cpp \
$(NULL)

TestInetLayerDNS_LDADD = libTestInetCommon.a $(COMMON_LDADD)

TestInetLayer_SOURCES = TestInetLayer.cpp \
Expand Down
28 changes: 10 additions & 18 deletions src/inet/tests/TestInetEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define __STDC_LIMIT_MACROS
#endif

#include "TestInetLayer.h"

#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
Expand Down Expand Up @@ -55,11 +57,6 @@ using namespace chip::System;

#define TOOL_NAME "TestInetEndPoint"

static ArgParser::HelpOptions gHelpOptions(TOOL_NAME, "Usage: " TOOL_NAME " [<options...>]\n",
CHIP_VERSION_STRING "\n" CHIP_TOOL_COPYRIGHT);

static ArgParser::OptionSet * gToolOptionSets[] = { &gNetworkOptions, &gFaultInjectionOptions, &gHelpOptions, NULL };

bool callbackHandlerCalled = false;

void HandleDNSResolveComplete(void * appState, INET_ERROR err, uint8_t addrCount, IPAddress * addrArray)
Expand Down Expand Up @@ -129,7 +126,7 @@ static void TestInetPre(nlTestSuite * inSuite, void * inContext)
// Test Inet ResolveHostAddress functionality
static 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];
Expand Down Expand Up @@ -191,7 +188,7 @@ static void TestResolveHostAddress(nlTestSuite * inSuite, void * inContext)
static 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" };
Expand Down Expand Up @@ -296,7 +293,7 @@ static void TestInetInterface(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, !addrIterator.HasBroadcastAddress());
}

static void TestInetEndPoint(nlTestSuite * inSuite, void * inContext)
static void TestInetEndPointInternal(nlTestSuite * inSuite, void * inContext)
{
INET_ERROR err;
IPAddress addr_any = IPAddress::Any;
Expand Down Expand Up @@ -525,7 +522,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", TestInetEndPointInternal),
NL_TEST_DEF("InetEndPoint::TestEndPointLimit", TestInetEndPointLimit),
NL_TEST_SENTINEL() };

Expand All @@ -550,7 +547,7 @@ static int TestTeardown(void * inContext)
}
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS

int TestInetEndPoint(void)
int TestInetEndPointInternal(void)
{
#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
// clang-format off
Expand All @@ -574,20 +571,15 @@ int TestInetEndPoint(void)

static void __attribute__((constructor)) TestCHIPInetEndpointCtor(void)
{
VerifyOrDie(RegisterUnitTests(&TestInetEndPoint) == CHIP_NO_ERROR);
VerifyOrDie(RegisterUnitTests(&TestInetEndPointInternal) == CHIP_NO_ERROR);
}

int main(int argc, char * argv[])
int TestInetEndPoint()
{
SetSIGUSR1Handler();

if (!ParseArgs(TOOL_NAME, argc, argv, gToolOptionSets, NULL))
{
exit(EXIT_FAILURE);
}

// Generate machine-readable, comma-separated value (CSV) output.
nlTestSetOutputStyle(OUTPUT_CSV);

return (TestInetEndPoint());
return (TestInetEndPointInternal());
}
36 changes: 36 additions & 0 deletions src/inet/tests/TestInetEndPointDriver.cpp
Original file line number Diff line number Diff line change
@@ -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 <nlunit-test.h>

int main(void)
{
// Generate machine-readable, comma-separated value (CSV) output.
nlTestSetOutputStyle(OUTPUT_CSV);

return (TestInetEndPoint());
}
3 changes: 2 additions & 1 deletion src/inet/tests/TestInetLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ int TestInetAddress(void);
int TestInetBuffer(void);
int TestInetErrorStr(void);
int TestInetTimer(void);

int TestInetEndPoint(void);
int TestInetLayerDNS(void);
#ifdef __cplusplus
}
#endif
Expand Down
35 changes: 7 additions & 28 deletions src/inet/tests/TestInetLayerDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define __STDC_LIMIT_MACROS
#endif

#include "TestInetLayer.h"

#include <inttypes.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -82,20 +84,6 @@ static void HandleResolutionComplete(void * appState, INET_ERROR err, uint8_t ad
static void ServiceNetworkUntilDone(uint32_t timeoutMS);
static void HandleSIGUSR1(int sig);

// clang-format off
static ArgParser::HelpOptions gHelpOptions(TOOL_NAME,
"Usage: " TOOL_NAME " [<options...>]\n",
CHIP_VERSION_STRING "\n" CHIP_TOOL_COPYRIGHT);

static ArgParser::OptionSet * gToolOptionSets[] =
{
&gNetworkOptions,
&gFaultInjectionOptions,
&gHelpOptions,
NULL
};
// clang-format on

/**
* Test basic name resolution functionality.
*/
Expand Down Expand Up @@ -678,7 +666,7 @@ static void HandleSIGUSR1(int sig)
exit(0);
}

int TestInetLayerDNS(void)
int TestInetLayerDNSInternal(void)
{
// clang-format off
const nlTest DNSTests[] =
Expand Down Expand Up @@ -719,12 +707,11 @@ int TestInetLayerDNS(void)

static void __attribute__((constructor)) TestCHIPInetLayerDNSCtor(void)
{
VerifyOrDie(RegisterUnitTests(&TestInetLayerDNS) == CHIP_NO_ERROR);
VerifyOrDie(RegisterUnitTests(&TestInetLayerDNSInternal) == CHIP_NO_ERROR);
}

#else // !INET_CONFIG_ENABLE_DNS_RESOLVER

int TestInetLayerDNS(void)
int TestInetLayerDNSInternal(void)
{
fprintf(stderr, "Please assert INET_CONFIG_ENABLE_DNS_RESOLVER to use this test.\n");

Expand All @@ -733,19 +720,11 @@ int TestInetLayerDNS(void)

#endif // !INET_CONFIG_ENABLE_DNS_RESOLVER

int main(int argc, char * argv[])
int TestInetLayerDNS()
{
SetupFaultInjectionContext(argc, argv);

SetSignalHandler(HandleSIGUSR1);

if (!ParseArgsFromEnvVar(TOOL_NAME, TOOL_OPTIONS_ENV_VAR_NAME, gToolOptionSets, NULL, true) ||
!ParseArgs(TOOL_NAME, argc, argv, gToolOptionSets, NULL))
{
exit(EXIT_FAILURE);
}

nlTestSetOutputStyle(OUTPUT_CSV);

return (TestInetLayerDNS());
return (TestInetLayerDNSInternal());
}
36 changes: 36 additions & 0 deletions src/inet/tests/TestInetLayerDNSDriver.cpp
Original file line number Diff line number Diff line change
@@ -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 <nlunit-test.h>

int main(void)
{
// Generate machine-readable, comma-separated value (CSV) output.
nlTestSetOutputStyle(OUTPUT_CSV);

return (TestInetLayerDNS());
}

0 comments on commit 15b4c2d

Please sign in to comment.