31
31
TV_APP_MAX_START_WAIT_SEC = 2
32
32
33
33
# The maximum amount of time to commission the Linux tv-casting-app and the tv-app before timeout.
34
- COMMISSIONING_STAGE_MAX_WAIT_SEC = 3
34
+ COMMISSIONING_STAGE_MAX_WAIT_SEC = 10
35
35
36
36
# File names of logs for the Linux tv-casting-app and the Linux tv-app.
37
37
LINUX_TV_APP_LOGS = 'Linux-tv-app-logs.txt'
@@ -75,7 +75,7 @@ def dump_temporary_logs_to_console(log_file_path: str):
75
75
print (line .rstrip ())
76
76
77
77
78
- def handle_casting_state_failure (casting_state : str , log_file_paths : List [str ]):
78
+ def handle_casting_failure (casting_state : str , log_file_paths : List [str ]):
79
79
"""Log '{casting_state} failed!' as error, dump log files to console, exit on error."""
80
80
logging .error (casting_state + ' failed!' )
81
81
@@ -88,10 +88,10 @@ def handle_casting_state_failure(casting_state: str, log_file_paths: List[str]):
88
88
sys .exit (1 )
89
89
90
90
91
- def extract_value_from_string (line : str ) -> Union [ int , str ] :
92
- """Extract and return either an integer or substring from given input string.
91
+ def extract_value_from_string (line : str ) -> str :
92
+ """Extract and return value from given input string.
93
93
94
- The input string is expected to be in the following format as it is received
94
+ The string is expected to be in the following format as it is received
95
95
from the Linux tv-casting-app output:
96
96
\x1b [0;34m[1713741926895] [7276:9521344] [DIS] Vendor ID: 65521\x1b [0m
97
97
The integer value to be extracted here is 65521.
@@ -101,22 +101,21 @@ def extract_value_from_string(line: str) -> Union[int, str]:
101
101
"""
102
102
value = line .split (':' )[- 1 ].strip ().replace ('\x1b [0m' , '' )
103
103
104
- try :
105
- value = int (value )
106
- return value
107
- except ValueError :
108
- return value
104
+ return value
109
105
110
106
111
- def validate_value (casting_state : str , expected_value : int , log_paths : List [str ], line : str , value_name : str ) -> Optional [str ]:
107
+ def validate_value (casting_state : str , expected_value : Union [ str , int ] , log_paths : List [str ], line : str , value_name : str ) -> Optional [str ]:
112
108
"""Validate a value in a string against an expected value during a given casting state."""
113
109
value = extract_value_from_string (line )
114
110
111
+ if isinstance (expected_value , int ):
112
+ value = int (value )
113
+
115
114
if value != expected_value :
116
115
logging .error (f'{ value_name } does not match the expected value!' )
117
116
logging .error (f'Expected { value_name } : { expected_value } ' )
118
117
logging .error (line .rstrip ('\n ' ))
119
- handle_casting_state_failure (casting_state , log_paths )
118
+ handle_casting_failure (casting_state , log_paths )
120
119
121
120
# Return the line containing the valid value.
122
121
return line .rstrip ('\n ' )
@@ -153,7 +152,7 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
153
152
# Check if we exceeded the maximum wait time for initiating 'cast request' from the Linux tv-casting-app to the Linux tv-app.
154
153
if time .time () - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC :
155
154
logging .error ('The command `cast request ' + valid_discovered_commissioner_number +
156
- '` was not sent to the Linux tv-casting-app process within the timeout.' )
155
+ '` was not issued to the Linux tv-casting-app process within the timeout.' )
157
156
return False
158
157
159
158
tv_casting_app_output_line = tv_casting_app_process .stdout .readline ()
@@ -172,7 +171,7 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
172
171
return True
173
172
174
173
175
- def extract_device_info (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ]) -> Tuple [Optional [str ], Optional [str ], Optional [str ]]:
174
+ def extract_device_info_from_tv_casting_app (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ]) -> Tuple [Optional [str ], Optional [int ], Optional [int ]]:
176
175
"""Extract device information from the 'Identification Declaration' block in the Linux tv-casting-app output."""
177
176
tv_casting_app_process , linux_tv_casting_app_log_file = tv_casting_app_info
178
177
@@ -188,16 +187,18 @@ def extract_device_info(tv_casting_app_info: Tuple[subprocess.Popen, TextIO]) ->
188
187
device_name = extract_value_from_string (line )
189
188
elif 'vendor id' in line :
190
189
vendor_id = extract_value_from_string (line )
190
+ vendor_id = int (vendor_id )
191
191
elif 'product id' in line :
192
192
product_id = extract_value_from_string (line )
193
+ product_id = int (product_id )
193
194
194
195
if device_name and vendor_id and product_id :
195
196
break
196
197
197
198
return device_name , vendor_id , product_id
198
199
199
200
200
- def validate_tv_app_device_info (tv_app_info , device_name , vendor_id , product_id , log_paths ) -> bool :
201
+ def validate_identification_declaration_message_on_tv_app (tv_app_info : Tuple [ subprocess . Popen , TextIO ], expected_device_name : str , expected_vendor_id : int , expected_product_id : int , log_paths : List [ str ] ) -> bool :
201
202
"""Validate device information from the 'Identification Declaration' block from the Linux tv-app output against the expected values."""
202
203
tv_app_process , linux_tv_app_log_file = tv_app_info
203
204
@@ -223,18 +224,18 @@ def validate_tv_app_device_info(tv_app_info, device_name, vendor_id, product_id,
223
224
elif parsing_identification_block :
224
225
logging .info (tv_app_line .rstrip ('\n ' ))
225
226
if 'device Name' in tv_app_line :
226
- validate_value ('Commissioning' , device_name , log_paths , tv_app_line , 'device Name' )
227
+ validate_value ('Commissioning' , expected_device_name , log_paths , tv_app_line , 'device Name' )
227
228
elif 'vendor id' in tv_app_line :
228
- validate_value ('Commissioning' , vendor_id , log_paths , tv_app_line , 'vendor id' )
229
+ validate_value ('Commissioning' , expected_vendor_id , log_paths , tv_app_line , 'vendor id' )
229
230
elif 'product id' in tv_app_line :
230
- validate_value ('Commissioning' , product_id , log_paths , tv_app_line , 'product id' )
231
+ validate_value ('Commissioning' , expected_product_id , log_paths , tv_app_line , 'product id' )
231
232
elif 'Identification Declaration End' in tv_app_line :
232
233
parsing_identification_block = False
233
234
return True
234
235
235
236
236
- def approve_tv_casting_request (tv_app_info : Tuple [subprocess .Popen , TextIO ], log_paths : List [str ]) -> bool :
237
- """Approve the TV casting request from the Linux tv-casting-app to the Linux tv-app by sending `controller ux ok` via Linux tv-app process."""
237
+ def validate_tv_casting_request_approval (tv_app_info : Tuple [subprocess .Popen , TextIO ], log_paths : List [str ]) -> bool :
238
+ """Validate that the TV casting request from the Linux tv-casting-app to the Linux tv-app is approved by sending `controller ux ok` via Linux tv-app process."""
238
239
tv_app_process , linux_tv_app_log_file = tv_app_info
239
240
240
241
start_wait_time = time .time ()
@@ -323,7 +324,7 @@ def test_discovery_fn(tv_casting_app_info: Tuple[subprocess.Popen, TextIO], log_
323
324
# Fail fast if "No commissioner discovered" string found.
324
325
if "No commissioner discovered" in line :
325
326
logging .error (line .rstrip ('\n ' ))
326
- handle_casting_state_failure ('Discovery' , log_paths )
327
+ handle_casting_failure ('Discovery' , log_paths )
327
328
328
329
elif "Discovered Commissioner" in line :
329
330
valid_discovered_commissioner = line .rstrip ('\n ' )
@@ -356,19 +357,19 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
356
357
"""Test commissioning between Linux tv-casting-app and Linux tv-app."""
357
358
358
359
if not initiate_cast_request_success (tv_casting_app_info , valid_discovered_commissioner_number ):
359
- handle_casting_state_failure ('Commissioning' , log_paths )
360
+ handle_casting_failure ('Commissioning' , log_paths )
360
361
361
362
# Extract the values from the 'Identification Declaration' block in the tv-casting-app output that we want to validate against.
362
- device_name , vendor_id , product_id = extract_device_info (tv_casting_app_info )
363
+ expected_device_name , expected_vendor_id , expected_product_id = extract_device_info_from_tv_casting_app (tv_casting_app_info )
363
364
364
- if not validate_tv_app_device_info (tv_app_info , device_name , vendor_id , product_id , log_paths ):
365
- handle_casting_state_failure ('Commissioning' , log_paths )
365
+ if not validate_identification_declaration_message_on_tv_app (tv_app_info , expected_device_name , expected_vendor_id , expected_product_id , log_paths ):
366
+ handle_casting_failure ('Commissioning' , log_paths )
366
367
367
- if not approve_tv_casting_request (tv_app_info , log_paths ):
368
- handle_casting_state_failure ('Commissioning' , log_paths )
368
+ if not validate_tv_casting_request_approval (tv_app_info , log_paths ):
369
+ handle_casting_failure ('Commissioning' , log_paths )
369
370
370
371
if not validate_commissioning_success (tv_casting_app_info , tv_app_info , log_paths ):
371
- handle_casting_state_failure ('Commissioning' , log_paths )
372
+ handle_casting_failure ('Commissioning' , log_paths )
372
373
373
374
374
375
@click .command ()
@@ -399,7 +400,7 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
399
400
with ProcessManager (disable_stdout_buffering_cmd + [tv_app_abs_path ], stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE ) as tv_app_process :
400
401
401
402
if not start_up_tv_app_success (tv_app_process , linux_tv_app_log_file ):
402
- handle_casting_state_failure ('Discovery' , [linux_tv_app_log_path ])
403
+ handle_casting_failure ('Discovery' , [linux_tv_app_log_path ])
403
404
404
405
tv_casting_app_abs_path = os .path .abspath (tv_casting_app_rel_path )
405
406
# Run the Linux tv-casting-app subprocess.
@@ -410,7 +411,7 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
410
411
valid_discovered_commissioner = test_discovery_fn (tv_casting_app_info , log_paths )
411
412
412
413
if not valid_discovered_commissioner :
413
- handle_casting_state_failure ('Discovery' , log_paths )
414
+ handle_casting_failure ('Discovery' , log_paths )
414
415
415
416
# We need the valid discovered commissioner number to continue with commissioning.
416
417
# Example string: \x1b[0;32m[1714582264602] [77989:2286038] [SVR] Discovered Commissioner #0\x1b[0m
0 commit comments