Skip to content

Commit c16ef0f

Browse files
Move defaults vars to its own file. (project-chip#39696)
* Moved _DEFAULTS_ to single file * Update file name * Trying new import type * Fix lint * Removed _ prefix from DEFAULT variables * Updated name from matter_global_defaults to matter_testing_defaults * isort fix * Update matter_test_config to use variables from matter_testing_defaults * Restyled by isort * Restyled by isort * Conflict typo * Fix from CI jo * Restyled by gn * Restyled by isort * Fix import path * Restyled by gn * Restyled by isort * Update file name to match new path matter/testing instead of chip * Restyled by gn --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 5f00804 commit c16ef0f

4 files changed

Lines changed: 49 additions & 26 deletions

File tree

src/python_testing/matter_testing_infrastructure/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pw_python_package("matter-testing-module") {
4646
"matter/testing/conformance.py",
4747
"matter/testing/conversions.py",
4848
"matter/testing/decorators.py",
49+
"matter/testing/defaults.py",
4950
"matter/testing/event_attribute_reporting.py",
5051
"matter/testing/global_attribute_ids.py",
5152
"matter/testing/global_stash.py",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright (c) 2025 Project CHIP Authors
3+
# All rights reserved.
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+
"""
19+
This module contains global variables that are used across several scripts and classes.
20+
"""
21+
from typing import final
22+
23+
24+
class TestingDefaults:
25+
26+
ADMIN_VENDOR_ID: final = 0xFFF1
27+
STORAGE_PATH: final = "admin_storage.json"
28+
LOG_PATH: final = "/tmp/matter_testing/logs"
29+
CONTROLLER_NODE_ID: final = 112233
30+
DUT_NODE_ID: final = 0x12344321
31+
TRUST_ROOT_INDEX: final = 1

src/python_testing/matter_testing_infrastructure/matter/testing/matter_test_config.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
from datetime import timedelta
2121
from typing import List, Optional
2222

23-
_DEFAULT_ADMIN_VENDOR_ID = 0xFFF1
24-
_DEFAULT_CONTROLLER_NODE_ID = 112233
25-
_DEFAULT_TRUST_ROOT_INDEX = 1
23+
from matter.testing.defaults import TestingDefaults
2624

2725

2826
@dataclass
@@ -33,7 +31,7 @@ class MatterTestConfig:
3331
ble_controller: Optional[int] = None
3432
commission_only: bool = False
3533

36-
admin_vendor_id: int = _DEFAULT_ADMIN_VENDOR_ID
34+
admin_vendor_id: int = TestingDefaults.ADMIN_VENDOR_ID
3735
case_admin_subject: Optional[int] = None
3836
global_test_params: dict = field(default_factory=dict)
3937
# List of explicit tests to run by name. If empty, all tests will run
@@ -68,7 +66,7 @@ class MatterTestConfig:
6866
# Node ID for basic DUT
6967
dut_node_ids: List[int] = field(default_factory=list)
7068
# Node ID to use for controller/commissioner
71-
controller_node_id: int = _DEFAULT_CONTROLLER_NODE_ID
69+
controller_node_id: int = TestingDefaults.CONTROLLER_NODE_ID
7270
# CAT Tags for default controller/commissioner
7371
# By default, we commission with CAT tags specified for RR-1.1
7472
# so the cert tests can be run without re-commissioning the device
@@ -79,7 +77,7 @@ class MatterTestConfig:
7977
fabric_id: int = 1
8078

8179
# "Alpha" by default
82-
root_of_trust_index: int = _DEFAULT_TRUST_ROOT_INDEX
80+
root_of_trust_index: int = TestingDefaults.TRUST_ROOT_INDEX
8381

8482
# If this is set, we will reuse root of trust keys at that location
8583
chip_tool_credentials_path: Optional[pathlib.Path] = None

src/python_testing/matter_testing_infrastructure/matter/testing/runner.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import matter.testing.global_stash as global_stash
4343
from matter.clusters import Attribute
4444
# Add imports for argument parsing dependencies
45+
from matter.testing.defaults import TestingDefaults
46+
# Add imports for argument parsing dependencies
4547
from matter.testing.pics import read_pics_from_file
4648

4749
try:
@@ -67,15 +69,6 @@ def StartFromString(self, destination):
6769
if TYPE_CHECKING:
6870
from matter.testing.matter_test_config import MatterTestConfig
6971

70-
_DEFAULT_LOG_PATH = "/tmp/matter_testing/logs"
71-
72-
# Default constants for argument parsing
73-
_DEFAULT_ADMIN_VENDOR_ID = 0xFFF1
74-
_DEFAULT_STORAGE_PATH = "admin_storage.json"
75-
_DEFAULT_CONTROLLER_NODE_ID = 112233
76-
_DEFAULT_DUT_NODE_ID = 0x12344321
77-
_DEFAULT_TRUST_ROOT_INDEX = 1
78-
7972

8073
def default_paa_rootstore_from_root(root_path: pathlib.Path) -> Optional[pathlib.Path]:
8174
"""Attempt to find a PAA trust store following SDK convention at `root_path`
@@ -287,7 +280,7 @@ def generate_mobly_test_config(matter_test_config):
287280
test_run_config.testbed_name = "MatterTest"
288281

289282
log_path = matter_test_config.logs_path
290-
log_path = _DEFAULT_LOG_PATH if log_path is None else log_path
283+
log_path = TestingDefaults.LOG_PATH if log_path is None else log_path
291284
if ENV_MOBLY_LOGPATH in os.environ:
292285
log_path = os.environ[ENV_MOBLY_LOGPATH]
293286

@@ -659,7 +652,7 @@ def populate_commissioning_args(args: argparse.Namespace, config) -> bool:
659652
device_descriptors = config.qr_code_content + config.manual_code + config.discriminators
660653

661654
if not config.dut_node_ids:
662-
config.dut_node_ids = [_DEFAULT_DUT_NODE_ID]
655+
config.dut_node_ids = [TestingDefaults.DUT_NODE_ID]
663656

664657
if args.commissioning_method is None:
665658
return True
@@ -733,8 +726,8 @@ def convert_args_to_matter_config(args: argparse.Namespace):
733726
if not populate_commissioning_args(args, config):
734727
sys.exit(1)
735728

736-
config.storage_path = pathlib.Path(_DEFAULT_STORAGE_PATH) if args.storage_path is None else args.storage_path
737-
config.logs_path = pathlib.Path(_DEFAULT_LOG_PATH) if args.logs_path is None else args.logs_path
729+
config.storage_path = pathlib.Path(TestingDefaults.STORAGE_PATH) if args.storage_path is None else args.storage_path
730+
config.logs_path = pathlib.Path(TestingDefaults.LOG_PATH) if args.logs_path is None else args.logs_path
738731
config.paa_trust_store_path = args.paa_trust_store_path
739732
config.ble_controller = args.ble_controller
740733
if args.PICS is None:
@@ -802,12 +795,12 @@ def parse_matter_test_args(argv: Optional[List[str]] = None):
802795
metavar="CONTROLLER_ID", help="BLE controller selector, see example or platform docs for details")
803796
basic_group.add_argument('-N', '--controller-node-id', type=int_decimal_or_hex,
804797
metavar='NODE_ID',
805-
default=_DEFAULT_CONTROLLER_NODE_ID,
806-
help='NodeID to use for initial/default controller (default: %d)' % _DEFAULT_CONTROLLER_NODE_ID)
798+
default=TestingDefaults.CONTROLLER_NODE_ID,
799+
help='NodeID to use for initial/default controller (default: %d)' % TestingDefaults.CONTROLLER_NODE_ID)
807800
basic_group.add_argument('-n', '--dut-node-id', '--nodeId', type=int_decimal_or_hex,
808801
metavar='NODE_ID', dest='dut_node_ids', default=[],
809802
help='Node ID for primary DUT communication, '
810-
'and NodeID to assign if commissioning (default: %d)' % _DEFAULT_DUT_NODE_ID, nargs="+")
803+
'and NodeID to assign if commissioning (default: %d)' % TestingDefaults.DUT_NODE_ID, nargs="+")
811804
basic_group.add_argument('--endpoint', type=int, default=None, help="Endpoint under test")
812805
basic_group.add_argument('--app-pipe', type=str, default=None, help="The full path of the app to send an out-of-band command")
813806
basic_group.add_argument('--timeout', type=int, help="Test timeout in seconds")
@@ -848,9 +841,9 @@ def parse_matter_test_args(argv: Optional[List[str]] = None):
848841
metavar='OPERATIONAL_DATASET_HEX',
849842
help='Thread operational dataset as a hex string for ble-thread commissioning')
850843

851-
commission_group.add_argument('--admin-vendor-id', action="store", type=int_decimal_or_hex, default=_DEFAULT_ADMIN_VENDOR_ID,
844+
commission_group.add_argument('--admin-vendor-id', action="store", type=int_decimal_or_hex, default=TestingDefaults.ADMIN_VENDOR_ID,
852845
metavar="VENDOR_ID",
853-
help="VendorID to use during commissioning (default 0x%04X)" % _DEFAULT_ADMIN_VENDOR_ID)
846+
help="VendorID to use during commissioning (default 0x%04X)" % TestingDefaults.ADMIN_VENDOR_ID)
854847
commission_group.add_argument('--case-admin-subject', action="store", type=int_decimal_or_hex,
855848
metavar="CASE_ADMIN_SUBJECT",
856849
help="Set the CASE admin subject to an explicit value (default to commissioner Node ID)")
@@ -876,9 +869,9 @@ def parse_matter_test_args(argv: Optional[List[str]] = None):
876869
help='Fabric ID on which to operate under the root of trust')
877870

878871
fabric_group.add_argument('-r', '--root-index', type=root_index,
879-
metavar='ROOT_INDEX_OR_NAME', default=_DEFAULT_TRUST_ROOT_INDEX,
872+
metavar='ROOT_INDEX_OR_NAME', default=TestingDefaults.TRUST_ROOT_INDEX,
880873
help='Root of trust under which to operate/commission for single-fabric basic usage. '
881-
'alpha/beta/gamma are aliases for 1/2/3. Default (%d)' % _DEFAULT_TRUST_ROOT_INDEX)
874+
'alpha/beta/gamma are aliases for 1/2/3. Default (%d)' % TestingDefaults.TRUST_ROOT_INDEX)
882875

883876
fabric_group.add_argument('-c', '--chip-tool-credentials-path', type=pathlib.Path,
884877
metavar='PATH',

0 commit comments

Comments
 (0)