14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
+ import pdb # SHAO remove when done testing!
17
18
import logging
18
19
import os
19
20
import subprocess
31
32
TV_APP_MAX_START_WAIT_SEC = 2
32
33
33
34
# 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
35
+ COMMISSIONING_STAGE_MAX_WAIT_SEC = 15
35
36
36
37
# 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
38
TEST_LAUNCHURL_MAX_WAIT_SEC = 10
38
39
39
40
# The maximum amount of time to verify the subscription state in the Linux tv-casting-app output before timeout.
40
41
VERIFY_SUBSCRIPTION_STATE_MAX_WAIT_SEC = 10
41
42
43
+ # Start the clock for this function
44
+ # START_TIME = 0 # SHAO remove when done testing!
45
+ START_TIME = time .time ()
46
+
42
47
# File names of logs for the Linux tv-casting-app and the Linux tv-app.
43
48
LINUX_TV_APP_LOGS = 'Linux-tv-app-logs.txt'
44
49
LINUX_TV_CASTING_APP_LOGS = 'Linux-tv-casting-app-logs.txt'
@@ -88,6 +93,8 @@ def dump_temporary_logs_to_console(log_file_path: str):
88
93
def handle_casting_failure (casting_state : str , log_file_paths : List [str ]):
89
94
"""Log '{casting_state} failed!' as error, dump log files to console, exit on error."""
90
95
logging .error (casting_state + ' failed!' )
96
+ pdb .set_trace ()
97
+ print ('SHAO remove when done testing!!!' )
91
98
92
99
for log_file_path in log_file_paths :
93
100
try :
@@ -99,45 +106,53 @@ def handle_casting_failure(casting_state: str, log_file_paths: List[str]):
99
106
100
107
101
108
# def extract_value_from_string(line: str) -> str: # SHAO OG
102
- def extract_value_from_string (line : str , casting_state : str , log_paths ) -> str :
109
+ def extract_value_from_string (line : str , value_name : str , casting_state : str , log_paths ) -> str :
103
110
"""Extract and return value from given input string.
104
111
105
112
The string is expected to be in the following format as it is received
106
113
from the Linux tv-casting-app output:
107
114
\x1b [0;34m[1715206773402] [20056:2842184] [DMG] Cluster = 0x506,\x1b [0m
108
115
The substring to be extracted here is '0x506'.
109
116
Or:
117
+ \x1b [0;32m[1714582264602] [77989:2286038] [SVR] Discovered Commissioner #0\x1b [0m
118
+ The value '0' will be extracted from the string.
119
+ Or:
110
120
\x1b [0;34m[1713741926895] [7276:9521344] [DIS] Vendor ID: 65521\x1b [0m
111
121
The integer value to be extracted here is 65521.
112
122
Or:
113
123
\x1b [0;34m[1714583616179] [7029:2386956] [SVR] device Name: Test TV casting app\x1b [0m
114
124
The substring to be extracted here is 'Test TV casting app'.
115
125
"""
116
- # if '=' in line:
117
- # value = line.split('=')[-1].strip().replace(',\x1b[0m', '')
118
- # else:
119
- # value = line.split(':')[-1].strip().replace('\x1b[0m', '')
126
+ if '=' in line :
127
+ value = line .split ('=' )[- 1 ].strip ().replace (',\x1b [0m' , '' )
128
+ else :
129
+ value = line .split (':' )[- 1 ].strip ().replace ('\x1b [0m' , '' )
120
130
121
- # return value
131
+ return value
122
132
123
- if ':' in line :
124
- if '=' in line :
125
- delimiter = '='
126
- else :
127
- delimiter = ':'
133
+ # SHAO working
134
+ # if ':' in line:
135
+ # if '=' in line:
136
+ # delimiter = '='
137
+ # elif '#' in line:
138
+ # delimiter = '#'
139
+ # else:
140
+ # delimiter = ':'
128
141
129
- value = line .split (delimiter )[- 1 ].strip ().replace ('\x1b [0m' , '' ).rstrip (',' )
130
- else :
131
- logging .error ('Could not extract the value from the following line: %s' , line )
132
- handle_casting_failure (casting_state , log_paths )
142
+ # value = line.split(delimiter)[-1].strip().replace('\x1b[0m', '').rstrip(',') # SHAO OG working
143
+ # # value = line.split(delimiter)[-1].strip().replace('\x1b[0m', '') # SHAO forcing timeout!
133
144
134
- return value
145
+ # else:
146
+ # logging.error(f'Could not extract {value_name} from the following line: {line}')
147
+ # handle_casting_failure(casting_state, log_paths)
148
+
149
+ # return value
135
150
136
151
137
152
def validate_value (casting_state : str , expected_value : Union [str , int ], log_paths : List [str ], line : str , value_name : str ) -> Optional [str ]:
138
153
"""Validate a value in a string against an expected value during a given casting state."""
139
154
# value = extract_value_from_string(line) # SHAO OG
140
- value = extract_value_from_string (line , casting_state , log_paths )
155
+ value = extract_value_from_string (line , value_name , casting_state , log_paths )
141
156
142
157
if isinstance (expected_value , int ):
143
158
value = int (value )
@@ -157,8 +172,10 @@ def start_up_tv_app_success(tv_app_process: subprocess.Popen, linux_tv_app_log_f
157
172
start_wait_time = time .time ()
158
173
159
174
while True :
175
+ current_time = time .time ()
160
176
# Check if the time elapsed since the start wait time exceeds the maximum allowed startup time for the TV app.
161
- if time .time () - start_wait_time > TV_APP_MAX_START_WAIT_SEC :
177
+ # if time.time() - start_wait_time > TV_APP_MAX_START_WAIT_SEC: # SHAO OG
178
+ if current_time - start_wait_time > TV_APP_MAX_START_WAIT_SEC or current_time - START_TIME > 50 : # SHAO remove when done
162
179
logging .error ('The Linux tv-app process did not start successfully within the timeout.' )
163
180
return False
164
181
@@ -180,8 +197,10 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
180
197
start_wait_time = time .time ()
181
198
182
199
while True :
200
+ current_time = time .time ()
183
201
# Check if we exceeded the maximum wait time for initiating 'cast request' from the Linux tv-casting-app to the Linux tv-app.
184
- if time .time () - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC :
202
+ # if time.time() - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC: # SHAO OG
203
+ if current_time - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC or current_time - START_TIME > 50 : # SHAO remove when done
185
204
logging .error ('The command `cast request ' + valid_discovered_commissioner_number +
186
205
'` was not issued to the Linux tv-casting-app process within the timeout.' )
187
206
return False
@@ -217,14 +236,14 @@ def extract_device_info_from_tv_casting_app(tv_casting_app_info: Tuple[subproces
217
236
218
237
if 'device Name' in line :
219
238
# device_name = extract_value_from_string(line) # SHAO OG
220
- device_name = extract_value_from_string (line , casting_state , log_paths )
239
+ device_name = extract_value_from_string (line , '`device Name`' , casting_state , log_paths )
221
240
elif 'vendor id' in line :
222
241
# vendor_id = extract_value_from_string(line) # SHAO OG
223
- vendor_id = extract_value_from_string (line , casting_state , log_paths )
242
+ vendor_id = extract_value_from_string (line , '`vendor id`' , casting_state , log_paths )
224
243
vendor_id = int (vendor_id )
225
244
elif 'product id' in line :
226
245
# product_id = extract_value_from_string(line) # SHAO OG
227
- product_id = extract_value_from_string (line , casting_state , log_paths )
246
+ product_id = extract_value_from_string (line , '`product id`' , casting_state , log_paths )
228
247
product_id = int (product_id )
229
248
230
249
if device_name and vendor_id and product_id :
@@ -241,8 +260,11 @@ def validate_identification_declaration_message_on_tv_app(tv_app_info: Tuple[sub
241
260
start_wait_time = time .time ()
242
261
243
262
while True :
263
+ current_time = time .time () # SHAO remove when done
244
264
# Check if we exceeded the maximum wait time for validating the device information from the Linux tv-app to the corresponding values from the Linux tv-app.
245
- if time .time () - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC :
265
+ # if time.time() - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC: # SHAO OG
266
+ if current_time - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC or current_time - START_TIME > 50 : # SHAO remove when done
267
+ # print(f'current_elapsed_time: {current_elapsed_time}, elapsed_time: {elapsed_time}, current_time: {current_time}, START_TIME: {START_TIME}') # SHAO remove when done testing
246
268
logging .error (
247
269
'The device information from the Linux tv-app output was not validated against the corresponding values from the Linux tv-casting-app output within the timeout.' )
248
270
return False
@@ -277,8 +299,10 @@ def validate_tv_casting_request_approval(tv_app_info: Tuple[subprocess.Popen, Te
277
299
start_wait_time = time .time ()
278
300
279
301
while True :
302
+ current_time = time .time () # SHAO remove when done
280
303
# Check if we exceeded the maximum wait time for sending 'controller ux ok' from the Linux tv-app to the Linux tv-casting-app.
281
- if time .time () - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC :
304
+ # if time.time() - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC: # SHAO OG
305
+ if current_time - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC or current_time - START_TIME > 50 : # SHAO remove when done
282
306
logging .error ('The cast request from the Linux tv-casting-app to the Linux tv-app was not approved within the timeout.' )
283
307
return False
284
308
@@ -312,8 +336,10 @@ def validate_commissioning_success(tv_casting_app_info: Tuple[subprocess.Popen,
312
336
start_wait_time = time .time ()
313
337
314
338
while True :
339
+ current_time = time .time () # SHAO remove when done
315
340
# Check if we exceeded the maximum wait time for validating commissioning success between the Linux tv-casting-app and the Linux tv-app.
316
- if time .time () - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC :
341
+ if time .time () - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC : # SHAO OG
342
+
317
343
logging .error (
318
344
'The commissioning between the Linux tv-casting-app process and the Linux tv-app process did not complete successfully within the timeout.' )
319
345
return False
@@ -353,8 +379,10 @@ def parse_tv_casting_app_for_report_data_msg(tv_casting_app_info: Tuple[subproce
353
379
start_wait_time = time .time ()
354
380
355
381
while True :
382
+ current_time = time .time ()
356
383
# Check if we exceeded the maximum wait time to parse the Linux tv-casting-app output for `ReportDataMessage` block.
357
- if time .time () - start_wait_time > VERIFY_SUBSCRIPTION_STATE_MAX_WAIT_SEC :
384
+ # if time.time() - start_wait_time > VERIFY_SUBSCRIPTION_STATE_MAX_WAIT_SEC: # SHAO OG
385
+ if current_time - start_wait_time > VERIFY_SUBSCRIPTION_STATE_MAX_WAIT_SEC or current_time - START_TIME > 50 : # SHAO remove when done
358
386
logging .error (
359
387
'The relevant `ReportDataMessage` block was not found in the Linux tv-casting-app process within the timeout.' )
360
388
report_data_message .clear ()
@@ -374,14 +402,14 @@ def parse_tv_casting_app_for_report_data_msg(tv_casting_app_info: Tuple[subproce
374
402
375
403
if 'Cluster =' in tv_casting_line :
376
404
# cluster_value = extract_value_from_string(tv_casting_line) # SHAO OG
377
- cluster_value = extract_value_from_string (tv_casting_line , 'Testing subscription' , log_paths )
405
+ cluster_value = extract_value_from_string (tv_casting_line , '`Cluster ID`' , ' Testing subscription' , log_paths )
378
406
if cluster_value != CLUSTER_MEDIA_PLAYBACK :
379
407
report_data_message .clear ()
380
408
continue_parsing = False
381
409
382
410
elif 'Attribute =' in tv_casting_line :
383
411
# attribute_value = extract_value_from_string(tv_casting_line) # SHAO OG
384
- attribute_value = extract_value_from_string (tv_casting_line , 'Testing subscription' , log_paths )
412
+ attribute_value = extract_value_from_string (tv_casting_line , '`Attribute ID`' , ' Testing subscription' , log_paths )
385
413
if attribute_value != ATTRIBUTE_CURRENT_PLAYBACK_STATE :
386
414
report_data_message .clear ()
387
415
continue_parsing = False
@@ -403,8 +431,10 @@ def parse_tv_app_output_for_launchUrl_msg_success(tv_app_info: Tuple[subprocess.
403
431
start_wait_time = time .time ()
404
432
405
433
while True :
434
+ current_time = time .time () # SHAO remove when done
406
435
# Check if we exceeded the maximum wait time to parse the Linux tv-app output for the string related to the launchUrl.
407
- if time .time () - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC :
436
+ # if time.time() - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC: # SHAO OG
437
+ if current_time - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC or current_time - START_TIME > 50 : # SHAO remove when done
408
438
logging .error (
409
439
'The relevant launchUrl string was not found in the Linux tv-app process within the timeout.' )
410
440
return False
@@ -431,8 +461,10 @@ def parse_tv_casting_app_output_for_launchUrl_msg_success(tv_casting_app_info: T
431
461
start_wait_time = time .time ()
432
462
433
463
while True :
464
+ current_time = time .time ()
434
465
# Check if we exceeded the maximum wait time to parse the Linux tv-casting-app output for strings related to the launchUrl.
435
- if time .time () - start_wait_time > TEST_LAUNCHURL_MAX_WAIT_SEC :
466
+ # if time.time() - start_wait_time > TEST_LAUNCHURL_MAX_WAIT_SEC: # SHAO OG
467
+ if current_time - start_wait_time > TEST_LAUNCHURL_MAX_WAIT_SEC or current_time - START_TIME > 50 : # SHAO remove when done
436
468
logging .error (
437
469
'The relevant launchUrl strings were not found in the Linux tv-casting-app process within the timeout.' )
438
470
return False
@@ -479,6 +511,11 @@ def test_discovery_fn(tv_casting_app_info: Tuple[subprocess.Popen, TextIO], log_
479
511
linux_tv_casting_app_log_file .write (line )
480
512
linux_tv_casting_app_log_file .flush ()
481
513
514
+ # SHAO remove when done
515
+ if time .time () - START_TIME > 50 :
516
+ logging .error ('Could not find a valid discovered commissioner within timeout.' )
517
+ handle_casting_failure ('Discovery' , log_paths )
518
+
482
519
# Fail fast if "No commissioner discovered" string found.
483
520
if "No commissioner discovered" in line :
484
521
logging .error (line .rstrip ('\n ' ))
@@ -570,6 +607,9 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
570
607
For example: python3 run_tv_casting_test.py --tv-app-rel-path=path/to/tv-app
571
608
--tv-casting-app-rel-path=path/to/tv-casting-app
572
609
"""
610
+ # START_TIME = time.time() # SHAO added
611
+ # print(f'START_TIME set at beginning: {START_TIME}')
612
+
573
613
# Store the log files to a temporary directory.
574
614
with tempfile .TemporaryDirectory () as temp_dir :
575
615
linux_tv_app_log_path = os .path .join (temp_dir , LINUX_TV_APP_LOGS )
@@ -604,7 +644,8 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
604
644
# We need the valid discovered commissioner number to continue with commissioning.
605
645
# Example string: \x1b[0;32m[1714582264602] [77989:2286038] [SVR] Discovered Commissioner #0\x1b[0m
606
646
# The value '0' will be extracted from the string.
607
- valid_discovered_commissioner_number = valid_discovered_commissioner .split ('#' )[- 1 ].replace ('\x1b [0m' , '' )
647
+ valid_discovered_commissioner_number = valid_discovered_commissioner .split ('#' )[- 1 ].replace ('\x1b [0m' , '' ) # SHAO OG
648
+ # valid_discovered_commissioner_number = extract_value_from_string(valid_discovered_commissioner, '`Discovered Commissioner Number`', 'Discovery', log_paths)
608
649
609
650
test_commissioning_fn (valid_discovered_commissioner_number , tv_casting_app_info , tv_app_info , log_paths )
610
651
test_subscription_fn (tv_casting_app_info , log_paths )
0 commit comments