Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Mar 15, 2022
1 parent bfbe841 commit c120ccc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1401,3 +1401,6 @@ kManage
kOperate
kView
xFFFFFFFD
ClusterObjectTests
TestTimedRequestTimeout
datamodel
23 changes: 17 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,12 @@ jobs:
name: REPL Tests - Linux
timeout-minutes: 120

strategy:
matrix:
build_variant: [no-ble-tsan]

env:
BUILD_VARIANT: ${{matrix.build_variant}}
CHIP_TOOL_VARIANT: ${{matrix.chip_tool}}
TSAN_OPTIONS: "halt_on_error=1 suppressions=scripts/tests/chiptest/tsan-linux-suppressions.txt"

if: github.actor != 'restyled-io[bot]'
Expand Down Expand Up @@ -258,8 +261,12 @@ jobs:
timeout-minutes: 50
run: |
scripts/run_in_build_env.sh './scripts/build_python.sh --install_wheel build-env'
scripts/examples/gn_build_example.sh examples/all-clusters-app/linux out/all_clusters_debug chip_enable_wifi=false
cp out/all_clusters_debug/chip-all-clusters-app objdir-clone/chip-all-clusters-app
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py \
--target linux-x64-all-clusters-${BUILD_VARIANT} \
build \
--copy-artifacts-to objdir-clone \
"
- name: Run Tests
timeout-minutes: 30
run: |
Expand Down Expand Up @@ -336,12 +343,16 @@ jobs:
timeout-minutes: 50
run: |
scripts/run_in_build_env.sh './scripts/build_python.sh --install_wheel build-env'
scripts/examples/gn_build_example.sh examples/all-clusters-app/linux out/all_clusters_debug chip_enable_wifi=false
cp out/all_clusters_debug/chip-all-clusters-app objdir-clone/chip-all-clusters-app
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py \
--target darwin-x64-all-clusters-${BUILD_VARIANT} \
build \
--copy-artifacts-to objdir-clone \
"
- name: Run Tests
timeout-minutes: 30
run: |
scripts/run_in_build_env.sh './scripts/tests/run_python_test.py --app chip-all-clusters-app --factoryreset -- -t 90 --disable-test ClusterObjectTests.TestTimedRequestTimeout'
scripts/run_in_build_env.sh './scripts/tests/run_python_test.py --app chip-all-clusters-app --factoryreset --app-params "--discriminator 3840 --interface-id -1" -- -t 90 --disable-test ClusterObjectTests.TestTimedRequestTimeout'
- name: Uploading core files
uses: actions/upload-artifact@v2
if: ${{ failure() }} && ${{ !env.ACT }}
Expand Down
25 changes: 17 additions & 8 deletions scripts/tests/run_python_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pty
import subprocess
import click
import os
Expand All @@ -24,6 +25,8 @@
import sys
import time
import datetime
import shlex
import logging

DEFAULT_CHIP_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..'))
Expand Down Expand Up @@ -61,9 +64,11 @@ def RedirectQueueThread(fp, tag, queue):
log_queue_thread.start()


def DumpLogOutput(q):
def DumpLogOutput(q: queue.Queue, timeout: int = 0):
deadline = time.time() + timeout
while True:
line = q.get_nowait()
line = q.get((time.time() - deadline) > 0,
max(deadline - time.time(), 0))
sys.stdout.buffer.write(
(f"[{line[2]}]").encode() + line[0] + line[1])
sys.stdout.flush()
Expand All @@ -73,9 +78,10 @@ def DumpLogOutput(q):
@click.option("--app", type=str, default=None, help='Local application to use, omit to use external apps.')
@click.option("--factoryreset", is_flag=True, help='Remove /tmp/chip* before running the tests.')
@click.option("--wait-before-test", type=int, default=3, help='Time for the device to start before running the tests.')
@click.option("--app-params", type=str, default='', help='The extra parameters passed to the device.')
@click.option("--script", type=click.Path(exists=True), default=FindBinaryPath("mobile-device-test.py"), help='Test script to use.')
@click.argument("script-args", nargs=-1, type=str)
def main(app: str, factoryreset: bool, wait_before_test: int, script: str, script_args: typing.List[str]):
def main(app: str, factoryreset: bool, wait_before_test: int, app_params: str, script: str, script_args: typing.List[str]):
if factoryreset:
retcode = subprocess.call("rm -rf /tmp/chip*", shell=True)
if retcode != 0:
Expand All @@ -88,22 +94,25 @@ def main(app: str, factoryreset: bool, wait_before_test: int, script: str, scrip
app = FindBinaryPath(app)
if app is None:
raise FileNotFoundError(f"{app} not found")
app_args = [app] + shlex.split(app_params)
logging.info(f"Execute: {app_args}")
app_process = subprocess.Popen(
[app], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
app_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
RedirectQueueThread(app_process.stdout,
b"[\33[34mAPP \33[0m][\33[33mSTDOUT\33[0m]", log_queue)
RedirectQueueThread(app_process.stderr,
b"[\33[34mAPP \33[0m][\33[31mSTDERR\33[0m]", log_queue)

try:
DumpLogOutput(log_queue)
DumpLogOutput(log_queue, wait_before_test)
except queue.Empty:
pass

time.sleep(wait_before_test)

script_command = ["/usr/bin/env", "python3", script,
'--log-format', '%(message)s'] + [v for v in script_args]
logging.info(f"Execute: {script_command}")
test_script_process = subprocess.Popen(
["/usr/bin/env", "python3", script, '--log-format', '%(message)s'] + [v for v in script_args], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
script_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
RedirectQueueThread(test_script_process.stdout,
b"[\33[32mTEST\33[0m][\33[33mSTDOUT\33[0m]", log_queue)
RedirectQueueThread(test_script_process.stderr,
Expand Down
6 changes: 4 additions & 2 deletions src/controller/python/test/test_scripts/mobile-device-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
ALL_TESTS = ['network_commissioning', 'datamodel']


def ethernet_commissioning(test: BaseTestHelper, discriminator, setup_pin, address_override, device_nodeid):
def ethernet_commissioning(test: BaseTestHelper, discriminator: int, setup_pin: int, address_override: str, device_nodeid: int):
logger.info("Testing discovery")
address = test.TestDiscovery(discriminator=discriminator)
FailIfNot(address, "Failed to discover any devices.")
Expand All @@ -66,9 +66,11 @@ def ethernet_commissioning(test: BaseTestHelper, discriminator, setup_pin, addre

if address_override:
address = address_override
else:
address = address.decode("utf-8")

logger.info("Testing key exchange")
FailIfNot(test.TestKeyExchange(ip=address.decode("utf-8"),
FailIfNot(test.TestKeyExchange(ip=address,
setuppin=setup_pin,
nodeid=device_nodeid),
"Failed to finish key exchange")
Expand Down
2 changes: 1 addition & 1 deletion src/test_driver/linux-cirque/MobileDeviceTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def run_controller_test(self):

command = "gdb -return-child-result -q -ex run -ex bt --args python3 {} -t 150 -a {}".format(
os.path.join(
CHIP_REPO, "src/controller/python/test/test_scripts/mobile-device-test.py", ethernet_ip))
CHIP_REPO, "src/controller/python/test/test_scripts/mobile-device-test.py"), ethernet_ip)
ret = self.execute_device_cmd(req_device_id, command)

self.assertEqual(ret['return_code'], '0',
Expand Down

0 comments on commit c120ccc

Please sign in to comment.