| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 | 7 |
| 8 from google.appengine.ext import testbed | 8 from google.appengine.ext import testbed |
| 9 | 9 |
| 10 import webapp2 | 10 import webapp2 |
| 11 import webtest | 11 import webtest |
| 12 | 12 |
| 13 from common.waterfall import failure_type | 13 from common.waterfall import failure_type |
| 14 from handlers import build_failure | 14 from handlers import build_failure |
| 15 from handlers import handlers_util | 15 from handlers import handlers_util |
| 16 from handlers import result_status | 16 from handlers import result_status |
| 17 from model import analysis_approach_type | 17 from model import analysis_approach_type |
| 18 from model import analysis_status | 18 from model import analysis_status |
| 19 from model import suspected_cl_status | 19 from model import suspected_cl_status |
| 20 from model.suspected_cl_confidence import ConfidenceInformation | 20 from model.suspected_cl_confidence import ConfidenceInformation |
| 21 from model.suspected_cl_confidence import SuspectedCLConfidence | 21 from model.suspected_cl_confidence import SuspectedCLConfidence |
| 22 from model.wf_analysis import WfAnalysis | 22 from model.wf_analysis import WfAnalysis |
| 23 from model.wf_suspected_cl import WfSuspectedCL | 23 from model.wf_suspected_cl import WfSuspectedCL |
| 24 from model.wf_try_job import WfTryJob | 24 from model.wf_try_job import WfTryJob |
| 25 from waterfall import build_util | 25 from waterfall import build_util |
| 26 from waterfall import buildbot | 26 from waterfall import buildbot |
| 27 from waterfall import build_util |
| 27 from waterfall.test import wf_testcase | 28 from waterfall.test import wf_testcase |
| 28 | 29 |
| 29 # Root directory appengine/findit. | 30 # Root directory appengine/findit. |
| 30 ROOT_DIR = os.path.join(os.path.dirname(__file__), | 31 ROOT_DIR = os.path.join(os.path.dirname(__file__), |
| 31 os.path.pardir, os.path.pardir) | 32 os.path.pardir, os.path.pardir) |
| 32 | 33 |
| 33 SAMPLE_TRY_JOB_INFO = { | 34 SAMPLE_TRY_JOB_INFO = { |
| 34 'm/b/119': { | 35 'm/b/119': { |
| 35 'step1 on platform': { | 36 'step1 on platform': { |
| 36 'try_jobs': [ | 37 'try_jobs': [ |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 'first_failure': 122, | 776 'first_failure': 122, |
| 776 'last_pass': 121, | 777 'last_pass': 121, |
| 777 'suspected_cls_by_heuristic': [], | 778 'suspected_cls_by_heuristic': [], |
| 778 } | 779 } |
| 779 | 780 |
| 780 data = {} | 781 data = {} |
| 781 build_failure._PopulateHeuristicDataForCompileFailure( | 782 build_failure._PopulateHeuristicDataForCompileFailure( |
| 782 analysis, data) | 783 analysis, data) |
| 783 self.assertEqual(expected_data, data) | 784 self.assertEqual(expected_data, data) |
| 784 | 785 |
| 786 def _PercentFormat(self, float_number): |
| 787 return '%d%%' % (round(float_number * 100)) |
| 788 |
| 785 def testGetTryJobResultForCompileFailure(self): | 789 def testGetTryJobResultForCompileFailure(self): |
| 786 analysis = WfAnalysis.Create('m', 'b', 123) | 790 analysis = WfAnalysis.Create('m', 'b', 123) |
| 787 analysis.result = { | 791 analysis.result = { |
| 788 'failures': [ | 792 'failures': [ |
| 789 { | 793 { |
| 790 'step_name': 'compile', | 794 'step_name': 'compile', |
| 791 'first_failure': 122, | 795 'first_failure': 122, |
| 792 'last_pass': 121, | 796 'last_pass': 121, |
| 793 'suspected_cls': [], | 797 'suspected_cls': [], |
| 794 }, | 798 }, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 'failed': False, | 852 'failed': False, |
| 849 } | 853 } |
| 850 | 854 |
| 851 expected_suspected_cls = [ | 855 expected_suspected_cls = [ |
| 852 { | 856 { |
| 853 'repo_name': 'chromium', | 857 'repo_name': 'chromium', |
| 854 'revision': 'rev', | 858 'revision': 'rev', |
| 855 'commit_position': 122, | 859 'commit_position': 122, |
| 856 'url': None, | 860 'url': None, |
| 857 'status': suspected_cl_status.CORRECT, | 861 'status': suspected_cl_status.CORRECT, |
| 858 'confidence': build_failure._PercentFormat( | 862 'confidence': self._PercentFormat( |
| 859 self.cl_confidences.compile_heuristic_try_job.confidence) | 863 self.cl_confidences.compile_heuristic_try_job.confidence) |
| 860 } | 864 } |
| 861 ] | 865 ] |
| 862 | 866 |
| 863 build_url = buildbot.CreateBuildUrl('m', 'b', 123) | 867 build_url = buildbot.CreateBuildUrl('m', 'b', 123) |
| 864 response = self.test_app.get('/build-failure', | 868 response = self.test_app.get('/build-failure', |
| 865 params={'url': build_url, 'format': 'json'}) | 869 params={'url': build_url, 'format': 'json'}) |
| 866 | 870 |
| 867 self.assertEquals(200, response.status_int) | 871 self.assertEquals(200, response.status_int) |
| 868 self.assertEqual(expected_try_job_result, response.json_body['try_job']) | 872 self.assertEqual(expected_try_job_result, response.json_body['try_job']) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 'url': None, | 907 'url': None, |
| 904 'status': None, | 908 'status': None, |
| 905 'confidence': None | 909 'confidence': None |
| 906 } | 910 } |
| 907 ] | 911 ] |
| 908 | 912 |
| 909 suspected_cls = build_failure._GetAllSuspectedCLsAndCheckStatus( | 913 suspected_cls = build_failure._GetAllSuspectedCLsAndCheckStatus( |
| 910 master_name, builder_name, build_number, analysis) | 914 master_name, builder_name, build_number, analysis) |
| 911 self.assertEqual( | 915 self.assertEqual( |
| 912 expected_suspected_cls, suspected_cls) | 916 expected_suspected_cls, suspected_cls) |
| 913 | |
| 914 def testGetConfidenceScoreTestHeuristic(self): | |
| 915 build = { | |
| 916 'failure_type': failure_type.TEST, | |
| 917 'failures': None, | |
| 918 'status': suspected_cl_status.CORRECT, | |
| 919 'approaches': [analysis_approach_type.HEURISTIC], | |
| 920 'top_score': 5 | |
| 921 } | |
| 922 | |
| 923 self.assertEqual( | |
| 924 build_failure._PercentFormat( | |
| 925 self.cl_confidences.test_heuristic[1].confidence), | |
| 926 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 927 | |
| 928 def testGetConfidenceScoreCompileHeuristic(self): | |
| 929 build = { | |
| 930 'failure_type': failure_type.COMPILE, | |
| 931 'failures': None, | |
| 932 'status': suspected_cl_status.CORRECT, | |
| 933 'approaches': [analysis_approach_type.HEURISTIC], | |
| 934 'top_score': 4 | |
| 935 } | |
| 936 | |
| 937 self.assertEqual( | |
| 938 build_failure._PercentFormat( | |
| 939 self.cl_confidences.compile_heuristic[1].confidence), | |
| 940 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 941 | |
| 942 def testGetConfidenceScoreTestTryJob(self): | |
| 943 build = { | |
| 944 'failure_type': failure_type.TEST, | |
| 945 'failures': None, | |
| 946 'status': suspected_cl_status.CORRECT, | |
| 947 'approaches': [analysis_approach_type.TRY_JOB], | |
| 948 'top_score': 5 | |
| 949 } | |
| 950 | |
| 951 self.assertEqual( | |
| 952 build_failure._PercentFormat( | |
| 953 self.cl_confidences.test_try_job.confidence), | |
| 954 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 955 | |
| 956 def testGetConfidenceScoreCompileTryJob(self): | |
| 957 build = { | |
| 958 'failure_type': failure_type.COMPILE, | |
| 959 'failures': None, | |
| 960 'status': suspected_cl_status.CORRECT, | |
| 961 'approaches': [analysis_approach_type.TRY_JOB], | |
| 962 'top_score': 5 | |
| 963 } | |
| 964 | |
| 965 self.assertEqual( | |
| 966 build_failure._PercentFormat( | |
| 967 self.cl_confidences.test_try_job.confidence), | |
| 968 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 969 | |
| 970 def testGetConfidenceScoreTestHeuristicTryJob(self): | |
| 971 build = { | |
| 972 'failure_type': failure_type.TEST, | |
| 973 'failures': None, | |
| 974 'status': suspected_cl_status.CORRECT, | |
| 975 'approaches': [analysis_approach_type.HEURISTIC, | |
| 976 analysis_approach_type.TRY_JOB], | |
| 977 'top_score': 5 | |
| 978 } | |
| 979 | |
| 980 self.assertEqual( | |
| 981 build_failure._PercentFormat( | |
| 982 self.cl_confidences.test_heuristic_try_job.confidence), | |
| 983 build_failure._GetConfidenceScore(self.cl_confidences, build)) | |
| 984 | |
| 985 def testGetConfidenceScoreNone(self): | |
| 986 self.assertIsNone(build_failure._GetConfidenceScore(None, None)) | |
| 987 | |
| 988 def testGetConfidenceScoreUnexpected(self): | |
| 989 build = { | |
| 990 'failure_type': failure_type.COMPILE, | |
| 991 'failures': None, | |
| 992 'status': suspected_cl_status.CORRECT, | |
| 993 'approaches': [analysis_approach_type.HEURISTIC], | |
| 994 'top_score': 2 | |
| 995 } | |
| 996 | |
| 997 self.assertIsNone(build_failure._GetConfidenceScore( | |
| 998 self.cl_confidences, build)) | |
| 999 | |
| 1000 def testGetConfidenceScoreCompileNone(self): | |
| 1001 build = { | |
| 1002 'failure_type': failure_type.COMPILE, | |
| 1003 'approaches': [] | |
| 1004 } | |
| 1005 self.assertIsNone(build_failure._GetConfidenceScore( | |
| 1006 self.cl_confidences, build)) | |
| 1007 | |
| 1008 def testGetConfidenceScoreUnexpectedTest(self): | |
| 1009 build = { | |
| 1010 'failure_type': failure_type.TEST, | |
| 1011 'failures': None, | |
| 1012 'status': suspected_cl_status.CORRECT, | |
| 1013 'approaches': [analysis_approach_type.HEURISTIC], | |
| 1014 'top_score': 2 | |
| 1015 } | |
| 1016 | |
| 1017 self.assertIsNone(build_failure._GetConfidenceScore( | |
| 1018 self.cl_confidences, build)) | |
| 1019 | |
| 1020 def testGetConfidenceScoreTestNone(self): | |
| 1021 build = { | |
| 1022 'failure_type': failure_type.TEST, | |
| 1023 'approaches': [] | |
| 1024 } | |
| 1025 self.assertIsNone(build_failure._GetConfidenceScore( | |
| 1026 self.cl_confidences, build)) | |
| 1027 | |
| 1028 def testPercentFormatNone(self): | |
| 1029 self.assertIsNone(build_failure._PercentFormat(None)) | |
| OLD | NEW |