Python script to automate chip-tool commands to perform tests.
--chip_path: Path to the CHIP repo (default:~/connectedhomeip)--otbrhex: The OTBR hex string (default: None).--discriminator: The discriminator (default: '3840').--pin: The PIN code (default: '20202021').--nodeID: The node ID (default: None).--endpointID: The endpoint ID (default: '1').--target_device_ip: The target device IP (default: '10.4.215.46').--target_device_serial_num: The target device serial number (default: None).--test_list: Comma-separated list of YAML test names to run (default: None).--use_json_list: Whether to use a JSON file for the test list (default: False).--single_run_count: The number of single fabric commissioning test runs (default: 1).--multiple_run_count: The number of multiple fabric commissioning test runs (default: 0).--test_list_run_count: The number of times to run the whole test list (default: 0).--test_plan_run_count: The number of times to run a single YAML test plan (default: 0).--toggle_test_run_count: The number of times to run the toggle test (default: 0).--toggle_sleep_time: The sleep time between toggle actions in seconds (default: 1).--factory_reset_device: Whether to factory reset the device before running tests (default: False).--commission_device: Whether to commission the device (default: False).--use_script_input_json: If set, loads all arguments fromscript_input.jsonand ignores other CLI arguments.
python3 main.pypython3 main.py --otbrhex "0e08000000000001000000030000154a0300000c35060004001fffe0020836f26e038696ff5d0708fdb3d465ff59e0860510dfe8b148f078dd4003b4b332687a0a3b030f4f70656e5468726561642d36376261010267ba041015791942db7b3b4cc82db2336d0eb0190c0402a0f7f8" --discriminator "3840" --pin "20202021" --endpointID "1" --target_device_ip "10.4.215.46" --single_run_count 2 --multiple_run_count 3You can provide all arguments in a JSON file (script_input.json) and run the script using:
python3 main.py --use_script_input_jsonor with the provided helper script:
./run_from_json.shThe script_input.json file should contain all the arguments as keys, for example:
{
"otbrhex": "...",
"discriminator": "1234",
"pin": "20202021",
"nodeID": "1",
"endpointID": "1",
"target_device_ip": "10.4.215.46",
"target_device_serial_num": "440266221",
"use_json_list": false,
"commission_device": true,
"single_run_count": 0,
"multiple_run_count": 0,
"test_list_run_count": 1,
"test_plan_run_count": 1,
"test_list": ["Test_TC_CC_3_1"],
"factory_reset_device": true
}When --use_script_input_json is set, all other CLI arguments are ignored and values from the JSON file are used.
The single fabric commissioning test loop runs the single_fabric_commissioning_test function for the specified number of times (single_run_count). This function performs the following steps:
- Commissions the device using BLE.
- Toggles the device on and off.
- Reads the on-off state.
- Unpairs the device.
If any error occurs during the test, the error is handled, and the test is terminated.
The multiple fabric commissioning test loop runs the multiple_fabric_commissioning_test function for the specified number of times (multiple_run_count). This function performs the following steps:
- Commissions the device using BLE on fabric 1.
- For each fabric predefined on chip-tool:
- Opens the commissioning window from fabric 1.
- Pairs the device with the pairing code on the new fabric using a new nodeId (here the fabric index).
- Toggles the device on and off.
- Reads the on-off state.
- For each commissioned fabric, starting by the last one:
- Unpairs the device.
If any error occurs during the test, the error is handled, and the test is terminated.
The YAML Test List Test Loop runs a set of YAML-based test scripts as specified in the test_list argument or loaded from a JSON file. This loop is controlled by the test_plan_run_count argument, which determines how many times the entire test plan is executed. For each run:
- The device is commissioned using BLE.
- For each test name in the test list, the script runs the corresponding YAML test using
chiptool.py. - Device logs are collected for each test.
- After all tests are run, the device is unpaired.
- If any error occurs during a test, error handling is performed and the loop is terminated early.
This loop is useful for running a batch of YAML-defined tests in a repeatable and automated fashion.
The toggle test loop runs the toggle_test function for the specified number of times (toggle_test_run_count). This test does not require the device to be commissioned, only to be reachable via IP. The function performs the following steps:
- Connects to the device via telnet
- Press and release the device button 1
- Wait a defined amount of time
- Repeat step 2 and 3 for the number of times specified in
toggle_test_run_count