Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chip-tool] Add an option to continue running tests even after a test… #20945

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ void TestCommand::ExitAsync(intptr_t context)

void TestCommand::Exit(std::string message, CHIP_ERROR err)
{
bool shouldContinueOnFailure = mContinueOnFailure.HasValue() && mContinueOnFailure.Value();
if (shouldContinueOnFailure)
{
if (CHIP_NO_ERROR != err)
{
ChipLogError(chipTool, " ***** Step Failure: %s\n", message.c_str());
mErrorMessages.push_back(message);
ContinueOnChipMainThread(CHIP_NO_ERROR);
return;
}

// If the test runner has been configured to not stop after a test failure, exit can be called with a success but it could
// be pending errors from previous steps.
uint32_t errorsCount = static_cast<uint32_t>(mErrorMessages.size());
if (errorsCount)
{
ChipLogError(chipTool, "Error: %u error(s) has been encountered:", errorsCount);

for (uint32_t i = 0; i < errorsCount; i++)
{
ChipLogError(chipTool, "\t%u. %s", (i + 1), mErrorMessages.at(i).c_str());
}
err = CHIP_ERROR_INTERNAL;
}
}

mContinueProcessing = false;

LogEnd(message, err);
Expand Down
6 changes: 6 additions & 0 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class TestCommand : public TestRunner,
TestRunner(commandName, testsCount), CHIPCommand(commandName, credsIssuerConfig),
mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this)
{
AddArgument("continueOnFailure", 0, 1, &mContinueOnFailure,
"Boolean indicating if the test runner should continue execution if a test fails. Default to false.");
AddArgument("delayInMs", 0, UINT64_MAX, &mDelayInMs);
AddArgument("PICS", &mPICSFilePath);
}
Expand Down Expand Up @@ -100,4 +102,8 @@ class TestCommand : public TestRunner,
// as it still used by the stack afterward. So a task is scheduled to run to close the
// test suite as soon as possible, and pending events are ignored in between.
bool mContinueProcessing = true;

// When set to true, the test runner continue to run after a test failure.
chip::Optional<bool> mContinueOnFailure;
std::vector<std::string> mErrorMessages;
};