From e60afe432e3dee09ec1fd079ec31813b91841029 Mon Sep 17 00:00:00 2001 From: Jerry Johns Date: Fri, 11 Jun 2021 12:55:36 -0700 Subject: [PATCH] Forgot a file.. --- .../chip-tool/templates/partials/test_cluster.zapt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/chip-tool/templates/partials/test_cluster.zapt b/examples/chip-tool/templates/partials/test_cluster.zapt index 2a201787bb4525..5d461c438c043a 100644 --- a/examples/chip-tool/templates/partials/test_cluster.zapt +++ b/examples/chip-tool/templates/partials/test_cluster.zapt @@ -2,7 +2,7 @@ class {{asCamelCased filename false}}: public TestCommand { public: - {{asCamelCased filename false}}(): TestCommand("{{filename}}") {} + {{asCamelCased filename false}}(): TestCommand("{{filename}}"), mTestIndex(0) {} /////////// TestCommand Interface ///////// CHIP_ERROR NextTest() override @@ -15,7 +15,11 @@ class {{asCamelCased filename false}}: public TestCommand SetCommandExitStatus(true); } - switch (mTestIndex) + // Ensure we increment mTestIndex before we start running the relevant + // command. That way if we lose the timeslice after we send the message + // but before our function call returns, we won't end up with an + // incorrect mTestIndex value observed when we get the response. + switch (mTestIndex++) { {{#chip_tests_items}} case {{index}}: @@ -23,7 +27,6 @@ class {{asCamelCased filename false}}: public TestCommand break; {{/chip_tests_items}} } - mTestIndex++; if (CHIP_NO_ERROR != err) { @@ -36,8 +39,8 @@ class {{asCamelCased filename false}}: public TestCommand private: - uint16_t mTestIndex = 0; - uint16_t mTestCount = {{totalTests}}; + std::atomic_uint16_t mTestIndex; + const uint16_t mTestCount = {{totalTests}}; // // Tests methods