From d381a234e5645db39205f041000c6d4125db2b55 Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Fri, 12 Aug 2016 13:05:09 +0200 Subject: [PATCH] Add tsp/scripts/publish_cmp.py "Unclear" is printed in case: * number of tests run is different * prerelease's result is not 'PASS', but snapshot's is "OK" is printed otherwise. Change-Id: Ic01e7652808f62e5d3c63925d1ea4326a2eeef2c Signed-off-by: Aleksander Mistewicz --- tsp/scripts/publish_cmp.py | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 tsp/scripts/publish_cmp.py diff --git a/tsp/scripts/publish_cmp.py b/tsp/scripts/publish_cmp.py new file mode 100755 index 0000000..15dac31 --- /dev/null +++ b/tsp/scripts/publish_cmp.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +## +# @author Aleksander Mistewicz + +import argparse +import logging +import json + +__version__ = "0.0.1" +__license__ = "APACHE-2.0" +__author__ = "Aleksander Mistewicz" +__author_email__ = "a.mistewicz@samsung.com" + +USAGE = "%prog " + +AGENT = "%s/%s" % (__name__, __version__) + +def compare(snap, pre): + with open(snap, 'r') as snap_f: + snap_json = json.load(snap_f) + + with open(pre, 'r') as pre_f: + pre_json = json.load(pre_f) + + snap_tests = snap_json['tests'] + pre_tests = pre_json['tests'] + + if len(snap_tests) != len(pre_tests): + logging.warn("Number of tests run does not match (%d %d)" % (len(snap_tests), len(pre_tests))) + print "Unclear" + return + + for i in xrange(0, len(snap_tests)): + snap_status = snap_tests[i]['status'] + pre_status = pre_tests[i]['status'] + logging.info("[%s] " % pre_tests[i]['test']\ + + "Snapshot: %s " % snap_status\ + + "Prerelease: %s" % pre_status) + if pre_status != 'PASS' and snap_status != pre_status: + print "Unclear" + return + print "OK" + +def parse_arguments(): + """parse_arguments() -> args + + Parse any command-line options given returning both + the parsed options and arguments. + """ + + parser = argparse.ArgumentParser(description="Comparator of avocado test results in JSON format") + + parser.add_argument("snap", metavar='', type=str, + help='Path to json format of results of test run on snapshot') + + parser.add_argument("pre", metavar='
', type=str,
+            help='Path to json format of results of test run on prerelease')
+
+    parser.add_argument("-l", "--log",
+            action="store", dest="loglevel",
+            help="Verbosity level")
+
+    args = parser.parse_args()
+
+    return args
+
+def main():
+    args = parse_arguments()
+    if args.loglevel:
+        numeric_level = getattr(logging, args.loglevel.upper(), None)
+        if not isinstance(numeric_level, int):
+            raise ValueError('Invalid log level: %s' % args.loglevel)
+        logging.basicConfig(format='%(asctime)s %(message)s',level=numeric_level)
+    logging.debug("Begin")
+    if args.snap and args.pre:
+        compare(args.snap, args.pre)
+    logging.debug("End")
+
+if __name__ == '__main__':
+    main()
-- 
2.7.4