Skip to content

Commit

Permalink
Updated unit tests in src/transport/raw/tests/ to use PW instead of N…
Browse files Browse the repository at this point in the history
…L. (#33099)

* Updated unit tests in src/transport/tests/ to use PW instead of NL.

* Updated unit tests in src/protocols/bdx/tests/ to use PW instead of NL

* Updated unit tests in src/transport/raw/tests/ to use PW instead of NL.

* Undid the accidental reformatting of the comments at the top.

* Update src/transport/raw/tests/TestTCP.cpp

Co-authored-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com>

* Update src/transport/raw/tests/TestUDP.cpp

Co-authored-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com>

* Changed some EXPECT_ to ASSERT_.  Changed C-casts to unsigned literals.  Chagned strcmp to EXPECT_STREQ.

* Resolved merge conflicts in test_components[_nl].txt

* Added a destructor to TestUDP to delete the TestContext.

* Added destructor to TestTCP to delete the TestContext.

* Added destructor to TestTCP to delete TestContext.

* Fixed issue with SystemLayerTests being listed multiple times.

* Changed MemoryInit line to ASSERT instead of EXPECT.  Added corresponding MemoryShutdown.

* Inherited TCP test from IOContext so we don't have to create a new context.

* Moved ChckSimpleInitTest and CheckMessageTest into the test context class.

---------

Co-authored-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com>
  • Loading branch information
2 people authored and pull[bot] committed Jun 3, 2024
1 parent 1e7790a commit 3699070
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 500 deletions.
1 change: 1 addition & 0 deletions src/test_driver/openiotsdk/unit-tests/test_components.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CoreTests
MdnsTests
CredentialsTest
PlatformTests
RawTransportTests
RetransmitTests
TestShell
SetupPayloadTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ AppTests
DataModelTests
InetLayerTests
MessagingLayerTests
RawTransportTests
SecureChannelTestsNL
SupportTestsNL
TransportLayerTests
7 changes: 2 additions & 5 deletions src/transport/raw/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/nlunit_test.gni")
import("//build_overrides/pigweed.gni")

import("${chip_root}/build/chip/chip_test_suite.gni")

static_library("helpers") {
output_name = "libNetworkTestHelpers"
output_dir = "${root_out_dir}/lib"
Expand All @@ -35,7 +34,7 @@ static_library("helpers") {
]
}

chip_test_suite_using_nltest("tests") {
chip_test_suite("tests") {
output_name = "libRawTransportTests"

test_sources = [
Expand All @@ -51,10 +50,8 @@ chip_test_suite_using_nltest("tests") {
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
"${chip_root}/src/lib/support:test_utils",
"${chip_root}/src/lib/support:testing_nlunit",
"${chip_root}/src/transport",
"${chip_root}/src/transport/raw",
"${nlunit_test_root}:nlunit-test",
]

cflags = [ "-Wconversion" ]
Expand Down
300 changes: 138 additions & 162 deletions src/transport/raw/tests/TestMessageHeader.cpp

Large diffs are not rendered by default.

60 changes: 13 additions & 47 deletions src/transport/raw/tests/TestPeerAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
#include <inet/IPAddress.h>
#include <lib/core/DataModelTypes.h>
#include <lib/core/PeerId.h>
#include <lib/support/UnitTestRegistration.h>
#include <transport/raw/PeerAddress.h>

#include <nlunit-test.h>
#include <gtest/gtest.h>

namespace {

Expand All @@ -39,47 +38,47 @@ using chip::Transport::PeerAddress;
/**
* Test correct identification of IPv6 multicast addresses.
*/
void TestPeerAddressMulticast(nlTestSuite * inSuite, void * inContext)
TEST(TestPeerAddress, TestPeerAddressMulticast)
{
constexpr chip::FabricId fabric = 0xa1a2a4a8b1b2b4b8;
constexpr chip::GroupId group = 0xe10f;
PeerAddress addr = PeerAddress::Multicast(fabric, group);
NL_TEST_ASSERT(inSuite, chip::Transport::Type::kUdp == addr.GetTransportType());
NL_TEST_ASSERT(inSuite, addr.IsMulticast());
EXPECT_EQ(chip::Transport::Type::kUdp, addr.GetTransportType());
EXPECT_TRUE(addr.IsMulticast());

const Inet::IPAddress & ip = addr.GetIPAddress();
NL_TEST_ASSERT(inSuite, ip.IsIPv6Multicast());
NL_TEST_ASSERT(inSuite, chip::Inet::IPAddressType::kIPv6 == ip.Type());
EXPECT_TRUE(ip.IsIPv6Multicast());
EXPECT_EQ(chip::Inet::IPAddressType::kIPv6, ip.Type());

constexpr uint8_t expected[NL_INET_IPV6_ADDR_LEN_IN_BYTES] = { 0xff, 0x35, 0x00, 0x40, 0xfd, 0xa1, 0xa2, 0xa4,
0xa8, 0xb1, 0xb2, 0xb4, 0xb8, 0x00, 0xe1, 0x0f };
uint8_t result[NL_INET_IPV6_ADDR_LEN_IN_BYTES];
uint8_t * p = result;
ip.WriteAddress(p);
NL_TEST_ASSERT(inSuite, !memcmp(expected, result, NL_INET_IPV6_ADDR_LEN_IN_BYTES));
EXPECT_EQ(0, memcmp(expected, result, NL_INET_IPV6_ADDR_LEN_IN_BYTES));
}

void TestToString(nlTestSuite * inSuite, void * inContext)
TEST(TestPeerAddress, TestToString)
{
char buff[PeerAddress::kMaxToStringSize];
IPAddress ip;
{
IPAddress::FromString("::1", ip);
PeerAddress::UDP(ip, 1122).ToString(buff);

NL_TEST_ASSERT(inSuite, !strcmp(buff, "UDP:[::1]:1122"));
EXPECT_STREQ(buff, "UDP:[::1]:1122");
}

{
IPAddress::FromString("::1", ip);
PeerAddress::TCP(ip, 1122).ToString(buff);

NL_TEST_ASSERT(inSuite, !strcmp(buff, "TCP:[::1]:1122"));
EXPECT_STREQ(buff, "TCP:[::1]:1122");
}

{
PeerAddress::BLE().ToString(buff);
NL_TEST_ASSERT(inSuite, !strcmp(buff, "BLE"));
EXPECT_STREQ(buff, "BLE");
}

{
Expand All @@ -89,49 +88,16 @@ void TestToString(nlTestSuite * inSuite, void * inContext)
int res1 = strcmp(buff, "UDP:[1223::3456:789a]:8080");
int res2 = strcmp(buff, "UDP:[1223::3456:789A]:8080");

NL_TEST_ASSERT(inSuite, (!res1 || !res2));
EXPECT_TRUE(!res1 || !res2);
}

{

PeerAddress udp = PeerAddress(Transport::Type::kUdp);
udp.SetPort(5840);
udp.ToString(buff);
NL_TEST_ASSERT(inSuite, !strcmp(buff, "UDP:[::]:5840"));
EXPECT_STREQ(buff, "UDP:[::]:5840");
}
}

/**
* Test Suite. It lists all the test functions.
*/

// clang-format off
const nlTest sTests[] =
{
NL_TEST_DEF("PeerAddress Multicast", TestPeerAddressMulticast),
NL_TEST_DEF("ToString", TestToString),
NL_TEST_SENTINEL()
};
// clang-format on

} // namespace

int TestPeerAddress()
{
// clang-format off
nlTestSuite theSuite =
{
"PeerAddress",
&sTests[0],
nullptr,
nullptr
};
// clang-format on

// Run test suite against one context.
nlTestRunner(&theSuite, nullptr);

return (nlTestRunnerStats(&theSuite));
}

CHIP_REGISTER_TEST_SUITE(TestPeerAddress)
Loading

0 comments on commit 3699070

Please sign in to comment.