aboutsummaryrefslogtreecommitdiff
path: root/crosperf/download_images_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'crosperf/download_images_unittest.py')
-rwxr-xr-xcrosperf/download_images_unittest.py48
1 files changed, 37 insertions, 11 deletions
diff --git a/crosperf/download_images_unittest.py b/crosperf/download_images_unittest.py
index 349a2dbb..8d9b9e72 100755
--- a/crosperf/download_images_unittest.py
+++ b/crosperf/download_images_unittest.py
@@ -1,6 +1,9 @@
#!/usr/bin/env python2
-#
-# Copyright 2014 Google Inc. All Rights Reserved
+#-*- coding: utf-8 -*-
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
"""Download image unittest."""
from __future__ import print_function
@@ -27,6 +30,7 @@ class ImageDownloaderTestcast(unittest.TestCase):
self.called_uncompress_image = False
self.called_get_build_id = False
self.called_download_autotest_files = False
+ self.called_download_debug_file = False
@mock.patch.object(os, 'makedirs')
@mock.patch.object(os.path, 'exists')
@@ -126,8 +130,8 @@ class ImageDownloaderTestcast(unittest.TestCase):
# 2nd arg must be exception handler
except_handler_string = 'RunCommandExceptionHandler.HandleException'
self.assertTrue(
- except_handler_string in repr(
- mock_cmd_exec.RunCommand.call_args_list[0][1]))
+ except_handler_string in repr(mock_cmd_exec.RunCommand.call_args_list[0]
+ [1]))
# Call 2, should have 2 arguments
self.assertEqual(len(mock_cmd_exec.RunCommand.call_args_list[1]), 2)
@@ -160,13 +164,17 @@ class ImageDownloaderTestcast(unittest.TestCase):
test_chroot = '/usr/local/home/chromeos'
test_build_id = 'remote/lumpy/latest-dev'
test_empty_autotest_path = ''
+ test_empty_debug_path = ''
test_autotest_path = '/tmp/autotest'
+ test_debug_path = '/tmp/debug'
+ perf_args = '-a'
# Set values to test/check.
self.called_download_image = False
self.called_uncompress_image = False
self.called_get_build_id = False
self.called_download_autotest_files = False
+ self.called_download_debug_file = False
# Define fake stub functions for Run to call
def FakeGetBuildID(unused_root, unused_xbuddy_label):
@@ -197,6 +205,12 @@ class ImageDownloaderTestcast(unittest.TestCase):
self.called_download_autotest_files = True
return 'autotest'
+ def FakeDownloadDebugFile(root, build_id):
+ if root or build_id:
+ pass
+ self.called_download_debug_file = True
+ return 'debug'
+
# Initialize downloader
downloader = download_images.ImageDownloader(logger_to_use=MOCK_LOGGER)
@@ -205,46 +219,58 @@ class ImageDownloaderTestcast(unittest.TestCase):
downloader.UncompressImage = FakeUncompressImage
downloader.DownloadImage = GoodDownloadImage
downloader.DownloadAutotestFiles = FakeDownloadAutotestFiles
+ downloader.DownloadDebugFile = FakeDownloadDebugFile
# Call Run.
- image_path, autotest_path = downloader.Run(test_chroot, test_build_id,
- test_empty_autotest_path)
+ image_path, autotest_path, debug_path = downloader.Run(
+ test_chroot, test_build_id, test_empty_autotest_path,
+ test_empty_debug_path, perf_args)
# Make sure it called both _DownloadImage and _UncompressImage
self.assertTrue(self.called_download_image)
self.assertTrue(self.called_uncompress_image)
# Make sure it called DownloadAutotestFiles
self.assertTrue(self.called_download_autotest_files)
- # Make sure it returned an image and autotest path returned from this call
+ # Make sure it called DownloadDebugFile
+ self.assertTrue(self.called_download_debug_file)
+ # Make sure it returned an image and autotest path returned from this call
self.assertTrue(image_path == 'chromiumos_test_image.bin')
self.assertTrue(autotest_path == 'autotest')
+ self.assertTrue(debug_path == 'debug')
- # Call Run with a non-empty autotest path
+ # Call Run with a non-empty autotest and debug path
self.called_download_autotest_files = False
+ self.called_download_debug_file = False
- image_path, autotest_path = downloader.Run(test_chroot, test_build_id,
- test_autotest_path)
+ image_path, autotest_path, debug_path = downloader.Run(
+ test_chroot, test_build_id, test_autotest_path, test_debug_path,
+ perf_args)
# Verify that downloadAutotestFiles was not called
self.assertFalse(self.called_download_autotest_files)
# Make sure it returned the specified autotest path returned from this call
self.assertTrue(autotest_path == test_autotest_path)
+ # Make sure it returned the specified debug path returned from this call
+ self.assertTrue(debug_path == test_debug_path)
# Reset values; Now use fake stub that simulates DownloadImage failing.
self.called_download_image = False
self.called_uncompress_image = False
self.called_download_autotest_files = False
+ self.called_download_debug_file = False
downloader.DownloadImage = BadDownloadImage
# Call Run again.
self.assertRaises(download_images.MissingImage, downloader.Run, test_chroot,
- test_autotest_path, test_build_id)
+ test_autotest_path, test_debug_path, test_build_id,
+ perf_args)
# Verify that UncompressImage and downloadAutotestFiles were not called,
# since _DownloadImage "failed"
self.assertTrue(self.called_download_image)
self.assertFalse(self.called_uncompress_image)
self.assertFalse(self.called_download_autotest_files)
+ self.assertFalse(self.called_download_debug_file)
if __name__ == '__main__':