Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: appengine/findit/util_scripts/crash_queries/delta_test/delta_test.py

Issue 2435863003: [Findit] Add local git parsers. (Closed)
Patch Set: Rebase. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 json 5 import json
6 import logging 6 import logging
7 import os 7 import os
8 import pickle 8 import pickle
9 import subprocess 9 import subprocess
10 10
11 from crash_queries import crash_iterator 11 from crash_queries import crash_iterator
12 from crash_queries.delta_test import delta_util 12 from crash_queries.delta_test import delta_util
13 13
14 AZALEA_RESULTS_DIRECTORY = os.path.join(os.path.dirname(__file__), 14 AZALEA_RESULTS_DIRECTORY = os.path.join(os.path.dirname(__file__),
15 'azalea_results') 15 'azalea_results')
16 DELTA_TEST_DIRECTORY = os.path.dirname(__file__) 16 DELTA_TEST_DIRECTORY = os.path.dirname(__file__)
17 17
18 18
19 class Delta(object): 19 # TODO(crbug.com/662540): Add unittests.
20 class Delta(object): # pragma: no cover.
20 """Stands for delta between two results. 21 """Stands for delta between two results.
21 22
22 Note, the 2 results should be the same kind and have the same structure. 23 Note, the 2 results should be the same kind and have the same structure.
23 """ 24 """
24 25
25 def __init__(self, result1, result2, fields): 26 def __init__(self, result1, result2, fields):
26 self._result1 = result1 27 self._result1 = result1
27 self._result2 = result2 28 self._result2 = result2
28 self._fields = fields 29 self._fields = fields
29 self._delta_dict = {} 30 self._delta_dict = {}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 def __str__(self): 74 def __str__(self):
74 return '\n'.join(self.delta_str_dict.values()) 75 return '\n'.join(self.delta_str_dict.values())
75 76
76 def __bool__(self): 77 def __bool__(self):
77 return bool(self.delta_dict) 78 return bool(self.delta_dict)
78 79
79 def __nonzero__(self): 80 def __nonzero__(self):
80 return self.__bool__() 81 return self.__bool__()
81 82
82 83
83 def GetDeltasFromTwoSetsOfResults(set1, set2): 84 # TODO(crbug.com/662540): Add unittests.
85 def GetDeltasFromTwoSetsOfResults(set1, set2): # pragma: no cover.
84 """Gets delta from two sets of results. 86 """Gets delta from two sets of results.
85 87
86 Set1 and set2 are dicts mapping id to result. 88 Set1 and set2 are dicts mapping id to result.
87 Results are a list of (message, matches, component_name, cr_label) 89 Results are a list of (message, matches, component_name, cr_label)
88 Returns a list of delta results (results1, results2). 90 Returns a list of delta results (results1, results2).
89 """ 91 """
90 deltas = {} 92 deltas = {}
91 for result_id, result1 in set1.iteritems(): 93 for result_id, result1 in set1.iteritems():
92 # Even when the command are exactly the same, it's possible that one set is 94 # Even when the command are exactly the same, it's possible that one set is
93 # loaded from local result file, another is just queried from database, 95 # loaded from local result file, another is just queried from database,
94 # sometimes some crash results would get deleted. 96 # sometimes some crash results would get deleted.
95 if result_id not in set2: 97 if result_id not in set2:
96 continue 98 continue
97 99
98 result2 = set2[result_id] 100 result2 = set2[result_id]
99 delta = Delta(result1, result2, result1.fields) 101 delta = Delta(result1, result2, result1.fields)
100 if delta: 102 if delta:
101 deltas[result_id] = delta 103 deltas[result_id] = delta
102 104
103 return deltas 105 return deltas
104 106
105 107
106 def GetResults(crashes, client_id, git_hash, result_path, verbose=False): 108 # TODO(crbug.com/662540): Add unittests.
109 def GetResults(crashes, client_id, git_hash, result_path,
110 verbose=False): # pragma: no cover.
107 """Returns an evaluator function to compute delta between 2 findit githashes. 111 """Returns an evaluator function to compute delta between 2 findit githashes.
108 112
109 Args: 113 Args:
110 crashes (list): A list of crash infos. 114 crashes (list): A list of crash infos.
111 client_id (str): Possible values - fracas/cracas/clustefuzz. 115 client_id (str): Possible values - fracas/cracas/clustefuzz.
112 git_hash (str): A git hash of findit repository. 116 git_hash (str): A git hash of findit repository.
113 result_path (str): file path for subprocess to write results on. 117 result_path (str): file path for subprocess to write results on.
114 verbose (bool): If True, print all the findit results. 118 verbose (bool): If True, print all the findit results.
115 119
116 Return: 120 Return:
(...skipping 29 matching lines...) Expand all
146 if not os.path.exists(result_path): 150 if not os.path.exists(result_path):
147 logging.error('Failed to get results.') 151 logging.error('Failed to get results.')
148 return {} 152 return {}
149 153
150 with open(result_path) as f: 154 with open(result_path) as f:
151 return pickle.load(f) 155 return pickle.load(f)
152 156
153 return {} 157 return {}
154 158
155 159
160 # TODO(crbug.com/662540): Add unittests.
156 def DeltaEvaluator(git_hash1, git_hash2, 161 def DeltaEvaluator(git_hash1, git_hash2,
157 client_id, app_id, 162 client_id, app_id,
158 start_date, end_date, batch_size, 163 start_date, end_date, batch_size,
159 property_values=None, verbose=False): 164 property_values=None, verbose=False): # pragma: no cover.
160 """Evaluates delta between git_hash1 and git_hash2 on a set of Testcases. 165 """Evaluates delta between git_hash1 and git_hash2 on a set of Testcases.
161 166
162 Args: 167 Args:
163 git_hash1 (str): A git hash of findit repository. 168 git_hash1 (str): A git hash of findit repository.
164 git_hash2 (str): A git hash of findit repository. 169 git_hash2 (str): A git hash of findit repository.
165 start_date (str): Run delta test on testcases after (including) 170 start_date (str): Run delta test on testcases after (including)
166 the start_date, format should be '%Y-%m-%d'. 171 the start_date, format should be '%Y-%m-%d'.
167 end_date (str): Run delta test on testcases before (not including) 172 end_date (str): Run delta test on testcases before (not including)
168 the end_date, format should be '%Y-%m-%d'. 173 the end_date, format should be '%Y-%m-%d'.
169 client_id (CrashClient): Possible values are 'fracas', 'cracas', 174 client_id (CrashClient): Possible values are 'fracas', 'cracas',
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 207
203 crash_count += len(crashes) 208 crash_count += len(crashes)
204 deltas.update(GetDeltasFromTwoSetsOfResults(*results)) 209 deltas.update(GetDeltasFromTwoSetsOfResults(*results))
205 210
206 return deltas, crash_count 211 return deltas, crash_count
207 finally: 212 finally:
208 with open(os.devnull, 'w') as null_handle: 213 with open(os.devnull, 'w') as null_handle:
209 subprocess.check_call(['git', 'checkout', head_branch_name], 214 subprocess.check_call(['git', 'checkout', head_branch_name],
210 stdout=null_handle, 215 stdout=null_handle,
211 stderr=null_handle) 216 stderr=null_handle)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698