Skip to content

Commit

Permalink
[CI] Add an additional delayInMs argument when running a test (#10560)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored Oct 18, 2021
1 parent fee3d26 commit f0b6cbc
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 7 deletions.
14 changes: 13 additions & 1 deletion examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "../common/CHIPCommand.h"
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <lib/support/UnitTestUtils.h>
#include <zap-generated/tests/CHIPClustersTest.h>

class TestCommand : public CHIPCommand
Expand All @@ -28,7 +29,9 @@ class TestCommand : public CHIPCommand
TestCommand(const char * commandName) :
CHIPCommand(commandName), mOnDeviceConnectedCallback(OnDeviceConnectedFn, this),
mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this)
{}
{
AddArgument("delayInMs", 0, UINT64_MAX, &mDelayInMs);
}

/////////// CHIPCommand Interface /////////
CHIP_ERROR Run(NodeId remoteId) override;
Expand Down Expand Up @@ -103,4 +106,13 @@ class TestCommand : public CHIPCommand

chip::Callback::Callback<chip::Controller::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::Controller::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;

void Wait()
{
if (mDelayInMs)
{
chip::test_utils::SleepMillis(mDelayInMs);
}
};
uint64_t mDelayInMs = 0;
};
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class {{filename}}: public TestCommand
return;
}

Wait();

// 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
Expand Down
15 changes: 9 additions & 6 deletions scripts/tests/test_suites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
set -e

declare -i iterations=2
declare -i delay=0
declare -i background_pid=0
declare test_case_wrapper=()

usage() {
echo "test_suites.sh [-a APPLICATION] [-i ITERATIONS] [-h] [-s CASE_NAME] [-w COMMAND]"
echo "test_suites.sh [-a APPLICATION] [-i ITERATIONS] [-h] [-s CASE_NAME] [-w COMMAND] [-d DELAY]"
echo " -a APPLICATION: runs chip-tool against 'chip-<APPLICATION>-app' (default: all-clusters)"
echo " -i ITERATIONS: number of iterations to run (default: $iterations)"
echo " -d DELAY: milliseconds to wait before running an individual test step (default: $delay)"
echo " -h: this help message"
echo " -i ITERATIONS: number of iterations to run (default: $iterations)"
echo " -s CASE_NAME: runs single test case name (e.g. Test_TC_OO_2_2"
echo " for Test_TC_OO_2_2.yaml) (by default, all are run)"
echo " -w COMMAND: prefix all instantiations with a command (e.g. valgrind) (default: '')"
Expand All @@ -35,11 +37,12 @@ usage() {
}

# read shell arguments
while getopts a:i:hs:w: flag; do
while getopts a:d:i:hs:w: flag; do
case "$flag" in
a) application=$OPTARG ;;
i) iterations=$OPTARG ;;
d) delay=$OPTARG ;;
h) usage ;;
i) iterations=$OPTARG ;;
s) single_case=$OPTARG ;;
w) test_case_wrapper=("$OPTARG") ;;
esac
Expand All @@ -61,7 +64,7 @@ if [[ $iterations == 0 ]]; then
exit 1
fi

echo "Running tests for application: $application, with iterations set to: $iterations"
echo "Running tests for application: $application, with iterations set to: $iterations and delay set to $delay"

cleanup() {
if [[ $background_pid != 0 ]]; then
Expand Down Expand Up @@ -123,7 +126,7 @@ for j in "${iter_array[@]}"; do
echo " * Pairing to device"
"${test_case_wrapper[@]}" out/debug/standalone/chip-tool pairing qrcode MT:D8XA0CQM00KA0648G00
echo " * Starting test run: $i"
"${test_case_wrapper[@]}" out/debug/standalone/chip-tool tests "$i"
"${test_case_wrapper[@]}" out/debug/standalone/chip-tool tests "$i" "$delay"
# Prevent cleanup trying to kill a process we already killed.
temp_background_pid=$background_pid
background_pid=0
Expand Down
Loading

0 comments on commit f0b6cbc

Please sign in to comment.