Skip to content

Commit ae32172

Browse files
Adding changes to fix the timeout bug which was caused by the fact that ',' was not removed from '0x506,'.
1 parent d7781bf commit ae32172

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

scripts/tests/run_tv_casting_test.py

+34-12
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def handle_casting_failure(casting_state: str, log_file_paths: List[str]):
9898
sys.exit(1)
9999

100100

101-
def extract_value_from_string(line: str) -> str:
101+
# def extract_value_from_string(line: str) -> str: # SHAO OG
102+
def extract_value_from_string(line: str, casting_state: str, log_paths) -> str:
102103
"""Extract and return value from given input string.
103104
104105
The string is expected to be in the following format as it is received
@@ -112,17 +113,31 @@ def extract_value_from_string(line: str) -> str:
112113
\x1b[0;34m[1714583616179] [7029:2386956] [SVR] device Name: Test TV casting app\x1b[0m
113114
The substring to be extracted here is 'Test TV casting app'.
114115
"""
115-
if '=' in line:
116-
value = line.split('=')[-1].strip().replace(',\x1b[0m', '')
116+
# if '=' in line:
117+
# value = line.split('=')[-1].strip().replace(',\x1b[0m', '')
118+
# else:
119+
# value = line.split(':')[-1].strip().replace('\x1b[0m', '')
120+
121+
# return value
122+
123+
if ':' in line:
124+
if '=' in line:
125+
delimiter = '='
126+
else:
127+
delimiter = ':'
128+
129+
value = line.split(delimiter)[-1].strip().replace('\x1b[0m', '').rstrip(',')
117130
else:
118-
value = line.split(':')[-1].strip().replace('\x1b[0m', '')
131+
logging.error('Could not extract the value from the following line: %s', line)
132+
handle_casting_failure(casting_state, log_paths)
119133

120134
return value
121135

122136

123137
def validate_value(casting_state: str, expected_value: Union[str, int], log_paths: List[str], line: str, value_name: str) -> Optional[str]:
124138
"""Validate a value in a string against an expected value during a given casting state."""
125-
value = extract_value_from_string(line)
139+
# value = extract_value_from_string(line) # SHAO OG
140+
value = extract_value_from_string(line, casting_state, log_paths)
126141

127142
if isinstance(expected_value, int):
128143
value = int(value)
@@ -187,7 +202,8 @@ def initiate_cast_request_success(tv_casting_app_info: Tuple[subprocess.Popen, T
187202
return True
188203

189204

190-
def extract_device_info_from_tv_casting_app(tv_casting_app_info: Tuple[subprocess.Popen, TextIO]) -> Tuple[Optional[str], Optional[int], Optional[int]]:
205+
# 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
206+
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]]:
191207
"""Extract device information from the 'Identification Declaration' block in the Linux tv-casting-app output."""
192208
tv_casting_app_process, linux_tv_casting_app_log_file = tv_casting_app_info
193209

@@ -200,12 +216,15 @@ def extract_device_info_from_tv_casting_app(tv_casting_app_info: Tuple[subproces
200216
linux_tv_casting_app_log_file.flush()
201217

202218
if 'device Name' in line:
203-
device_name = extract_value_from_string(line)
219+
# device_name = extract_value_from_string(line) # SHAO OG
220+
device_name = extract_value_from_string(line, casting_state, log_paths)
204221
elif 'vendor id' in line:
205-
vendor_id = extract_value_from_string(line)
222+
# vendor_id = extract_value_from_string(line) # SHAO OG
223+
vendor_id = extract_value_from_string(line, casting_state, log_paths)
206224
vendor_id = int(vendor_id)
207225
elif 'product id' in line:
208-
product_id = extract_value_from_string(line)
226+
# product_id = extract_value_from_string(line) # SHAO OG
227+
product_id = extract_value_from_string(line, casting_state, log_paths)
209228
product_id = int(product_id)
210229

211230
if device_name and vendor_id and product_id:
@@ -354,13 +373,15 @@ def parse_tv_casting_app_for_report_data_msg(tv_casting_app_info: Tuple[subproce
354373
report_data_message.append(tv_casting_line.rstrip('\n'))
355374

356375
if 'Cluster =' in tv_casting_line:
357-
cluster_value = extract_value_from_string(tv_casting_line)
376+
# 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)
358378
if cluster_value != CLUSTER_MEDIA_PLAYBACK:
359379
report_data_message.clear()
360380
continue_parsing = False
361381

362382
elif 'Attribute =' in tv_casting_line:
363-
attribute_value = extract_value_from_string(tv_casting_line)
383+
# 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)
364385
if attribute_value != ATTRIBUTE_CURRENT_PLAYBACK_STATE:
365386
report_data_message.clear()
366387
continue_parsing = False
@@ -497,7 +518,8 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
497518
handle_casting_failure('Commissioning', log_paths)
498519

499520
# 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)
521+
# expected_device_name, expected_vendor_id, expected_product_id = extract_device_info_from_tv_casting_app(tv_casting_app_info) # SHAO OG
522+
expected_device_name, expected_vendor_id, expected_product_id = extract_device_info_from_tv_casting_app(tv_casting_app_info, 'Commissioning', log_paths)
501523

502524
if not validate_identification_declaration_message_on_tv_app(tv_app_info, expected_device_name, expected_vendor_id, expected_product_id, log_paths):
503525
handle_casting_failure('Commissioning', log_paths)

0 commit comments

Comments
 (0)