Skip to content

Commit

Permalink
[ICD] Enable ICD run for unit tests (#30097)
Browse files Browse the repository at this point in the history
* Enable ICD run of unit tests

* Adapt test to run as an ICD

* Restyled by clang-format

* Increase default IdleModeDuration for unit tests to be able to run

* generated files

* Fix Test values with different default

* Restyled by clang-format

* remove debug logs

* Enable TestSubscribeUrgentWildcardEvent for ICD run

* Update TestRead for ICDs

* add missing define checks

* restyle

* fix typo

* fix more typos

* fix missing tests

* restyle

* fix typo

* Fix TestReliableMessageProtocol

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Feb 13, 2024
1 parent 0a163fd commit 1677556
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/unit_integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

strategy:
matrix:
type: [main, clang, mbedtls, rotating_device_id]
type: [main, clang, mbedtls, rotating_device_id, icd]
env:
BUILD_TYPE: ${{ matrix.type }}

Expand Down Expand Up @@ -65,6 +65,7 @@ jobs:
"clang") GN_ARGS='is_clang=true';;
"mbedtls") GN_ARGS='chip_crypto="mbedtls"';;
"rotating_device_id") GN_ARGS='chip_crypto="boringssl" chip_enable_rotating_device_id=true';;
"icd") GN_ARGS='chip_enable_icd_server=true';;
*) ;;
esac
Expand Down
43 changes: 23 additions & 20 deletions src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,8 +1687,8 @@ void TestReadInteraction::TestICDProcessSubscribeRequestSupMinInterval(nlTestSui
err = engine->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable(), app::reporting::GetDefaultReportScheduler());
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

uint16_t kMinInterval = 3;
uint16_t kMaxIntervalCeiling = 5;
uint16_t kMinInterval = 305; // Default IdleModeDuration is 300
uint16_t kMaxIntervalCeiling = 605;

Messaging::ExchangeContext * exchangeCtx = ctx.NewExchangeToAlice(nullptr, false);

Expand Down Expand Up @@ -1837,8 +1837,8 @@ void TestReadInteraction::TestICDProcessSubscribeRequestInvalidIdleModeDuration(
err = engine->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable(), app::reporting::GetDefaultReportScheduler());
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

uint16_t kMinInterval = 3;
uint16_t kMaxIntervalCeiling = 3;
uint16_t kMinInterval = 400;
uint16_t kMaxIntervalCeiling = 400;

Messaging::ExchangeContext * exchangeCtx = ctx.NewExchangeToAlice(nullptr, false);

Expand Down Expand Up @@ -2080,9 +2080,13 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a
NL_TEST_ASSERT(apSuite, delegate.mGotReport);
NL_TEST_ASSERT(apSuite, delegate.mNumAttributeResponse == 2);

uint16_t minInterval;
uint16_t maxInterval;
delegate.mpReadHandler->GetReportingIntervals(minInterval, maxInterval);

// Test empty report
// Advance monotonic timestamp for min interval to elapse
gMockClock.AdvanceMonotonic(System::Clock::Seconds16(readPrepareParams.mMaxIntervalCeilingSeconds));
gMockClock.AdvanceMonotonic(System::Clock::Seconds16(maxInterval));
ctx.GetIOContext().DriveIO();

NL_TEST_ASSERT(apSuite, engine->GetReportingEngine().IsRunScheduled());
Expand Down Expand Up @@ -2150,6 +2154,10 @@ void TestReadInteraction::TestSubscribeEarlyReport(nlTestSuite * apSuite, void *
NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr);
delegate.mpReadHandler = engine->ActiveHandlerAt(0);

uint16_t minInterval;
uint16_t maxInterval;
delegate.mpReadHandler->GetReportingIntervals(minInterval, maxInterval);

NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse);
NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1);

Expand All @@ -2158,7 +2166,7 @@ void TestReadInteraction::TestSubscribeEarlyReport(nlTestSuite * apSuite, void *
gMockClock.GetMonotonicTimestamp() + Seconds16(readPrepareParams.mMinIntervalFloorSeconds));
NL_TEST_ASSERT(apSuite,
reportScheduler->GetMaxTimestampForHandler(delegate.mpReadHandler) ==
gMockClock.GetMonotonicTimestamp() + Seconds16(readPrepareParams.mMaxIntervalCeilingSeconds));
gMockClock.GetMonotonicTimestamp() + Seconds16(maxInterval));

// Confirm that the node is scheduled to run
NL_TEST_ASSERT(apSuite, reportScheduler->IsReportScheduled(delegate.mpReadHandler));
Expand Down Expand Up @@ -2204,7 +2212,7 @@ void TestReadInteraction::TestSubscribeEarlyReport(nlTestSuite * apSuite, void *
gMockClock.GetMonotonicTimestamp() + Seconds16(readPrepareParams.mMinIntervalFloorSeconds));
NL_TEST_ASSERT(apSuite,
reportScheduler->GetMaxTimestampForHandler(delegate.mpReadHandler) ==
gMockClock.GetMonotonicTimestamp() + Seconds16(readPrepareParams.mMaxIntervalCeilingSeconds));
gMockClock.GetMonotonicTimestamp() + Seconds16(maxInterval));

// Confirm that the node is scheduled to run
NL_TEST_ASSERT(apSuite, reportScheduler->IsReportScheduled(delegate.mpReadHandler));
Expand All @@ -2214,11 +2222,10 @@ void TestReadInteraction::TestSubscribeEarlyReport(nlTestSuite * apSuite, void *
node->SetIntervalTimeStamps(delegate.mpReadHandler, gMockClock.GetMonotonicTimestamp() + Milliseconds32(50));
NL_TEST_ASSERT(apSuite,
reportScheduler->GetMaxTimestampForHandler(delegate.mpReadHandler) ==
gMockClock.GetMonotonicTimestamp() + Seconds16(readPrepareParams.mMaxIntervalCeilingSeconds) +
Milliseconds32(50));
gMockClock.GetMonotonicTimestamp() + Seconds16(maxInterval) + Milliseconds32(50));

// Advance monotonic timestamp for min interval to elapse
gMockClock.AdvanceMonotonic(Seconds16(readPrepareParams.mMaxIntervalCeilingSeconds));
gMockClock.AdvanceMonotonic(Seconds16(maxInterval));

NL_TEST_ASSERT(apSuite, !InteractionModelEngine::GetInstance()->GetReportingEngine().IsRunScheduled());
// Service Timer expired event
Expand Down Expand Up @@ -2370,7 +2377,7 @@ void TestReadInteraction::TestSubscribeUrgentWildcardEvent(nlTestSuite * apSuite
NL_TEST_ASSERT(apSuite, !delegate.mGotEventResponse);
NL_TEST_ASSERT(apSuite, !nonUrgentDelegate.mGotEventResponse);

// The min-interval should have elapsed for urgen subscription, and our handler should still
// The min-interval should have elapsed for the urgent subscription, and our handler should still
// not be dirty or reportable.
NL_TEST_ASSERT(apSuite,
reportScheduler->GetMinTimestampForHandler(delegate.mpReadHandler) <
Expand Down Expand Up @@ -2831,8 +2838,12 @@ void TestReadInteraction::TestSubscribeInvalidAttributePathRoundtrip(nlTestSuite
NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr);
delegate.mpReadHandler = engine->ActiveHandlerAt(0);

uint16_t minInterval;
uint16_t maxInterval;
delegate.mpReadHandler->GetReportingIntervals(minInterval, maxInterval);

// Advance monotonic timestamp for min interval to elapse
gMockClock.AdvanceMonotonic(System::Clock::Seconds16(readPrepareParams.mMaxIntervalCeilingSeconds));
gMockClock.AdvanceMonotonic(System::Clock::Seconds16(maxInterval));
ctx.GetIOContext().DriveIO();

NL_TEST_ASSERT(apSuite, engine->GetReportingEngine().IsRunScheduled());
Expand Down Expand Up @@ -4956,15 +4967,7 @@ const nlTest sTests[] =
NL_TEST_DEF("TestReadHandlerInvalidSubscribeRequest", chip::app::TestReadInteraction::TestReadHandlerInvalidSubscribeRequest),
NL_TEST_DEF("TestSubscribeInvalidateFabric", chip::app::TestReadInteraction::TestSubscribeInvalidateFabric),
NL_TEST_DEF("TestShutdownSubscription", chip::app::TestReadInteraction::TestShutdownSubscription),
/*
Disable test when running the ICD specific unit tests.
Test tests reporting feature with hard coded time jumps which don't take into account that an ICD
can change the requested MaxInterval during the subscription response / request process
https://github.com/project-chip/connectedhomeip/issues/28419
*/
#if CHIP_CONFIG_ENABLE_ICD_SERVER != 1
NL_TEST_DEF("TestSubscribeUrgentWildcardEvent", chip::app::TestReadInteraction::TestSubscribeUrgentWildcardEvent),
#endif
NL_TEST_DEF("TestSubscribeWildcard", chip::app::TestReadInteraction::TestSubscribeWildcard),
NL_TEST_DEF("TestSubscribePartialOverlap", chip::app::TestReadInteraction::TestSubscribePartialOverlap),
NL_TEST_DEF("TestSubscribeSetDirtyFullyOverlap", chip::app::TestReadInteraction::TestSubscribeSetDirtyFullyOverlap),
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/suites/TestIcdManagementCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tests:
command: "readAttribute"
attribute: "IdleModeDuration"
response:
value: 2
value: 300

- label: "Read ActiveModeDuration"
command: "readAttribute"
Expand Down
39 changes: 36 additions & 3 deletions src/controller/tests/data_model/TestRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,17 @@ class TestReadInteraction : public app::ReadHandler::ApplicationCallback
static void TestReadHandler_OneSubscribeMultipleReads(nlTestSuite * apSuite, void * apContext);
static void TestReadHandler_TwoSubscribesMultipleReads(nlTestSuite * apSuite, void * apContext);
static void TestReadHandler_MultipleSubscriptionsWithDataVersionFilter(nlTestSuite * apSuite, void * apContext);
#if CHIP_CONFIG_ENABLE_ICD_SERVER != 1
static void TestReadHandler_SubscriptionReportingIntervalsTest1(nlTestSuite * apSuite, void * apContext);
static void TestReadHandler_SubscriptionReportingIntervalsTest2(nlTestSuite * apSuite, void * apContext);
static void TestReadHandler_SubscriptionReportingIntervalsTest3(nlTestSuite * apSuite, void * apContext);
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
static void TestReadHandler_SubscriptionReportingIntervalsTest4(nlTestSuite * apSuite, void * apContext);
#if CHIP_CONFIG_ENABLE_ICD_SERVER != 1
static void TestReadHandler_SubscriptionReportingIntervalsTest5(nlTestSuite * apSuite, void * apContext);
static void TestReadHandler_SubscriptionReportingIntervalsTest6(nlTestSuite * apSuite, void * apContext);
static void TestReadHandler_SubscriptionReportingIntervalsTest7(nlTestSuite * apSuite, void * apContext);
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
static void TestReadHandler_SubscriptionReportingIntervalsTest8(nlTestSuite * apSuite, void * apContext);
static void TestReadHandler_SubscriptionReportingIntervalsTest9(nlTestSuite * apSuite, void * apContext);
static void TestReadHandlerResourceExhaustion_MultipleReads(nlTestSuite * apSuite, void * apContext);
Expand Down Expand Up @@ -1719,12 +1723,18 @@ void TestReadInteraction::TestResubscribeAttributeTimeout(nlTestSuite * apSuite,
NL_TEST_ASSERT(apSuite, callback.mOnError == 0);
NL_TEST_ASSERT(apSuite, callback.mOnResubscriptionsAttempted == 0);

chip::app::ReadHandler * readHandler = app::InteractionModelEngine::GetInstance()->ActiveHandlerAt(0);

uint16_t minInterval;
uint16_t maxInterval;
readHandler->GetReportingIntervals(minInterval, maxInterval);

//
// Disable packet transmission, and drive IO till we have reported a re-subscription attempt.
//
//
ctx.GetLoopback().mNumMessagesToDrop = chip::Test::LoopbackTransport::kUnlimitedMessageCount;
ctx.GetIOContext().DriveIOUntil(ComputeSubscriptionTimeout(System::Clock::Seconds16(maxIntervalCeilingSeconds)),
ctx.GetIOContext().DriveIOUntil(ComputeSubscriptionTimeout(System::Clock::Seconds16(maxInterval)),
[&]() { return callback.mOnResubscriptionsAttempted > 0; });

NL_TEST_ASSERT(apSuite, callback.mOnResubscriptionsAttempted == 1);
Expand Down Expand Up @@ -1801,12 +1811,18 @@ void TestReadInteraction::TestSubscribeAttributeTimeout(nlTestSuite * apSuite, v
//
ctx.GetLoopback().mNumMessagesToDrop = chip::Test::LoopbackTransport::kUnlimitedMessageCount;

chip::app::ReadHandler * readHandler = app::InteractionModelEngine::GetInstance()->ActiveHandlerAt(0);

uint16_t minInterval;
uint16_t maxInterval;
readHandler->GetReportingIntervals(minInterval, maxInterval);

//
// Drive IO until we get an error on the subscription, which should be caused
// by the liveness timer firing once we hit our max-interval plus
// retransmit timeouts.
//
ctx.GetIOContext().DriveIOUntil(ComputeSubscriptionTimeout(System::Clock::Seconds16(maxIntervalCeilingSeconds)),
ctx.GetIOContext().DriveIOUntil(ComputeSubscriptionTimeout(System::Clock::Seconds16(maxInterval)),
[&]() { return callback.mOnError >= 1; });

NL_TEST_ASSERT(apSuite, callback.mOnError == 1);
Expand Down Expand Up @@ -1954,6 +1970,8 @@ void TestReadInteraction::TestReadHandler_SubscriptionAppRejection(nlTestSuite *
gTestReadInteraction.mEmitSubscriptionError = false;
}

#if CHIP_CONFIG_ENABLE_ICD_SERVER != 1

// Subscriber sends the request with particular max-interval value:
// Max interval equal to client-requested min-interval.
void TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest1(nlTestSuite * apSuite, void * apContext)
Expand Down Expand Up @@ -2181,6 +2199,8 @@ void TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest3(nl
gTestReadInteraction.mAlterSubscriptionIntervals = false;
}

#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

// Subscriber sends the request with particular max-interval value:
// Max interval greater than client-requested min-interval but lower than 60m:
// server adjustment to a value greater than client-requested, but greater than 60 (not allowed).
Expand Down Expand Up @@ -2247,6 +2267,8 @@ void TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest4(nl
gTestReadInteraction.mAlterSubscriptionIntervals = false;
}

#if CHIP_CONFIG_ENABLE_ICD_SERVER != 1

// Subscriber sends the request with particular max-interval value:
// Max interval greater than client-requested min-interval but greater than 60m:
// With no server adjustment.
Expand Down Expand Up @@ -2474,6 +2496,8 @@ void TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest7(nl
gTestReadInteraction.mAlterSubscriptionIntervals = false;
}

#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

// Subscriber sends the request with particular max-interval value:
// Max interval greater than client-requested min-interval but greater than 60m:
// With server adjustment to a value larger than 60m, but larger than max interval. Disallowed
Expand Down Expand Up @@ -4680,13 +4704,22 @@ const nlTest sTests[] =
NL_TEST_DEF("TestReadHandler_TwoSubscribesMultipleReads", TestReadInteraction::TestReadHandler_TwoSubscribesMultipleReads),
NL_TEST_DEF("TestReadHandlerResourceExhaustion_MultipleReads", TestReadInteraction::TestReadHandlerResourceExhaustion_MultipleReads),
NL_TEST_DEF("TestReadAttributeTimeout", TestReadInteraction::TestReadAttributeTimeout),
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest1", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest1),
/*
Disabling SubscriptionReportingIntervals tests for ICD run.
These tests test the non-ICD behavior and cannot take into account that an ICD will always
change the max interval of a subscription.
*/
#if CHIP_CONFIG_ENABLE_ICD_SERVER != 1
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest1", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest1), // no good
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest2", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest2),
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest3", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest3),
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest4", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest4),
#if CHIP_CONFIG_ENABLE_ICD_SERVER != 1
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest5", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest5),
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest6", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest6),
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest7", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest7),
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest8", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest8),
NL_TEST_DEF("TestReadHandler_SubscriptionReportingIntervalsTest9", TestReadInteraction::TestReadHandler_SubscriptionReportingIntervalsTest9),
NL_TEST_DEF("TestReadSubscribeAttributeResponseWithVersionOnlyCache", TestReadInteraction::TestReadSubscribeAttributeResponseWithVersionOnlyCache),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
* @brief Default value for the ICD Management cluster IdleModeDuration attribute, in seconds
*/
#ifndef CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC
#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC 2
#define CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC 300
#endif

/**
Expand Down
6 changes: 6 additions & 0 deletions src/messaging/tests/TestAbortExchangesForFabric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ void CommonCheckAbortAllButOneExchange(nlTestSuite * inSuite, TestContext & ctx,
// trigger a MRP failure due to timing out waiting for an ACK.
//
auto waitTimeout = System::Clock::Milliseconds32(1000);

#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
// If running as an ICD, increase waitTimeout to account for the polling interval
waitTimeout += CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL;
#endif

// Account for the retry delay booster, so that we do not timeout our IO processing before the
// retransmission failure is triggered.
waitTimeout += CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS * CHIP_CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST;
Expand Down
Loading

0 comments on commit 1677556

Please sign in to comment.