Skip to content

Commit

Permalink
Add controller tests to the build. (project-chip#10729)
Browse files Browse the repository at this point in the history
* Add controller tests to the build.

A number of important controller-side tests got added recently, but they
are not being run in CI. Well, let's add them.

* Fixed up the builds

* Fixed up the tests to pass
  • Loading branch information
mrjerryjohns authored and PSONALl committed Dec 2, 2021
1 parent 86e0d9b commit c1b7f6f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ if (chip_build_tests) {
if (chip_device_platform != "nrfconnect" &&
chip_device_platform != "efr32") {
# TODO(#10447): Controller test has HF on EFR32.
deps += [ "${chip_root}/src/controller/tests" ]
deps += [
"${chip_root}/src/controller/tests",
"${chip_root}/src/controller/tests/data_model",
]
}

if (current_os != "zephyr" && current_os != "mbed" &&
Expand Down
1 change: 0 additions & 1 deletion src/controller/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ chip_test_suite("tests") {
"${chip_root}/src/app/common:cluster-objects",
"${chip_root}/src/app/tests:helpers",
"${chip_root}/src/controller",
"${chip_root}/src/controller/tests/data_model:interaction-tests",
"${chip_root}/src/messaging/tests:helpers",
"${chip_root}/src/transport/raw/tests:helpers",
"${nlunit_test_root}:nlunit-test",
Expand Down
4 changes: 2 additions & 2 deletions src/controller/tests/data_model/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import("//build_overrides/nlunit_test.gni")
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/src/platform/device.gni")

chip_test_suite("interaction-tests") {
output_name = "libInteractionTests"
chip_test_suite("data_model") {
output_name = "libDataModelTests"

if (chip_device_platform != "mbed" && chip_device_platform != "efr32") {
test_sources = [ "TestCommands.cpp" ]
Expand Down
22 changes: 19 additions & 3 deletions src/controller/tests/data_model/TestCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
*/

#include "app/data-model/NullObject.h"
#include <app-common/zap-generated/cluster-objects.h>
#include <app/AppBuildConfig.h>
#include <app/InteractionModelEngine.h>
Expand Down Expand Up @@ -223,8 +224,13 @@ void TestCommandInteraction::TestDataResponse(nlTestSuite * apSuite, void * apCo

void TestCommandInteraction::TestSuccessNoDataResponse(nlTestSuite * apSuite, void * apContext)
{
struct FakeRequest : public TestCluster::Commands::TestSimpleArgumentRequest::Type
{
using ResponseType = DataModel::NullObjectType;
};

TestContext & ctx = *static_cast<TestContext *>(apContext);
TestCluster::Commands::TestSimpleArgumentRequest::Type request;
FakeRequest request;
auto sessionHandle = ctx.GetSessionBobToAlice();

bool onSuccessWasCalled = false;
Expand Down Expand Up @@ -257,8 +263,13 @@ void TestCommandInteraction::TestSuccessNoDataResponse(nlTestSuite * apSuite, vo

void TestCommandInteraction::TestAsyncResponse(nlTestSuite * apSuite, void * apContext)
{
struct FakeRequest : public TestCluster::Commands::TestSimpleArgumentRequest::Type
{
using ResponseType = DataModel::NullObjectType;
};

TestContext & ctx = *static_cast<TestContext *>(apContext);
TestCluster::Commands::TestSimpleArgumentRequest::Type request;
FakeRequest request;
auto sessionHandle = ctx.GetSessionBobToAlice();

bool onSuccessWasCalled = false;
Expand Down Expand Up @@ -342,8 +353,13 @@ void TestCommandInteraction::TestFailure(nlTestSuite * apSuite, void * apContext

void TestCommandInteraction::TestSuccessNoDataResponseWithClusterStatus(nlTestSuite * apSuite, void * apContext)
{
struct FakeRequest : public TestCluster::Commands::TestSimpleArgumentRequest::Type
{
using ResponseType = DataModel::NullObjectType;
};

TestContext & ctx = *static_cast<TestContext *>(apContext);
TestCluster::Commands::TestSimpleArgumentRequest::Type request;
FakeRequest request;
auto sessionHandle = ctx.GetSessionBobToAlice();

bool onSuccessWasCalled = false;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/tests/data_model/TestRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CHIP_ERROR ReadSingleClusterData(FabricIndex aAccessingFabricIndex, const Concre

ReturnErrorOnFailure(DataModel::Encode(*(attributeData.GetWriter()),
chip::TLV::ContextTag(chip::to_underlying(AttributeDataIB::Tag::kData)), value));
attributeData.DataVersion(0);
attributeData.DataVersion(0).EndOfAttributeDataIB();
return CHIP_NO_ERROR;
}
else
Expand Down

0 comments on commit c1b7f6f

Please sign in to comment.