14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
+ import pdb # SHAO
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
@@ -98,7 +99,8 @@ def handle_casting_failure(casting_state: str, log_file_paths: List[str]):
98
99
sys .exit (1 )
99
100
100
101
101
- def extract_value_from_string (line : str ) -> str :
102
+ # def extract_value_from_string(line: str) -> str: # SHAO OG
103
+ def extract_value_from_string (line : str , casting_state : str , log_paths ) -> str :
102
104
"""Extract and return value from given input string.
103
105
104
106
The string is expected to be in the following format as it is received
@@ -112,20 +114,49 @@ def extract_value_from_string(line: str) -> str:
112
114
\x1b [0;34m[1714583616179] [7029:2386956] [SVR] device Name: Test TV casting app\x1b [0m
113
115
The substring to be extracted here is 'Test TV casting app'.
114
116
"""
115
- if '=' in line :
116
- # value = line.split('=')[-1].strip().replace(',\x1b[0m', '') # SHAO OG
117
- # value = line.split('=')[-1].strip().replace(',\n', '')
118
- value = line .split ('=' )[- 1 ].strip ().replace ('\x1b [0m' , '' )
119
- value = value .rstrip (',' )
117
+ # if '=' in line:
118
+ # # value = line.split('=')[-1].strip().replace(',\x1b[0m', '') # SHAO OG
119
+ # # value = line.split('=')[-1].strip().replace(',\n', '')
120
+ # value = line.split('=')[-1].strip().replace('\x1b[0m', '')
121
+ # value = value.rstrip(',')
122
+ # else:
123
+ # value = line.split(':')[-1].strip().replace('\x1b[0m', '')
124
+
125
+ # return value
126
+
127
+ # # SHAO mod
128
+ # if ':' in line:
129
+ # if '=' in line:
130
+ # value = line.split('=')[-1].strip().replace('\x1b[0m', '')
131
+ # value = value.rstrip(',')
132
+ # else:
133
+ # value = line.split(':')[-1].strip().replace('\x1b[0m', '')
134
+ # else:
135
+ # handle_casting_failure(casting_state, log_paths)
136
+
137
+ # return value
138
+
139
+ # SHAO mod 2
140
+ line = 'SHAO Hello World!'
141
+ if ':' in line :
142
+ if '=' in line :
143
+ delimiter = '='
144
+ else :
145
+ delimiter = ':'
146
+
147
+ value = line .split (delimiter )[- 1 ].strip ().replace ('\x1b [0m' , '' ).rstrip (',' )
148
+ print ('SHAO value: ' , value )
120
149
else :
121
- value = line .split (':' )[- 1 ].strip ().replace ('\x1b [0m' , '' )
150
+ logging .error ('Could not extract the value from the following line: %s' , line )
151
+ handle_casting_failure (casting_state , log_paths )
122
152
123
153
return value
124
154
125
155
126
156
def validate_value (casting_state : str , expected_value : Union [str , int ], log_paths : List [str ], line : str , value_name : str ) -> Optional [str ]:
127
157
"""Validate a value in a string against an expected value during a given casting state."""
128
- value = extract_value_from_string (line )
158
+ # value = extract_value_from_string(line) # SHAO OG
159
+ value = extract_value_from_string (line , casting_state , log_paths )
129
160
130
161
if isinstance (expected_value , int ):
131
162
value = int (value )
@@ -190,7 +221,8 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
190
221
return True
191
222
192
223
193
- def extract_device_info_from_tv_casting_app (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ]) -> Tuple [Optional [str ], Optional [int ], Optional [int ]]:
224
+ # def extract_device_info_from_tv_casting_app(tv_casting_app_info: Tuple[subprocess.Popen, TextIO]) -> Tuple[Optional[str], Optional[int], Optional[int]]: # SHAO OG
225
+ 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 ]]:
194
226
"""Extract device information from the 'Identification Declaration' block in the Linux tv-casting-app output."""
195
227
tv_casting_app_process , linux_tv_casting_app_log_file = tv_casting_app_info
196
228
@@ -203,12 +235,15 @@ def extract_device_info_from_tv_casting_app(tv_casting_app_info: Tuple[subproces
203
235
linux_tv_casting_app_log_file .flush ()
204
236
205
237
if 'device Name' in line :
206
- device_name = extract_value_from_string (line )
238
+ # device_name = extract_value_from_string(line) # SHAO OG
239
+ device_name = extract_value_from_string (line , casting_state , log_paths )
207
240
elif 'vendor id' in line :
208
- vendor_id = extract_value_from_string (line )
241
+ # vendor_id = extract_value_from_string(line) # SHAO OG
242
+ vendor_id = extract_value_from_string (line , casting_state , log_paths )
209
243
vendor_id = int (vendor_id )
210
244
elif 'product id' in line :
211
- product_id = extract_value_from_string (line )
245
+ # product_id = extract_value_from_string(line) # SHAO OG
246
+ product_id = extract_value_from_string (line , casting_state , log_paths ) # SHAO OG
212
247
product_id = int (product_id )
213
248
214
249
if device_name and vendor_id and product_id :
@@ -335,16 +370,16 @@ def parse_tv_casting_app_for_report_data_msg(tv_casting_app_info: Tuple[subproce
335
370
report_data_message = []
336
371
337
372
start_wait_time = time .time ()
338
- print ('SHAO before parsing for the `ReportDataMessage` block!' )
373
+ # print('SHAO before parsing for the `ReportDataMessage` block!')
339
374
while True :
340
375
# Check if we exceeded the maximum wait time to parse the Linux tv-casting-app output for `ReportDataMessage` block.
341
376
if time .time () - start_wait_time > VERIFY_SUBSCRIPTION_STATE_MAX_WAIT_SEC :
342
377
logging .error (
343
378
'The relevant `ReportDataMessage` block was not found in the Linux tv-casting-app process within the timeout.' )
344
379
345
- logging .error ('SHAO debugging when we hit timeout:' )
346
- for report_data_msg_line in report_data_message :
347
- logging .error (report_data_msg_line )
380
+ # logging.error('SHAO debugging when we hit timeout:')
381
+ # for report_data_msg_line in report_data_message:
382
+ # logging.error(report_data_msg_line)
348
383
349
384
report_data_message .clear () # SHAO OG
350
385
# report_data_message = [] # SHAO
@@ -365,41 +400,44 @@ def parse_tv_casting_app_for_report_data_msg(tv_casting_app_info: Tuple[subproce
365
400
logging .info (tv_casting_line .rstrip ('\n ' )) # SHAO
366
401
367
402
if 'Cluster =' in tv_casting_line :
368
- print ('SHAO char by char of the Cluster string: ' )
369
- result = ''
370
- for char in repr (tv_casting_line ):
371
- # print(char)
372
- result += char
373
- print (result )
403
+ # print('SHAO char by char of the Cluster string: ')
404
+ # result = ''
405
+ # for char in repr(tv_casting_line):
406
+ # # print(char)
407
+ # result += char
408
+ # print(result)
374
409
375
410
376
- cluster_value = extract_value_from_string (tv_casting_line )
411
+ # cluster_value = extract_value_from_string(tv_casting_line) # SHAO OG
412
+ cluster_value = extract_value_from_string (tv_casting_line , 'Testing subscription' , log_paths )
377
413
# cluster_value = cluster_value.rstrip(',') # SHAO added to make it work on CI check
378
414
if cluster_value != CLUSTER_MEDIA_PLAYBACK :
379
415
print ('SHAO we entered into the mismatch cluster ID block!!!!' )
380
416
print ('cluster_value: ' , cluster_value )
381
- print ('len(cluster_value): ' , len (cluster_value ))
382
- print ('type(cluster_value): ' , type (cluster_value ))
417
+ # print('len(cluster_value): ', len(cluster_value))
418
+ # print('type(cluster_value): ', type(cluster_value))
383
419
report_data_message .clear () # SHAO OG
384
420
# report_data_message = [] # SHAO
385
421
continue_parsing = False
422
+ pdb .set_trace () # SHAO
386
423
387
424
elif 'Attribute =' in tv_casting_line :
388
- print ('SHAO char by char of the Attribute string: ' )
389
- result = ''
390
- for char in repr (tv_casting_line ):
391
- # print(char)
392
- result += char
393
- print (result )
425
+ # print('SHAO char by char of the Attribute string: ')
426
+ # result = ''
427
+ # for char in repr(tv_casting_line):
428
+ # # print(char)
429
+ # result += char
430
+ # print(result)
394
431
395
432
396
- attribute_value = extract_value_from_string (tv_casting_line )
433
+ # attribute_value = extract_value_from_string(tv_casting_line) # SHAO OG
434
+ attribute_value = extract_value_from_string (tv_casting_line , 'Testing subscription' , log_paths )
397
435
# attribute_value = attribute_value.rstrip(',') # SHAO added to make it work on CI check
398
436
if attribute_value != ATTRIBUTE_CURRENT_PLAYBACK_STATE :
399
- print ('SHAO we entered into the mismatch attribute ID block!!!!' )
400
- print ('attr_value: ' , attribute_value )
401
- print ('len(attr_value): ' , len (attribute_value ))
402
- print ('type(attr_value): ' , type (attribute_value ))
437
+ # print('SHAO we entered into the mismatch attribute ID block!!!!')
438
+ # print('attr_value: ', attribute_value)
439
+ # print('len(attr_value): ', len(attribute_value))
440
+ # print('type(attr_value): ', type(attribute_value))
403
441
report_data_message .clear () # SHAO OG
404
442
# report_data_message = [] # SHAO
405
443
continue_parsing = False
@@ -537,7 +575,8 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
537
575
handle_casting_failure ('Commissioning' , log_paths )
538
576
539
577
# Extract the values from the 'Identification Declaration' block in the tv-casting-app output that we want to validate against.
540
- expected_device_name , expected_vendor_id , expected_product_id = extract_device_info_from_tv_casting_app (tv_casting_app_info )
578
+ # expected_device_name, expected_vendor_id, expected_product_id = extract_device_info_from_tv_casting_app(tv_casting_app_info) # SHAO OG
579
+ expected_device_name , expected_vendor_id , expected_product_id = extract_device_info_from_tv_casting_app (tv_casting_app_info , 'Commissioning' , log_paths )
541
580
542
581
if not validate_identification_declaration_message_on_tv_app (tv_app_info , expected_device_name , expected_vendor_id , expected_product_id , log_paths ):
543
582
handle_casting_failure ('Commissioning' , log_paths )
@@ -552,10 +591,10 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
552
591
def test_subscription_fn (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ], log_paths : List [str ]):
553
592
"""Test the subscription state of the Linux tv-casting-app by validating the `ReportDataMessage` block."""
554
593
555
- print ('SHAO inside test_subscr_fn' )
594
+ # print('SHAO inside test_subscr_fn')
556
595
valid_report_data_msg = parse_tv_casting_app_for_report_data_msg (tv_casting_app_info , log_paths )
557
- print ('SHAOOOOOOOOOOOOOOOOOOOOOOOO' )
558
- print ('SHAO list len: ' , len (valid_report_data_msg ))
596
+ # print('SHAOOOOOOOOOOOOOOOOOOOOOOOO')
597
+ # print('SHAO list len: ', len(valid_report_data_msg))
559
598
560
599
if valid_report_data_msg :
561
600
logging .info ('Found the `ReportDataMessage` block in the Linux tv-casting-app output:' )
0 commit comments