Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace nl-unit-test with pigweed for system #33046

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/system/SystemPacketBuffer.h
Original file line number Diff line number Diff line change
@@ -44,8 +44,6 @@
#include <lwip/pbuf.h>
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

class PacketBufferTest;

namespace chip {
namespace System {

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

friend class PacketBufferHandle;
friend class ::PacketBufferTest;
friend class TestSystemPacketBuffer;
};

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

friend class PacketBuffer;
friend class ::PacketBufferTest;
friend class TestSystemPacketBuffer;
};

inline void PacketBuffer::SetDataLength(uint16_t aNewLen, const PacketBufferHandle & aChainHead)
3 changes: 1 addition & 2 deletions src/system/SystemTimer.h
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ namespace chip {
namespace System {

class Layer;
class TestTimer;

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

private:
friend class TestTimer;
friend class TestSystemTimer_CheckTimerPool_Test;
ObjectPool<Timer, CHIP_SYSTEM_CONFIG_NUM_TIMERS> mTimerPool;
};

5 changes: 1 addition & 4 deletions src/system/tests/BUILD.gn
Original file line number Diff line number Diff line change
@@ -14,11 +14,10 @@

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

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

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

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

public_deps = [
"${chip_root}/src/inet",
"${chip_root}/src/lib/support:testing_nlunit",
"${chip_root}/src/platform",
"${chip_root}/src/system",
"${nlunit_test_root}:nlunit-test",
]
}
60 changes: 16 additions & 44 deletions src/system/tests/TestSystemClock.cpp
Original file line number Diff line number Diff line change
@@ -15,14 +15,13 @@
* limitations under the License.
*/

#include <system/SystemConfig.h>
#include <gtest/gtest.h>

#include <lib/core/ErrorStr.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/TimeUtils.h>
#include <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>
#include <system/SystemClock.h>
#include <system/SystemConfig.h>

#if !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME

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

namespace {

void TestRealClock(nlTestSuite * inSuite, void * inContext)
TEST(TestSystemClock, TestRealClock)
{
Clock::Milliseconds64 oldMilli = SystemClock().GetMonotonicMilliseconds64();
Clock::Milliseconds64 newMilli = SystemClock().GetMonotonicMilliseconds64();
NL_TEST_ASSERT(inSuite, newMilli >= oldMilli);
EXPECT_GE(newMilli, oldMilli);

Clock::Microseconds64 oldMicro = SystemClock().GetMonotonicMicroseconds64();
Clock::Microseconds64 newMicro = SystemClock().GetMonotonicMicroseconds64();
NL_TEST_ASSERT(inSuite, newMicro >= oldMicro);
EXPECT_GE(newMicro, oldMicro);

Clock::Microseconds64::rep microseconds = newMicro.count();
NL_TEST_ASSERT(inSuite, (microseconds & 0x8000'0000'0000'0000) == 0);
EXPECT_EQ((microseconds & 0x8000'0000'0000'0000), 0UL);

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

newMilli = SystemClock().GetMonotonicMilliseconds64();
NL_TEST_ASSERT(inSuite, newMilli > oldMilli);
EXPECT_GT(newMilli, oldMilli);

newMicro = SystemClock().GetMonotonicMicroseconds64();
NL_TEST_ASSERT(inSuite, newMicro > oldMicro);
EXPECT_GT(newMicro, oldMicro);

#endif // !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME && (CHIP_SYSTEM_CONFIG_USE_LWIP_MONOTONIC_TIME ||
// CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS)
#endif // !CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME &&
// (CHIP_SYSTEM_CONFIG_USE_LWIP_MONOTONIC_TIME || CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS)
}

void TestMockClock(nlTestSuite * inSuite, void * inContext)
TEST(TestSystemClock, TestMockClock)
{
Clock::Internal::MockClock clock;

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

NL_TEST_ASSERT(inSuite, SystemClock().GetMonotonicMilliseconds64() == Clock::kZero);
NL_TEST_ASSERT(inSuite, SystemClock().GetMonotonicMicroseconds64() == Clock::kZero);
EXPECT_EQ(SystemClock().GetMonotonicMilliseconds64(), Clock::kZero);
EXPECT_EQ(SystemClock().GetMonotonicMicroseconds64(), Clock::kZero);

constexpr Clock::Milliseconds64 k1234 = Clock::Milliseconds64(1234);
clock.SetMonotonic(k1234);
NL_TEST_ASSERT(inSuite, SystemClock().GetMonotonicMilliseconds64() == k1234);
NL_TEST_ASSERT(inSuite, SystemClock().GetMonotonicMicroseconds64() == k1234);
EXPECT_EQ(SystemClock().GetMonotonicMilliseconds64(), k1234);
EXPECT_EQ(SystemClock().GetMonotonicMicroseconds64(), k1234);

Clock::Internal::SetSystemClockForTesting(savedRealClock);
}

} // namespace

/**
* Test Suite. It lists all the test functions.
*/
// clang-format off
static const nlTest sTests[] =
{
NL_TEST_DEF("TestRealClock", TestRealClock),
NL_TEST_DEF("TestMockClock", TestMockClock),
NL_TEST_SENTINEL()
};
// clang-format on

int TestSystemClock()
{
nlTestSuite theSuite = {
"chip-systemclock", &sTests[0], nullptr /* setup */, nullptr /* teardown */
};

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

return (nlTestRunnerStats(&theSuite));
}

CHIP_REGISTER_TEST_SUITE(TestSystemClock)
53 changes: 7 additions & 46 deletions src/system/tests/TestSystemErrorStr.cpp
Original file line number Diff line number Diff line change
@@ -28,34 +28,28 @@
#include <stdint.h>
#include <string.h>

#include <gtest/gtest.h>

#include <inet/InetError.h>
#include <lib/core/ErrorStr.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTestRegistration.h>

#include <nlunit-test.h>

using namespace chip;

// Test input data.

// clang-format off
static const CHIP_ERROR kTestElements[] =
{
static const CHIP_ERROR kTestElements[] = {
CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE,
CHIP_ERROR_INVALID_ARGUMENT,
CHIP_ERROR_INCORRECT_STATE,
CHIP_ERROR_UNEXPECTED_EVENT,
CHIP_ERROR_NO_MEMORY,
CHIP_ERROR_REAL_TIME_NOT_SYNCED,
CHIP_ERROR_ACCESS_DENIED
CHIP_ERROR_ACCESS_DENIED,
};
// clang-format on

static void CheckSystemErrorStr(nlTestSuite * inSuite, void * inContext)
TEST(TestSystemErrorStr, CheckSystemErrorStr)
{
// Register the layer error formatter

RegisterCHIPLayerErrorFormatter();

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

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

#if !CHIP_CONFIG_SHORT_ERROR_STR
// Assert that the error string contains a description, which is signaled
// by a presence of a colon proceeding the description.
NL_TEST_ASSERT(inSuite, (strchr(errStr, ':') != nullptr));
EXPECT_NE(strchr(errStr, ':'), nullptr);
#endif // !CHIP_CONFIG_SHORT_ERROR_STR
}
}

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

// clang-format off
static const nlTest sTests[] =
{
NL_TEST_DEF("SystemErrorStr", CheckSystemErrorStr),

NL_TEST_SENTINEL()
};
// clang-format on

int TestSystemErrorStr()
{
// clang-format off
nlTestSuite theSuite =
{
"System-Error-Strings",
&sTests[0],
nullptr,
nullptr
};
// clang-format on

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

return (nlTestRunnerStats(&theSuite));
}

CHIP_REGISTER_TEST_SUITE(TestSystemErrorStr)
1,291 changes: 502 additions & 789 deletions src/system/tests/TestSystemPacketBuffer.cpp

Large diffs are not rendered by default.

91 changes: 22 additions & 69 deletions src/system/tests/TestSystemScheduleLambda.cpp
Original file line number Diff line number Diff line change
@@ -14,83 +14,36 @@
* limitations under the License.
*/

#include <system/SystemConfig.h>
#include <gtest/gtest.h>

#include <lib/core/ErrorStr.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>
#include <platform/CHIPDeviceLayer.h>
#include <system/SystemConfig.h>

// Test input data.
class TestSystemScheduleLambda : public ::testing::Test
{
public:
static void SetUpTestSuite()
{
ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR);
ASSERT_EQ(chip::DeviceLayer::PlatformMgr().InitChipStack(), CHIP_NO_ERROR);
}

static void TearDownTestSuite()
{
chip::DeviceLayer::PlatformMgr().Shutdown();
chip::Platform::MemoryShutdown();
}
};

static void CheckScheduleLambda(nlTestSuite * inSuite, void * aContext)
TEST_F(TestSystemScheduleLambda, CheckScheduleLambda)
{
bool * called = new bool(false);
chip::DeviceLayer::SystemLayer().ScheduleLambda([called] {
*called = true;
bool called = false;
chip::DeviceLayer::SystemLayer().ScheduleLambda([&called] {
called = true;
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
});
chip::DeviceLayer::PlatformMgr().RunEventLoop();
NL_TEST_ASSERT(inSuite, *called);
delete called;
}

// Test Suite

/**
* Test Suite. It lists all the test functions.
*/
// clang-format off
static const nlTest sTests[] =
{
NL_TEST_DEF("System::TestScheduleLambda", CheckScheduleLambda),
NL_TEST_SENTINEL()
};
// clang-format on

static int TestSetup(void * aContext);
static int TestTeardown(void * aContext);

// clang-format off
static nlTestSuite kTheSuite =
{
"chip-system-schedule-lambda",
&sTests[0],
TestSetup,
TestTeardown
};
// clang-format on

/**
* Set up the test suite.
*/
static int TestSetup(void * aContext)
{
if (chip::Platform::MemoryInit() != CHIP_NO_ERROR)
return FAILURE;
if (chip::DeviceLayer::PlatformMgr().InitChipStack() != CHIP_NO_ERROR)
return FAILURE;
return (SUCCESS);
EXPECT_TRUE(called);
}

/**
* Tear down the test suite.
* Free memory reserved at TestSetup.
*/
static int TestTeardown(void * aContext)
{
chip::DeviceLayer::PlatformMgr().Shutdown();
chip::Platform::MemoryShutdown();
return (SUCCESS);
}

int TestSystemScheduleLambda()
{
// Run test suit againt one lContext.
nlTestRunner(&kTheSuite, nullptr);

return nlTestRunnerStats(&kTheSuite);
}

CHIP_REGISTER_TEST_SUITE(TestSystemScheduleLambda)
97 changes: 24 additions & 73 deletions src/system/tests/TestSystemScheduleWork.cpp
Original file line number Diff line number Diff line change
@@ -14,13 +14,28 @@
* limitations under the License.
*/

#include <system/SystemConfig.h>
#include <gtest/gtest.h>

#include <lib/core/ErrorStr.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>
#include <platform/CHIPDeviceLayer.h>
#include <system/SystemConfig.h>

class TestSystemScheduleWork : public ::testing::Test
{
public:
static void SetUpTestSuite()
{
ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR);
ASSERT_EQ(chip::DeviceLayer::PlatformMgr().InitChipStack(), CHIP_NO_ERROR);
}

static void TearDownTestSuite()
{
chip::DeviceLayer::PlatformMgr().Shutdown();
chip::Platform::MemoryShutdown();
}
};

static void IncrementIntCounter(chip::System::Layer *, void * state)
{
@@ -32,76 +47,12 @@ static void StopEventLoop(chip::System::Layer *, void *)
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
}

static void CheckScheduleWorkTwice(nlTestSuite * inSuite, void * aContext)
TEST_F(TestSystemScheduleWork, CheckScheduleWork)
{
int * callCount = new int(0);
NL_TEST_ASSERT(inSuite, chip::DeviceLayer::SystemLayer().ScheduleWork(IncrementIntCounter, callCount) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, chip::DeviceLayer::SystemLayer().ScheduleWork(IncrementIntCounter, callCount) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, chip::DeviceLayer::SystemLayer().ScheduleWork(StopEventLoop, nullptr) == CHIP_NO_ERROR);
int callCount = 0;
EXPECT_EQ(chip::DeviceLayer::SystemLayer().ScheduleWork(IncrementIntCounter, &callCount), CHIP_NO_ERROR);
EXPECT_EQ(chip::DeviceLayer::SystemLayer().ScheduleWork(IncrementIntCounter, &callCount), CHIP_NO_ERROR);
EXPECT_EQ(chip::DeviceLayer::SystemLayer().ScheduleWork(StopEventLoop, nullptr), CHIP_NO_ERROR);
chip::DeviceLayer::PlatformMgr().RunEventLoop();
NL_TEST_ASSERT(inSuite, *callCount == 2);
delete callCount;
}

// Test Suite

/**
* Test Suite. It lists all the test functions.
*/
// clang-format off
static const nlTest sTests[] =
{
NL_TEST_DEF("System::TestScheduleWorkTwice", CheckScheduleWorkTwice),
NL_TEST_SENTINEL()
};
// clang-format on

static int TestSetup(void * aContext);
static int TestTeardown(void * aContext);

// clang-format off
static nlTestSuite kTheSuite =
{
"chip-system-schedule-work",
&sTests[0],
TestSetup,
TestTeardown
};
// clang-format on

/**
* Set up the test suite.
*/
static int TestSetup(void * aContext)
{
if (chip::Platform::MemoryInit() != CHIP_NO_ERROR)
{
return FAILURE;
}

if (chip::DeviceLayer::PlatformMgr().InitChipStack() != CHIP_NO_ERROR)
return FAILURE;

return (SUCCESS);
EXPECT_EQ(callCount, 2);
}

/**
* Tear down the test suite.
* Free memory reserved at TestSetup.
*/
static int TestTeardown(void * aContext)
{
chip::DeviceLayer::PlatformMgr().Shutdown();
chip::Platform::MemoryShutdown();
return (SUCCESS);
}

int TestSystemScheduleWork()
{
// Run test suit againt one lContext.
nlTestRunner(&kTheSuite, nullptr);

return nlTestRunnerStats(&kTheSuite);
}

CHIP_REGISTER_TEST_SUITE(TestSystemScheduleWork)
403 changes: 150 additions & 253 deletions src/system/tests/TestSystemTimer.cpp

Large diffs are not rendered by default.

121 changes: 41 additions & 80 deletions src/system/tests/TestSystemWakeEvent.cpp
Original file line number Diff line number Diff line change
@@ -21,13 +21,11 @@
*
*/

#include <system/SystemConfig.h>
#include <gtest/gtest.h>

#include <lib/core/ErrorStr.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTestContext.h>
#include <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>
#include <system/SystemConfig.h>
#include <system/SystemError.h>
#include <system/SystemLayerImpl.h>

@@ -51,25 +49,27 @@ class WakeEventTest

namespace {

struct TestContext
class TestSystemWakeEvent : public ::testing::Test
{
::chip::System::LayerImpl mSystemLayer;
WakeEvent mWakeEvent;
fd_set mReadSet;
fd_set mWriteSet;
fd_set mErrorSet;

TestContext()
public:
void SetUp()
{
mSystemLayer.Init();
mWakeEvent.Open(mSystemLayer);
}
~TestContext()

void TearDown()
{
mWakeEvent.Close(mSystemLayer);
mSystemLayer.Shutdown();
}

::chip::System::LayerImpl mSystemLayer;
WakeEvent mWakeEvent;
fd_set mReadSet;
fd_set mWriteSet;
fd_set mErrorSet;

int SelectWakeEvent(timeval timeout = {})
{
// NOLINTBEGIN(clang-analyzer-security.insecureAPI.bzero)
@@ -85,108 +85,69 @@ struct TestContext
}
};

void TestOpen(nlTestSuite * inSuite, void * aContext)
TEST_F(TestSystemWakeEvent, TestOpen)
{
TestContext & lContext = *static_cast<TestContext *>(aContext);
NL_TEST_ASSERT(inSuite, WakeEventTest::GetReadFD(lContext.mWakeEvent) >= 0);
NL_TEST_ASSERT(inSuite, lContext.SelectWakeEvent() == 0);
EXPECT_GE(WakeEventTest::GetReadFD(mWakeEvent), 0);
EXPECT_EQ(SelectWakeEvent(), 0);
}

void TestNotify(nlTestSuite * inSuite, void * aContext)
TEST_F(TestSystemWakeEvent, TestNotify)
{
TestContext & lContext = *static_cast<TestContext *>(aContext);
NL_TEST_ASSERT(inSuite, lContext.SelectWakeEvent() == 0);
EXPECT_EQ(SelectWakeEvent(), 0);

// Check that select() succeeds after Notify() has been called
lContext.mWakeEvent.Notify();
NL_TEST_ASSERT(inSuite, lContext.SelectWakeEvent() == 1);
NL_TEST_ASSERT(inSuite, FD_ISSET(WakeEventTest::GetReadFD(lContext.mWakeEvent), &lContext.mReadSet));
mWakeEvent.Notify();
EXPECT_EQ(SelectWakeEvent(), 1);
EXPECT_TRUE(FD_ISSET(WakeEventTest::GetReadFD(mWakeEvent), &mReadSet));

// ...and state of the event is not cleared automatically
NL_TEST_ASSERT(inSuite, lContext.SelectWakeEvent() == 1);
NL_TEST_ASSERT(inSuite, FD_ISSET(WakeEventTest::GetReadFD(lContext.mWakeEvent), &lContext.mReadSet));
EXPECT_EQ(SelectWakeEvent(), 1);
EXPECT_TRUE(FD_ISSET(WakeEventTest::GetReadFD(mWakeEvent), &mReadSet));
}

void TestConfirm(nlTestSuite * inSuite, void * aContext)
TEST_F(TestSystemWakeEvent, TestConfirm)
{
TestContext & lContext = *static_cast<TestContext *>(aContext);

// Check that select() succeeds after Notify() has been called
lContext.mWakeEvent.Notify();
NL_TEST_ASSERT(inSuite, lContext.SelectWakeEvent() == 1);
NL_TEST_ASSERT(inSuite, FD_ISSET(WakeEventTest::GetReadFD(lContext.mWakeEvent), &lContext.mReadSet));
mWakeEvent.Notify();
EXPECT_EQ(SelectWakeEvent(), 1);
EXPECT_TRUE(FD_ISSET(WakeEventTest::GetReadFD(mWakeEvent), &mReadSet));

// Check that Confirm() clears state of the event
lContext.mWakeEvent.Confirm();
NL_TEST_ASSERT(inSuite, lContext.SelectWakeEvent() == 0);
mWakeEvent.Confirm();
EXPECT_EQ(SelectWakeEvent(), 0);
}

#if CHIP_SYSTEM_CONFIG_POSIX_LOCKING
void * WaitForEvent(void * aContext)
{
TestContext & lContext = *static_cast<TestContext *>(aContext);
// wait 5 seconds
return reinterpret_cast<void *>(lContext.SelectWakeEvent(timeval{ 5, 0 }));
auto * context = static_cast<TestSystemWakeEvent *>(aContext);
return reinterpret_cast<void *>(context->SelectWakeEvent(timeval{ 5, 0 }));
}

void TestBlockingSelect(nlTestSuite * inSuite, void * aContext)
TEST_F(TestSystemWakeEvent, TestBlockingSelect)
{
TestContext & lContext = *static_cast<TestContext *>(aContext);

// Spawn a thread waiting for the event
pthread_t tid = 0;
NL_TEST_ASSERT(inSuite, 0 == pthread_create(&tid, nullptr, WaitForEvent, aContext));
EXPECT_EQ(0, pthread_create(&tid, nullptr, WaitForEvent, this));

lContext.mWakeEvent.Notify();
mWakeEvent.Notify();
void * selectResult = nullptr;
NL_TEST_ASSERT(inSuite, 0 == pthread_join(tid, &selectResult));
NL_TEST_ASSERT(inSuite, selectResult == reinterpret_cast<void *>(1));
EXPECT_EQ(0, pthread_join(tid, &selectResult));
EXPECT_EQ(selectResult, reinterpret_cast<void *>(1));
}
#else // CHIP_SYSTEM_CONFIG_POSIX_LOCKING
void TestBlockingSelect(nlTestSuite *, void *) {}
#endif // CHIP_SYSTEM_CONFIG_POSIX_LOCKING

void TestClose(nlTestSuite * inSuite, void * aContext)
TEST_F(TestSystemWakeEvent, TestClose)
{
TestContext & lContext = *static_cast<TestContext *>(aContext);
lContext.mWakeEvent.Close(lContext.mSystemLayer);
mWakeEvent.Close(mSystemLayer);

const auto notifFD = WakeEventTest::GetReadFD(lContext.mWakeEvent);
const auto notifFD = WakeEventTest::GetReadFD(mWakeEvent);

// Check that Close() has cleaned up itself and reopen is possible
NL_TEST_ASSERT(inSuite, lContext.mWakeEvent.Open(lContext.mSystemLayer) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, notifFD < 0);
EXPECT_EQ(mWakeEvent.Open(mSystemLayer), CHIP_NO_ERROR);
EXPECT_LT(notifFD, 0);
}
} // namespace

// Test Suite

/**
* Test Suite. It lists all the test functions.
*/
// clang-format off
static const nlTest sTests[] =
{
NL_TEST_DEF("WakeEvent::TestOpen", TestOpen),
NL_TEST_DEF("WakeEvent::TestNotify", TestNotify),
NL_TEST_DEF("WakeEvent::TestConfirm", TestConfirm),
NL_TEST_DEF("WakeEvent::TestBlockingSelect", TestBlockingSelect),
NL_TEST_DEF("WakeEvent::TestClose", TestClose),
NL_TEST_SENTINEL()
};
// clang-format on

static nlTestSuite kTheSuite = { "chip-system-wake-event", sTests };

int TestSystemWakeEvent()
{
return chip::ExecuteTestsWithContext<TestContext>(&kTheSuite);
}

CHIP_REGISTER_TEST_SUITE(TestSystemWakeEvent)
#else // CHIP_SYSTEM_CONFIG_USE_SOCKETS
int TestSystemWakeEvent(void)
{
return SUCCESS;
}
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS
238 changes: 89 additions & 149 deletions src/system/tests/TestTLVPacketBufferBackingStore.cpp

Large diffs are not rendered by default.

45 changes: 7 additions & 38 deletions src/system/tests/TestTimeSource.cpp
Original file line number Diff line number Diff line change
@@ -21,29 +21,26 @@
* the ability to compile and use the test implementation of the time source.
*/

#include <system/SystemConfig.h>
#include <gtest/gtest.h>

#include <lib/core/ErrorStr.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>
#include <system/SystemConfig.h>
#include <system/TimeSource.h>

namespace {

void TestTimeSourceSetAndGet(nlTestSuite * inSuite, void * inContext)
TEST(TestTimeSource, TestTimeSourceSetAndGet)
{

chip::Time::TimeSource<chip::Time::Source::kTest> source;

NL_TEST_ASSERT(inSuite, source.GetMonotonicTimestamp() == chip::System::Clock::kZero);
EXPECT_EQ(source.GetMonotonicTimestamp(), chip::System::Clock::kZero);

constexpr chip::System::Clock::Milliseconds64 k1234 = chip::System::Clock::Milliseconds64(1234);
source.SetMonotonicTimestamp(k1234);
NL_TEST_ASSERT(inSuite, source.GetMonotonicTimestamp() == k1234);
EXPECT_EQ(source.GetMonotonicTimestamp(), k1234);
}

void SystemTimeSourceGet(nlTestSuite * inSuite, void * inContext)
TEST(TestTimeSource, SystemTimeSourceGet)
{

chip::Time::TimeSource<chip::Time::Source::kSystem> source;
@@ -55,35 +52,7 @@ void SystemTimeSourceGet(nlTestSuite * inSuite, void * inContext)
for (int i = 0; i < 100; i++)
{
chip::System::Clock::Timestamp newValue = source.GetMonotonicTimestamp();
NL_TEST_ASSERT(inSuite, newValue >= oldValue);
EXPECT_GE(newValue, oldValue);
oldValue = newValue;
}
}

} // namespace

/**
* Test Suite. It lists all the test functions.
*/
// clang-format off
static const nlTest sTests[] =
{
NL_TEST_DEF("TimeSource<Test>::SetAndGet", TestTimeSourceSetAndGet),
NL_TEST_DEF("TimeSource<System>::SetAndGet", SystemTimeSourceGet),
NL_TEST_SENTINEL()
};
// clang-format on

int TestTimeSource()
{
nlTestSuite theSuite = {
"chip-timesource", &sTests[0], nullptr /* setup */, nullptr /* teardown */
};

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

return (nlTestRunnerStats(&theSuite));
}

CHIP_REGISTER_TEST_SUITE(TestTimeSource)
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
@@ -1,4 +1,5 @@
accesstest
SystemLayerTests
ASN1Tests
PlatformTests
TestShell
Original file line number Diff line number Diff line change
@@ -15,6 +15,5 @@ RetransmitTests
SecureChannelTests
SetupPayloadTests
SupportTests
SystemLayerTests
TransportLayerTests
UserDirectedCommissioningTests