Skip to content

Commit

Permalink
[YAML] Add a mechanism to specify the test timeout for a given YAML f…
Browse files Browse the repository at this point in the history
…ile (#11861)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jun 22, 2022
1 parent aa17d03 commit 59a94af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <type_traits>
#include <zap-generated/tests/CHIPClustersTest.h>

constexpr uint16_t kTimeoutInSeconds = 30;

class TestCommand : public CHIPCommand
{
public:
Expand All @@ -39,20 +41,26 @@ class TestCommand : public CHIPCommand
{
AddArgument("node-id", 0, UINT64_MAX, &mNodeId);
AddArgument("delayInMs", 0, UINT64_MAX, &mDelayInMs);
AddArgument("timeout", 0, UINT16_MAX, &mTimeout);
AddArgument("endpoint-id", CHIP_ZCL_ENDPOINT_MIN, CHIP_ZCL_ENDPOINT_MAX, &mEndpointId);
AddArgument("PICS", &mPICSFilePath);
}

/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override;
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(30); }
chip::System::Clock::Timeout GetWaitDuration() const override
{
return chip::System::Clock::Seconds16(mTimeout.HasValue() ? mTimeout.Value() : kTimeoutInSeconds);
}

virtual void NextTest() = 0;

/////////// GlobalCommands Interface /////////
CHIP_ERROR Wait(chip::System::Clock::Timeout ms);
CHIP_ERROR WaitForMs(uint16_t ms) { return Wait(chip::System::Clock::Milliseconds32(ms)); }
CHIP_ERROR WaitForCommissionee();
CHIP_ERROR Log(const char * message);
CHIP_ERROR Prompt(const char * message);

protected:
ChipDevice * mDevice;
Expand Down Expand Up @@ -261,5 +269,6 @@ class TestCommand : public CHIPCommand
chip::Optional<uint64_t> mDelayInMs;
chip::Optional<char *> mPICSFilePath;
chip::Optional<chip::EndpointId> mEndpointId;
chip::Optional<uint16_t> mTimeout;
chip::Optional<std::map<std::string, bool>> PICS;
};
3 changes: 3 additions & 0 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class {{filename}}: public TestCommand
}
}

{{#if timeout}}
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(mTimeout.HasValue() : mTimeout.Value() : {{timeout}}); }
{{/if}}

private:
std::atomic_uint16_t mTestIndex;
Expand Down
1 change: 1 addition & 0 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ function parse(filename)
});

yaml.filename = filename;
yaml.timeout = yaml.config.timeout;
yaml.totalTests = yaml.tests.length;

return yaml;
Expand Down

0 comments on commit 59a94af

Please sign in to comment.