* [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility @ 2014-09-02 13:10 Lucian Musat 2014-09-02 13:10 ` [PATCH 2/2] oeqa/runtime: Automatic test for ptest Lucian Musat 2014-09-03 14:58 ` [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility Burton, Ross 0 siblings, 2 replies; 7+ messages in thread From: Lucian Musat @ 2014-09-02 13:10 UTC (permalink / raw) To: openembedded-core A module for parsing results based logs like ptest, compliance and performance. Supports breaking the logs into multiple sections and also provides a result object to use the parser with. The parser is initialized with the regex required to identify results and section statements in the target log file. Signed-off-by: Corneliu Stoicescu <corneliux.stoicescu@intel.com> Signed-off-by: Lucian Musat <georgex.l.musat@intel.com> --- meta/lib/oeqa/utils/logparser.py | 127 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 meta/lib/oeqa/utils/logparser.py diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py new file mode 100644 index 0000000..90116c7 --- /dev/null +++ b/meta/lib/oeqa/utils/logparser.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python + +import sys +import os +import re + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'meta/lib'))) +import oeqa.utils.ftools as ftools + + +# A parser that can be used to identify weather a line is a test result or a section statement. +class Lparser(object): + + def __init__(self, test_0_pass_regex, test_0_fail_regex, section_0_begin_regex=None, section_0_end_regex=None, **kwargs): + # Initialize the arguments dictionary + if kwargs: + self.args = kwargs + else: + self.args = {} + + # Add the default args to the dictionary + self.args['test_0_pass_regex'] = test_0_pass_regex + self.args['test_0_fail_regex'] = test_0_fail_regex + if section_0_begin_regex: + self.args['section_0_begin_regex'] = section_0_begin_regex + if section_0_end_regex: + self.args['section_0_end_regex'] = section_0_end_regex + + self.test_possible_status = ['pass', 'fail', 'error'] + self.section_possible_status = ['begin', 'end'] + + self.initialized = False + + + # Initialize the parser with the current configuration + def init(self): + + # extra arguments can be added by the user to define new test and section categories. They must follow a pre-defined pattern: <type>_<category_name>_<status>_regex + self.test_argument_pattern = "^test_(.+?)_(%s)_regex" % '|'.join(map(str, self.test_possible_status)) + self.section_argument_pattern = "^section_(.+?)_(%s)_regex" % '|'.join(map(str, self.section_possible_status)) + + # Initialize the test and section regex dictionaries + self.test_regex = {} + self.section_regex ={} + + for arg, value in self.args.items(): + if not value: + raise Exception('The value of provided argument %s is %s. Should have a valid value.' % (key, value)) + is_test = re.search(self.test_argument_pattern, arg) + is_section = re.search(self.section_argument_pattern, arg) + if is_test: + if not is_test.group(1) in self.test_regex: + self.test_regex[is_test.group(1)] = {} + self.test_regex[is_test.group(1)][is_test.group(2)] = re.compile(value) + elif is_section: + if not is_section.group(1) in self.section_regex: + self.section_regex[is_section.group(1)] = {} + self.section_regex[is_section.group(1)][is_section.group(2)] = re.compile(value) + else: + # TODO: Make these call a traceback instead of a simple exception.. + raise Exception("The provided argument name does not correspond to any valid type. Please give one of the following types:\nfor tests: %s\nfor sections: %s" % (self.test_argument_pattern, self.section_argument_pattern)) + + self.initialized = True + + # Parse a line and return a tuple containing the type of result (test/section) and its category, status and name + def parse_line(self, line): + if not self.initialized: + raise Exception("The parser is not initialized..") + + for test_category, test_status_list in self.test_regex.items(): + for test_status, status_regex in test_status_list.items(): + test_name = status_regex.search(line) + if test_name: + return ['test', test_category, test_status, test_name.group(1)] + + for section_category, section_status_list in self.section_regex.items(): + for section_status, status_regex in section_status_list.items(): + section_name = status_regex.search(line) + if section_name: + return ['section', section_category, section_status, section_name.group(1)] + return None + + +class Result(object): + + def __init__(self): + self.result_dict = {} + + def store(self, section, test, status): + if not section in self.result_dict: + self.result_dict[section] = [] + + self.result_dict[section].append((test, status)) + + # sort tests by the test name(the first element of the tuple), for each section. This can be helpful when using git to diff for changes by making sure they are always in the same order. + def sort_tests(self): + for package in self.result_dict: + sorted_results = sorted(self.result_dict[package], key=lambda tup: tup[0]) + self.result_dict[package] = sorted_results + + # Log the results as files. The file name is the section name and the contents are the tests in that section. + def log_as_files(self, target_dir, test_status): + status_regex = re.compile('|'.join(map(str, test_status))) + if not type(test_status) == type([]): + raise Exception("test_status should be a list. Got " + str(test_status) + " instead.") + if not os.path.exists(target_dir): + raise Exception("Target directory does not exist: %s" % target_dir) + + for section, test_results in self.result_dict.items(): + prefix = '' + for x in test_status: + prefix +=x+'.' + if (section != ''): + prefix += section + section_file = os.path.join(target_dir, prefix) + # purge the file contents if it exists + open(section_file, 'w').close() + for test_result in test_results: + (test_name, status) = test_result + # we log only the tests with status in the test_status list + match_status = status_regex.search(status) + if match_status: + ftools.append_file(section_file, status + ": " + test_name) + + # Not yet implemented! + def log_to_lava(self): + pass \ No newline at end of file -- 1.9.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] oeqa/runtime: Automatic test for ptest 2014-09-02 13:10 [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility Lucian Musat @ 2014-09-02 13:10 ` Lucian Musat 2014-09-03 15:14 ` Burton, Ross 2014-09-03 14:58 ` [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility Burton, Ross 1 sibling, 1 reply; 7+ messages in thread From: Lucian Musat @ 2014-09-02 13:10 UTC (permalink / raw) To: openembedded-core For images without ptest the packages are automatically installed alongside ptest-runner. Log results are saved in ./results folder. No cleanup is done for packages after the test is finished. Signed-off-by: Lucian Musat <georgex.l.musat@intel.com> --- meta/lib/oeqa/runtime/_ptest.py | 124 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 meta/lib/oeqa/runtime/_ptest.py diff --git a/meta/lib/oeqa/runtime/_ptest.py b/meta/lib/oeqa/runtime/_ptest.py new file mode 100644 index 0000000..f945647 --- /dev/null +++ b/meta/lib/oeqa/runtime/_ptest.py @@ -0,0 +1,124 @@ +import unittest, os, shutil +from oeqa.oetest import oeRuntimeTest, skipModule +from oeqa.utils.decorators import * +from oeqa.utils.logparser import * +from oeqa.utils.httpserver import HTTPService +import bb +import glob +from oe.package_manager import RpmPkgsList +import subprocess + +def setUpModule(): + if not oeRuntimeTest.hasFeature("package-management"): + skipModule("Image doesn't have package management feature") + if not oeRuntimeTest.hasPackage("smart"): + skipModule("Image doesn't have smart installed") + if "package_rpm" != oeRuntimeTest.tc.d.getVar("PACKAGE_CLASSES", True).split()[0]: + skipModule("Rpm is not the primary package manager") + +class PtestRunnerTest(oeRuntimeTest): + + # a ptest log parser + def parse_ptest(self, logfile): + parser = Lparser(test_0_pass_regex="^PASS:(.+)", test_0_fail_regex="^FAIL:(.+)", section_0_begin_regex="^BEGIN: .*/(.+)/ptest", section_0_end_regex="^END: .*/(.+)/ptest") + parser.init() + result = Result() + + with open(logfile) as f: + for line in f: + result_tuple = parser.parse_line(line) + if not result_tuple: + continue + result_tuple = line_type, category, status, name = parser.parse_line(line) + + if line_type == 'section' and status == 'begin': + current_section = name + continue + + if line_type == 'section' and status == 'end': + current_section = None + continue + + if line_type == 'test' and status == 'pass': + result.store(current_section, name, status) + continue + + if line_type == 'test' and status == 'fail': + result.store(current_section, name, status) + continue + + result.sort_tests() + return result + + @classmethod + def setUpClass(self): + #note the existing channels that are on the board before creating new ones + self.existingchannels = set() + (status, result) = oeRuntimeTest.tc.target.run('smart channel --show | grep "\["', 0) + for x in result.split("\n"): + self.existingchannels.add(x) + self.repo_server = HTTPService(oeRuntimeTest.tc.d.getVar('DEPLOY_DIR', True), oeRuntimeTest.tc.target.server_ip) + self.repo_server.start() + + @classmethod + def tearDownClass(self): + self.repo_server.stop() + #remove created channels to be able to repeat the tests on same image + (status, result) = oeRuntimeTest.tc.target.run('smart channel --show | grep "\["', 0) + for x in result.split("\n"): + if x not in self.existingchannels: + oeRuntimeTest.tc.target.run('smart channel --remove '+x[1:-1]+' -y', 0) + + def add_smart_channel(self): + image_pkgtype = self.tc.d.getVar('IMAGE_PKGTYPE', True) + deploy_url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, image_pkgtype) + pkgarchs = self.tc.d.getVar('PACKAGE_ARCHS', True).replace("-","_").split() + for arch in os.listdir('%s/%s' % (self.repo_server.root_dir, image_pkgtype)): + if arch in pkgarchs: + self.target.run('smart channel -y --add {a} type=rpm-md baseurl={u}/{a}'.format(a=arch, u=deploy_url), 0) + self.target.run('smart update', 0) + + def install_complementary(self, globs=None): + installed_pkgs_file = os.path.join(oeRuntimeTest.tc.d.getVar('WORKDIR', True), + "installed_pkgs.txt") + self.pkgs_list = RpmPkgsList(oeRuntimeTest.tc.d, oeRuntimeTest.tc.d.getVar('IMAGE_ROOTFS', True), oeRuntimeTest.tc.d.getVar('arch_var', True), oeRuntimeTest.tc.d.getVar('os_var', True)) + with open(installed_pkgs_file, "w+") as installed_pkgs: + installed_pkgs.write(self.pkgs_list.list("arch")) + + cmd = [bb.utils.which(os.getenv('PATH'), "oe-pkgdata-util"), + "glob", oeRuntimeTest.tc.d.getVar('PKGDATA_DIR', True), installed_pkgs_file, + globs] + try: + bb.note("Installing complementary packages ...") + complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + bb.fatal("Could not compute complementary packages list. Command " + "'%s' returned %d:\n%s" % + (' '.join(cmd), e.returncode, e.output)) + + return complementary_pkgs.split() + + def setUp(self): + self.buildhist_dir = oeRuntimeTest.tc.d.getVar("BUILDHISTORY_DIR_IMAGE", True) + self.assertTrue(os.path.exists(self.buildhist_dir)) + self.ptest_log = os.path.join(oeRuntimeTest.tc.d.getVar("TEST_LOG_DIR",True), "ptest-%s.log" % oeRuntimeTest.tc.d.getVar('DATETIME', True)) + + @skipUnlessPassed('test_ssh') + def test_ptestrunner(self): + self.add_smart_channel() + self.install_packages(self.install_complementary("*-ptest")) + self.install_packages(['ptest-runner']) + + self.target.run('/usr/bin/ptest-runner > /tmp/ptest.log 2>&1', 0) + self.target.copy_from('/tmp/ptest.log', self.ptest_log) + shutil.copyfile(self.ptest_log, os.path.join(self.buildhist_dir, "ptest.log")) + + result = self.parse_ptest(os.path.join(self.buildhist_dir, "ptest.log")) + log_results_to_location = os.path.join('./results') + if not os.path.exists(log_results_to_location): + os.makedirs(log_results_to_location) + + # clear the results directory each time + for path in os.listdir(log_results_to_location): + os.remove(os.path.join(log_results_to_location, path)) + result.log_as_files(log_results_to_location, test_status = ['fail']) -- 1.9.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] oeqa/runtime: Automatic test for ptest 2014-09-02 13:10 ` [PATCH 2/2] oeqa/runtime: Automatic test for ptest Lucian Musat @ 2014-09-03 15:14 ` Burton, Ross 2014-09-03 22:10 ` Richard Purdie 2014-09-04 9:54 ` Musat, GeorgeX L 0 siblings, 2 replies; 7+ messages in thread From: Burton, Ross @ 2014-09-03 15:14 UTC (permalink / raw) To: Lucian Musat; +Cc: OE-core On 2 September 2014 14:10, Lucian Musat <georgex.l.musat@intel.com> wrote: > + @classmethod > + def tearDownClass(self): > + self.repo_server.stop() > + #remove created channels to be able to repeat the tests on same image > + (status, result) = oeRuntimeTest.tc.target.run('smart channel --show | grep "\["', 0) > + for x in result.split("\n"): > + if x not in self.existingchannels: > + oeRuntimeTest.tc.target.run('smart channel --remove '+x[1:-1]+' -y', 0) If we're not removing the packages we've installed, why do we bother removing the smart channels? > + @skipUnlessPassed('test_ssh') > + def test_ptestrunner(self): > + self.add_smart_channel() > + self.install_packages(self.install_complementary("*-ptest")) > + self.install_packages(['ptest-runner']) Can't you check if the ptest IMAGE_FEATURE is enabled and if so, skip this? > + log_results_to_location = os.path.join('./results') Joining a single item doesn't do anything. > + if not os.path.exists(log_results_to_location): > + os.makedirs(log_results_to_location) > + > + # clear the results directory each time > + for path in os.listdir(log_results_to_location): > + os.remove(os.path.join(log_results_to_location, path)) I'd do something more like as it's a lot less lines and clear that you're deleting the old tree and then creating a fresh one: if os.path.exists(logdir): shutil.rmtree(logdir) os.makedirs(logdir) Ross ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] oeqa/runtime: Automatic test for ptest 2014-09-03 15:14 ` Burton, Ross @ 2014-09-03 22:10 ` Richard Purdie 2014-09-04 9:54 ` Musat, GeorgeX L 1 sibling, 0 replies; 7+ messages in thread From: Richard Purdie @ 2014-09-03 22:10 UTC (permalink / raw) To: Burton, Ross; +Cc: OE-core On Wed, 2014-09-03 at 16:14 +0100, Burton, Ross wrote: > On 2 September 2014 14:10, Lucian Musat <georgex.l.musat@intel.com> wrote: > > + @classmethod > > + def tearDownClass(self): > > + self.repo_server.stop() > > + #remove created channels to be able to repeat the tests on same image > > + (status, result) = oeRuntimeTest.tc.target.run('smart channel --show | grep "\["', 0) > > + for x in result.split("\n"): > > + if x not in self.existingchannels: > > + oeRuntimeTest.tc.target.run('smart channel --remove '+x[1:-1]+' -y', 0) > > If we're not removing the packages we've installed, why do we bother > removing the smart channels? > > > + @skipUnlessPassed('test_ssh') > > + def test_ptestrunner(self): > > + self.add_smart_channel() > > + self.install_packages(self.install_complementary("*-ptest")) > > + self.install_packages(['ptest-runner']) > > Can't you check if the ptest IMAGE_FEATURE is enabled and if so, skip this? Also, this is smart specific so we probably need an "isRPM?" type check somewhere in this test (or use librbary functions and have support for other package backends but that is something for another patch series sometime). Cheers, Richard > > + log_results_to_location = os.path.join('./results') > > Joining a single item doesn't do anything. > > > + if not os.path.exists(log_results_to_location): > > + os.makedirs(log_results_to_location) > > + > > + # clear the results directory each time > > + for path in os.listdir(log_results_to_location): > > + os.remove(os.path.join(log_results_to_location, path)) > > I'd do something more like as it's a lot less lines and clear that > you're deleting the old tree and then creating a fresh one: > > if os.path.exists(logdir): > shutil.rmtree(logdir) > os.makedirs(logdir) > > > Ross ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] oeqa/runtime: Automatic test for ptest 2014-09-03 15:14 ` Burton, Ross 2014-09-03 22:10 ` Richard Purdie @ 2014-09-04 9:54 ` Musat, GeorgeX L 1 sibling, 0 replies; 7+ messages in thread From: Musat, GeorgeX L @ 2014-09-04 9:54 UTC (permalink / raw) To: Burton, Ross, Richard Purdie; +Cc: OE-core I remove the Smart channels because it helps me to retest using simpleremote. I think I should comment that part but leave it there for future use. isRPM test is being done in setupModule(): if "package_rpm" != oeRuntimeTest.tc.d.getVar("PACKAGE_CLASSES", True).split()[0]: skipModule("Rpm is not the primary package manager") I will do the rest of the modifications, thank you for the suggestions Regards, Lucian -----Original Message----- From: Burton, Ross [mailto:ross.burton@intel.com] Sent: Wednesday, September 03, 2014 6:14 PM To: Musat, GeorgeX L Cc: OE-core Subject: Re: [OE-core] [PATCH 2/2] oeqa/runtime: Automatic test for ptest On 2 September 2014 14:10, Lucian Musat <georgex.l.musat@intel.com> wrote: > + @classmethod > + def tearDownClass(self): > + self.repo_server.stop() > + #remove created channels to be able to repeat the tests on same image > + (status, result) = oeRuntimeTest.tc.target.run('smart channel --show | grep "\["', 0) > + for x in result.split("\n"): > + if x not in self.existingchannels: > + oeRuntimeTest.tc.target.run('smart channel --remove > + '+x[1:-1]+' -y', 0) If we're not removing the packages we've installed, why do we bother removing the smart channels? > + @skipUnlessPassed('test_ssh') > + def test_ptestrunner(self): > + self.add_smart_channel() > + self.install_packages(self.install_complementary("*-ptest")) > + self.install_packages(['ptest-runner']) Can't you check if the ptest IMAGE_FEATURE is enabled and if so, skip this? > + log_results_to_location = os.path.join('./results') Joining a single item doesn't do anything. > + if not os.path.exists(log_results_to_location): > + os.makedirs(log_results_to_location) > + > + # clear the results directory each time > + for path in os.listdir(log_results_to_location): > + os.remove(os.path.join(log_results_to_location, path)) I'd do something more like as it's a lot less lines and clear that you're deleting the old tree and then creating a fresh one: if os.path.exists(logdir): shutil.rmtree(logdir) os.makedirs(logdir) Ross ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility 2014-09-02 13:10 [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility Lucian Musat 2014-09-02 13:10 ` [PATCH 2/2] oeqa/runtime: Automatic test for ptest Lucian Musat @ 2014-09-03 14:58 ` Burton, Ross 2014-09-03 15:14 ` Stoicescu, CorneliuX 1 sibling, 1 reply; 7+ messages in thread From: Burton, Ross @ 2014-09-03 14:58 UTC (permalink / raw) To: Lucian Musat; +Cc: OE-core On 2 September 2014 14:10, Lucian Musat <georgex.l.musat@intel.com> wrote: > +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'meta/lib'))) > +import oeqa.utils.ftools as ftools Doesn't that add .../poky/meta/lib/oeqa/meta/lib to the search path, which doesn't make any sense. You shouldn't need to mess with the path to import a sibling module. Ross ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility 2014-09-03 14:58 ` [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility Burton, Ross @ 2014-09-03 15:14 ` Stoicescu, CorneliuX 0 siblings, 0 replies; 7+ messages in thread From: Stoicescu, CorneliuX @ 2014-09-03 15:14 UTC (permalink / raw) To: Burton, Ross, Musat, GeorgeX L; +Cc: OE-core > -----Original Message----- > From: openembedded-core-bounces@lists.openembedded.org > [mailto:openembedded-core-bounces@lists.openembedded.org] On Behalf > Of Burton, Ross > Sent: Wednesday, September 03, 2014 5:59 PM > To: Musat, GeorgeX L > Cc: OE-core > Subject: Re: [OE-core] [PATCH 1/2] oeqa/utils/logparser.py: results based log > parser utility > > On 2 September 2014 14:10, Lucian Musat <georgex.l.musat@intel.com> > wrote: > > +sys.path.insert(0, > > +os.path.abspath(os.path.join(os.path.dirname(__file__), '..', > > +'meta/lib'))) import oeqa.utils.ftools as ftools > > Doesn't that add .../poky/meta/lib/oeqa/meta/lib to the search path, which > doesn't make any sense. You shouldn't need to mess with the path to import > a sibling module. > > Ross Yes, that should be removed. It stayed over from when this was a standalone script. Please remove this and just use 'import ftools' . Regards, Corneliu ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-09-04 9:54 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-09-02 13:10 [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility Lucian Musat 2014-09-02 13:10 ` [PATCH 2/2] oeqa/runtime: Automatic test for ptest Lucian Musat 2014-09-03 15:14 ` Burton, Ross 2014-09-03 22:10 ` Richard Purdie 2014-09-04 9:54 ` Musat, GeorgeX L 2014-09-03 14:58 ` [PATCH 1/2] oeqa/utils/logparser.py: results based log parser utility Burton, Ross 2014-09-03 15:14 ` Stoicescu, CorneliuX
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox