24
24
import os
25
25
import queue
26
26
import secrets
27
- import signal
28
27
import struct
29
- import subprocess
28
+ import tempfile
30
29
import time
31
- import uuid
32
30
from dataclasses import dataclass
33
31
34
32
import chip .clusters as Clusters
37
35
from matter_testing_support import MatterBaseTest , TestStep , async_test_body , default_matter_test_main , type_matches
38
36
from mobly import asserts
39
37
from TC_SC_3_6 import AttributeChangeAccumulator
38
+ from TC_MCORE_FS_1_1 import AppServer
40
39
41
40
# Length of `w0s` and `w1s` elements
42
41
WS_LENGTH = NIST256p .baselen + 8
@@ -63,44 +62,48 @@ class TC_MCORE_FS_1_2(MatterBaseTest):
63
62
@async_test_body
64
63
async def setup_class (self ):
65
64
super ().setup_class ()
65
+
66
66
self ._partslist_subscription = None
67
- self ._app_th_server_process = None
68
- self ._th_server_kvs = None
67
+ self .th_server = None
68
+ self .storage = None
69
+
70
+ th_server_port = self .user_params .get ("th_server_port" , 5543 )
71
+ th_server_app = self .user_params .get ("th_server_app_path" , None )
72
+ if not th_server_app :
73
+ asserts .fail ('This test requires a TH_SERVER app. Specify app path with --string-arg th_server_app_path:<path_to_app>' )
74
+ if not os .path .exists (th_server_app ):
75
+ asserts .fail (f'The path { th_server_app } does not exist' )
76
+
77
+ # Create a temporary storage directory for keeping KVS files.
78
+ self .storage = tempfile .TemporaryDirectory (prefix = self .__class__ .__name__ )
79
+ logging .info ("Temporary storage directory: %s" , self .storage .name )
80
+
81
+ self .th_server_port = th_server_port
82
+ self .th_server_setup_params = _SetupParameters (
83
+ setup_qr_code = "MT:-24J0AFN00KA0648G00" ,
84
+ manual_code = 34970112332 ,
85
+ discriminator = 3840 ,
86
+ passcode = 20202021 )
87
+
88
+ # Start the TH_SERVER_NO_UID app.
89
+ self .th_server = AppServer (
90
+ th_server_app ,
91
+ storage_dir = self .storage .name ,
92
+ port = self .th_server_port ,
93
+ discriminator = self .th_server_setup_params .discriminator ,
94
+ passcode = self .th_server_setup_params .passcode )
95
+ self .th_server .start ()
69
96
70
97
def teardown_class (self ):
71
98
if self ._partslist_subscription is not None :
72
99
self ._partslist_subscription .Shutdown ()
73
100
self ._partslist_subscription = None
74
-
75
- if self ._app_th_server_process is not None :
76
- logging .warning ("Stopping app with SIGTERM" )
77
- self ._app_th_server_process .send_signal (signal .SIGTERM .value )
78
- self ._app_th_server_process .wait ()
79
-
80
- if self ._th_server_kvs is not None :
81
- os .remove (self ._th_server_kvs )
101
+ if self .th_server is not None :
102
+ self .th_server .terminate ()
103
+ if self .storage is not None :
104
+ self .storage .cleanup ()
82
105
super ().teardown_class ()
83
106
84
- async def _create_th_server (self , port ):
85
- # These are default testing values
86
- setup_params = _SetupParameters (setup_qr_code = "MT:-24J0AFN00KA0648G00" ,
87
- manual_code = 34970112332 , discriminator = 3840 , passcode = 20202021 )
88
- kvs = f'kvs_{ str (uuid .uuid4 ())} '
89
-
90
- cmd = [self ._th_server_app_path ]
91
- cmd .extend (['--secured-device-port' , str (port )])
92
- cmd .extend (['--discriminator' , str (setup_params .discriminator )])
93
- cmd .extend (['--passcode' , str (setup_params .passcode )])
94
- cmd .extend (['--KVS' , kvs ])
95
-
96
- # TODO: Determine if we want these logs cooked or pushed to somewhere else
97
- logging .info ("Starting TH_SERVER" )
98
- self ._app_th_server_process = subprocess .Popen (cmd )
99
- self ._th_server_kvs = kvs
100
- logging .info ("Started TH_SERVER" )
101
- time .sleep (3 )
102
- return setup_params
103
-
104
107
def _ask_for_vendor_commissioning_ux_operation (self , setup_params : _SetupParameters ):
105
108
self .wait_for_user_input (
106
109
prompt_msg = f"Using the DUT vendor's provided interface, commission the ICD device using the following parameters:\n "
@@ -115,7 +118,6 @@ def steps_TC_MCORE_FS_1_2(self) -> list[TestStep]:
115
118
steps = [TestStep (1 , "TH subscribes to PartsList attribute of the Descriptor cluster of DUT_FSA endpoint 0." ),
116
119
TestStep (2 , "Follow manufacturer provided instructions to have DUT_FSA commission TH_SERVER" ),
117
120
TestStep (3 , "TH waits up to 30 seconds for subscription report from the PartsList attribute of the Descriptor to contain new endpoint" ),
118
-
119
121
TestStep (4 , "TH uses DUT to open commissioning window to TH_SERVER" ),
120
122
TestStep (5 , "TH commissions TH_SERVER" ),
121
123
TestStep (6 , "TH reads all attributes in Basic Information cluster from TH_SERVER directly" ),
@@ -134,12 +136,6 @@ async def test_TC_MCORE_FS_1_2(self):
134
136
135
137
min_report_interval_sec = self .user_params .get ("min_report_interval_sec" , 0 )
136
138
max_report_interval_sec = self .user_params .get ("max_report_interval_sec" , 30 )
137
- th_server_port = self .user_params .get ("th_server_port" , 5543 )
138
- self ._th_server_app_path = self .user_params .get ("th_server_app_path" , None )
139
- if not self ._th_server_app_path :
140
- asserts .fail ('This test requires a TH_SERVER app. Specify app path with --string-arg th_server_app_path:<path_to_app>' )
141
- if not os .path .exists (self ._th_server_app_path ):
142
- asserts .fail (f'The path { self ._th_server_app_path } does not exist' )
143
139
144
140
self .step (1 )
145
141
# Subscribe to the PartsList
@@ -164,8 +160,7 @@ async def test_TC_MCORE_FS_1_2(self):
164
160
asserts .assert_true (type_matches (step_1_dut_parts_list , list ), "PartsList is expected to be a list" )
165
161
166
162
self .step (2 )
167
- setup_params = await self ._create_th_server (th_server_port )
168
- self ._ask_for_vendor_commissioning_ux_operation (setup_params )
163
+ self ._ask_for_vendor_commissioning_ux_operation (self .th_server_setup_params )
169
164
170
165
self .step (3 )
171
166
report_waiting_timeout_delay_sec = 30
0 commit comments