Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / test_driver / linux-cirque / test-interaction-model.py
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 time
21 import sys
22
23 from helper.CHIPTestBase import CHIPVirtualHome
24
25 logger = logging.getLogger('CHIPInteractionModelTest')
26 logger.setLevel(logging.INFO)
27
28 sh = logging.StreamHandler()
29 sh.setFormatter(
30     logging.Formatter(
31         '%(asctime)s [%(name)s] %(levelname)s %(message)s'))
32 logger.addHandler(sh)
33
34 DEVICE_CONFIG = {
35     'device0': {
36         'type': 'CHIP-IM-Initiator',
37         'base_image': 'chip_im_initiator',
38         'capability': ['Thread', 'Interactive'],
39         'rcp_mode': True,
40     },
41     'device1': {
42         'type': 'CHIP-IM-Responder',
43         'base_image': 'chip_im_responder',
44         'capability': ['Thread', 'Interactive'],
45         'rcp_mode': True,
46     }
47 }
48
49 CHIP_PORT = 11097
50
51 CIRQUE_URL = "http://localhost:5000"
52
53
54 class TestInteractionModel(CHIPVirtualHome):
55     def __init__(self, device_config):
56         super().__init__(CIRQUE_URL, device_config)
57         self.logger = logger
58
59     def setup(self):
60         self.initialize_home()
61         self.connect_to_thread_network()
62
63     def test_routine(self):
64         self.run_data_model_test()
65
66     def run_data_model_test(self):
67         resp_ips = [device['description']['ipv4_addr'] for device in self.non_ap_devices
68                     if device['type'] == 'CHIP-IM-Responder']
69         req_ids = [device['id'] for device in self.non_ap_devices
70                    if device['type'] == 'CHIP-IM-Initiator']
71
72         req_device_id = req_ids[0]
73
74         command = "chip-im-initiator {}"
75
76         for ip in resp_ips:
77             ret = self.execute_device_cmd(
78                 req_device_id, command.format(ip))
79             self.assertEqual(
80                 ret['return_code'], '0', "{} failure: {}".format("IM", ret['output']))
81
82
83 if __name__ == "__main__":
84     sys.exit(TestInteractionModel(DEVICE_CONFIG).run_test())