Skip to content

Commit ef07814

Browse files
Latest working version.
1 parent 681c10b commit ef07814

File tree

1 file changed

+80
-41
lines changed

1 file changed

+80
-41
lines changed

scripts/tests/run_tv_casting_test.py

+80-41
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import pdb # SHAO
1718
import logging
1819
import os
1920
import subprocess
@@ -31,7 +32,7 @@
3132
TV_APP_MAX_START_WAIT_SEC = 2
3233

3334
# 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
3536

3637
# 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.
3738
TEST_LAUNCHURL_MAX_WAIT_SEC = 10
@@ -98,7 +99,8 @@ def handle_casting_failure(casting_state: str, log_file_paths: List[str]):
9899
sys.exit(1)
99100

100101

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:
102104
"""Extract and return value from given input string.
103105
104106
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:
112114
\x1b[0;34m[1714583616179] [7029:2386956] [SVR] device Name: Test TV casting app\x1b[0m
113115
The substring to be extracted here is 'Test TV casting app'.
114116
"""
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)
120149
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)
122152

123153
return value
124154

125155

126156
def validate_value(casting_state: str, expected_value: Union[str, int], log_paths: List[str], line: str, value_name: str) -> Optional[str]:
127157
"""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)
129160

130161
if isinstance(expected_value, int):
131162
value = int(value)
@@ -190,7 +221,8 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
190221
return True
191222

192223

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]]:
194226
"""Extract device information from the 'Identification Declaration' block in the Linux tv-casting-app output."""
195227
tv_casting_app_process, linux_tv_casting_app_log_file = tv_casting_app_info
196228

@@ -203,12 +235,15 @@ def extract_device_info_from_tv_casting_app(tv_casting_app_info: Tuple[subproces
203235
linux_tv_casting_app_log_file.flush()
204236

205237
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)
207240
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)
209243
vendor_id = int(vendor_id)
210244
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
212247
product_id = int(product_id)
213248

214249
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
335370
report_data_message = []
336371

337372
start_wait_time = time.time()
338-
print('SHAO before parsing for the `ReportDataMessage` block!')
373+
# print('SHAO before parsing for the `ReportDataMessage` block!')
339374
while True:
340375
# Check if we exceeded the maximum wait time to parse the Linux tv-casting-app output for `ReportDataMessage` block.
341376
if time.time() - start_wait_time > VERIFY_SUBSCRIPTION_STATE_MAX_WAIT_SEC:
342377
logging.error(
343378
'The relevant `ReportDataMessage` block was not found in the Linux tv-casting-app process within the timeout.')
344379

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)
348383

349384
report_data_message.clear() # SHAO OG
350385
# report_data_message = [] # SHAO
@@ -365,41 +400,44 @@ def parse_tv_casting_app_for_report_data_msg(tv_casting_app_info: Tuple[subproce
365400
logging.info(tv_casting_line.rstrip('\n')) # SHAO
366401

367402
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)
374409

375410

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)
377413
# cluster_value = cluster_value.rstrip(',') # SHAO added to make it work on CI check
378414
if cluster_value != CLUSTER_MEDIA_PLAYBACK:
379415
print('SHAO we entered into the mismatch cluster ID block!!!!')
380416
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))
383419
report_data_message.clear() # SHAO OG
384420
# report_data_message = [] # SHAO
385421
continue_parsing = False
422+
pdb.set_trace() # SHAO
386423

387424
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)
394431

395432

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)
397435
# attribute_value = attribute_value.rstrip(',') # SHAO added to make it work on CI check
398436
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))
403441
report_data_message.clear() # SHAO OG
404442
# report_data_message = [] # SHAO
405443
continue_parsing = False
@@ -537,7 +575,8 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
537575
handle_casting_failure('Commissioning', log_paths)
538576

539577
# 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)
541580

542581
if not validate_identification_declaration_message_on_tv_app(tv_app_info, expected_device_name, expected_vendor_id, expected_product_id, log_paths):
543582
handle_casting_failure('Commissioning', log_paths)
@@ -552,10 +591,10 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
552591
def test_subscription_fn(tv_casting_app_info: Tuple[subprocess.Popen, TextIO], log_paths: List[str]):
553592
"""Test the subscription state of the Linux tv-casting-app by validating the `ReportDataMessage` block."""
554593

555-
print('SHAO inside test_subscr_fn')
594+
# print('SHAO inside test_subscr_fn')
556595
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))
559598

560599
if valid_report_data_msg:
561600
logging.info('Found the `ReportDataMessage` block in the Linux tv-casting-app output:')

0 commit comments

Comments
 (0)