[oe-commits] [openembedded-core] 13/14: resulttool/regression: Change to use gitarchive git repo code

git at git.openembedded.org git at git.openembedded.org
Wed Feb 20 18:01:02 UTC 2019


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit c2cd79691cea5cb9c1d2a7c5009342e2bf01cc14
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Wed Feb 20 17:10:14 2019 +0000

    resulttool/regression: Change to use gitarchive git repo code
    
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 scripts/lib/resulttool/regression.py  | 84 +++++++++++++++++++++++++++++------
 scripts/lib/resulttool/report.py      | 22 ++++-----
 scripts/lib/resulttool/resultutils.py | 43 +++++++++++++-----
 3 files changed, 115 insertions(+), 34 deletions(-)

diff --git a/scripts/lib/resulttool/regression.py b/scripts/lib/resulttool/regression.py
index 112f1ad..ff77332 100644
--- a/scripts/lib/resulttool/regression.py
+++ b/scripts/lib/resulttool/regression.py
@@ -12,10 +12,12 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 #
-from resulttool.resultutils import checkout_git_dir
 import resulttool.resultutils as resultutils
 import json
 
+from oeqa.utils.git import GitRepo
+import oeqa.utils.gitarchive as gitarchive
+
 def compare_result(logger, base_name, target_name, base_result, target_result):
     base_result = base_result.get('result')
     target_result = target_result.get('result')
@@ -89,12 +91,66 @@ def regression_common(args, logger, base_results, target_results):
 def regression_git(args, logger):
     base_results = {}
     target_results = {}
-    if checkout_git_dir(args.source_dir, args.base_git_branch):
-        base_results = get_results(logger, args.source_dir)
-    if checkout_git_dir(args.source_dir, args.target_git_branch):
-        target_results = get_results(logger, args.source_dir)
 
-    regression_common(args, logger, base_result, target_result)
+    tag_name = "{branch}/{commit_number}-g{commit}/{tag_number}"
+    repo = GitRepo(args.repo)
+
+    revs = gitarchive.get_test_revs(logger, repo, tag_name, branch=args.branch)
+
+    if args.branch2:
+        revs2 = gitarchive.get_test_revs(logger, repo, tag_name, branch=args.branch2)
+        if not len(revs2):
+            logger.error("No revisions found to compare against")
+            return 1
+        if not len(revs):
+            logger.error("No revision to report on found")
+            return 1
+    else:
+        if len(revs) < 2:
+            logger.error("Only %d tester revisions found, unable to generate report" % len(revs))
+            return 1
+
+    # Pick revisions
+    if args.commit:
+        if args.commit_number:
+            logger.warning("Ignoring --commit-number as --commit was specified")
+        index1 = gitarchive.rev_find(revs, 'commit', args.commit)
+    elif args.commit_number:
+        index1 = gitarchive.rev_find(revs, 'commit_number', args.commit_number)
+    else:
+        index1 = len(revs) - 1
+
+    if args.branch2:
+        revs2.append(revs[index1])
+        index1 = len(revs2) - 1
+        revs = revs2
+
+    if args.commit2:
+        if args.commit_number2:
+            logger.warning("Ignoring --commit-number2 as --commit2 was specified")
+        index2 = gitarchive.rev_find(revs, 'commit', args.commit2)
+    elif args.commit_number2:
+        index2 = gitarchive.rev_find(revs, 'commit_number', args.commit_number2)
+    else:
+        if index1 > 0:
+            index2 = index1 - 1
+            # Find the closest matching commit number for comparision
+            # In future we could check the commit is a common ancestor and
+            # continue back if not but this good enough for now
+            while index2 > 0 and revs[index2].commit_number > revs[index1].commit_number:
+                index2 = index2 - 1
+        else:
+            logger.error("Unable to determine the other commit, use "
+                      "--commit2 or --commit-number2 to specify it")
+            return 1
+
+    logger.info("Comparing:\n%s\nto\n%s\n" % (revs[index1], revs[index2]))
+
+    base_results = resultutils.git_get_result(repo, revs[index1][2])
+    target_results = resultutils.git_get_result(repo, revs[index2][2])
+
+    regression_common(args, logger, base_results, target_results)
+
     return 0
 
 def register_commands(subparsers):
@@ -118,13 +174,8 @@ def register_commands(subparsers):
                                                      'result set',
                                          group='analysis')
     parser_build.set_defaults(func=regression_git)
-    parser_build.add_argument('source_dir',
-                              help='source directory that contain the git repository with test result files')
-    parser_build.add_argument('base_git_branch',
-                              help='base git branch that provide the files for base result set')
-    parser_build.add_argument('target_git_branch',
-                              help='target git branch that provide the files for target result set for comparison with '
-                                   'base result')
+    parser_build.add_argument('repo',
+                              help='the git repository containing the data')
     parser_build.add_argument('-b', '--base-result-id', default='',
                               help='(optional) default select regression based on configurations unless base result '
                                    'id was provided')
@@ -132,3 +183,10 @@ def register_commands(subparsers):
                               help='(optional) default select regression based on configurations unless target result '
                                    'id was provided')
 
+    parser_build.add_argument('--branch', '-B', default='master', help="Branch to find commit in")
+    parser_build.add_argument('--branch2', help="Branch to find comparision revisions in")
+    parser_build.add_argument('--commit', help="Revision to search for")
+    parser_build.add_argument('--commit-number', help="Revision number to search for, redundant if --commit is specified")
+    parser_build.add_argument('--commit2', help="Revision to compare with")
+    parser_build.add_argument('--commit-number2', help="Revision number to compare with, redundant if --commit2 is specified")
+
diff --git a/scripts/lib/resulttool/report.py b/scripts/lib/resulttool/report.py
index ec7d583..2f5ea30 100644
--- a/scripts/lib/resulttool/report.py
+++ b/scripts/lib/resulttool/report.py
@@ -15,8 +15,10 @@
 import os
 import glob
 import json
-from resulttool.resultutils import checkout_git_dir
 import resulttool.resultutils as resultutils
+from oeqa.utils.git import GitRepo
+import oeqa.utils.gitarchive as gitarchive
+
 
 class ResultsTextReport(object):
     def __init__(self):
@@ -99,11 +101,13 @@ class ResultsTextReport(object):
                                  maxlen=maxlen)
         print(output)
 
-    def view_test_report(self, logger, source_dir, git_branch):
-        if git_branch:
-            checkout_git_dir(source_dir, git_branch)
+    def view_test_report(self, logger, source_dir, tag):
         test_count_reports = []
-        testresults = resultutils.load_resultsdata(source_dir)
+        if tag:
+            repo = GitRepo(source_dir)
+            testresults = resultutils.git_get_result(repo, [tag])
+        else:
+            testresults = resultutils.load_resultsdata(source_dir)
         for testsuite in testresults:
             for resultid in testresults[testsuite]:
                 result = testresults[testsuite][resultid]
@@ -115,7 +119,7 @@ class ResultsTextReport(object):
 
 def report(args, logger):
     report = ResultsTextReport()
-    report.view_test_report(logger, args.source_dir, args.git_branch)
+    report.view_test_report(logger, args.source_dir, args.tag)
     return 0
 
 def register_commands(subparsers):
@@ -126,7 +130,5 @@ def register_commands(subparsers):
     parser_build.set_defaults(func=report)
     parser_build.add_argument('source_dir',
                               help='source file/directory that contain the test result files to summarise')
-    parser_build.add_argument('-b', '--git-branch', default='',
-                              help='(optional) default assume source directory contains all available files for '
-                                   'reporting unless a git branch was provided where it will try to checkout '
-                                   'the provided git branch assuming source directory was a git repository')
+    parser_build.add_argument('-t', '--tag', default='',
+                              help='source_dir is a git repository, report on the tag specified from that repository')
diff --git a/scripts/lib/resulttool/resultutils.py b/scripts/lib/resulttool/resultutils.py
index 464d693..06cceef 100644
--- a/scripts/lib/resulttool/resultutils.py
+++ b/scripts/lib/resulttool/resultutils.py
@@ -16,15 +16,6 @@ import os
 import json
 import scriptpath
 scriptpath.add_oe_lib_path()
-from oeqa.utils.git import GitRepo, GitError
-
-def checkout_git_dir(git_dir, git_branch):
-    try:
-        repo = GitRepo(git_dir, is_topdir=True)
-        repo.run_cmd('checkout %s' % git_branch)
-        return True
-    except GitError:
-        return False
 
 flatten_map = {
     "oeselftest": [],
@@ -49,8 +40,11 @@ store_map = {
 # Load the json file and append the results data into the provided results dict
 #
 def append_resultsdata(results, f, configmap=store_map):
-    with open(f, "r") as filedata:
-        data = json.load(filedata)
+    if type(f) is str:
+        with open(f, "r") as filedata:
+            data = json.load(filedata)
+    else:
+        data = f
     for res in data:
         if "configuration" not in data[res] or "result" not in data[res]:
             raise ValueError("Test results data without configuration or result section?")
@@ -104,3 +98,30 @@ def save_resultsdata(results, destdir, fn="testresults.json"):
         os.makedirs(os.path.dirname(dst), exist_ok=True)
         with open(dst, 'w') as f:
             f.write(json.dumps(results[res], sort_keys=True, indent=4))
+
+def git_get_result(repo, tags):
+    git_objs = []
+    for tag in tags:
+        files = repo.run_cmd(['ls-tree', "--name-only", "-r", tag]).splitlines()
+        git_objs.extend([tag + ':' + f for f in files if f.endswith("testresults.json")])
+
+    def parse_json_stream(data):
+        """Parse multiple concatenated JSON objects"""
+        objs = []
+        json_d = ""
+        for line in data.splitlines():
+            if line == '}{':
+                json_d += '}'
+                objs.append(json.loads(json_d))
+                json_d = '{'
+            else:
+                json_d += line
+        objs.append(json.loads(json_d))
+        return objs
+
+    # Optimize by reading all data with one git command
+    results = {}
+    for obj in parse_json_stream(repo.run_cmd(['show'] + git_objs + ['--'])):
+        append_resultsdata(results, obj)
+
+    return results

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list