33
33
# The maximum amount of time to commission the Linux tv-casting-app and the tv-app before timeout.
34
34
COMMISSIONING_STAGE_MAX_WAIT_SEC = 10
35
35
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
+ TEST_LAUNCHURL_MAX_WAIT_SEC = 10
38
+
36
39
# File names of logs for the Linux tv-casting-app and the Linux tv-app.
37
40
LINUX_TV_APP_LOGS = 'Linux-tv-app-logs.txt'
38
41
LINUX_TV_CASTING_APP_LOGS = 'Linux-tv-casting-app-logs.txt'
@@ -303,10 +306,80 @@ def validate_commissioning_success(tv_casting_app_info: Tuple[subprocess.Popen,
303
306
304
307
if 'PROMPT USER: commissioning success' in tv_app_line :
305
308
logging .info ('Commissioning success noted on the Linux tv-app output:' )
309
+ logging .info (tv_app_line )
310
+ return True
311
+
312
+
313
+ def parse_tv_app_output_for_launchUrl_msg_success (tv_app_info : Tuple [subprocess .Popen , TextIO ], log_paths : List [str ]):
314
+ """Parse the Linux tv-app output for the relevant string indicating that the launchUrl was received."""
315
+
316
+ tv_app_process , linux_tv_app_log_file = tv_app_info
317
+
318
+ start_wait_time = time .time ()
319
+
320
+ while True :
321
+ # Check if we exceeded the maximum wait time to parse the Linux tv-app output for the string related to the launchUrl.
322
+ if time .time () - start_wait_time > COMMISSIONING_STAGE_MAX_WAIT_SEC :
323
+ logging .error (
324
+ 'The relevant launchUrl string was not found in the Linux tv-app process within the timeout.' )
325
+ return False
326
+
327
+ tv_app_line = tv_app_process .stdout .readline ()
328
+
329
+ if tv_app_line :
330
+ linux_tv_app_log_file .write (tv_app_line )
331
+ linux_tv_app_log_file .flush ()
332
+
333
+ if 'ContentLauncherManager::HandleLaunchUrl TEST CASE ContentURL=https://www.test.com/videoid DisplayString=Test video' in tv_app_line :
334
+ logging .info ('Found the launchUrl in the Linux tv-app output:' )
306
335
logging .info (tv_app_line .rstrip ('\n ' ))
307
336
return True
308
337
309
338
339
+ def parse_tv_casting_app_output_for_launchUrl_msg_success (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ], log_paths : List [str ]):
340
+ """Parse the Linux tv-casting-app output for relevant strings indicating that the launchUrl was sent."""
341
+
342
+ tv_casting_app_process , linux_tv_casting_app_log_file = tv_casting_app_info
343
+
344
+ continue_parsing_invoke_response_msg_block = False
345
+ found_example_data_msg = False
346
+ start_wait_time = time .time ()
347
+
348
+ while True :
349
+ # Check if we exceeded the maximum wait time to parse the Linux tv-casting-app output for strings related to the launchUrl.
350
+ if time .time () - start_wait_time > TEST_LAUNCHURL_MAX_WAIT_SEC :
351
+ logging .error (
352
+ 'The relevant launchUrl strings were not found in the Linux tv-casting-app process within the timeout.' )
353
+ return False
354
+
355
+ tv_casting_line = tv_casting_app_process .stdout .readline ()
356
+
357
+ if tv_casting_line :
358
+ linux_tv_casting_app_log_file .write (tv_casting_line )
359
+ linux_tv_casting_app_log_file .flush ()
360
+
361
+ if 'InvokeResponseMessage =' in tv_casting_line :
362
+ logging .info ('Found the InvokeResponseMessage block in the Linux tv-casting-app output:' )
363
+ logging .info (tv_casting_line .rstrip ('\n ' ))
364
+ continue_parsing_invoke_response_msg_block = True
365
+
366
+ elif continue_parsing_invoke_response_msg_block :
367
+ # Sanity check for `exampleData` in the `InvokeResponseMessage` block.
368
+ if 'exampleData' in tv_casting_line :
369
+ found_example_data_msg = True
370
+
371
+ elif 'Received Command Response Data' in tv_casting_line :
372
+ if not found_example_data_msg :
373
+ logging .error ('The `exampleData` string was not found in the `InvokeResponseMessage` block.' )
374
+ return False
375
+
376
+ logging .info ('Found the `Received Command Response Data` string in the Linux tv-casting-app output:' )
377
+ logging .info (tv_casting_line .rstrip ('\n ' ))
378
+ return True
379
+
380
+ logging .info (tv_casting_line .rstrip ('\n ' ))
381
+
382
+
310
383
def test_discovery_fn (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ], log_paths : List [str ]) -> Optional [str ]:
311
384
"""Parse the output of the Linux tv-casting-app to find a valid commissioner."""
312
385
tv_casting_app_process , linux_tv_casting_app_log_file = tv_casting_app_info
@@ -347,7 +420,7 @@ def test_discovery_fn(tv_casting_app_info: Tuple[subprocess.Popen, TextIO], log_
347
420
logging .info (valid_vendor_id )
348
421
logging .info (valid_product_id )
349
422
logging .info (valid_device_type )
350
- logging .info ('Discovery success!' )
423
+ logging .info ('Discovery success!\n ' )
351
424
break
352
425
353
426
return valid_discovered_commissioner
@@ -372,6 +445,18 @@ def test_commissioning_fn(valid_discovered_commissioner_number, tv_casting_app_i
372
445
handle_casting_failure ('Commissioning' , log_paths )
373
446
374
447
448
+ def test_launchUrl_fn (tv_casting_app_info : Tuple [subprocess .Popen , TextIO ], tv_app_info : Tuple [subprocess .Popen , TextIO ], log_paths : List [str ]):
449
+ """Test that the Linux tv-casting-app sent the launchUrl and that the Linux tv-app received the launchUrl."""
450
+
451
+ if not parse_tv_app_output_for_launchUrl_msg_success (tv_app_info , log_paths ):
452
+ handle_casting_failure ('Testing launchUrl' , log_paths )
453
+
454
+ if not parse_tv_casting_app_output_for_launchUrl_msg_success (tv_casting_app_info , log_paths ):
455
+ handle_casting_failure ('Testing launchUrl' , log_paths )
456
+
457
+ logging .info ('Testing launchUrl success!\n ' )
458
+
459
+
375
460
@click .command ()
376
461
@click .option ('--tv-app-rel-path' , type = str , default = 'out/tv-app/chip-tv-app' , help = 'Path to the Linux tv-app executable.' )
377
462
@click .option ('--tv-casting-app-rel-path' , type = str , default = 'out/tv-casting-app/chip-tv-casting-app' , help = 'Path to the Linux tv-casting-app executable.' )
@@ -420,6 +505,8 @@ def test_casting_fn(tv_app_rel_path, tv_casting_app_rel_path):
420
505
421
506
test_commissioning_fn (valid_discovered_commissioner_number , tv_casting_app_info , tv_app_info , log_paths )
422
507
508
+ test_launchUrl_fn (tv_casting_app_info , tv_app_info , log_paths )
509
+
423
510
424
511
if __name__ == '__main__' :
425
512
0 commit comments