From 8720e46f5466124556b232924d74aed7833dc233 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20Zingil=C3=A9?= Date: Mon, 22 Sep 2014 16:04:24 +0200 Subject: [PATCH] added merging functionality MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I4e3d6d288ff0f8c5c87c9b1479ead145cf9c79d5 Signed-off-by: Nicolas Zingilé --- packaging/common-suite-launcher.spec | 2 +- src/common-suite-launcher | 54 ++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/packaging/common-suite-launcher.spec b/packaging/common-suite-launcher.spec index 5312267..ebea239 100644 --- a/packaging/common-suite-launcher.spec +++ b/packaging/common-suite-launcher.spec @@ -1,5 +1,5 @@ Name: common-suite-launcher -Version: 2.0.0 +Version: 2.1.0 Release: 0 License: GPL-2.0 Summary: Launcher of Tizen Common test suites diff --git a/src/common-suite-launcher b/src/common-suite-launcher index 7316641..87548ac 100755 --- a/src/common-suite-launcher +++ b/src/common-suite-launcher @@ -28,6 +28,8 @@ from lxml import etree XSDFILE = '/usr/share/testkit-lite/xsd/test_definition.xsd' GLOBALSUITEPATH = '/usr/share/tests/' KNOWNPROFILES = ['ivi', 'common'] +RESXMLDIR = 'result' +RESXMLNAME ='result.xml' #---- Helper functions of the launch_suites function ----# def check_runtest(suitedir): @@ -124,6 +126,39 @@ def print_output(process): else: exit(1) +def format_resultfile(xmlfile, outdir): + """Transforms the testkit xml result file in a txt file. + + The transformation is performed with the result-format tool. + + Args: + xmlfile: xml file to transform. + outdir: output directory of the future txt result file. + + Returns: + """ + format_cmd = ['result-format', '-f', xmlfile, '-o', outdir] + subprocess.call(format_cmd) + +def merge_resultfile(xmlfile, outdir, name): + """Merges testkit-lite xml result files. + + The merging is performed with the testkit-merge tool. + + Args: + xmlfile: testkit-lit xml result files to merge. + outdir: Output directory. + name: Name of the xml result file that will be generated. + + Returns: + """ + resxmlpath = os.path.join(outdir, name) + if os.path.isfile(resxmlpath): + merge_cmd = ['testkit-merge', '-f', xmlfile, resxmlpath, '-o', outdir, '-n', name] + else: + merge_cmd = ['testkit-merge', '-f', xmlfile, '-o', outdir, '-n', name] + subprocess.call(merge_cmd) + #---- subcommand function ----# def list_suites(args): @@ -156,12 +191,17 @@ def list_suites(args): print '-' def launch_suites(args): - + mergedir = os.path.join(args.outdir, RESXMLDIR) + resxmlpath = os.path.join(mergedir, RESXMLNAME) print '##-- Checking integrity of the test suites' if len(args.suites) != len(set(args.suites)): print '-- List of given test suites is invalid !' print 'Error : the list of the test suites to launch should not contains duplicates !' exit (1) + ## remove and re-create final result directory + if os.path.isdir(mergedir): + shutil.rmtree(mergedir) + os.makedirs(mergedir, 0755) for suite in args.suites: profile = suite.split('-', 2)[0] suitepath = os.path.join(GLOBALSUITEPATH, profile, suite) @@ -198,10 +238,11 @@ def launch_suites(args): process = subprocess.Popen([os.path.join(suitepath, 'runtest'), finaloutdir], cwd=suitepath, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print_output(process) - for afile in os.listdir(finaloutdir): - if afile.endswith(".xml"): - format_cmd = ['result-format', '-f', os.path.join(finaloutdir, afile), '-o', finaloutdir] - subprocess.call(format_cmd) + suiteresxmlfiles = get_xmlfiles(finaloutdir) + for asuiteresxmlfile in suiteresxmlfiles: + suiteresxmlpath = os.path.join(finaloutdir, asuiteresxmlfile) + merge_resultfile(suiteresxmlpath, mergedir, RESXMLNAME) + format_resultfile(suiteresxmlpath, finaloutdir) def main (): @@ -219,6 +260,9 @@ def main (): list_suites(args) elif args.subcommand == 'launch': launch_suites(args) + resxmlpath = os.path.join(args.outdir, RESXMLDIR, RESXMLNAME) + if os.path.isfile(resxmlpath): + format_resultfile(resxmlpath, os.path.dirname(resxmlpath)) else: parser.print_usage() -- 2.7.4