From 07e20db42dbf866e76ae52f8f7dfd6274e1f1045 Mon Sep 17 00:00:00 2001 From: jansson Date: Wed, 12 Apr 2017 01:36:02 -0700 Subject: [PATCH] return comparevideos stdout and fix missing device case BUG=webrtc:7203 NOTRY=True Review-Url: https://codereview.webrtc.org/2809913002 Cr-Commit-Position: refs/heads/master@{#17665} --- webrtc/tools/video_analysis.py | 43 +++++++++++++++++------------ webrtc/tools/video_analysis_test.py | 9 ++++++ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/webrtc/tools/video_analysis.py b/webrtc/tools/video_analysis.py index b13543d65a..68575f3e26 100755 --- a/webrtc/tools/video_analysis.py +++ b/webrtc/tools/video_analysis.py @@ -184,18 +184,23 @@ def FindUsbPortForV4lDevices(ref_video_device, test_video_device): # Split on the driver folder first since we are only interested in the # folders thereafter. - ref_path = str(v4l_ref_device).split('driver')[1].split('/') - test_path = str(v4l_test_device).split('driver')[1].split('/') - paths.append(ref_path) - paths.append(test_path) + try: + ref_path = str(v4l_ref_device).split('driver')[1].split('/') + test_path = str(v4l_test_device).split('driver')[1].split('/') + except IndexError: + print 'Could not find one or both of the specified recording devices.' + else: + paths.append(ref_path) + paths.append(test_path) + + for path in paths: + for usb_id in path: + # Look for : separator and then use the first element in the list. + # E.g 3-3.1:1.0 split on : and [0] becomes 3-3.1 which can be used + # for bind/unbind. + if ':' in usb_id: + usb_ports.append(usb_id.split(':')[0]) - for path in paths: - for usb_id in path: - # Look for : separator and then use the first element in the list. - # E.g 3-3.1:1.0 split on : and [0] becomes 3-3.1 which can be used - # for bind/unbind. - if ':' in usb_id: - usb_ports.append(usb_id.split(':')[0]) return usb_ports @@ -448,13 +453,15 @@ def CompareVideos(options, cropped_ref_file, cropped_test_file): ] with open(result_file_name, 'w') as f: - compare_video_recordings = subprocess.Popen(compare_cmd, stdout=f) - compare_video_recordings.wait() - if compare_video_recordings.returncode != 0: - raise CompareVideosError('Failed to perform comparison.') - else: - print 'Result recorded to: ' + os.path.abspath(result_file_name) - print 'Comparison done!' + try: + compare_video_recordings = subprocess.check_output(compare_cmd) + f.write(compare_video_recordings) + except subprocess.CalledProcessError as error: + raise CompareVideosError('Failed to perform comparison: %s' % error) + else: + print 'Result recorded to: %s' % os.path.abspath(result_file_name) + print 'Comparison done!' + return compare_video_recordings def main(): diff --git a/webrtc/tools/video_analysis_test.py b/webrtc/tools/video_analysis_test.py index f4cd74b31c..483632bc48 100755 --- a/webrtc/tools/video_analysis_test.py +++ b/webrtc/tools/video_analysis_test.py @@ -56,5 +56,14 @@ class RunVideoAnalysisTest(unittest.TestCase): self.assertEqual(FindUsbPortForV4lDevices('video0', 'video1'), long_usb_ids) + def testFindUSBPortForV4lDevicesNoDevice(self): + noDeviceFound = ('') + V4lDevice = ('/sys/bus/usb/devices/usb1/1-1/driver/3-2/3-2.1:1.0/' + 'video4linux/video1') + self.setGlobPath(noDeviceFound, V4lDevice) + empty_list = [] + self.assertEqual(FindUsbPortForV4lDevices('video0', 'video1'), empty_list) + + if __name__ == "__main__": unittest.main()