Skip to content

Commit cf98818

Browse files
committedApr 18, 2024
Use pigweed for system tests
1 parent 84fd7fc commit cf98818

14 files changed

+871
-1548
lines changed
 

‎src/system/SystemPacketBuffer.h

+44-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,31 @@ 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;
394+
friend class TestSystemPacketBuffer_CheckNew_Test;
395+
friend class TestSystemPacketBuffer_CheckSetStart_Test;
396+
friend class TestSystemPacketBuffer_CheckDataLength_Test;
397+
friend class TestSystemPacketBuffer_CheckSetDataLength_Test;
398+
friend class TestSystemPacketBuffer_CheckAddToEnd_Test;
399+
friend class TestSystemPacketBuffer_CheckPopHead_Test;
400+
friend class TestSystemPacketBuffer_CheckCompactHead_Test;
401+
friend class TestSystemPacketBuffer_CheckConsumeHead_Test;
402+
friend class TestSystemPacketBuffer_CheckConsume_Test;
403+
friend class TestSystemPacketBuffer_CheckEnsureReservedSize_Test;
404+
friend class TestSystemPacketBuffer_CheckNext_Test;
405+
friend class TestSystemPacketBuffer_CheckRead_Test;
406+
friend class TestSystemPacketBuffer_CheckAddRef_Test;
407+
friend class TestSystemPacketBuffer_CheckFree_Test;
408+
friend class TestSystemPacketBuffer_CheckFreeHead_Test;
409+
friend class TestSystemPacketBuffer_CheckHandleMove_Test;
410+
friend class TestSystemPacketBuffer_CheckHandleRelease_Test;
411+
friend class TestSystemPacketBuffer_CheckHandleFree_Test;
412+
friend class TestSystemPacketBuffer_CheckHandleRetain_Test;
413+
friend class TestSystemPacketBuffer_CheckHandleAdopt_Test;
414+
friend class TestSystemPacketBuffer_CheckHandleHold_Test;
415+
friend class TestSystemPacketBuffer_CheckHandleAdvance_Test;
416+
friend class TestSystemPacketBuffer_CheckHandleRightSize_Test;
417+
friend class TestSystemPacketBuffer_CheckHandleCloneData_Test;
396418
};
397419

398420
static_assert(sizeof(pbuf) == sizeof(PacketBuffer), "PacketBuffer must not have additional members");
@@ -696,7 +718,25 @@ class DLL_EXPORT PacketBufferHandle
696718
PacketBuffer * mBuffer;
697719

698720
friend class PacketBuffer;
699-
friend class ::PacketBufferTest;
721+
friend class TestSystemPacketBuffer;
722+
friend class TestSystemPacketBuffer_CheckNew_Test;
723+
friend class TestSystemPacketBuffer_CheckAddToEnd_Test;
724+
friend class TestSystemPacketBuffer_CheckPopHead_Test;
725+
friend class TestSystemPacketBuffer_CheckConsume_Test;
726+
friend class TestSystemPacketBuffer_CheckNext_Test;
727+
friend class TestSystemPacketBuffer_CheckLast_Test;
728+
friend class TestSystemPacketBuffer_CheckFree_Test;
729+
friend class TestSystemPacketBuffer_CheckFreeHead_Test;
730+
friend class TestSystemPacketBuffer_CheckHandleConstruct_Test;
731+
friend class TestSystemPacketBuffer_CheckHandleMove_Test;
732+
friend class TestSystemPacketBuffer_CheckHandleRelease_Test;
733+
friend class TestSystemPacketBuffer_CheckHandleFree_Test;
734+
friend class TestSystemPacketBuffer_CheckHandleRetain_Test;
735+
friend class TestSystemPacketBuffer_CheckHandleAdopt_Test;
736+
friend class TestSystemPacketBuffer_CheckHandleHold_Test;
737+
friend class TestSystemPacketBuffer_CheckHandleAdvance_Test;
738+
friend class TestSystemPacketBuffer_CheckHandleRightSize_Test;
739+
friend class TestSystemPacketBuffer_CheckHandleCloneData_Test;
700740
};
701741

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

‎src/system/SystemTimer.h

+9-4
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.
@@ -80,12 +79,18 @@ class DLL_EXPORT TimerData
8079
/**
8180
* Return the expiration time.
8281
*/
83-
Clock::Timestamp AwakenTime() const { return mAwakenTime; }
82+
Clock::Timestamp AwakenTime() const
83+
{
84+
return mAwakenTime;
85+
}
8486

8587
/**
8688
* Return callback information.
8789
*/
88-
const Callback & GetCallback() const { return mCallback; }
90+
const Callback & GetCallback() const
91+
{
92+
return mCallback;
93+
}
8994

9095
private:
9196
Clock::Timestamp mAwakenTime;
@@ -238,7 +243,7 @@ class TimerPool
238243
}
239244

240245
private:
241-
friend class TestTimer;
246+
friend class TestSystemTimer_CheckTimerPool_Test;
242247
ObjectPool<Timer, CHIP_SYSTEM_CONFIG_NUM_TIMERS> mTimerPool;
243248
};
244249

‎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)