Skip to content

Commit 307cffb

Browse files
feasel0andy31415
andauthored
Updated unit tests in src/transport/tests/ to use PW instead of NL. (#33249)
* Refactored TestSecureSessionTable.cpp to use TestSecureSessionTable as the pw test context. * Updated test_components[_nl].txt to move TransportLayerTests * Fixed formatting * Fixing merge conflict in test components nl * Fixing merge conflict * Updated TestSessionManagerDispatch to use staticly allocated context instead of dynamically. Changed all tests to use XTestSuite instead of per-test SetUp/TearDown. * Made context a non-pointer which is created/destroyed implicitly when each test case is run. * Reordered includes to be consistent with the standard. --------- Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent cd85f36 commit 307cffb

11 files changed

+519
-915
lines changed

src/test_driver/openiotsdk/unit-tests/test_components.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ SetupPayloadTests
1717
SupportTests
1818
UserDirectedCommissioningTests
1919
SecureChannelTests
20-
ICDServerTests
21-
InetLayerTests
20+
ICDServerTests

src/test_driver/openiotsdk/unit-tests/test_components_nl.txt

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ AppTests
22
DataModelTests
33
MessagingLayerTests
44
SecureChannelTestsNL
5-
TransportLayerTests

src/transport/tests/BUILD.gn

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17-
import("//build_overrides/nlunit_test.gni")
17+
import("//build_overrides/pigweed.gni")
1818

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

@@ -31,7 +31,7 @@ source_set("helpers") {
3131
]
3232
}
3333

34-
chip_test_suite_using_nltest("tests") {
34+
chip_test_suite("tests") {
3535
output_name = "libTransportLayerTests"
3636

3737
test_sources = [
@@ -59,10 +59,8 @@ chip_test_suite_using_nltest("tests") {
5959
"${chip_root}/src/lib/core",
6060
"${chip_root}/src/lib/support",
6161
"${chip_root}/src/lib/support:testing",
62-
"${chip_root}/src/lib/support:testing_nlunit",
6362
"${chip_root}/src/protocols",
6463
"${chip_root}/src/transport",
6564
"${chip_root}/src/transport/tests:helpers",
66-
"${nlunit_test_root}:nlunit-test",
6765
]
6866
}

src/transport/tests/TestCryptoContext.cpp

+12-44
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
*/
1818

1919
#include <inttypes.h>
20-
#include <nlunit-test.h>
20+
21+
#include <gtest/gtest.h>
2122

2223
#include <crypto/CHIPCryptoPAL.h>
2324
#include <lib/core/CHIPCore.h>
2425
#include <lib/support/CHIPMem.h>
25-
#include <lib/support/UnitTestRegistration.h>
26-
2726
#include <transport/CryptoContext.h>
2827

2928
using namespace chip;
@@ -48,7 +47,14 @@ struct PrivacyNonceTestEntry thePrivacyNonceTestVector[] = {
4847
},
4948
};
5049

51-
void TestBuildPrivacyNonce(nlTestSuite * apSuite, void * apContext)
50+
class TestGroupCryptoContext : public ::testing::Test
51+
{
52+
public:
53+
static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
54+
static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
55+
};
56+
57+
TEST_F(TestGroupCryptoContext, TestBuildPrivacyNonce)
5258
{
5359
for (const auto & testVector : thePrivacyNonceTestVector)
5460
{
@@ -60,47 +66,9 @@ void TestBuildPrivacyNonce(nlTestSuite * apSuite, void * apContext)
6066

6167
mic.SetTag(nullptr, testVector.mic, MIC_LENGTH);
6268

63-
NL_TEST_ASSERT(apSuite, CHIP_NO_ERROR == chip::CryptoContext::BuildPrivacyNonce(privacyNonce, sessionId, mic));
64-
NL_TEST_ASSERT(apSuite, 0 == memcmp(privacyNonceView.data(), expectedPrivacyNonce.data(), NONCE_LENGTH));
69+
EXPECT_EQ(CHIP_NO_ERROR, chip::CryptoContext::BuildPrivacyNonce(privacyNonce, sessionId, mic));
70+
EXPECT_EQ(0, memcmp(privacyNonceView.data(), expectedPrivacyNonce.data(), NONCE_LENGTH));
6571
}
6672
}
6773

68-
/**
69-
* Test Suite. It lists all the test functions.
70-
*/
71-
const nlTest sTests[] = { NL_TEST_DEF("TestBuildPrivacyNonce", TestBuildPrivacyNonce), NL_TEST_SENTINEL() };
72-
73-
/**
74-
* Set up the test suite.
75-
*/
76-
int Test_Setup(void * inContext)
77-
{
78-
CHIP_ERROR error = chip::Platform::MemoryInit();
79-
VerifyOrReturnError(error == CHIP_NO_ERROR, FAILURE);
80-
return SUCCESS;
81-
}
82-
83-
/**
84-
* Tear down the test suite.
85-
*/
86-
int Test_Teardown(void * inContext)
87-
{
88-
chip::Platform::MemoryShutdown();
89-
return SUCCESS;
90-
}
91-
9274
} // namespace
93-
94-
/**
95-
* Main
96-
*/
97-
int TestGroupCryptoContext()
98-
{
99-
nlTestSuite theSuite = { "TestGroupCryptoContext", &sTests[0], Test_Setup, Test_Teardown };
100-
101-
// Run test suite againt one context.
102-
nlTestRunner(&theSuite, nullptr);
103-
return nlTestRunnerStats(&theSuite);
104-
}
105-
106-
CHIP_REGISTER_TEST_SUITE(TestGroupCryptoContext)

0 commit comments

Comments
 (0)