|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# |
| 4 | +# Copyright (c) 2024 Project CHIP Authors |
| 5 | +# All rights reserved. |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | + |
| 20 | +# Commissioning test. |
| 21 | + |
| 22 | +import os |
| 23 | +import sys |
| 24 | +from optparse import OptionParser |
| 25 | + |
| 26 | +from base import BaseTestHelper, FailIfNot, TestFail, TestTimeout, logger |
| 27 | + |
| 28 | +TEST_DISCRIMINATOR = 3840 |
| 29 | +TEST_SETUPPIN = 20202021 |
| 30 | + |
| 31 | +TEST_ENDPOINT_ID = 0 |
| 32 | + |
| 33 | + |
| 34 | +def main(): |
| 35 | + optParser = OptionParser() |
| 36 | + optParser.add_option( |
| 37 | + "-t", |
| 38 | + "--timeout", |
| 39 | + action="store", |
| 40 | + dest="testTimeout", |
| 41 | + default=90, |
| 42 | + type='int', |
| 43 | + help="The program will return with timeout after specified seconds.", |
| 44 | + metavar="<timeout-second>", |
| 45 | + ) |
| 46 | + optParser.add_option( |
| 47 | + "-a", |
| 48 | + "--address", |
| 49 | + action="store", |
| 50 | + dest="deviceAddress", |
| 51 | + default='', |
| 52 | + type='str', |
| 53 | + help="Address of the device", |
| 54 | + metavar="<device-addr>", |
| 55 | + ) |
| 56 | + optParser.add_option( |
| 57 | + "--nodeid", |
| 58 | + action="store", |
| 59 | + dest="nodeid", |
| 60 | + default=1, |
| 61 | + type=int, |
| 62 | + help="The Node ID issued to the device", |
| 63 | + metavar="<nodeid>" |
| 64 | + ) |
| 65 | + optParser.add_option( |
| 66 | + "--discriminator", |
| 67 | + action="store", |
| 68 | + dest="discriminator", |
| 69 | + default=TEST_DISCRIMINATOR, |
| 70 | + type=int, |
| 71 | + help="Discriminator of the device", |
| 72 | + metavar="<nodeid>" |
| 73 | + ) |
| 74 | + optParser.add_option( |
| 75 | + "--setuppin", |
| 76 | + action="store", |
| 77 | + dest="setuppin", |
| 78 | + default=TEST_SETUPPIN, |
| 79 | + type=int, |
| 80 | + help="Setup PIN of the device", |
| 81 | + metavar="<nodeid>" |
| 82 | + ) |
| 83 | + optParser.add_option( |
| 84 | + "-p", |
| 85 | + "--paa-trust-store-path", |
| 86 | + action="store", |
| 87 | + dest="paaTrustStorePath", |
| 88 | + default='', |
| 89 | + type='str', |
| 90 | + help="Path that contains valid and trusted PAA Root Certificates.", |
| 91 | + metavar="<paa-trust-store-path>" |
| 92 | + ) |
| 93 | + |
| 94 | + (options, remainingArgs) = optParser.parse_args(sys.argv[1:]) |
| 95 | + |
| 96 | + timeoutTicker = TestTimeout(options.testTimeout) |
| 97 | + timeoutTicker.start() |
| 98 | + |
| 99 | + test = BaseTestHelper( |
| 100 | + nodeid=112233, paaTrustStorePath=options.paaTrustStorePath, testCommissioner=True) |
| 101 | + |
| 102 | + FailIfNot( |
| 103 | + test.TestOnNetworkCommissioning(options.discriminator, options.setuppin, options.nodeid, options.deviceAddress), |
| 104 | + "Failed on on-network commissioing") |
| 105 | + try: |
| 106 | + test.devCtrl.ZCLSubscribeAttribute("BasicInformation", "NodeLabel", options.nodeid, TEST_ENDPOINT_ID, 1, 2, |
| 107 | + keepSubscriptions=True, autoResubscribe=False) |
| 108 | + except Exception as ex: |
| 109 | + TestFail(f"Failed to subscribe attribute: {ex}") |
| 110 | + |
| 111 | + timeoutTicker.stop() |
| 112 | + |
| 113 | + logger.info("Test finished") |
| 114 | + |
| 115 | + # TODO: Python device controller cannot be shutdown clean sometimes and will block on AsyncDNSResolverSockets shutdown. |
| 116 | + # Call os._exit(0) to force close it. |
| 117 | + os._exit(0) |
| 118 | + |
| 119 | + |
| 120 | +if __name__ == "__main__": |
| 121 | + try: |
| 122 | + main() |
| 123 | + except Exception as ex: |
| 124 | + logger.exception(ex) |
| 125 | + TestFail("Exception occurred when running tests.") |
0 commit comments