| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import shutil | 10 import shutil |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 for (entry_name, entry_count) in test_cases: | 147 for (entry_name, entry_count) in test_cases: |
| 148 self.assertTrue(entry_name in actual['test_cases']) | 148 self.assertTrue(entry_name in actual['test_cases']) |
| 149 self.assertEqual( | 149 self.assertEqual( |
| 150 entry_count, | 150 entry_count, |
| 151 len(actual['test_cases'][entry_name]), | 151 len(actual['test_cases'][entry_name]), |
| 152 (entry_count, len(actual['test_cases'][entry_name]), entry_name)) | 152 (entry_count, len(actual['test_cases'][entry_name]), entry_name)) |
| 153 | 153 |
| 154 def test_simple_pass(self): | 154 def test_simple_pass(self): |
| 155 out, err, return_code = RunTest( | 155 out, err, return_code = RunTest( |
| 156 [ | 156 [ |
| 157 '--clusters', '1', |
| 157 '--jobs', '3', | 158 '--jobs', '3', |
| 158 '--result', self.filename, | 159 '--result', self.filename, |
| 159 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_pass.py'), | 160 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_pass.py'), |
| 160 ]) | 161 ]) |
| 161 | 162 |
| 162 self.assertEqual(0, return_code) | 163 self.assertEqual(0, return_code) |
| 163 | 164 |
| 164 expected_out_re = [ | 165 expected_out_re = [ |
| 165 r'\[\d/\d\] \d\.\d\ds .+', | 166 r'\[\d/\d\] \d\.\d\ds .+', |
| 166 r'\[\d/\d\] \d\.\d\ds .+', | 167 r'\[\d/\d\] \d\.\d\ds .+', |
| (...skipping 10 matching lines...) Expand all Loading... |
| 177 ('Foo.Bar1', 1), | 178 ('Foo.Bar1', 1), |
| 178 ('Foo.Bar2', 1), | 179 ('Foo.Bar2', 1), |
| 179 ('Foo.Bar/3', 1) | 180 ('Foo.Bar/3', 1) |
| 180 ] | 181 ] |
| 181 self._check_results_file( | 182 self._check_results_file( |
| 182 fail=[], | 183 fail=[], |
| 183 flaky=[], | 184 flaky=[], |
| 184 success=sorted([u'Foo.Bar1', u'Foo.Bar2', u'Foo.Bar/3']), | 185 success=sorted([u'Foo.Bar1', u'Foo.Bar2', u'Foo.Bar/3']), |
| 185 test_cases=test_cases) | 186 test_cases=test_cases) |
| 186 | 187 |
| 188 def test_simple_pass_cluster(self): |
| 189 out, err, return_code = RunTest( |
| 190 [ |
| 191 '--clusters', '10', |
| 192 '--jobs', '1', |
| 193 '--result', self.filename, |
| 194 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_pass.py'), |
| 195 ]) |
| 196 |
| 197 self.assertEqual(0, return_code) |
| 198 |
| 199 expected_out_re = [ |
| 200 r'\[\d/\d\] \d\.\d\ds .+', |
| 201 r'\[\d/\d\] \d\.\d\ds .+', |
| 202 r'\[\d/\d\] \d\.\d\ds .+', |
| 203 re.escape('Summary:'), |
| 204 re.escape(' Success: 3 100.00% ') + r' +\d+\.\d\ds', |
| 205 re.escape(' Flaky: 0 0.00% ') + r' +\d+\.\d\ds', |
| 206 re.escape(' Fail: 0 0.00% ') + r' +\d+\.\d\ds', |
| 207 r' \d+\.\d\ds Done running 3 tests with 3 executions. \d+\.\d\d test/s', |
| 208 ] |
| 209 self._check_results(expected_out_re, out, err) |
| 210 |
| 211 test_cases = [ |
| 212 ('Foo.Bar1', 1), |
| 213 ('Foo.Bar2', 1), |
| 214 ('Foo.Bar/3', 1) |
| 215 ] |
| 216 self._check_results_file( |
| 217 fail=[], |
| 218 flaky=[], |
| 219 success=sorted([u'Foo.Bar1', u'Foo.Bar2', u'Foo.Bar/3']), |
| 220 test_cases=test_cases) |
| 221 |
| 187 def test_simple_pass_verbose(self): | 222 def test_simple_pass_verbose(self): |
| 188 # We take verbosity seriously so test it. | 223 # We take verbosity seriously so test it. |
| 189 out, err, return_code = RunTest( | 224 out, err, return_code = RunTest( |
| 190 [ | 225 [ |
| 191 # Linearize execution. | 226 # Linearize execution. |
| 227 '--clusters', '1', |
| 192 '--jobs', '1', | 228 '--jobs', '1', |
| 193 '--verbose', | 229 '--verbose', |
| 194 '--result', self.filename, | 230 '--result', self.filename, |
| 195 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_pass.py'), | 231 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_pass.py'), |
| 196 ]) | 232 ]) |
| 197 | 233 |
| 198 self.assertEqual(0, return_code) | 234 self.assertEqual(0, return_code) |
| 199 | 235 |
| 200 expected_out_re = [] | 236 expected_out_re = [] |
| 201 test_cases = ( | 237 test_cases = ( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 230 self.assertTrue( | 266 self.assertTrue( |
| 231 re.match( | 267 re.match( |
| 232 r'INFO run_test_cases\(\d+\)\: Found 3 test cases in \S+ ' | 268 r'INFO run_test_cases\(\d+\)\: Found 3 test cases in \S+ ' |
| 233 r'\S+gtest_fake_pass.py', | 269 r'\S+gtest_fake_pass.py', |
| 234 err.strip()), | 270 err.strip()), |
| 235 err) | 271 err) |
| 236 | 272 |
| 237 def test_simple_fail(self): | 273 def test_simple_fail(self): |
| 238 out, err, return_code = RunTest( | 274 out, err, return_code = RunTest( |
| 239 [ | 275 [ |
| 276 # Linearize execution. |
| 277 '--clusters', '1', |
| 240 '--jobs', '1', | 278 '--jobs', '1', |
| 241 '--result', self.filename, | 279 '--result', self.filename, |
| 242 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_fail.py'), | 280 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_fail.py'), |
| 243 ]) | 281 ]) |
| 244 | 282 |
| 245 self.assertEqual(1, return_code) | 283 self.assertEqual(1, return_code) |
| 246 | 284 |
| 247 test_failure_output = [ | 285 test_failure_output = [ |
| 248 re.escape('Note: Google Test filter = Baz.Fail'), | 286 re.escape('Note: Google Test filter = Baz.Fail'), |
| 249 r'', | 287 r'', |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 fail=['Baz.Fail'], | 330 fail=['Baz.Fail'], |
| 293 flaky=[], | 331 flaky=[], |
| 294 success=[u'Foo.Bar1', u'Foo.Bar2', u'Foo.Bar3'], | 332 success=[u'Foo.Bar1', u'Foo.Bar2', u'Foo.Bar3'], |
| 295 test_cases=test_cases) | 333 test_cases=test_cases) |
| 296 | 334 |
| 297 def test_simple_fail_verbose(self): | 335 def test_simple_fail_verbose(self): |
| 298 # We take verbosity seriously so test it. | 336 # We take verbosity seriously so test it. |
| 299 out, err, return_code = RunTest( | 337 out, err, return_code = RunTest( |
| 300 [ | 338 [ |
| 301 # Linearize execution. | 339 # Linearize execution. |
| 340 '--clusters', '1', |
| 302 '--jobs', '1', | 341 '--jobs', '1', |
| 303 '--verbose', | 342 '--verbose', |
| 304 '--result', self.filename, | 343 '--result', self.filename, |
| 305 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_fail.py'), | 344 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_fail.py'), |
| 306 ]) | 345 ]) |
| 307 | 346 |
| 308 self.assertEqual(1, return_code) | 347 self.assertEqual(1, return_code) |
| 309 | 348 |
| 310 expected_out_re = [] | 349 expected_out_re = [] |
| 311 test_cases = ( | 350 test_cases = ( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 self.assertEqual('', err) | 441 self.assertEqual('', err) |
| 403 self.assertEqual(expected_out, out) | 442 self.assertEqual(expected_out, out) |
| 404 self.assertEqual(0, return_code) | 443 self.assertEqual(0, return_code) |
| 405 | 444 |
| 406 def test_flaky_stop_early(self): | 445 def test_flaky_stop_early(self): |
| 407 # gtest_fake_flaky.py has Foo.Bar[1-9]. Each of the test fails once and | 446 # gtest_fake_flaky.py has Foo.Bar[1-9]. Each of the test fails once and |
| 408 # succeeds on the second pass. | 447 # succeeds on the second pass. |
| 409 out, err, return_code = RunTest( | 448 out, err, return_code = RunTest( |
| 410 [ | 449 [ |
| 411 '--result', self.filename, | 450 '--result', self.filename, |
| 412 # Make it determinist. | 451 # Linearize execution. |
| 413 '--clusters', '1', | 452 '--clusters', '1', |
| 414 '--jobs', '1', | 453 '--jobs', '1', |
| 415 '--retries', '1', | 454 '--retries', '1', |
| 416 '--max-failures', '2', | 455 '--max-failures', '2', |
| 417 os.path.join( | 456 os.path.join( |
| 418 ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_flaky.py'), | 457 ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_flaky.py'), |
| 419 self.tempdirpath, | 458 self.tempdirpath, |
| 420 ]) | 459 ]) |
| 421 self.assertEqual(1, return_code) | 460 self.assertEqual(1, return_code) |
| 422 # Give up on checking the stdout. | 461 # Give up on checking the stdout. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 435 test_cases=test_cases) | 474 test_cases=test_cases) |
| 436 | 475 |
| 437 def test_flaky_stop_early_xml(self): | 476 def test_flaky_stop_early_xml(self): |
| 438 # Create an unique filename and delete the file. | 477 # Create an unique filename and delete the file. |
| 439 os.remove(self.filename) | 478 os.remove(self.filename) |
| 440 _, err, return_code = RunTest( | 479 _, err, return_code = RunTest( |
| 441 [ | 480 [ |
| 442 # In that case, it's an XML file even if it has the wrong extension. | 481 # In that case, it's an XML file even if it has the wrong extension. |
| 443 '--gtest_output=xml:' + self.filename, | 482 '--gtest_output=xml:' + self.filename, |
| 444 '--no-dump', | 483 '--no-dump', |
| 445 # Make it determinist. | 484 # Linearize execution. |
| 446 '--clusters', '1', | 485 '--clusters', '1', |
| 447 '--jobs', '1', | 486 '--jobs', '1', |
| 448 '--retries', '1', | 487 '--retries', '1', |
| 449 '--max-failures', '2', | 488 '--max-failures', '2', |
| 450 os.path.join( | 489 os.path.join( |
| 451 ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_flaky.py'), | 490 ROOT_DIR, 'tests', 'gtest_fake', 'gtest_fake_flaky.py'), |
| 452 self.tempdirpath, | 491 self.tempdirpath, |
| 453 ]) | 492 ]) |
| 454 self.assertEqual(1, return_code) | 493 self.assertEqual(1, return_code) |
| 455 # Give up on checking the stdout. | 494 # Give up on checking the stdout. |
| 456 #self.assertTrue('STOPPED EARLY' in out, out) | 495 #self.assertTrue('STOPPED EARLY' in out, out) |
| 457 self.assertEqual('', err) | 496 self.assertEqual('', err) |
| 458 try: | 497 try: |
| 459 actual_xml = load_xml_as_string_and_filter(self.filename) | 498 actual_xml = load_xml_as_string_and_filter(self.filename) |
| 460 except Exception as e: | 499 except Exception as e: |
| 461 print >> sys.stderr, e | 500 print >> sys.stderr, e |
| 462 print >> sys.stderr, self.filename | 501 print >> sys.stderr, self.filename |
| 463 with open(self.filename, 'rb') as f: | 502 with open(self.filename, 'rb') as f: |
| 464 print >> sys.stderr, f.read() | 503 print >> sys.stderr, f.read() |
| 465 self.fail() | 504 self.fail() |
| 466 expected_xml = load_xml_as_string_and_filter( | 505 expected_xml = load_xml_as_string_and_filter( |
| 467 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'expected.xml')) | 506 os.path.join(ROOT_DIR, 'tests', 'gtest_fake', 'expected.xml')) |
| 468 self.assertEqual(expected_xml, actual_xml) | 507 self.assertEqual(expected_xml, actual_xml) |
| 469 | 508 |
| 470 | 509 |
| 471 if __name__ == '__main__': | 510 if __name__ == '__main__': |
| 472 VERBOSE = '-v' in sys.argv | 511 VERBOSE = '-v' in sys.argv |
| 473 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 512 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
| 474 unittest.main() | 513 unittest.main() |
| OLD | NEW |