Skip to content

Commit

Permalink
Fix incorrect test termination condition in TestCommand subclasses. (#…
Browse files Browse the repository at this point in the history
…7428)

The logic in NextTest was doing the following:

1. Start the test at mTestIndex.
2. Increment mTestIndex.
3. If mTestCount == mTestIndex (i.e. no more tests to run), start shutdown (by
   calling SetCommandExitStatus, which unblocks the shutdown sequence)..

This failed when running the last test: we would start the test,
increment mTestIndex, then hit that mTestCount condition and
immediately start shutdown, before waiting for the last test to
complete.

The fix is to test for the "no more tests to run" condition on entry
to NextTest.  This way the last test runs compeletely, and when it's
done and calls NextTest we go ahead and shut down.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 21, 2021
1 parent 5757bf9 commit 4021443
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 16 additions & 4 deletions examples/chip-tool/commands/tests/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class TestCluster : public TestCommand
{
CHIP_ERROR err = CHIP_NO_ERROR;

if (mTestCount == mTestIndex)
{
ChipLogProgress(chipTool, "TestCluster: Test complete");
SetCommandExitStatus(true);
}

switch (mTestIndex)
{
case 0:
Expand All @@ -51,10 +57,10 @@ class TestCluster : public TestCommand
}
mTestIndex++;

if (mTestCount == mTestIndex || CHIP_NO_ERROR != err)
if (CHIP_NO_ERROR != err)
{
ChipLogProgress(chipTool, "TestCluster: %s", chip::ErrorStr(err));
SetCommandExitStatus(CHIP_NO_ERROR == err);
SetCommandExitStatus(false);
}

return err;
Expand Down Expand Up @@ -438,6 +444,12 @@ class OnOffCluster : public TestCommand
{
CHIP_ERROR err = CHIP_NO_ERROR;

if (mTestCount == mTestIndex)
{
ChipLogProgress(chipTool, "OnOffCluster: Test complete");
SetCommandExitStatus(true);
}

switch (mTestIndex)
{
case 0:
Expand All @@ -458,10 +470,10 @@ class OnOffCluster : public TestCommand
}
mTestIndex++;

if (mTestCount == mTestIndex || CHIP_NO_ERROR != err)
if (CHIP_NO_ERROR != err)
{
ChipLogProgress(chipTool, "OnOffCluster: %s", chip::ErrorStr(err));
SetCommandExitStatus(CHIP_NO_ERROR == err);
SetCommandExitStatus(false);
}

return err;
Expand Down
10 changes: 8 additions & 2 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class {{asCamelCased filename false}}: public TestCommand
{
CHIP_ERROR err = CHIP_NO_ERROR;

if (mTestCount == mTestIndex)
{
ChipLogProgress(chipTool, "{{filename}}: Test complete");
SetCommandExitStatus(true);
}

switch (mTestIndex)
{
{{#chip_tests_items}}
Expand All @@ -19,10 +25,10 @@ class {{asCamelCased filename false}}: public TestCommand
}
mTestIndex++;

if (mTestCount == mTestIndex || CHIP_NO_ERROR != err)
if (CHIP_NO_ERROR != err)
{
ChipLogProgress(chipTool, "{{filename}}: %s", chip::ErrorStr(err));
SetCommandExitStatus(CHIP_NO_ERROR == err);
SetCommandExitStatus(false);
}

return err;
Expand Down

0 comments on commit 4021443

Please sign in to comment.