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}
diff --git a/webrtc/tools/video_analysis.py b/webrtc/tools/video_analysis.py
index b13543d..68575f3 100755
--- a/webrtc/tools/video_analysis.py
+++ b/webrtc/tools/video_analysis.py
@@ -184,18 +184,23 @@
# 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 @@
]
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 f4cd74b..483632b 100755
--- a/webrtc/tools/video_analysis_test.py
+++ b/webrtc/tools/video_analysis_test.py
@@ -56,5 +56,14 @@
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()