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 = 10
34
+ COMMISSIONING_STAGE_MAX_WAIT_SEC = 15
35
35
36
36
# The maximum amount of time to test that the launchURL is sent from the Linux tv-casting-app and received on the tv-app before timeout.
37
37
TEST_LAUNCHURL_MAX_WAIT_SEC = 10
@@ -98,31 +98,42 @@ def handle_casting_failure(casting_state: str, log_file_paths: List[str]):
98
98
sys .exit (1 )
99
99
100
100
101
- def extract_value_from_string (line : str ) -> str :
101
+ def extract_value_from_string (line : str , value_name : str , casting_state : str , log_paths ) -> str :
102
102
"""Extract and return value from given input string.
103
103
104
104
The string is expected to be in the following format as it is received
105
105
from the Linux tv-casting-app output:
106
106
\x1b [0;34m[1715206773402] [20056:2842184] [DMG] Cluster = 0x506,\x1b [0m
107
107
The substring to be extracted here is '0x506'.
108
108
Or:
109
+ \x1b [0;32m[1714582264602] [77989:2286038] [SVR] Discovered Commissioner #0\x1b [0m
110
+ The integer value to be extracted here is '0'.
111
+ Or:
109
112
\x1b [0;34m[1713741926895] [7276:9521344] [DIS] Vendor ID: 65521\x1b [0m
110
- The integer value to be extracted here is 65521.
113
+ The integer value to be extracted here is ' 65521' .
111
114
Or:
112
115
\x1b [0;34m[1714583616179] [7029:2386956] [SVR] device Name: Test TV casting app\x1b [0m
113
116
The substring to be extracted here is 'Test TV casting app'.
114
117
"""
115
- if '=' in line :
116
- value = line .split ('=' )[- 1 ].strip ().replace (',\x1b [0m' , '' )
118
+ if ':' in line :
119
+ if '=' in line :
120
+ delimiter = '='
121
+ elif '#' in line :
122
+ delimiter = '#'
123
+ else :
124
+ delimiter = ':'
125
+
126
+ value = line .split (delimiter )[- 1 ].strip ().replace ('\x1b [0m' , '' ).rstrip (',' )
117
127
else :
118
- value = line .split (':' )[- 1 ].strip ().replace ('\x1b [0m' , '' )
128
+ logging .error (f'Could not extract { value_name } from the following line: { line } ' )
129
+ handle_casting_failure (casting_state , log_paths )
119
130
120
131
return value
121
132
122
133
123
134
def validate_value (casting_state : str , expected_value : Union [str , int ], log_paths : List [str ], line : str , value_name : str ) -> Optional [str ]:
124
135
"""Validate a value in a string against an expected value during a given casting state."""
125
- value = extract_value_from_string (line )
136
+ value = extract_value_from_string (line , value_name , casting_state , log_paths )
126
137
127
138
if isinstance (expected_value , int ):
128
139
value = int (value )
@@ -187,7 +198,7 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
187
198
return True
188
199
189
200
190
- def extract_device_info_from_tv_casting_app (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ]) -> Tuple [Optional [str ], Optional [int ], Optional [int ]]:
201
+ def extract_device_info_from_tv_casting_app (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ], casting_state : str , log_paths : List [ str ] ) -> Tuple [Optional [str ], Optional [int ], Optional [int ]]:
191
202
"""Extract device information from the 'Identification Declaration' block in the Linux tv-casting-app output."""
192
203
tv_casting_app_process , linux_tv_casting_app_log_file = tv_casting_app_info
193
204
@@ -200,12 +211,12 @@ def extract_device_info_from_tv_casting_app(tv_casting_app_info: Tuple[subproces
200
211
linux_tv_casting_app_log_file .flush ()
201
212
202
213
if 'device Name' in line :
203
- device_name = extract_value_from_string (line )
214
+ device_name = extract_value_from_string (line , 'device Name' , casting_state , log_paths )
204
215
elif 'vendor id' in line :
205
- vendor_id = extract_value_from_string (line )
216
+ vendor_id = extract_value_from_string (line , 'vendor id' , casting_state , log_paths )
206
217
vendor_id = int (vendor_id )
207
218
elif 'product id' in line :
208
- product_id = extract_value_from_string (line )
219
+ product_id = extract_value_from_string (line , 'product id' , casting_state , log_paths )
209
220
product_id = int (product_id )
210
221
211
222
if device_name and vendor_id and product_id :
@@ -337,7 +348,7 @@ def parse_tv_casting_app_for_report_data_msg(tv_casting_app_info: Tuple[subproce
337
348
# Check if we exceeded the maximum wait time to parse the Linux tv-casting-app output for `ReportDataMessage` block.
338
349
if time .time () - start_wait_time > VERIFY_SUBSCRIPTION_STATE_MAX_WAIT_SEC :
339
350
logging .error (
340
- 'The relevant `ReportDataMessage` block was not found in the Linux tv-casting-app process within the timeout.' )
351
+ 'The relevant `ReportDataMessage` block for the MediaPlayback:CurrentState subscription was not found in the Linux tv-casting-app process within the timeout.' )
341
352
report_data_message .clear ()
342
353
return report_data_message
343
354
@@ -354,13 +365,14 @@ def parse_tv_casting_app_for_report_data_msg(tv_casting_app_info: Tuple[subproce
354
365
report_data_message .append (tv_casting_line .rstrip ('\n ' ))
355
366
356
367
if 'Cluster =' in tv_casting_line :
357
- cluster_value = extract_value_from_string (tv_casting_line )
368
+ cluster_value = extract_value_from_string (tv_casting_line , 'Cluster value' , 'Testing subscription' , log_paths )
358
369
if cluster_value != CLUSTER_MEDIA_PLAYBACK :
359
370
report_data_message .clear ()
360
371
continue_parsing = False
361
372
362
373
elif 'Attribute =' in tv_casting_line :
363
- attribute_value = extract_value_from_string (tv_casting_line )
374
+ attribute_value = extract_value_from_string (
375
+ tv_casting_line , 'Attribute value' , 'Testing subscription' , log_paths )
364
376
if attribute_value != ATTRIBUTE_CURRENT_PLAYBACK_STATE :
365
377
report_data_message .clear ()
366
378
continue_parsing = False
@@ -459,11 +471,11 @@ def test_discovery_fn(tv_casting_app_info: Tuple[subprocess.Popen, TextIO], log_
459
471
linux_tv_casting_app_log_file .flush ()
460
472
461
473
# Fail fast if "No commissioner discovered" string found.
462
- if " No commissioner discovered" in line :
474
+ if ' No commissioner discovered' in line :
463
475
logging .error (line .rstrip ('\n ' ))
464
476
handle_casting_failure ('Discovery' , log_paths )
465
477
466
- elif " Discovered Commissioner" in line :
478
+ elif ' Discovered Commissioner' in line :
467
479
valid_discovered_commissioner = line .rstrip ('\n ' )
468
480
469
481
elif valid_discovered_commissioner :
@@ -497,7 +509,8 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
497
509
handle_casting_failure ('Commissioning' , log_paths )
498
510
499
511
# Extract the values from the 'Identification Declaration' block in the tv-casting-app output that we want to validate against.
500
- expected_device_name , expected_vendor_id , expected_product_id = extract_device_info_from_tv_casting_app (tv_casting_app_info )
512
+ expected_device_name , expected_vendor_id , expected_product_id = extract_device_info_from_tv_casting_app (
513
+ tv_casting_app_info , 'Commissioning' , log_paths )
501
514
502
515
if not validate_identification_declaration_message_on_tv_app (tv_app_info , expected_device_name , expected_vendor_id , expected_product_id , log_paths ):
503
516
handle_casting_failure ('Commissioning' , log_paths )
@@ -580,9 +593,8 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
580
593
handle_casting_failure ('Discovery' , log_paths )
581
594
582
595
# We need the valid discovered commissioner number to continue with commissioning.
583
- # Example string: \x1b[0;32m[1714582264602] [77989:2286038] [SVR] Discovered Commissioner #0\x1b[0m
584
- # The value '0' will be extracted from the string.
585
- valid_discovered_commissioner_number = valid_discovered_commissioner .split ('#' )[- 1 ].replace ('\x1b [0m' , '' )
596
+ valid_discovered_commissioner_number = extract_value_from_string (
597
+ valid_discovered_commissioner , 'Discovered Commissioner number' , 'Commissioning' , log_paths )
586
598
587
599
test_commissioning_fn (valid_discovered_commissioner_number , tv_casting_app_info , tv_app_info , log_paths )
588
600
test_subscription_fn (tv_casting_app_info , log_paths )
0 commit comments