diff options
Diffstat (limited to 'scripts/patchtest')
-rwxr-xr-x | scripts/patchtest | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/scripts/patchtest b/scripts/patchtest index 0be7062dc2..9218db232a 100755 --- a/scripts/patchtest +++ b/scripts/patchtest | |||
@@ -9,12 +9,12 @@ | |||
9 | # SPDX-License-Identifier: GPL-2.0-only | 9 | # SPDX-License-Identifier: GPL-2.0-only |
10 | # | 10 | # |
11 | 11 | ||
12 | import sys | 12 | import json |
13 | import os | ||
14 | import unittest | ||
15 | import logging | 13 | import logging |
14 | import os | ||
15 | import sys | ||
16 | import traceback | 16 | import traceback |
17 | import json | 17 | import unittest |
18 | 18 | ||
19 | # Include current path so test cases can see it | 19 | # Include current path so test cases can see it |
20 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) | 20 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) |
@@ -22,16 +22,17 @@ sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) | |||
22 | # Include patchtest library | 22 | # Include patchtest library |
23 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '../meta/lib/patchtest')) | 23 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '../meta/lib/patchtest')) |
24 | 24 | ||
25 | from data import PatchTestInput | 25 | from patchtest_parser import PatchtestParser |
26 | from repo import PatchTestRepo | 26 | from repo import PatchTestRepo |
27 | 27 | ||
28 | import utils | 28 | logger = logging.getLogger("patchtest") |
29 | logger = utils.logger_create('patchtest') | 29 | loggerhandler = logging.StreamHandler() |
30 | loggerhandler.setFormatter(logging.Formatter("%(message)s")) | ||
31 | logger.addHandler(loggerhandler) | ||
32 | logger.setLevel(logging.INFO) | ||
30 | info = logger.info | 33 | info = logger.info |
31 | error = logger.error | 34 | error = logger.error |
32 | 35 | ||
33 | import repo | ||
34 | |||
35 | def getResult(patch, mergepatch, logfile=None): | 36 | def getResult(patch, mergepatch, logfile=None): |
36 | 37 | ||
37 | class PatchTestResult(unittest.TextTestResult): | 38 | class PatchTestResult(unittest.TextTestResult): |
@@ -46,10 +47,10 @@ def getResult(patch, mergepatch, logfile=None): | |||
46 | def startTestRun(self): | 47 | def startTestRun(self): |
47 | # let's create the repo already, it can be used later on | 48 | # let's create the repo already, it can be used later on |
48 | repoargs = { | 49 | repoargs = { |
49 | 'repodir': PatchTestInput.repodir, | 50 | "repodir": PatchtestParser.repodir, |
50 | 'commit' : PatchTestInput.basecommit, | 51 | "commit": PatchtestParser.basecommit, |
51 | 'branch' : PatchTestInput.basebranch, | 52 | "branch": PatchtestParser.basebranch, |
52 | 'patch' : patch, | 53 | "patch": patch, |
53 | } | 54 | } |
54 | 55 | ||
55 | self.repo_error = False | 56 | self.repo_error = False |
@@ -57,7 +58,7 @@ def getResult(patch, mergepatch, logfile=None): | |||
57 | self.test_failure = False | 58 | self.test_failure = False |
58 | 59 | ||
59 | try: | 60 | try: |
60 | self.repo = PatchTestInput.repo = PatchTestRepo(**repoargs) | 61 | self.repo = PatchtestParser.repo = PatchTestRepo(**repoargs) |
61 | except: | 62 | except: |
62 | logger.error(traceback.print_exc()) | 63 | logger.error(traceback.print_exc()) |
63 | self.repo_error = True | 64 | self.repo_error = True |
@@ -128,7 +129,11 @@ def _runner(resultklass, prefix=None): | |||
128 | loader.testMethodPrefix = prefix | 129 | loader.testMethodPrefix = prefix |
129 | 130 | ||
130 | # create the suite with discovered tests and the corresponding runner | 131 | # create the suite with discovered tests and the corresponding runner |
131 | suite = loader.discover(start_dir=PatchTestInput.testdir, pattern=PatchTestInput.pattern, top_level_dir=PatchTestInput.topdir) | 132 | suite = loader.discover( |
133 | start_dir=PatchtestParser.testdir, | ||
134 | pattern=PatchtestParser.pattern, | ||
135 | top_level_dir=PatchtestParser.topdir, | ||
136 | ) | ||
132 | ntc = suite.countTestCases() | 137 | ntc = suite.countTestCases() |
133 | 138 | ||
134 | # if there are no test cases, just quit | 139 | # if there are no test cases, just quit |
@@ -160,24 +165,31 @@ def run(patch, logfile=None): | |||
160 | postmerge_resultklass = getResult(patch, True, logfile) | 165 | postmerge_resultklass = getResult(patch, True, logfile) |
161 | postmerge_result = _runner(postmerge_resultklass, 'test') | 166 | postmerge_result = _runner(postmerge_resultklass, 'test') |
162 | 167 | ||
163 | print('----------------------------------------------------------------------\n') | 168 | print_result_message(premerge_result, postmerge_result) |
164 | if premerge_result == 2 and postmerge_result == 2: | ||
165 | logger.error('patchtest: No test cases found - did you specify the correct suite directory?') | ||
166 | if premerge_result == 1 or postmerge_result == 1: | ||
167 | logger.error('WARNING: patchtest: At least one patchtest caused a failure or an error - please check https://wiki.yoctoproject.org/wiki/Patchtest for further guidance') | ||
168 | else: | ||
169 | logger.info('OK: patchtest: All patchtests passed') | ||
170 | print('----------------------------------------------------------------------\n') | ||
171 | return premerge_result or postmerge_result | 169 | return premerge_result or postmerge_result |
172 | 170 | ||
171 | def print_result_message(preresult, postresult): | ||
172 | print("----------------------------------------------------------------------\n") | ||
173 | if preresult == 2 and postresult == 2: | ||
174 | logger.error( | ||
175 | "patchtest: No test cases found - did you specify the correct suite directory?" | ||
176 | ) | ||
177 | if preresult == 1 or postresult == 1: | ||
178 | logger.error( | ||
179 | "WARNING: patchtest: At least one patchtest caused a failure or an error - please check https://wiki.yoctoproject.org/wiki/Patchtest for further guidance" | ||
180 | ) | ||
181 | else: | ||
182 | logger.info("OK: patchtest: All patchtests passed") | ||
183 | print("----------------------------------------------------------------------\n") | ||
184 | |||
173 | def main(): | 185 | def main(): |
174 | tmp_patch = False | 186 | tmp_patch = False |
175 | patch_path = PatchTestInput.patch_path | 187 | patch_path = PatchtestParser.patch_path |
176 | log_results = PatchTestInput.log_results | 188 | log_results = PatchtestParser.log_results |
177 | log_path = None | 189 | log_path = None |
178 | patch_list = None | 190 | patch_list = None |
179 | 191 | ||
180 | git_status = os.popen("(cd %s && git status)" % PatchTestInput.repodir).read() | 192 | git_status = os.popen("(cd %s && git status)" % PatchtestParser.repodir).read() |
181 | status_matches = ["Changes not staged for commit", "Changes to be committed"] | 193 | status_matches = ["Changes not staged for commit", "Changes to be committed"] |
182 | if any([match in git_status for match in status_matches]): | 194 | if any([match in git_status for match in status_matches]): |
183 | logger.error("patchtest: there are uncommitted changes in the target repo that would be overwritten. Please commit or restore them before running patchtest") | 195 | logger.error("patchtest: there are uncommitted changes in the target repo that would be overwritten. Please commit or restore them before running patchtest") |
@@ -212,16 +224,16 @@ def main(): | |||
212 | if __name__ == '__main__': | 224 | if __name__ == '__main__': |
213 | ret = 1 | 225 | ret = 1 |
214 | 226 | ||
215 | # Parse the command line arguments and store it on the PatchTestInput namespace | 227 | # Parse the command line arguments and store it on the PatchtestParser namespace |
216 | PatchTestInput.set_namespace() | 228 | PatchtestParser.set_namespace() |
217 | 229 | ||
218 | # set debugging level | 230 | # set debugging level |
219 | if PatchTestInput.debug: | 231 | if PatchtestParser.debug: |
220 | logger.setLevel(logging.DEBUG) | 232 | logger.setLevel(logging.DEBUG) |
221 | 233 | ||
222 | # if topdir not define, default it to testdir | 234 | # if topdir not define, default it to testdir |
223 | if not PatchTestInput.topdir: | 235 | if not PatchtestParser.topdir: |
224 | PatchTestInput.topdir = PatchTestInput.testdir | 236 | PatchtestParser.topdir = PatchtestParser.testdir |
225 | 237 | ||
226 | try: | 238 | try: |
227 | ret = main() | 239 | ret = main() |