perfalizer_unittest.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Copyright (C) 2012 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. import unittest2 as unittest
  29. from webkitpy.common.net.buildbot import Builder
  30. from webkitpy.common.system.executive import ScriptError
  31. from webkitpy.common.system.outputcapture import OutputCapture
  32. from webkitpy.port.test import TestPort
  33. from webkitpy.tool.commands.perfalizer import PerfalizerTask
  34. from webkitpy.tool.mocktool import MockTool
  35. class PerfalizerTaskTest(unittest.TestCase):
  36. def _create_and_run_perfalizer(self, commands_to_fail=[]):
  37. tool = MockTool()
  38. patch = tool.bugs.fetch_attachment(10000)
  39. logs = []
  40. def logger(message):
  41. logs.append(message)
  42. def run_webkit_patch(args):
  43. if args[0] in commands_to_fail:
  44. raise ScriptError
  45. def run_perf_test(build_path, description):
  46. self.assertTrue(description == 'without 10000' or description == 'with 10000')
  47. if 'run-perf-tests' in commands_to_fail:
  48. return -1
  49. if 'results-page' not in commands_to_fail:
  50. tool.filesystem.write_text_file(tool.filesystem.join(build_path, 'PerformanceTestResults.html'), 'results page')
  51. return 0
  52. perfalizer = PerfalizerTask(tool, patch, logger)
  53. perfalizer._port = TestPort(tool)
  54. perfalizer.run_webkit_patch = run_webkit_patch
  55. perfalizer._run_perf_test = run_perf_test
  56. capture = OutputCapture()
  57. capture.capture_output()
  58. if commands_to_fail:
  59. self.assertFalse(perfalizer.run())
  60. else:
  61. self.assertTrue(perfalizer.run())
  62. capture.restore_output()
  63. return logs
  64. def test_run(self):
  65. self.assertEqual(self._create_and_run_perfalizer(), [
  66. 'Preparing to run performance tests for the attachment 10000...',
  67. 'Building WebKit at r1234 without the patch',
  68. 'Building WebKit at r1234 with the patch',
  69. 'Running performance tests...',
  70. 'Uploaded the results on the bug 50000'])
  71. def test_run_with_clean_fails(self):
  72. self.assertEqual(self._create_and_run_perfalizer(['clean']), [
  73. 'Preparing to run performance tests for the attachment 10000...',
  74. 'Unable to clean working directory'])
  75. def test_run_with_update_fails(self):
  76. logs = self._create_and_run_perfalizer(['update'])
  77. self.assertEqual(len(logs), 2)
  78. self.assertEqual(logs[-1], 'Unable to update working directory')
  79. def test_run_with_build_fails(self):
  80. logs = self._create_and_run_perfalizer(['build'])
  81. self.assertEqual(len(logs), 3)
  82. def test_run_with_build_fails(self):
  83. logs = self._create_and_run_perfalizer(['apply-attachment'])
  84. self.assertEqual(len(logs), 4)
  85. def test_run_with_perf_test_fails(self):
  86. logs = self._create_and_run_perfalizer(['run-perf-tests'])
  87. self.assertEqual(len(logs), 5)
  88. self.assertEqual(logs[-1], 'Failed to run performance tests without the patch.')
  89. def test_run_without_results_page(self):
  90. logs = self._create_and_run_perfalizer(['results-page'])
  91. self.assertEqual(len(logs), 5)
  92. self.assertEqual(logs[-1], 'Failed to generate the results page.')