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

pw_unit_test migration: apps #33358

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ab4ce0a
TestReportingEnginer failure to link ember
Alami-Amine May 2, 2024
d126a45
Merge branch 'master' into AA/Appv1
Alami-Amine May 7, 2024
304f3e8
making TestContext dynamically allocated
Alami-Amine May 7, 2024
f3c23e5
Adding *TestAccess Classes to allow access to private Members of test…
Alami-Amine May 8, 2024
9a4fd05
namespace fix
Alami-Amine May 8, 2024
4c488df
Merge branch 'master' into AA/Appv1
Alami-Amine May 8, 2024
c1c8084
Migrating App Tests - not linking
Alami-Amine May 14, 2024
0ef1e42
adding ember-test-compatibility
Alami-Amine May 16, 2024
1b6c148
moving function definitions to ember-test-compatibility (execpt Comma…
Alami-Amine May 16, 2024
be04176
Merge branch 'master' into AA/Appv1
Alami-Amine May 16, 2024
1a01dea
factoring out some ember functions into ember-test-compatibility.cpp …
Alami-Amine May 16, 2024
13e11e6
applying restyled patch
Alami-Amine May 16, 2024
c882cb3
adding sourcefile to gn
Alami-Amine May 16, 2024
b761799
openiot fix
Alami-Amine May 16, 2024
14c0590
clang-tidy fix
Alami-Amine May 17, 2024
db0160d
Adding TestCommandInteraction and WriteInteraction
Alami-Amine May 20, 2024
37cf366
build.gn fix
Alami-Amine May 20, 2024
41a4bb8
build.gn fix v2
Alami-Amine May 20, 2024
64020eb
removing TestACLAttribute
Alami-Amine May 21, 2024
eb01e7a
Revert "removing TestACLAttribute"
Alami-Amine May 23, 2024
418cf2f
Merge branch 'master' into AA/Appv1
Alami-Amine May 23, 2024
46dd357
Add more tests
Alami-Amine May 23, 2024
9d4b98a
Merge branch 'master' into AA/Appv1
Alami-Amine May 24, 2024
2f71a2d
switching order of running tests for nordic
Alami-Amine May 27, 2024
642671c
workaround, make TestAclAttribute run after other tests
Alami-Amine May 27, 2024
8733696
Merge branch 'master' into AA/Appv1
Alami-Amine May 28, 2024
74d663b
Fix TearDown issue of some App Tests
Alami-Amine May 28, 2024
6d7f58e
clean TestAclAttribute and TestAclEvent
Alami-Amine May 28, 2024
d033c0b
Check if fix for Test Teardown works for OpenIoTSDK
Alami-Amine May 28, 2024
f5e8b47
Merge branch 'master' into AA/Appv1
Alami-Amine May 28, 2024
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
1 change: 1 addition & 0 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ if (chip_build_tests) {
if (chip_device_platform != "efr32") {
tests += [
"${chip_root}/src/app/tests",
"${chip_root}/src/app/tests:tests_nltest",
"${chip_root}/src/credentials/tests",
"${chip_root}/src/lib/format/tests",
"${chip_root}/src/lib/support/tests",
Expand Down
4 changes: 4 additions & 0 deletions src/app/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#include <app/MessageDef/InvokeResponseMessage.h>

namespace chip {
namespace Test {
class CommandHandlerTestAccess;
}
namespace app {

/// Defines an abstract class of something that can be encoded
Expand Down Expand Up @@ -506,6 +509,7 @@ class CommandHandler
private:
friend class TestCommandInteraction;
friend class CommandHandler::Handle;
friend class chip::Test::CommandHandlerTestAccess;

enum class State : uint8_t
{
Expand Down
5 changes: 5 additions & 0 deletions src/app/CommandSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#define COMMON_STATUS_SUCCESS 0

namespace chip {
namespace Test {
class CommandSenderTestAccess;

}
namespace app {

class CommandSender final : public Messaging::ExchangeDelegate
Expand Down Expand Up @@ -491,6 +495,7 @@ class CommandSender final : public Messaging::ExchangeDelegate

private:
friend class TestCommandInteraction;
friend class chip::Test::CommandSenderTestAccess;

enum class State : uint8_t
{
Expand Down
7 changes: 7 additions & 0 deletions src/app/ReadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
inline constexpr uint16_t kSubscriptionMaxIntervalPublisherLimit = 3600; // seconds (60 minutes)

namespace chip {

// Forward declaration of ReadHandlerTestAccess class to allow it to be friend with the ReadHandler.
// This is not for general API use. It is only to be used for (Unit) Tests to expose private Methods/Members.
namespace Test {
class ReadHandlerTestAccess;
}
namespace app {

//
Expand Down Expand Up @@ -426,6 +432,7 @@ class ReadHandler : public Messaging::ExchangeDelegate
friend class TestReadInteraction;
friend class chip::app::reporting::TestReportingEngine;
friend class chip::app::reporting::TestReportScheduler;
friend class chip::Test::ReadHandlerTestAccess;

//
// The engine needs to be able to Abort/Close a ReadHandler instance upon completion of work for a given read/subscribe
Expand Down
5 changes: 5 additions & 0 deletions src/app/WriteClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
#include <system/TLVPacketBufferBackingStore.h>

namespace chip {
namespace Test {
class WriteClientTestAccess;

}
namespace app {

class InteractionModelEngine;
Expand Down Expand Up @@ -237,6 +241,7 @@ class WriteClient : public Messaging::ExchangeDelegate
private:
friend class TestWriteInteraction;
friend class InteractionModelEngine;
friend class chip::Test::WriteClientTestAccess;

enum class State
{
Expand Down
5 changes: 5 additions & 0 deletions src/app/WriteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <system/TLVPacketBufferBackingStore.h>

namespace chip {
namespace Test {
class WriteHandlerTestAccess;
}
namespace app {

class WriteHandler;
Expand Down Expand Up @@ -132,6 +135,8 @@ class WriteHandler : public Messaging::ExchangeDelegate

private:
friend class TestWriteInteraction;
friend class chip::Test::WriteHandlerTestAccess;

enum class State
{
Uninitialized = 0, // The handler has not been initialized
Expand Down
5 changes: 5 additions & 0 deletions src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include <system/TLVPacketBufferBackingStore.h>

namespace chip {
namespace Test {
class EngineTestAccess;

}
namespace app {

class InteractionModelEngine;
Expand Down Expand Up @@ -148,6 +152,7 @@ class Engine

friend class TestReportingEngine;
friend class ::chip::app::TestReadInteraction;
friend class ::chip::Test::EngineTestAccess;

bool IsRunScheduled() const { return mRunScheduled; }

Expand Down
6 changes: 6 additions & 0 deletions src/app/tests/AppTestContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
95 changes: 73 additions & 22 deletions src/app/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/nlunit_test.gni")
import("//build_overrides/pigweed.gni")

import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/src/app/icd/icd.gni")
Expand All @@ -37,9 +38,10 @@ static_library("helpers") {
"${chip_root}/src/access",
"${chip_root}/src/app",
"${chip_root}/src/lib/support",
"${chip_root}/src/messaging/tests:helpers",
"${chip_root}/src/transport/raw/tests:helpers",
]

public_deps = [ "${chip_root}/src/messaging/tests:helpers" ]
}

source_set("binding-test-srcs") {
Expand Down Expand Up @@ -119,21 +121,80 @@ source_set("operational-state-test-srcs") {
]
}

chip_test_suite_using_nltest("tests") {
source_set("ember-apptest-compatibility") {
sources = [
"ember-test-compatibility.cpp",
"ember-test-compatibility.h",
]
public_configs = [ "${chip_root}/src/lib/support/pw_log_chip:config" ]

public_deps = [
"${chip_root}/src/app/util/mock:mock_ember",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
]
}

chip_test_suite("tests") {
output_name = "libAppTests"

sources = [
"CommandHandlerTestAccess.h",
"CommandSenderTestAccess.h",
"EngineTestAccess.h",
"ReadHandlerTestAccess.h",
"WriteClientTestAccess.h",
"WriteHandlerTestAccess.h",
]
test_sources = [
"TestAclAttribute.cpp",
"TestAclEvent.cpp",
"TestBindingTable.cpp",
"TestBuilderParser.cpp",
"TestCommandInteraction.cpp",
"TestMessageDef.cpp",
"TestNullable.cpp",
"TestReportingEngine.cpp",
"TestStatusIB.cpp",
"TestStatusResponseMessage.cpp",
"TestTimedHandler.cpp",
"TestWriteInteraction.cpp",
]

if (!chip_fake_platform) {
test_sources += [ "TestFailSafeContext.cpp" ]
}

cflags = [ "-Wconversion" ]

public_deps = [
":binding-test-srcs",
":ember-apptest-compatibility",
":operational-state-test-srcs",
":ota-requestor-test-srcs",
":time-sync-data-provider-test-srcs",
"${chip_root}/src/app",
"${chip_root}/src/app/common:cluster-objects",
"${chip_root}/src/app/icd/client:manager",
"${chip_root}/src/app/tests:helpers",
"${chip_root}/src/app/util/mock:mock_ember",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support:test_utils",
"${chip_root}/src/lib/support:testing",
]
}

chip_test_suite_using_nltest("tests_nltest") {
output_name = "libAppTestsNL"

test_sources = [
"TestAttributeAccessInterfaceCache.cpp",
"TestAttributePathExpandIterator.cpp",
"TestAttributePersistenceProvider.cpp",
"TestAttributeValueDecoder.cpp",
"TestAttributeValueEncoder.cpp",
"TestBasicCommandPathRegistry.cpp",
"TestBindingTable.cpp",
"TestBuilderParser.cpp",
"TestClusterInfo.cpp",
"TestCommandInteraction.cpp",
"TestCommandPathParams.cpp",
"TestConcreteAttributePath.cpp",
"TestDataModelSerialization.cpp",
Expand All @@ -143,29 +204,17 @@ chip_test_suite_using_nltest("tests") {
"TestEventPathParams.cpp",
"TestFabricScopedEventLogging.cpp",
"TestInteractionModelEngine.cpp",
"TestMessageDef.cpp",
"TestNullable.cpp",
"TestNumericAttributeTraits.cpp",
"TestOperationalStateClusterObjects.cpp",
"TestPendingNotificationMap.cpp",
"TestPendingResponseTrackerImpl.cpp",
"TestPowerSourceCluster.cpp",
"TestReadInteraction.cpp",
"TestReportingEngine.cpp",
"TestStatusIB.cpp",
"TestStatusResponseMessage.cpp",
"TestReportScheduler.cpp",
"TestTestEventTriggerDelegate.cpp",
"TestTimeSyncDataProvider.cpp",
"TestTimedHandler.cpp",
"TestWriteInteraction.cpp",
]

if (!chip_fake_platform) {
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" ]
Expand All @@ -191,18 +240,20 @@ chip_test_suite_using_nltest("tests") {

# 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
# runs are remaining, causing tests to crash in Open IoT SDK 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" ]
# Update: This was fixed for Nordic Zephyr Tests by calling DrainAndServiceIO in AppContext::TearDownTestSuite()
# TODO: check if above solution works for openiotsdk as well
if (chip_device_platform != "openiotsdk") {
test_sources += []
}

cflags = [ "-Wconversion" ]

public_deps = [
":binding-test-srcs",
":ember-apptest-compatibility",
":operational-state-test-srcs",
":ota-requestor-test-srcs",
":time-sync-data-provider-test-srcs",
Expand Down
57 changes: 57 additions & 0 deletions src/app/tests/CommandHandlerTestAccess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app/CommandHandler.h>

namespace chip {
namespace Test {

/**
* @brief Class acts as an accessor to private methods of the CommandHandler class without needing to give friend access to
* each individual test.
* This is not a Global API and should only be used for (Unit) Testing.
*/
class CommandHandlerTestAccess
{

public:
CommandHandlerTestAccess(app::CommandHandler * aCommandHandler) : pCommandHandler(aCommandHandler) {}

bool TestOnlyIsInIdleState() { return pCommandHandler->TestOnlyIsInIdleState(); }

Protocols::InteractionModel::Status ProcessInvokeRequest(System::PacketBufferHandle && payload, bool isTimedInvoke)
{
return pCommandHandler->ProcessInvokeRequest(std::move(payload), isTimedInvoke);
}

void SetReserveSpaceForMoreChunkMessages(bool aReserveSpaceForMoreChunkMessages)
{
pCommandHandler->mReserveSpaceForMoreChunkMessages = aReserveSpaceForMoreChunkMessages;
}

app::InvokeResponseMessage::Builder & GetInvokeResponseBuilder() { return pCommandHandler->mInvokeResponseBuilder; }

app::CommandHandlerExchangeInterface * GetmpResponder() { return pCommandHandler->mpResponder; }

private:
app::CommandHandler * pCommandHandler = nullptr;
};

} // namespace Test
} // namespace chip
Loading
Loading