Skip to content

Commit 72e7554

Browse files
jlatusekrestyled-commitsandy31415
authored
Replace nl-unit-test with pigweed for system (#33046)
* Use pigweed for system tests * Restyled by clang-format * Friend class fix --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent 69d8585 commit 72e7554

14 files changed

+863
-1552
lines changed

src/system/SystemPacketBuffer.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
#include <lwip/pbuf.h>
4545
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
4646

47-
class PacketBufferTest;
48-
4947
namespace chip {
5048
namespace System {
5149

@@ -392,7 +390,7 @@ class DLL_EXPORT PacketBuffer : private pbuf
392390
const uint8_t * ReserveStart() const;
393391

394392
friend class PacketBufferHandle;
395-
friend class ::PacketBufferTest;
393+
friend class TestSystemPacketBuffer;
396394
};
397395

398396
static_assert(sizeof(pbuf) == sizeof(PacketBuffer), "PacketBuffer must not have additional members");
@@ -696,7 +694,7 @@ class DLL_EXPORT PacketBufferHandle
696694
PacketBuffer * mBuffer;
697695

698696
friend class PacketBuffer;
699-
friend class ::PacketBufferTest;
697+
friend class TestSystemPacketBuffer;
700698
};
701699

702700
inline void PacketBuffer::SetDataLength(uint16_t aNewLen, const PacketBufferHandle & aChainHead)

src/system/SystemTimer.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace chip {
4444
namespace System {
4545

4646
class Layer;
47-
class TestTimer;
4847

4948
/**
5049
* Basic Timer information: time and callback.
@@ -238,7 +237,7 @@ class TimerPool
238237
}
239238

240239
private:
241-
friend class TestTimer;
240+
friend class TestSystemTimer_CheckTimerPool_Test;
242241
ObjectPool<Timer, CHIP_SYSTEM_CONFIG_NUM_TIMERS> mTimerPool;
243242
};
244243

src/system/tests/BUILD.gn

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17-
import("//build_overrides/nlunit_test.gni")
1817

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

21-
chip_test_suite_using_nltest("tests") {
20+
chip_test_suite("tests") {
2221
output_name = "libSystemLayerTests"
2322

2423
test_sources = [
@@ -47,9 +46,7 @@ chip_test_suite_using_nltest("tests") {
4746

4847
public_deps = [
4948
"${chip_root}/src/inet",
50-
"${chip_root}/src/lib/support:testing_nlunit",
5149
"${chip_root}/src/platform",
5250
"${chip_root}/src/system",
53-
"${nlunit_test_root}:nlunit-test",
5451
]
5552
}

src/system/tests/TestSystemClock.cpp

+16-44
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include <system/SystemConfig.h>
18+
#include <gtest/gtest.h>
1919

2020
#include <lib/core/ErrorStr.h>
2121
#include <lib/support/CodeUtils.h>
2222
#include <lib/support/TimeUtils.h>
23-
#include <lib/support/UnitTestRegistration.h>
24-
#include <nlunit-test.h>
2523
#include <system/SystemClock.h>
24+
#include <system/SystemConfig.h>
2625

2726
#if !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME
2827

@@ -41,18 +40,18 @@ using namespace chip::System;
4140

4241
namespace {
4342

44-
void TestRealClock(nlTestSuite * inSuite, void * inContext)
43+
TEST(TestSystemClock, TestRealClock)
4544
{
4645
Clock::Milliseconds64 oldMilli = SystemClock().GetMonotonicMilliseconds64();
4746
Clock::Milliseconds64 newMilli = SystemClock().GetMonotonicMilliseconds64();
48-
NL_TEST_ASSERT(inSuite, newMilli >= oldMilli);
47+
EXPECT_GE(newMilli, oldMilli);
4948

5049
Clock::Microseconds64 oldMicro = SystemClock().GetMonotonicMicroseconds64();
5150
Clock::Microseconds64 newMicro = SystemClock().GetMonotonicMicroseconds64();
52-
NL_TEST_ASSERT(inSuite, newMicro >= oldMicro);
51+
EXPECT_GE(newMicro, oldMicro);
5352

5453
Clock::Microseconds64::rep microseconds = newMicro.count();
55-
NL_TEST_ASSERT(inSuite, (microseconds & 0x8000'0000'0000'0000) == 0);
54+
EXPECT_EQ((microseconds & 0x8000'0000'0000'0000), 0UL);
5655

5756
#if !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME && \
5857
(CHIP_SYSTEM_CONFIG_USE_LWIP_MONOTONIC_TIME || CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS)
@@ -65,62 +64,35 @@ void TestRealClock(nlTestSuite * inSuite, void * inContext)
6564
#if CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS
6665
struct timespec delay = { 0, kDelayMilliseconds * chip::kNanosecondsPerMillisecond };
6766
while (nanosleep(&delay, &delay) == -1 && errno == EINTR)
68-
{
69-
}
67+
continue;
7068
#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS
7169

7270
newMilli = SystemClock().GetMonotonicMilliseconds64();
73-
NL_TEST_ASSERT(inSuite, newMilli > oldMilli);
71+
EXPECT_GT(newMilli, oldMilli);
7472

7573
newMicro = SystemClock().GetMonotonicMicroseconds64();
76-
NL_TEST_ASSERT(inSuite, newMicro > oldMicro);
74+
EXPECT_GT(newMicro, oldMicro);
7775

78-
#endif // !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME && (CHIP_SYSTEM_CONFIG_USE_LWIP_MONOTONIC_TIME ||
79-
// CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS)
76+
#endif // !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME &&
77+
// (CHIP_SYSTEM_CONFIG_USE_LWIP_MONOTONIC_TIME || CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS)
8078
}
8179

82-
void TestMockClock(nlTestSuite * inSuite, void * inContext)
80+
TEST(TestSystemClock, TestMockClock)
8381
{
8482
Clock::Internal::MockClock clock;
8583

8684
Clock::ClockBase * savedRealClock = &SystemClock();
8785
Clock::Internal::SetSystemClockForTesting(&clock);
8886

89-
NL_TEST_ASSERT(inSuite, SystemClock().GetMonotonicMilliseconds64() == Clock::kZero);
90-
NL_TEST_ASSERT(inSuite, SystemClock().GetMonotonicMicroseconds64() == Clock::kZero);
87+
EXPECT_EQ(SystemClock().GetMonotonicMilliseconds64(), Clock::kZero);
88+
EXPECT_EQ(SystemClock().GetMonotonicMicroseconds64(), Clock::kZero);
9189

9290
constexpr Clock::Milliseconds64 k1234 = Clock::Milliseconds64(1234);
9391
clock.SetMonotonic(k1234);
94-
NL_TEST_ASSERT(inSuite, SystemClock().GetMonotonicMilliseconds64() == k1234);
95-
NL_TEST_ASSERT(inSuite, SystemClock().GetMonotonicMicroseconds64() == k1234);
92+
EXPECT_EQ(SystemClock().GetMonotonicMilliseconds64(), k1234);
93+
EXPECT_EQ(SystemClock().GetMonotonicMicroseconds64(), k1234);
9694

9795
Clock::Internal::SetSystemClockForTesting(savedRealClock);
9896
}
9997

10098
} // namespace
101-
102-
/**
103-
* Test Suite. It lists all the test functions.
104-
*/
105-
// clang-format off
106-
static const nlTest sTests[] =
107-
{
108-
NL_TEST_DEF("TestRealClock", TestRealClock),
109-
NL_TEST_DEF("TestMockClock", TestMockClock),
110-
NL_TEST_SENTINEL()
111-
};
112-
// clang-format on
113-
114-
int TestSystemClock()
115-
{
116-
nlTestSuite theSuite = {
117-
"chip-systemclock", &sTests[0], nullptr /* setup */, nullptr /* teardown */
118-
};
119-
120-
// Run test suite against one context.
121-
nlTestRunner(&theSuite, nullptr /* context */);
122-
123-
return (nlTestRunnerStats(&theSuite));
124-
}
125-
126-
CHIP_REGISTER_TEST_SUITE(TestSystemClock)

src/system/tests/TestSystemErrorStr.cpp

+7-46
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,28 @@
2828
#include <stdint.h>
2929
#include <string.h>
3030

31+
#include <gtest/gtest.h>
32+
3133
#include <inet/InetError.h>
3234
#include <lib/core/ErrorStr.h>
3335
#include <lib/support/CodeUtils.h>
34-
#include <lib/support/UnitTestRegistration.h>
35-
36-
#include <nlunit-test.h>
3736

3837
using namespace chip;
3938

4039
// Test input data.
41-
42-
// clang-format off
43-
static const CHIP_ERROR kTestElements[] =
44-
{
40+
static const CHIP_ERROR kTestElements[] = {
4541
CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
4642
CHIP_ERROR_INVALID_ARGUMENT,
4743
CHIP_ERROR_INCORRECT_STATE,
4844
CHIP_ERROR_UNEXPECTED_EVENT,
4945
CHIP_ERROR_NO_MEMORY,
5046
CHIP_ERROR_REAL_TIME_NOT_SYNCED,
51-
CHIP_ERROR_ACCESS_DENIED
47+
CHIP_ERROR_ACCESS_DENIED,
5248
};
53-
// clang-format on
5449

55-
static void CheckSystemErrorStr(nlTestSuite * inSuite, void * inContext)
50+
TEST(TestSystemErrorStr, CheckSystemErrorStr)
5651
{
5752
// Register the layer error formatter
58-
5953
RegisterCHIPLayerErrorFormatter();
6054

6155
// For each defined error...
@@ -66,45 +60,12 @@ static void CheckSystemErrorStr(nlTestSuite * inSuite, void * inContext)
6660

6761
// Assert that the error string contains the error number in hex.
6862
snprintf(expectedText, sizeof(expectedText), "%08" PRIX32, err.AsInteger());
69-
NL_TEST_ASSERT(inSuite, (strstr(errStr, expectedText) != nullptr));
63+
EXPECT_NE(strstr(errStr, expectedText), nullptr);
7064

7165
#if !CHIP_CONFIG_SHORT_ERROR_STR
7266
// Assert that the error string contains a description, which is signaled
7367
// by a presence of a colon proceeding the description.
74-
NL_TEST_ASSERT(inSuite, (strchr(errStr, ':') != nullptr));
68+
EXPECT_NE(strchr(errStr, ':'), nullptr);
7569
#endif // !CHIP_CONFIG_SHORT_ERROR_STR
7670
}
7771
}
78-
79-
/**
80-
* Test Suite. It lists all the test functions.
81-
*/
82-
83-
// clang-format off
84-
static const nlTest sTests[] =
85-
{
86-
NL_TEST_DEF("SystemErrorStr", CheckSystemErrorStr),
87-
88-
NL_TEST_SENTINEL()
89-
};
90-
// clang-format on
91-
92-
int TestSystemErrorStr()
93-
{
94-
// clang-format off
95-
nlTestSuite theSuite =
96-
{
97-
"System-Error-Strings",
98-
&sTests[0],
99-
nullptr,
100-
nullptr
101-
};
102-
// clang-format on
103-
104-
// Run test suite against one context.
105-
nlTestRunner(&theSuite, nullptr);
106-
107-
return (nlTestRunnerStats(&theSuite));
108-
}
109-
110-
CHIP_REGISTER_TEST_SUITE(TestSystemErrorStr)

0 commit comments

Comments
 (0)