Skip to content

Commit

Permalink
Fix test causing SegFault in fake_x64 test
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs authored and pull[bot] committed Oct 11, 2023
1 parent 9ea03f0 commit 1228399
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/clusters/scenes/SceneTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static constexpr uint8_t kMaxScenePerFabric = CHIP_CONFIG_SCENES_MAX_PER_FABRIC;
class SceneTable
{
public:
static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_GROUP_CONCURRENT_ITERATORS;
static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS;
static constexpr size_t kSceneNameMax = CHIP_CONFIG_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH;

/// @brief struct used to identify a scene in storage by 3 ids, endpoint, group and scene
Expand Down
12 changes: 12 additions & 0 deletions src/app/tests/TestSceneTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ void TestIterateScenes(nlTestSuite * aSuite, void * aContext)
SceneTableEntry scene;
auto * iterator = sceneTable->IterateSceneEntry(kFabric1);

NL_TEST_ASSERT(aSuite, iterator != nullptr);

if (iterator)
{
NL_TEST_ASSERT(aSuite, iterator->Count() == 8);
Expand Down Expand Up @@ -311,27 +313,31 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext)
NL_TEST_ASSERT(aSuite, iterator->Count() == 7);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene10);
iterator->Release();

// Adde scene in middle, a spot should have been freed
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->SetSceneTableEntry(kFabric1, scene9));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 8);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId9, scene));
NL_TEST_ASSERT(aSuite, scene == scene9);
iterator->Release();

// Remove the recently added scene 9
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene9.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 7);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene10);
iterator->Release();

// Remove first
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene1.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 6);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene2);
iterator->Release();

// Remove Next
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene3.mStorageId));
Expand All @@ -341,36 +347,42 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext)
NL_TEST_ASSERT(aSuite, scene == scene2);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene4);
iterator->Release();

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene2.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 4);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene4);
iterator->Release();

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene4.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 3);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene6);
iterator->Release();

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene6.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 2);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene7);
iterator->Release();

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene7.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 1);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene12);
iterator->Release();

// Remove last
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene8.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 0);
NL_TEST_ASSERT(aSuite, iterator->Next(scene) == false);
iterator->Release();

NL_TEST_ASSERT(aSuite, CHIP_ERROR_NOT_FOUND == sceneTable->RemoveSceneTableEntry(kFabric1, scene8.mStorageId));

Expand Down
11 changes: 11 additions & 0 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,17 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
#define CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER 15
#endif

/**
* @def CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS
*
* @brief Defines the number of simultaneous Scenes iterators that can be allocated
*
* Number of iterator instances that can be allocated at any one time
*/
#ifndef CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS
#define CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS 2
#endif

/**
* @}
*/

0 comments on commit 1228399

Please sign in to comment.