From f7a5195c523c0a73e05da13fbfa922737b623aa2 Mon Sep 17 00:00:00 2001 From: AYA Date: Wed, 29 May 2024 11:32:41 +0200 Subject: [PATCH 1/2] Fix issue related to teardown of some App Tests --- src/app/tests/AppTestContext.cpp | 6 ++++++ src/app/tests/BUILD.gn | 14 ++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/app/tests/AppTestContext.cpp b/src/app/tests/AppTestContext.cpp index eca7a2db76c83b..a4f763046bf7a5 100644 --- a/src/app/tests/AppTestContext.cpp +++ b/src/app/tests/AppTestContext.cpp @@ -49,6 +49,12 @@ void AppContext::SetUpTestSuite() void AppContext::TearDownTestSuite() { + // Adding a DrainAndServiceIO call fixes the teardown for some tests (TestAclAttribute and TestReportScheduler); these were + // triggering failures in tests that follow them when running on nRF CI (Zephyr native_posix where all Unit Tests are compiled + // into a single file) + // TODO: understand this more and solve underlying issue + LoopbackMessagingContext::DrainAndServiceIO(); + chip::DeviceLayer::PlatformMgr().Shutdown(); LoopbackMessagingContext::TearDownTestSuite(); } diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn index df6737a713e6e4..28408773e15edf 100644 --- a/src/app/tests/BUILD.gn +++ b/src/app/tests/BUILD.gn @@ -123,6 +123,7 @@ chip_test_suite_using_nltest("tests") { output_name = "libAppTests" test_sources = [ + "TestAclAttribute.cpp", "TestAclEvent.cpp", "TestAttributeAccessInterfaceCache.cpp", "TestAttributePathExpandIterator.cpp", @@ -151,6 +152,7 @@ chip_test_suite_using_nltest("tests") { "TestPendingResponseTrackerImpl.cpp", "TestPowerSourceCluster.cpp", "TestReadInteraction.cpp", + "TestReportScheduler.cpp", "TestReportingEngine.cpp", "TestStatusIB.cpp", "TestStatusResponseMessage.cpp", @@ -164,8 +166,6 @@ chip_test_suite_using_nltest("tests") { test_sources += [ "TestFailSafeContext.cpp" ] } - test_sources += [ "TestAclAttribute.cpp" ] - # DefaultICDClientStorage assumes that raw AES key is used by the application if (chip_crypto != "psa") { test_sources += [ "TestDefaultICDClientStorage.cpp" ] @@ -189,16 +189,6 @@ chip_test_suite_using_nltest("tests") { test_sources += [ "TestEventLogging.cpp" ] } - # The platform manager is not properly clearing queues in test teardown, which results in - # DrainIO calls not being able to run in expected time (5seconds) if unprocessed reported engine - # runs are remaining, causing tests to crash in Open IoT SDK and Zephyr tests since they are - # running all tests in one file. We need to figure out how to properly clean the event queues - # before enabling this test for these platforms. - if (chip_device_platform != "nrfconnect" && - chip_device_platform != "openiotsdk") { - test_sources += [ "TestReportScheduler.cpp" ] - } - cflags = [ "-Wconversion" ] public_deps = [ From a40653f65b67d6e9c984ad37e8655b4f781071bb Mon Sep 17 00:00:00 2001 From: Amine Alami <43780877+Alami-Amine@users.noreply.github.com> Date: Thu, 30 May 2024 10:12:42 +0200 Subject: [PATCH 2/2] Update comment Co-authored-by: Boris Zbarsky --- src/app/tests/AppTestContext.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/tests/AppTestContext.cpp b/src/app/tests/AppTestContext.cpp index a4f763046bf7a5..ff1154dafbb306 100644 --- a/src/app/tests/AppTestContext.cpp +++ b/src/app/tests/AppTestContext.cpp @@ -49,10 +49,16 @@ void AppContext::SetUpTestSuite() void AppContext::TearDownTestSuite() { - // Adding a DrainAndServiceIO call fixes the teardown for some tests (TestAclAttribute and TestReportScheduler); these were - // triggering failures in tests that follow them when running on nRF CI (Zephyr native_posix where all Unit Tests are compiled - // into a single file) - // TODO: understand this more and solve underlying issue + // Some test suites finish with unprocessed work left in the platform manager event queue. + // This can particularly be a problem when this unprocessed work involves reporting engine runs, + // since those can take a while and cause later tests to not reach their queued work before + // their timeouts hit. This is only an issue in setups where all unit tests are compiled into + // a single file (e.g. nRF CI (Zephyr native_posix)). + // + // Work around this issue by doing a DrainAndServiceIO() here to attempt to flush out any queued-up work. + // + // TODO: Solve the underlying issue where test suites leave unprocessed work. Or is this actually + // the right solution? LoopbackMessagingContext::DrainAndServiceIO(); chip::DeviceLayer::PlatformMgr().Shutdown();