| 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 import optparse | 7 import optparse |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import unittest | 10 import unittest |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 for line in lines: | 57 for line in lines: |
| 58 if line.startswith("Total PASS:"): | 58 if line.startswith("Total PASS:"): |
| 59 # FORMAT: ^TOTAL PASS: num_passed/num_total (percent%)$ | 59 # FORMAT: ^TOTAL PASS: num_passed/num_total (percent%)$ |
| 60 percent_passed = line.split()[3].strip('()%') | 60 percent_passed = line.split()[3].strip('()%') |
| 61 Info('Percent of tests passed %s' % percent_passed) | 61 Info('Percent of tests passed %s' % percent_passed) |
| 62 break | 62 break |
| 63 | 63 |
| 64 return int(percent_passed) | 64 return int(percent_passed) |
| 65 | 65 |
| 66 # TODO(sosa) - Remove try and convert function to DeltaUpdateImage(). |
| 67 def TryDeltaAndFallbackToFull(self, src_image, image, stateful_change='old'): |
| 68 """Tries the delta update first if set and falls back to full update.""" |
| 69 if self.use_delta_updates: |
| 70 try: |
| 71 self.source_image = src_image |
| 72 self.UpdateImage(image) |
| 73 except: |
| 74 Warning('Delta update failed, disabling delta updates and retrying.') |
| 75 self.use_delta_updates = False |
| 76 self.source_image = '' |
| 77 self.UpdateImage(image) |
| 78 else: |
| 79 self.UpdateImage(image) |
| 80 |
| 66 def PrepareBase(self): | 81 def PrepareBase(self): |
| 67 """Prepares target with base_image_path.""" | 82 """Prepares target with base_image_path.""" |
| 68 pass | 83 pass |
| 69 | 84 |
| 70 def UpdateImage(self, image_path, stateful_change='old'): | 85 def UpdateImage(self, image_path, stateful_change='old'): |
| 71 """Updates target with the image given by the image_path. | 86 """Updates target with the image given by the image_path. |
| 72 | 87 |
| 73 Args: | 88 Args: |
| 74 image_path: Path to the image to update with. This image must be a test | 89 image_path: Path to the image to update with. This image must be a test |
| 75 image. | 90 image. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 This test checks that we can update by updating the stateful partition | 138 This test checks that we can update by updating the stateful partition |
| 124 rather than wiping it. | 139 rather than wiping it. |
| 125 """ | 140 """ |
| 126 # Just make sure some tests pass on original image. Some old images | 141 # Just make sure some tests pass on original image. Some old images |
| 127 # don't pass many tests. | 142 # don't pass many tests. |
| 128 self.PrepareBase() | 143 self.PrepareBase() |
| 129 # TODO(sosa): move to 100% once we start testing using the autotest paired | 144 # TODO(sosa): move to 100% once we start testing using the autotest paired |
| 130 # with the dev channel. | 145 # with the dev channel. |
| 131 percent_passed = self.VerifyImage(10) | 146 percent_passed = self.VerifyImage(10) |
| 132 | 147 |
| 133 if self.use_delta_updates: self.source_image = base_image_path | |
| 134 | |
| 135 # Update to - all tests should pass on new image. | 148 # Update to - all tests should pass on new image. |
| 136 Info('Updating from base image on vm to target image.') | 149 Info('Updating from base image on vm to target image.') |
| 137 try: | 150 self.TryDeltaAndFallbackToFull(base_image_path, target_image_path) |
| 138 self.UpdateImage(target_image_path) | |
| 139 except: | |
| 140 if self.use_delta_updates: | |
| 141 Warning('Delta update failed, disabling delta updates and retrying.') | |
| 142 self.use_delta_updates = False | |
| 143 self.source_image = '' | |
| 144 self.UpdateImage(target_image_path) | |
| 145 else: | |
| 146 raise | |
| 147 | |
| 148 self.VerifyImage(100) | 151 self.VerifyImage(100) |
| 149 | 152 |
| 150 if self.use_delta_updates: self.source_image = target_image_path | |
| 151 | |
| 152 # Update from - same percentage should pass that originally passed. | 153 # Update from - same percentage should pass that originally passed. |
| 153 Info('Updating from updated image on vm back to base image.') | 154 Info('Updating from updated image on vm back to base image.') |
| 154 self.UpdateImage(base_image_path) | 155 self.TryDeltaAndFallbackToFull(target_image_path, base_image_path) |
| 155 self.VerifyImage(percent_passed) | 156 self.VerifyImage(percent_passed) |
| 156 | 157 |
| 157 def testFullUpdateWipeStateful(self): | 158 def testFullUpdateWipeStateful(self): |
| 158 """Tests if we can update after cleaning the stateful partition. | 159 """Tests if we can update after cleaning the stateful partition. |
| 159 | 160 |
| 160 This test checks that we can update successfully after wiping the | 161 This test checks that we can update successfully after wiping the |
| 161 stateful partition. | 162 stateful partition. |
| 162 """ | 163 """ |
| 163 # Just make sure some tests pass on original image. Some old images | 164 # Just make sure some tests pass on original image. Some old images |
| 164 # don't pass many tests. | 165 # don't pass many tests. |
| 165 self.PrepareBase() | 166 self.PrepareBase() |
| 166 # TODO(sosa): move to 100% once we start testing using the autotest paired | 167 # TODO(sosa): move to 100% once we start testing using the autotest paired |
| 167 # with the dev channel. | 168 # with the dev channel. |
| 168 percent_passed = self.VerifyImage(10) | 169 percent_passed = self.VerifyImage(10) |
| 169 | 170 |
| 170 if self.use_delta_updates: self.source_image = base_image_path | |
| 171 | |
| 172 # Update to - all tests should pass on new image. | 171 # Update to - all tests should pass on new image. |
| 173 Info('Updating from base image on vm to target image and wiping stateful.') | 172 Info('Updating from base image on vm to target image and wiping stateful.') |
| 174 try: | 173 self.TryDeltaAndFallbackToFull(base_image_path, target_image_path, 'clean') |
| 175 self.UpdateImage(target_image_path, 'clean') | |
| 176 except: | |
| 177 if self.use_delta_updates: | |
| 178 Warning('Delta update failed, disabling delta updates and retrying.') | |
| 179 self.use_delta_updates = False | |
| 180 self.source_image = '' | |
| 181 self.UpdateImage(target_image_path) | |
| 182 else: | |
| 183 raise | |
| 184 | |
| 185 self.VerifyImage(100) | 174 self.VerifyImage(100) |
| 186 | 175 |
| 187 if self.use_delta_updates: self.source_image = target_image_path | |
| 188 | |
| 189 # Update from - same percentage should pass that originally passed. | 176 # Update from - same percentage should pass that originally passed. |
| 190 Info('Updating from updated image back to base image and wiping stateful.') | 177 Info('Updating from updated image back to base image and wiping stateful.') |
| 191 self.UpdateImage(base_image_path, 'clean') | 178 self.TryDeltaAndFallbackToFull(target_image_path, base_image_path, 'clean') |
| 192 self.VerifyImage(percent_passed) | 179 self.VerifyImage(percent_passed) |
| 193 | 180 |
| 194 | 181 |
| 195 class RealAUTest(unittest.TestCase, AUTest): | 182 class RealAUTest(unittest.TestCase, AUTest): |
| 196 """Test harness for updating real images.""" | 183 """Test harness for updating real images.""" |
| 197 | 184 |
| 198 def setUp(self): | 185 def setUp(self): |
| 199 AUTest.setUp(self) | 186 AUTest.setUp(self) |
| 200 | 187 |
| 201 def PrepareBase(self): | 188 def PrepareBase(self): |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 else: | 343 else: |
| 357 remote = options.remote | 344 remote = options.remote |
| 358 | 345 |
| 359 suite = unittest.TestLoader().loadTestsFromTestCase(RealAUTest) | 346 suite = unittest.TestLoader().loadTestsFromTestCase(RealAUTest) |
| 360 test_result = unittest.TextTestRunner(verbosity=2).run(suite) | 347 test_result = unittest.TextTestRunner(verbosity=2).run(suite) |
| 361 else: | 348 else: |
| 362 parser.error('Could not parse harness type %s.' % options.type) | 349 parser.error('Could not parse harness type %s.' % options.type) |
| 363 | 350 |
| 364 if not test_result.wasSuccessful(): | 351 if not test_result.wasSuccessful(): |
| 365 Die('Test harness was not successful') | 352 Die('Test harness was not successful') |
| OLD | NEW |