| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Unittests for cbuildbot. Needs to be run inside of chroot for mox.""" | 7 """Unittests for cbuildbot. Needs to be run inside of chroot for mox.""" |
| 8 | 8 |
| 9 import __builtin__ | 9 import __builtin__ |
| 10 import mox | 10 import mox |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 # Set vars for call. | 125 # Set vars for call. |
| 126 buildroot = '/fake_dir' | 126 buildroot = '/fake_dir' |
| 127 test_results_dir = 'fake_results_dir' | 127 test_results_dir = 'fake_results_dir' |
| 128 archive_dir = 1234 | 128 archive_dir = 1234 |
| 129 board = 'fake-board' | 129 board = 'fake-board' |
| 130 | 130 |
| 131 # Expected calls. | 131 # Expected calls. |
| 132 os.path.exists(cbuildbot.ARCHIVE_BASE).AndReturn(True) | 132 os.path.exists(cbuildbot.ARCHIVE_BASE).AndReturn(True) |
| 133 os.listdir(os.path.join(cbuildbot.ARCHIVE_BASE)).AndReturn(dir_listing) | 133 os.listdir(os.path.join(cbuildbot.ARCHIVE_BASE)).AndReturn(dir_listing) |
| 134 os.stat('file1').AndReturn(stat1) | 134 os.stat(os.path.join(cbuildbot.ARCHIVE_BASE, 'file1')).AndReturn(stat1) |
| 135 os.stat('file2').AndReturn(stat2) | 135 os.stat(os.path.join(cbuildbot.ARCHIVE_BASE, 'file2')).AndReturn(stat2) |
| 136 # Should remove the oldest path. | 136 # Should remove the oldest path. |
| 137 shutil.rmtree(os.path.join(cbuildbot.ARCHIVE_BASE, 'file2')) | 137 shutil.rmtree(os.path.join(cbuildbot.ARCHIVE_BASE, 'file2')) |
| 138 | 138 |
| 139 # Convenience variables to make archive easier to understand. | 139 # Convenience variables to make archive easier to understand. |
| 140 path_to_results = os.path.join(buildroot, 'chroot', test_results_dir) | 140 path_to_results = os.path.join(buildroot, 'chroot', test_results_dir) |
| 141 path_to_archive_dir = os.path.join(cbuildbot.ARCHIVE_BASE, str(archive_dir)) | 141 path_to_archive_dir = os.path.join(cbuildbot.ARCHIVE_BASE, str(archive_dir)) |
| 142 path_to_image = os.path.join(buildroot, 'src', 'build', 'images', board, | 142 path_to_image = os.path.join(buildroot, 'src', 'build', 'images', board, |
| 143 'latest', 'chromiumos_qemu_image.bin') | 143 'latest', 'chromiumos_qemu_image.bin') |
| 144 # Archive logic | 144 # Archive logic |
| 145 os.path.exists(path_to_archive_dir).AndReturn(False) | 145 os.path.exists(path_to_archive_dir).AndReturn(False) |
| 146 cbuildbot.RunCommand(['sudo', 'chmod', '-R', '+r', path_to_results]) | 146 cbuildbot.RunCommand(['sudo', 'chmod', '-R', '+r', path_to_results]) |
| 147 shutil.copytree(path_to_results, path_to_archive_dir) | 147 shutil.copytree(path_to_results, path_to_archive_dir) |
| 148 cbuildbot.RunCommand(['gzip', '-f', path_to_image]) | 148 cbuildbot.RunCommand(['gzip', '-f', '--fast', path_to_image]) |
| 149 shutil.copyfile(path_to_image + '.gz', os.path.join( | 149 shutil.copyfile(path_to_image + '.gz', os.path.join( |
| 150 path_to_archive_dir, 'chromiumos_qemu_image.bin.gz')) | 150 path_to_archive_dir, 'chromiumos_qemu_image.bin.gz')) |
| 151 | 151 |
| 152 self.mox.ReplayAll() | 152 self.mox.ReplayAll() |
| 153 cbuildbot.ARCHIVE_COUNT = 2 # Set equal to list size so we force clean up. | 153 cbuildbot.ARCHIVE_COUNT = 2 # Set equal to list size so we force clean up. |
| 154 cbuildbot._ArchiveTestResults(buildroot, board, archive_dir, | 154 cbuildbot._ArchiveTestResults(buildroot, board, archive_dir, |
| 155 test_results_dir) | 155 test_results_dir) |
| 156 self.mox.VerifyAll() | 156 self.mox.VerifyAll() |
| 157 | 157 |
| 158 # TODO(sosa): Remove once we un-comment above. | 158 # TODO(sosa): Remove once we un-comment above. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 enter_chroot=True) | 194 enter_chroot=True) |
| 195 | 195 |
| 196 self.mox.ReplayAll() | 196 self.mox.ReplayAll() |
| 197 cbuildbot._UprevPackages(self._buildroot, self.tracking_branch, | 197 cbuildbot._UprevPackages(self._buildroot, self.tracking_branch, |
| 198 self._revision_file, self._test_board) | 198 self._revision_file, self._test_board) |
| 199 self.mox.VerifyAll() | 199 self.mox.VerifyAll() |
| 200 | 200 |
| 201 | 201 |
| 202 if __name__ == '__main__': | 202 if __name__ == '__main__': |
| 203 unittest.main() | 203 unittest.main() |
| OLD | NEW |