Skip to content

Commit

Permalink
Disentangle data model tests by moving fixtures into their own file (#…
Browse files Browse the repository at this point in the history
…34154)

* Disentangle data model tests by moving fixtures into their own file

The data model tests all had linker dependencies on each other, which meant
that running any of Test{Read,Write,Commands} would run the tests from all of
them, because the global fixture function from that test was required.

This change moves all those fixture functions into DataModelFixtures.cpp.
Also disambiguate the enum types and control variable names involved.

* Address review comments

- Add more comments to DataModelFixtures.h
- Use ScopedChangeOnly for the fixture control variables
- Extend ScopedChange to allow assignments within the scope
  • Loading branch information
ksperling-apple authored and pull[bot] committed Aug 7, 2024
1 parent 5f8a3e8 commit 1621140
Show file tree
Hide file tree
Showing 9 changed files with 744 additions and 637 deletions.
19 changes: 19 additions & 0 deletions src/app/util/mock/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,24 @@ constexpr EventId MockEventId(const uint16_t & id)
{
return (0xFFF1'0000 | id);
}

// Cluster Revision value returned by mock clusters
extern const uint16_t mockClusterRevision;

// Feature Map value returned by mock clusters
extern const uint32_t mockFeatureMap;

// Scalar value returned by mock clusters for MockAttributeId(1)
extern const bool mockAttribute1;

// Scalar value returned by mock clusters for MockAttributeId(2)
extern const int16_t mockAttribute2;

// Scalar value returned by mock clusters for MockAttributeId(3)
extern const uint64_t mockAttribute3;

// MockAttributeId(4) returns a list of octstr with this value
extern const uint8_t mockAttribute4[256];

} // namespace Test
} // namespace chip
20 changes: 13 additions & 7 deletions src/app/util/mock/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,17 @@ const MockNodeConfig & GetMockNodeConfig()
return (mockConfig != nullptr) ? *mockConfig : DefaultMockNodeConfig();
}

uint16_t mockClusterRevision = 1;
uint32_t mockFeatureMap = 0x1234;
bool mockAttribute1 = true;
int16_t mockAttribute2 = 42;
uint64_t mockAttribute3 = 0xdeadbeef0000cafe;
uint8_t mockAttribute4[256] = {
} // namespace

namespace chip {
namespace Test {

const uint16_t mockClusterRevision = 1;
const uint32_t mockFeatureMap = 0x1234;
const bool mockAttribute1 = true;
const int16_t mockAttribute2 = 42;
const uint64_t mockAttribute3 = 0xdeadbeef0000cafe;
const uint8_t mockAttribute4[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
Expand All @@ -129,7 +134,8 @@ uint8_t mockAttribute4[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
};

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

uint16_t emberAfEndpointCount()
{
Expand Down
14 changes: 11 additions & 3 deletions src/controller/tests/data_model/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ import("${chip_root}/src/platform/device.gni")
chip_test_suite("data_model") {
output_name = "libDataModelTests"

sources = [
"DataModelFixtures.cpp",
"DataModelFixtures.h",
]

test_sources = []
if (chip_device_platform != "mbed" && chip_device_platform != "efr32" &&
chip_device_platform != "esp32" && chip_device_platform != "fake") {
test_sources = [ "TestCommands.cpp" ]
test_sources += [ "TestWrite.cpp" ]
test_sources += [ "TestRead.cpp" ]
test_sources += [
"TestCommands.cpp",
"TestRead.cpp",
"TestWrite.cpp",
]
}

public_deps = [
Expand Down
Loading

0 comments on commit 1621140

Please sign in to comment.