|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Copyright (c) 2021 Project CHIP Authors |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +""" |
| 17 | + |
| 18 | +import logging |
| 19 | +import os |
| 20 | +import sys |
| 21 | + |
| 22 | +from helper.CHIPTestBase import CHIPVirtualHome |
| 23 | + |
| 24 | +logger = logging.getLogger('MobileDeviceTest') |
| 25 | +logger.setLevel(logging.INFO) |
| 26 | + |
| 27 | +sh = logging.StreamHandler() |
| 28 | +sh.setFormatter( |
| 29 | + logging.Formatter( |
| 30 | + '%(asctime)s [%(name)s] %(levelname)s %(message)s')) |
| 31 | +logger.addHandler(sh) |
| 32 | + |
| 33 | +CHIP_PORT = 5540 |
| 34 | + |
| 35 | +CIRQUE_URL = "http://localhost:5000" |
| 36 | +CHIP_REPO = os.path.join(os.path.abspath( |
| 37 | + os.path.dirname(__file__)), "..", "..", "..") |
| 38 | +TEST_EXTPANID = "fedcba9876543210" |
| 39 | +TEST_DISCRIMINATOR = 3840 |
| 40 | +TEST_DISCRIMINATOR2 = 3584 |
| 41 | +TEST_DISCRIMINATOR3 = 1203 |
| 42 | +TEST_DISCRIMINATOR4 = 2145 |
| 43 | +TEST_DISCOVERY_TYPE = [0, 1, 2] |
| 44 | +MATTER_DEVELOPMENT_PAA_ROOT_CERTS = "credentials/development/paa-root-certs" |
| 45 | + |
| 46 | +DEVICE_CONFIG = { |
| 47 | + 'device0': { |
| 48 | + 'type': 'MobileDevice', |
| 49 | + 'base_image': '@default', |
| 50 | + 'capability': ['TrafficControl', 'Mount'], |
| 51 | + 'rcp_mode': True, |
| 52 | + 'docker_network': 'Ipv6', |
| 53 | + 'traffic_control': {'latencyMs': 25}, |
| 54 | + "mount_pairs": [[CHIP_REPO, CHIP_REPO]], |
| 55 | + }, |
| 56 | + 'device1': { |
| 57 | + 'type': 'CHIPEndDevice', |
| 58 | + 'base_image': '@default', |
| 59 | + 'capability': ['Thread', 'TrafficControl', 'Mount'], |
| 60 | + 'rcp_mode': True, |
| 61 | + 'docker_network': 'Ipv6', |
| 62 | + 'traffic_control': {'latencyMs': 25}, |
| 63 | + "mount_pairs": [[CHIP_REPO, CHIP_REPO]], |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +class TestCommissioner(CHIPVirtualHome): |
| 69 | + def __init__(self, device_config): |
| 70 | + super().__init__(CIRQUE_URL, device_config) |
| 71 | + self.logger = logger |
| 72 | + |
| 73 | + def setup(self): |
| 74 | + self.initialize_home() |
| 75 | + |
| 76 | + def test_routine(self): |
| 77 | + self.run_controller_test() |
| 78 | + |
| 79 | + def run_controller_test(self): |
| 80 | + ethernet_ip = [device['description']['ipv6_addr'] for device in self.non_ap_devices |
| 81 | + if device['type'] == 'CHIPEndDevice'][0] |
| 82 | + server_ids = [device['id'] for device in self.non_ap_devices |
| 83 | + if device['type'] == 'CHIPEndDevice'] |
| 84 | + req_ids = [device['id'] for device in self.non_ap_devices |
| 85 | + if device['type'] == 'MobileDevice'] |
| 86 | + |
| 87 | + for server in server_ids: |
| 88 | + self.execute_device_cmd( |
| 89 | + server, |
| 90 | + ("CHIPCirqueDaemon.py -- run gdb -batch -return-child-result -q -ex \"set pagination off\" " |
| 91 | + "-ex run -ex \"thread apply all bt\" --args {} --thread --discriminator {}").format( |
| 92 | + os.path.join(CHIP_REPO, "out/debug/lit_icd/lit-icd-app"), TEST_DISCRIMINATOR)) |
| 93 | + |
| 94 | + self.reset_thread_devices(server_ids) |
| 95 | + |
| 96 | + req_device_id = req_ids[0] |
| 97 | + |
| 98 | + self.execute_device_cmd(req_device_id, "pip3 install --break-system-packages {}".format(os.path.join( |
| 99 | + CHIP_REPO, "out/debug/linux_x64_gcc/controller/python/chip_clusters-0.0-py3-none-any.whl"))) |
| 100 | + self.execute_device_cmd(req_device_id, "pip3 install --break-system-packages {}".format(os.path.join( |
| 101 | + CHIP_REPO, "out/debug/linux_x64_gcc/controller/python/chip_core-0.0-cp37-abi3-linux_x86_64.whl"))) |
| 102 | + self.execute_device_cmd(req_device_id, "pip3 install --break-system-packages {}".format(os.path.join( |
| 103 | + CHIP_REPO, "out/debug/linux_x64_gcc/controller/python/chip_repl-0.0-py3-none-any.whl"))) |
| 104 | + |
| 105 | + command = ("gdb -batch -return-child-result -q -ex run -ex \"thread apply all bt\" " |
| 106 | + "--args python3 {} -t 300 -a {} --paa-trust-store-path {}").format( |
| 107 | + os.path.join( |
| 108 | + CHIP_REPO, "src/controller/python/test/test_scripts/icd_wait_for_device_test.py"), ethernet_ip, |
| 109 | + os.path.join(CHIP_REPO, MATTER_DEVELOPMENT_PAA_ROOT_CERTS)) |
| 110 | + ret = self.execute_device_cmd(req_device_id, command) |
| 111 | + |
| 112 | + self.assertEqual(ret['return_code'], '0', |
| 113 | + "Test failed: non-zero return code") |
| 114 | + |
| 115 | + |
| 116 | +if __name__ == "__main__": |
| 117 | + sys.exit(TestCommissioner(DEVICE_CONFIG).run_test()) |
0 commit comments