Skip to content

Commit

Permalink
Refactor for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs authored and pull[bot] committed Sep 20, 2023
1 parent bd82efb commit 2622297
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 43 deletions.
11 changes: 5 additions & 6 deletions src/app/clusters/scenes/ExtensionFieldsSetsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ bool ExtensionFieldsSetsImpl::is_empty() const
/// @return CHIP_NO_ERROR if insertion worked, CHIP_ERROR_BUFFER_TOO_SMALL if the array is already full
CHIP_ERROR ExtensionFieldsSetsImpl::insertField(ExtensionFieldsSet & field)
{
CHIP_ERROR err = CHIP_ERROR_INVALID_LIST_LENGTH;
uint8_t idPosition = 0xff, fisrtEmptyPosition = 0xff;
for (uint8_t i = 0; i < kMaxClusterPerScenes; i++)
{
Expand All @@ -102,18 +103,16 @@ CHIP_ERROR ExtensionFieldsSetsImpl::insertField(ExtensionFieldsSet & field)
if (idPosition < kMaxClusterPerScenes)
{
ReturnErrorOnFailure(this->mEFS[idPosition] = field);
return CHIP_NO_ERROR;
err = CHIP_NO_ERROR;
}
else if (fisrtEmptyPosition < kMaxClusterPerScenes)
{
ReturnErrorOnFailure(this->mEFS[fisrtEmptyPosition] = field);
this->mFieldNum++;
return CHIP_NO_ERROR;
}
else
{
return CHIP_ERROR_INVALID_LIST_LENGTH;
err = CHIP_NO_ERROR;
}

return err;
}

CHIP_ERROR ExtensionFieldsSetsImpl::getFieldAtPosition(ExtensionFieldsSet & field, uint8_t position)
Expand Down
16 changes: 7 additions & 9 deletions src/app/clusters/scenes/SceneTableImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ struct FabricSceneData : public PersistentData<kPersistentBufferMax>
idx = index;
return CHIP_NO_ERROR; // return scene at current index if scene found
}
else if (scene_map[index].mSceneEndpointId == kInvalidEndpointId && firstFreeIdx == kUndefinedSceneIndex)
if (scene_map[index].mSceneEndpointId == kInvalidEndpointId && firstFreeIdx == kUndefinedSceneIndex)
{
firstFreeIdx = index;
}
Expand Down Expand Up @@ -293,7 +293,8 @@ struct FabricSceneData : public PersistentData<kPersistentBufferMax>

return scene.Save(storage);
}
else if (CHIP_ERROR_NOT_FOUND == err) // If not found, scene.index should be the first free index

if (CHIP_ERROR_NOT_FOUND == err) // If not found, scene.index should be the first free index
{
scene_count++;
scene_map[scene.index] = scene.mStorageId;
Expand Down Expand Up @@ -404,6 +405,7 @@ CHIP_ERROR DefaultSceneTableImpl::RemoveSceneTableEntryAtPosition(FabricIndex fa
/// @return CHIP_ERROR_BUFFER_TO_SMALL if couldn't insert the handler, otherwise CHIP_NO_ERROR
CHIP_ERROR DefaultSceneTableImpl::registerHandler(ClusterId ID, clusterFieldsHandle get_function, clusterFieldsHandle set_function)
{
CHIP_ERROR err = CHIP_ERROR_INVALID_LIST_LENGTH;
uint8_t idPosition = 0xff, fisrtEmptyPosition = 0xff;
for (uint8_t i = 0; i < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES; i++)
{
Expand All @@ -422,20 +424,16 @@ CHIP_ERROR DefaultSceneTableImpl::registerHandler(ClusterId ID, clusterFieldsHan
if (idPosition < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
{
this->handlers[idPosition].initSceneHandler(ID, get_function, set_function);
return CHIP_NO_ERROR;
err = CHIP_NO_ERROR;
}
else if (fisrtEmptyPosition < CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES)
{
this->handlers[fisrtEmptyPosition].initSceneHandler(ID, get_function, set_function);
this->handlerNum++;
return CHIP_NO_ERROR;
}
else
{
return CHIP_ERROR_INVALID_LIST_LENGTH;
err = CHIP_NO_ERROR;
}

return CHIP_ERROR_INVALID_LIST_LENGTH;
return err;
}

CHIP_ERROR DefaultSceneTableImpl::unregisterHandler(uint8_t position)
Expand Down
18 changes: 9 additions & 9 deletions src/app/clusters/scenes/SceneTableImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ typedef CHIP_ERROR (*clusterFieldsHandle)(ExtensionFieldsSet & fields);
class SceneHandler
{
public:
SceneHandler(ClusterId Id = kInvalidClusterId, clusterFieldsHandle getClusterEFS = nullptr,
clusterFieldsHandle setClusterEFS = nullptr)
SceneHandler(ClusterId Id = kInvalidClusterId, clusterFieldsHandle getEFSHandle = nullptr,
clusterFieldsHandle setEFSHandle = nullptr)
{
if (getClusterEFS != nullptr && setClusterEFS != nullptr && Id != kInvalidClusterId)
if (getEFSHandle != nullptr && setEFSHandle != nullptr && Id != kInvalidClusterId)
{
getEFS = getClusterEFS;
setEFS = setClusterEFS;
getEFS = getEFSHandle;
setEFS = setEFSHandle;
cID = Id;
initialized = true;
}
};
~SceneHandler(){};

void initSceneHandler(ClusterId Id, clusterFieldsHandle getClusterEFS, clusterFieldsHandle setClusterEFS)
void initSceneHandler(ClusterId Id, clusterFieldsHandle getEFSHandle, clusterFieldsHandle setEFSHandle)
{
if (getClusterEFS != nullptr && setClusterEFS != nullptr && Id != kInvalidClusterId)
if (getEFSHandle != nullptr && setEFSHandle != nullptr && Id != kInvalidClusterId)
{
getEFS = getClusterEFS;
setEFS = setClusterEFS;
getEFS = getEFSHandle;
setEFS = setEFSHandle;
cID = Id;
initialized = true;
}
Expand Down
76 changes: 57 additions & 19 deletions src/lib/support/TestSceneTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,46 @@ namespace chip {

namespace SceneTesting {

using FabricIndex = chip::FabricIndex;
using SceneTableEntry = chip::scenes::DefaultSceneTableImpl::SceneTableEntry;
using SceneTableImpl = chip::scenes::DefaultSceneTableImpl;
using SceneStorageId = chip::scenes::DefaultSceneTableImpl::SceneStorageId;
using SceneData = chip::scenes::DefaultSceneTableImpl::SceneData;
using FabricIndex = chip::FabricIndex;
using SceneTableEntry = chip::scenes::DefaultSceneTableImpl::SceneTableEntry;
using SceneTableImpl = chip::scenes::DefaultSceneTableImpl;
using SceneStorageId = chip::scenes::DefaultSceneTableImpl::SceneStorageId;
using SceneData = chip::scenes::DefaultSceneTableImpl::SceneData;
using ExtensionFieldsSet = chip::scenes::ExtensionFieldsSet;

static const ExtensionFieldsSet onOffEFS1 = ExtensionFieldsSet(0x0006, (uint8_t *) "1", 1);
static const ExtensionFieldsSet levelControlEFS1 = ExtensionFieldsSet(0x0008, (uint8_t *) "511", 3);

static CHIP_ERROR test_on_off_from_cluster_callback(ExtensionFieldsSet & fields)
{
ReturnErrorOnFailure(fields = onOffEFS1);
return CHIP_NO_ERROR;
}
static CHIP_ERROR test_on_off_to_cluster_callback(ExtensionFieldsSet & fields)
{
VerifyOrReturnError(fields == onOffEFS1, CHIP_ERROR_WRITE_FAILED);
return CHIP_NO_ERROR;
}
static CHIP_ERROR test_level_control_from_cluster_callback(ExtensionFieldsSet & fields)
{
ReturnErrorOnFailure(fields = levelControlEFS1);
return CHIP_NO_ERROR;
}
static CHIP_ERROR test_level_control_to_cluster_callback(ExtensionFieldsSet & fields)
{
VerifyOrReturnError(fields == levelControlEFS1, CHIP_ERROR_WRITE_FAILED);
return CHIP_NO_ERROR;
}

CHIP_ERROR scene_store_test(SceneTableImpl * provider, FabricIndex fabric_index, SceneTableEntry & entry)
{
CHIP_ERROR err = CHIP_NO_ERROR;
SceneTableEntry temp;

LogErrorOnFailure(provider->SetSceneTableEntry(fabric_index, entry));
LogErrorOnFailure(provider->GetSceneTableEntry(fabric_index, entry.storageId, temp));
VerifyOrReturnError(temp.storageId == entry.storageId, CHIP_ERROR_WRITE_FAILED);
VerifyOrReturnError(temp.storageData == entry.storageData, CHIP_ERROR_WRITE_FAILED);
LogErrorOnFailure(provider->GetSceneTableEntry(fabric_index, entry.mStorageId, temp));
VerifyOrReturnError(temp.mStorageId == entry.mStorageId, CHIP_ERROR_WRITE_FAILED);
VerifyOrReturnError(temp.mStorageData == entry.mStorageData, CHIP_ERROR_WRITE_FAILED);

return err;
}
Expand All @@ -55,13 +80,13 @@ CHIP_ERROR scene_iterator_test(SceneTableImpl * provider, FabricIndex fabric_ind
VerifyOrReturnError(iterator->Count() == 3, CHIP_ERROR_INVALID_ARGUMENT);

VerifyOrReturnError(iterator->Next(temp), CHIP_ERROR_INVALID_ACCESS_TOKEN);
VerifyOrReturnError(temp.storageId == entry1.storageId, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(temp.mStorageId == entry1.mStorageId, CHIP_ERROR_INVALID_ARGUMENT);

VerifyOrReturnError(iterator->Next(temp), CHIP_ERROR_INVALID_ACCESS_TOKEN);
VerifyOrReturnError(temp.storageId == entry2.storageId, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(temp.mStorageId == entry2.mStorageId, CHIP_ERROR_INVALID_ARGUMENT);

VerifyOrReturnError(iterator->Next(temp), CHIP_ERROR_INVALID_ACCESS_TOKEN);
VerifyOrReturnError(temp.storageId == entry3.storageId, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(temp.mStorageId == entry3.mStorageId, CHIP_ERROR_INVALID_ARGUMENT);

// Iterator should return false here
VerifyOrReturnError(iterator->Next(temp) == false, CHIP_ERROR_INVALID_ACCESS_TOKEN);
Expand All @@ -78,21 +103,21 @@ CHIP_ERROR scene_remove_test(SceneTableImpl * provider, FabricIndex fabric_index
CHIP_ERROR err = CHIP_NO_ERROR;
SceneTableEntry temp;

LogErrorOnFailure(provider->RemoveSceneTableEntry(fabric_index, entry2.storageId));
LogErrorOnFailure(provider->RemoveSceneTableEntry(fabric_index, entry2.mStorageId));

auto * iterator = provider->IterateSceneEntry(fabric_index);
VerifyOrReturnError(iterator->Count() == 2, CHIP_ERROR_INVALID_ARGUMENT);
iterator->Next(temp);
VerifyOrReturnError(temp.storageId == entry1.storageId, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(temp.mStorageId == entry1.mStorageId, CHIP_ERROR_INVALID_ARGUMENT);
iterator->Release();

LogErrorOnFailure(provider->RemoveSceneTableEntry(fabric_index, entry1.storageId));
LogErrorOnFailure(provider->RemoveSceneTableEntry(fabric_index, entry1.mStorageId));
iterator = provider->IterateSceneEntry(fabric_index);
VerifyOrReturnError(iterator->Count() == 1, CHIP_ERROR_INVALID_ARGUMENT);
iterator->Next(temp);
VerifyOrReturnError(temp.storageId == entry3.storageId, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(temp.mStorageId == entry3.mStorageId, CHIP_ERROR_INVALID_ARGUMENT);

LogErrorOnFailure(provider->RemoveSceneTableEntry(fabric_index, entry3.storageId));
LogErrorOnFailure(provider->RemoveSceneTableEntry(fabric_index, entry3.mStorageId));
iterator = provider->IterateSceneEntry(fabric_index);
VerifyOrReturnError(iterator->Count() == 0, CHIP_ERROR_INVALID_ARGUMENT);

Expand All @@ -112,17 +137,30 @@ CHIP_ERROR TestSceneData(SceneTableImpl * provider, FabricIndex fabric_index)
static const SceneStorageId sceneId3(1, 0xCC, 0x102);

// Scene data
static const SceneData sceneData1("Scene #1");
static const SceneData sceneData2("Scene #2", 2, 5);
static const SceneData sceneData3("Scene #3", 25);
static const SceneData sceneData1(CharSpan("Scene #1", sizeof("Scene #1")));
static const SceneData sceneData2(CharSpan("Scene #2", sizeof("Scene #2")), 2, 5);
static const SceneData sceneData3(CharSpan(), 25);

// Scenes
SceneTableEntry scene1(sceneId1, sceneData1);
SceneTableEntry scene2(sceneId2, sceneData2);
SceneTableEntry scene3(sceneId3, sceneData3);

err = provider->registerHandler(onOffEFS1.mID, &test_on_off_from_cluster_callback, &test_on_off_to_cluster_callback);
LogErrorOnFailure(err);
err = provider->registerHandler(levelControlEFS1.mID, &test_level_control_from_cluster_callback,
&test_level_control_to_cluster_callback);
LogErrorOnFailure(err);
err = provider->EFSValuesFromCluster(scene1.mStorageData.mExtentsionFieldsSets);
LogErrorOnFailure(err);

// Tests
err = scene_store_test(provider, fabric_index, scene1);
LogErrorOnFailure(err);

err = provider->EFSValuesToCluster(scene1.mStorageData.mExtentsionFieldsSets);
LogErrorOnFailure(err);

err = scene_store_test(provider, fabric_index, scene2);
LogErrorOnFailure(err);
err = scene_store_test(provider, fabric_index, scene3);
Expand Down

0 comments on commit 2622297

Please sign in to comment.