[OE-core] [scripts][PATCH] yocto-layer: Stops duplication of "meta-" prefix

2015-07-29 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

The yocto-layer script puts an extra "meta-" prefix to the given layer
name even when the prefix is already there. This fix avoids
duplicating the prefix in these situations.

[YOCTO #8050]

Signed-off-by: Humberto Ibarra 
---
 scripts/yocto-layer | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/yocto-layer b/scripts/yocto-layer
index 53d2aab..0dbbf3b 100755
--- a/scripts/yocto-layer
+++ b/scripts/yocto-layer
@@ -74,6 +74,8 @@ def yocto_layer_create_subcommand(args, usage_str):
 
 if options.outdir:
 layer_output_dir = options.outdir
+elif layer_name.startswith("meta-"):
+layer_output_dir = layer_name
 else:
 layer_output_dir = "meta-" + layer_name
 
-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH v2] scripts/yocto-layer Change to the yocto-layer script. The fix avoids the duplication of the "meta-" prefix on the layer directory when creating a new layer with the prefix already

2015-12-08 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Before the change:

$ yocto-layer create meta-layer2
...
New layer created in meta-meta-layer2.

-

After the change:

$ yocto-layer create meta-layer2
...
New layer created in meta-layer2.

Signed-off-by: Humberto Ibarra 
---
 scripts/yocto-layer | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/scripts/yocto-layer b/scripts/yocto-layer
index 53d2aab..313d464 100755
--- a/scripts/yocto-layer
+++ b/scripts/yocto-layer
@@ -75,7 +75,11 @@ def yocto_layer_create_subcommand(args, usage_str):
 if options.outdir:
 layer_output_dir = options.outdir
 else:
-layer_output_dir = "meta-" + layer_name
+prefix="meta-"
+if not layer_name.startswith(prefix):
+layer_output_dir="%s%s"%(prefix,layer_name)
+else:
+layer_output_dir=layer_name
 
 yocto_layer_create(layer_name, scripts_path, layer_output_dir, 
options.codedump, options.properties_file, properties)
 
-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH v3] scripts/yocto-layer: Avoids duplication of "meta-" prefix

2015-12-09 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

The yocto-layer script puts and extra "meta-" prefix on the given layer
name even when the prefix is already there. This fix avoids duplicating
the prefix in these situations.

The change was done inside the create subcommand since this is a parsing
specific to the layer creation. Parsing this in the main method of
yocto-layer was not the right way to go.

Before the change:

$ yocto-layer create meta-layer
[...]
New layer created in meta-meta-layer.

After the change:

$ yocto-layer create meta-layer
[...]
New layer created in meta-layer.

[YOCTO #8050]

Signed-off-by: Humberto Ibarra 
---
 scripts/yocto-layer | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/scripts/yocto-layer b/scripts/yocto-layer
index 53d2aab..313d464 100755
--- a/scripts/yocto-layer
+++ b/scripts/yocto-layer
@@ -75,7 +75,11 @@ def yocto_layer_create_subcommand(args, usage_str):
 if options.outdir:
 layer_output_dir = options.outdir
 else:
-layer_output_dir = "meta-" + layer_name
+prefix="meta-"
+if not layer_name.startswith(prefix):
+layer_output_dir="%s%s"%(prefix,layer_name)
+else:
+layer_output_dir=layer_name
 
 yocto_layer_create(layer_name, scripts_path, layer_output_dir, 
options.codedump, options.properties_file, properties)
 
-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH] scripts/oe-selftest: Remove extra coverage data added to unittests

2015-12-23 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Coverage data tracking initiates too early, causing coverage data from the
oe-selftest environment setting to be added to each run. Even when no tests are 
run
oe-selftest reports around 24% of coverage due to this extra data.

Change the custom resultclass used by the TextTestRunner to one generated from 
the
command arguments. The generated class processes coverage when needed, running
coverage setup just before the first testcase is run and reporting after the 
last
one finished.

[Yocto #8846]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 172 +++-
 1 file changed, 103 insertions(+), 69 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index bc50b2a..0eb586c 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -342,6 +342,55 @@ def list_tags():
 
 print 'Tags:\t%s' % ', '.join(str(x) for x in tags)
 
+def coverage_setup(run_tests, run_all_tests):
+""" Set up the coverage measurement for the testcases to be run """
+builddir = os.environ.get("BUILDDIR")
+coveragerc = "%s/.coveragerc" % builddir
+data_file = "%s/.coverage." % builddir
+data_file += ((run_tests and '.'.join(run_tests)) or
+(run_all_tests and "all_tests") or "")
+if os.path.isfile(data_file):
+os.remove(data_file)
+with open(coveragerc, 'w') as cps:
+cps.write("[run]\n")
+cps.write("data_file = %s\n" % data_file)
+cps.write("branch = True\n")
+# Measure just BBLAYERS, scripts and bitbake folders
+cps.write("source = \n")
+for layer in get_bb_var('BBLAYERS').split():
+cps.write("%s\n" % layer)
+cps.write("%s\n" % os.path.dirname(os.path.realpath(__file__)))
+cps.write("%s\n" % 
os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),'bitbake'))
+
+return coveragerc
+
+def coverage_report():
+""" Loads the coverage data gathered and reports it back """
+try:
+# Coverage4 uses coverage.Coverage
+from coverage import Coverage
+except:
+# Coverage under version 4 uses coverage.coverage
+from coverage import coverage as Coverage
+
+import cStringIO as StringIO
+from coverage.misc import CoverageException
+
+cov_output = StringIO.StringIO()
+# Creating the coverage data with the setting from the configuration file
+cov = Coverage(config_file = os.environ.get('COVERAGE_PROCESS_START'))
+try:
+# Load data from the data file specified in the configuration
+cov.load()
+# Store report data in a StringIO variable
+cov.report(file = cov_output, show_missing=False)
+log.info("\n%s" % cov_output.getvalue())
+except CoverageException as e:
+# Show problems with the reporting. Since Coverage4 not finding  any 
data to report raises an exception
+log.warn("%s" % str(e))
+finally:
+cov_output.close()
+
 
 def main():
 parser = get_args_parser()
@@ -409,42 +458,6 @@ def main():
 if not preflight_check():
 return 1
 
-if args.coverage:
-try:
-# check if user can do coverage
-import coverage
-log.info("Coverage is enabled")
-except:
-log.warn(("python coverage is not installed\n",
-  "Make sure you are also coverage takes into account 
sub-process\n",
-  "More info on 
https://pypi.python.org/pypi/coverage\n";))
-
-# In case the user has not set the variable COVERAGE_PROCESS_START,
-# create a default one and export it. The COVERAGE_PROCESS_START
-# value indicates where the coverage configuration file resides
-# More info on https://pypi.python.org/pypi/coverage
-coverage_process_start = os.environ.get('COVERAGE_PROCESS_START')
-if not coverage_process_start:
-builddir = os.environ.get("BUILDDIR")
-coveragerc = "%s/.coveragerc" % builddir
-data_file = "%s/.coverage." % builddir
-data_file += ((args.run_tests and ".".join(args.run_tests)) or
-  (args.run_all_tests and ".all_tests") or '')
-if os.path.isfile(data_file):
-os.remove(data_file)
-with open(coveragerc, 'w') as cps:
-cps.write("[run]\n")
-cps.write("data_file = %s\n" % data_file)
-cps.write("branch = True\n")
-# Measure just BBLAYERS, scripts and bitbake folders
-cps.write("source = \n")
-for layer in get_bb_var('BBLAYERS').split():
-cps.write("%s\n" % layer)
-cps.write("%s\n" % 
os.path.dirname(os.path.realpath(__file__)))
-c

[OE-core] [PATCH 0/2] Coverage filering and configuration file for sub-process in $HOME

2016-02-16 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Enables filtering to the files to be measured with coverage and adds
temporal file to enable subprocessing

Humberto Ibarra (2):
  scripts/oe-selftest: Add filtering to the coverage data  gathered
by oe-selftest
  scripts/oe-selftest: Use site.USER_SITE to run coverage 
configuration code for sub-process

 scripts/oe-selftest | 71 +
 1 file changed, 55 insertions(+), 16 deletions(-)

-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH 1/2] scripts/oe-selftest: Add filtering to the coverage data gathered by oe-selftest

2016-02-16 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

When --coverage is used, oe-selftest gathers coverage data from the testcases
executed. The command lacks a way of filtering which files to gather coverage
data from.

This patch adds three options to specify which files should be considered.
The --coverage-source option specifies folders, while --coverage-include and
--coverage-omit specify patterns to have an extra level of filtering.

Some examples:

1. oe-selftest --run-all-tests --coverage

Gathers coverage data from the default poky folders

2. oe-selftest --run-all-tests --coverage --coverage-include 
/home/me/poky/scripts/*

Gathers coverage data only for the files located under '/home/me/poky/scripts'

3. oe-selftest --run-all-tests -coverage --coverage-omit /home/me/poky/meta*

Gathers coverage data. Files inside all the folders starting with 'meta' under
'/home/me/poky' are omited

4. oe-selftest --run-all-tests --coverage --coverage-source 
/home/me/poky/bitbake

Gathers coverage data only from files inside the folder: '/home/me/poky/bitbake'

[Yocto #8920]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 32 +---
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index 4eb404b..f3865e4 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -78,6 +78,9 @@ def get_args_parser():
 group.add_argument('--list-modules', required=False, action="store_true", 
dest="list_modules", default=False, help='List all available test modules.')
 group.add_argument('--list-classes', required=False, action="store_true", 
dest="list_allclasses", default=False, help='List all available test classes.')
 parser.add_argument('--coverage', action="store_true", help="Run code 
coverage when testing")
+parser.add_argument('--coverage-source', dest="coverage_source", 
nargs="+", help="Specifiy the directories to take coverage from")
+parser.add_argument('--coverage-include', dest="coverage_include", 
nargs="+", help="Specify extra patterns to include into the coverage 
measurement")
+parser.add_argument('--coverage-omit', dest="coverage_omit", nargs="+", 
help="Specify with extra patterns to exclude from the coverage measurement")
 group.add_argument('--run-tests-by', required=False, dest='run_tests_by', 
default=False, nargs='*',
help='run-tests-by  ')
 group.add_argument('--list-tests-by', required=False, 
dest='list_tests_by', default=False, nargs='*',
@@ -369,7 +372,7 @@ def list_tags():
 
 print 'Tags:\t%s' % ', '.join(str(x) for x in tags)
 
-def coverage_setup(run_tests, run_all_tests):
+def coverage_setup(run_tests, run_all_tests, coverage_source, 
coverage_include, coverage_omit):
 """ Set up the coverage measurement for the testcases to be run """
 builddir = os.environ.get("BUILDDIR")
 coveragerc = "%s/.coveragerc" % builddir
@@ -384,10 +387,25 @@ def coverage_setup(run_tests, run_all_tests):
 cps.write("branch = True\n")
 # Measure just BBLAYERS, scripts and bitbake folders
 cps.write("source = \n")
-for layer in get_bb_var('BBLAYERS').split():
-cps.write("%s\n" % layer)
-cps.write("%s\n" % os.path.dirname(os.path.realpath(__file__)))
-cps.write("%s\n" % 
os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),'bitbake'))
+if coverage_source:
+for directory in coverage_source:
+if not os.path.isdir(directory):
+log.warn("Directory %s is not valid.", directory)
+cps.write("%s\n" % directory)
+else:
+for layer in get_bb_var('BBLAYERS').split():
+cps.write("%s\n" % layer)
+cps.write("%s\n" % os.path.dirname(os.path.realpath(__file__)))
+cps.write("%s\n" % 
os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),'bitbake'))
+
+if coverage_include:
+cps.write("include = \n")
+for pattern in coverage_include:
+cps.write("%s\n" % pattern)
+if coverage_omit:
+cps.write("omit = \n")
+for pattern in coverage_omit:
+cps.write("%s\n" % pattern)
 
 return coveragerc
 
@@ -550,7 +568,7 @@ def buildResultClass(args):
 
 def startTestRun(self):
 """ Setup coverage before running any testcase """
-if args.coverage:
+if args.coverage or args.coverage_source or args.coverage_include 
or args.coverage_omit:
 try:
 # check if user can do coverage
 import coverage
@@ -561,7 +579,7 @@ def buildResultClass(args):
 # value indicates where the coverage configuration file 
resides
 # More info on https://pypi.python.org/pypi/coverage
 if not os.environ.get('COVERAGE_PROCESS_ST

[OE-core] [PATCH 2/2] scripts/oe-selftest: Use site.USER_SITE to run coverage configuration code for sub-process

2016-02-16 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Coverage in oe-selftest currently requires to create or modify
a sitecustomize.py file according the coverage tool setup instructions
(http://coverage.readthedocs.org/). This file has to be located in
the system's python folder, which is not a good solution since this
folder is not accesible to non-privileged users.

The best solution so far is to create this file in the home directory.
This is implemented by creating the temporal file in the user site
default folder.

[Yocto #8930]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 41 +++--
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index f3865e4..3159d22 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -553,6 +553,7 @@ def main():
 
 def buildResultClass(args):
 """Build a Result Class to use in the testcase execution"""
+import site
 
 class StampedResult(unittest.TextTestResult):
 """
@@ -568,26 +569,41 @@ def buildResultClass(args):
 
 def startTestRun(self):
 """ Setup coverage before running any testcase """
+
+# variable holding the coverage configuration file allowing 
subprocess to be measured
+self.coveragepth = None
+
+# indicates the system if coverage is currently installed
+self.coverage_installed = True
+
 if args.coverage or args.coverage_source or args.coverage_include 
or args.coverage_omit:
 try:
 # check if user can do coverage
 import coverage
-log.info("Coverage is enabled")
-
-# In case the user has not set the variable 
COVERAGE_PROCESS_START,
-# create a default one and export it. The 
COVERAGE_PROCESS_START
-# value indicates where the coverage configuration file 
resides
-# More info on https://pypi.python.org/pypi/coverage
-if not os.environ.get('COVERAGE_PROCESS_START'):
-os.environ['COVERAGE_PROCESS_START'] = 
coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, 
args.coverage_include, args.coverage_omit)
-
-self.coverage_installed = True
 except:
 log.warn('\n'.join(["python coverage is not installed",
 "Make sure your coverage takes into account 
sub-process",
 "More info on https://pypi.python.org/pypi/coverage";]))
 self.coverage_installed = False
 
+if self.coverage_installed:
+log.info("Coverage is enabled")
+
+# In case the user has not set the variable 
COVERAGE_PROCESS_START,
+# create a default one and export it. The 
COVERAGE_PROCESS_START
+# value indicates where the coverage configuration file resides
+# More info on https://pypi.python.org/pypi/coverage
+if not os.environ.get('COVERAGE_PROCESS_START'):
+os.environ['COVERAGE_PROCESS_START'] = 
coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, 
args.coverage_include, args.coverage_omit)
+
+# Use default site.USER_SITE and write corresponding config 
file
+site.ENABLE_USER_SITE = True
+if not os.path.exists(site.USER_SITE):
+os.makedirs(site.USER_SITE)
+self.coveragepth = os.path.join(site.USER_SITE, "coverage.pth")
+with open(self.coveragepth, 'w') as cps:
+cps.write('import sys,site; 
sys.path.extend(site.getsitepackages()); import coverage; 
coverage.process_startup();')
+
 def stopTestRun(self):
 """ Report coverage data after the testcases are run """
 
@@ -601,6 +617,11 @@ def buildResultClass(args):
 log.info("===")
 
 coverage_report()
+# remove the pth file
+try:
+os.remove(self.coveragepth)
+except OSError:
+pass
 
 return StampedResult
 
-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH v2 1/2] scripts/oe-selftest: Add filtering to the coverage data gathered by oe-selftest

2016-02-17 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

When --coverage is used, oe-selftest gathers coverage data from the testcases
executed. The command lacks a way of filtering which files to gather coverage
data from.

This patch adds three options to specify which files should be considered.
The --coverage-source option specifies folders, while --coverage-include and
--coverage-omit specify patterns to have an extra level of filtering.

Some examples:

1. oe-selftest --run-all-tests --coverage

Gathers coverage data from the default poky folders

2. oe-selftest --run-all-tests --coverage --coverage-include 
/home/me/poky/scripts/*

Gathers coverage data only for the files located under '/home/me/poky/scripts'

3. oe-selftest --run-all-tests -coverage --coverage-omit /home/me/poky/meta*

Gathers coverage data. Files inside all the folders starting with 'meta' under
'/home/me/poky' are omited

4. oe-selftest --run-all-tests --coverage --coverage-source 
/home/me/poky/bitbake

Gathers coverage data only from files inside the folder: '/home/me/poky/bitbake'

[Yocto #8920]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 32 +---
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index 4eb404b..f3865e4 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -78,6 +78,9 @@ def get_args_parser():
 group.add_argument('--list-modules', required=False, action="store_true", 
dest="list_modules", default=False, help='List all available test modules.')
 group.add_argument('--list-classes', required=False, action="store_true", 
dest="list_allclasses", default=False, help='List all available test classes.')
 parser.add_argument('--coverage', action="store_true", help="Run code 
coverage when testing")
+parser.add_argument('--coverage-source', dest="coverage_source", 
nargs="+", help="Specifiy the directories to take coverage from")
+parser.add_argument('--coverage-include', dest="coverage_include", 
nargs="+", help="Specify extra patterns to include into the coverage 
measurement")
+parser.add_argument('--coverage-omit', dest="coverage_omit", nargs="+", 
help="Specify with extra patterns to exclude from the coverage measurement")
 group.add_argument('--run-tests-by', required=False, dest='run_tests_by', 
default=False, nargs='*',
help='run-tests-by  ')
 group.add_argument('--list-tests-by', required=False, 
dest='list_tests_by', default=False, nargs='*',
@@ -369,7 +372,7 @@ def list_tags():
 
 print 'Tags:\t%s' % ', '.join(str(x) for x in tags)
 
-def coverage_setup(run_tests, run_all_tests):
+def coverage_setup(run_tests, run_all_tests, coverage_source, 
coverage_include, coverage_omit):
 """ Set up the coverage measurement for the testcases to be run """
 builddir = os.environ.get("BUILDDIR")
 coveragerc = "%s/.coveragerc" % builddir
@@ -384,10 +387,25 @@ def coverage_setup(run_tests, run_all_tests):
 cps.write("branch = True\n")
 # Measure just BBLAYERS, scripts and bitbake folders
 cps.write("source = \n")
-for layer in get_bb_var('BBLAYERS').split():
-cps.write("%s\n" % layer)
-cps.write("%s\n" % os.path.dirname(os.path.realpath(__file__)))
-cps.write("%s\n" % 
os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),'bitbake'))
+if coverage_source:
+for directory in coverage_source:
+if not os.path.isdir(directory):
+log.warn("Directory %s is not valid.", directory)
+cps.write("%s\n" % directory)
+else:
+for layer in get_bb_var('BBLAYERS').split():
+cps.write("%s\n" % layer)
+cps.write("%s\n" % os.path.dirname(os.path.realpath(__file__)))
+cps.write("%s\n" % 
os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),'bitbake'))
+
+if coverage_include:
+cps.write("include = \n")
+for pattern in coverage_include:
+cps.write("%s\n" % pattern)
+if coverage_omit:
+cps.write("omit = \n")
+for pattern in coverage_omit:
+cps.write("%s\n" % pattern)
 
 return coveragerc
 
@@ -550,7 +568,7 @@ def buildResultClass(args):
 
 def startTestRun(self):
 """ Setup coverage before running any testcase """
-if args.coverage:
+if args.coverage or args.coverage_source or args.coverage_include 
or args.coverage_omit:
 try:
 # check if user can do coverage
 import coverage
@@ -561,7 +579,7 @@ def buildResultClass(args):
 # value indicates where the coverage configuration file 
resides
 # More info on https://pypi.python.org/pypi/coverage
 if not os.environ.get('COVERAGE_PROCESS_ST

[OE-core] [PATCH v2 0/2] Coverage filtering and configuration file for sub-process in $HOME

2016-02-17 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Enables filtering to the files to be measured with coverage and adds temporal 
file to enable subprocessing

Humberto Ibarra (2):
  scripts/oe-selftest: Add filtering to the coverage data  gathered
by oe-selftest
  scripts/oe-selftest: Use site.USER_SITE to run coverage configuration 
   code for sub-process

 scripts/oe-selftest | 76 -
 1 file changed, 58 insertions(+), 18 deletions(-)

-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH v2 2/2] scripts/oe-selftest: Use site.USER_SITE to run coverage configuration code for sub-process

2016-02-17 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Coverage in oe-selftest currently requires to create or modify
a sitecustomize.py file according the coverage tool setup instructions
(http://coverage.readthedocs.org/). This file has to be located in
the system's python folder, which is not a good solution since this
folder is not accesible to non-privileged users.

The best solution so far is to create this file in the home directory.
This is implemented by creating the temporal file in the user site
default folder.

[Yocto #8930]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 46 ++
 1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index f3865e4..25ca632 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -553,6 +553,7 @@ def main():
 
 def buildResultClass(args):
 """Build a Result Class to use in the testcase execution"""
+import site
 
 class StampedResult(unittest.TextTestResult):
 """
@@ -568,26 +569,41 @@ def buildResultClass(args):
 
 def startTestRun(self):
 """ Setup coverage before running any testcase """
+
+# variable holding the coverage configuration file allowing 
subprocess to be measured
+self.coveragepth = None
+
+# indicates the system if coverage is currently installed
+self.coverage_installed = True
+
 if args.coverage or args.coverage_source or args.coverage_include 
or args.coverage_omit:
 try:
 # check if user can do coverage
 import coverage
-log.info("Coverage is enabled")
-
-# In case the user has not set the variable 
COVERAGE_PROCESS_START,
-# create a default one and export it. The 
COVERAGE_PROCESS_START
-# value indicates where the coverage configuration file 
resides
-# More info on https://pypi.python.org/pypi/coverage
-if not os.environ.get('COVERAGE_PROCESS_START'):
-os.environ['COVERAGE_PROCESS_START'] = 
coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, 
args.coverage_include, args.coverage_omit)
-
-self.coverage_installed = True
 except:
 log.warn('\n'.join(["python coverage is not installed",
 "Make sure your coverage takes into account 
sub-process",
 "More info on https://pypi.python.org/pypi/coverage";]))
 self.coverage_installed = False
 
+if self.coverage_installed:
+log.info("Coverage is enabled")
+
+# In case the user has not set the variable 
COVERAGE_PROCESS_START,
+# create a default one and export it. The 
COVERAGE_PROCESS_START
+# value indicates where the coverage configuration file resides
+# More info on https://pypi.python.org/pypi/coverage
+if not os.environ.get('COVERAGE_PROCESS_START'):
+os.environ['COVERAGE_PROCESS_START'] = 
coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, 
args.coverage_include, args.coverage_omit)
+
+# Use default site.USER_SITE and write corresponding config 
file
+site.ENABLE_USER_SITE = True
+if not os.path.exists(site.USER_SITE):
+os.makedirs(site.USER_SITE)
+self.coveragepth = os.path.join(site.USER_SITE, "coverage.pth")
+with open(self.coveragepth, 'w') as cps:
+cps.write('import sys,site; 
sys.path.extend(site.getsitepackages()); import coverage; 
coverage.process_startup();')
+
 def stopTestRun(self):
 """ Report coverage data after the testcases are run """
 
@@ -599,8 +615,14 @@ def buildResultClass(args):
 
 log.info("Coverage Report")
 log.info("===")
-
-coverage_report()
+try:
+coverage_report()
+# remove the pth file
+finally:
+try:
+os.remove(self.coveragepth)
+except OSError:
+pass
 
 return StampedResult
 
-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH v3 0/2] Coverage filtering and configuration file for sub-process in $HOME

2016-02-19 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Enables filtering to the files to be measured with coverage and adds temporal 
file to enable subprocessing

Humberto Ibarra (2):
  scripts/oe-selftest: Add filtering to the coverage data  gathered
by oe-selftest
  scripts/oe-selftest: Use site.USER_SITE to run coverage 
configuration code for sub-process

 scripts/oe-selftest | 76 -
 1 file changed, 58 insertions(+), 18 deletions(-)

-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH v3 1/2] scripts/oe-selftest: Add filtering to the coverage data gathered by oe-selftest

2016-02-19 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

When --coverage is used, oe-selftest gathers coverage data from the testcases
executed. The command lacks a way of filtering which files to gather coverage
data from.

This patch adds three options to specify which files should be considered.
The --coverage-source option specifies folders, while --coverage-include and
--coverage-omit specify patterns to have an extra level of filtering.

Some examples:

1. oe-selftest --run-all-tests --coverage

Gathers coverage data from the default poky folders

2. oe-selftest --run-all-tests --coverage --coverage-include 
/home/me/poky/scripts/*

Gathers coverage data only for the files located under '/home/me/poky/scripts'

3. oe-selftest --run-all-tests -coverage --coverage-omit /home/me/poky/meta*

Gathers coverage data. Files inside all the folders starting with 'meta' under
'/home/me/poky' are omited

4. oe-selftest --run-all-tests --coverage --coverage-source 
/home/me/poky/bitbake

Gathers coverage data only from files inside the folder: '/home/me/poky/bitbake'

[Yocto #8920]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 32 +---
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index 4eb404b..f3865e4 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -78,6 +78,9 @@ def get_args_parser():
 group.add_argument('--list-modules', required=False, action="store_true", 
dest="list_modules", default=False, help='List all available test modules.')
 group.add_argument('--list-classes', required=False, action="store_true", 
dest="list_allclasses", default=False, help='List all available test classes.')
 parser.add_argument('--coverage', action="store_true", help="Run code 
coverage when testing")
+parser.add_argument('--coverage-source', dest="coverage_source", 
nargs="+", help="Specifiy the directories to take coverage from")
+parser.add_argument('--coverage-include', dest="coverage_include", 
nargs="+", help="Specify extra patterns to include into the coverage 
measurement")
+parser.add_argument('--coverage-omit', dest="coverage_omit", nargs="+", 
help="Specify with extra patterns to exclude from the coverage measurement")
 group.add_argument('--run-tests-by', required=False, dest='run_tests_by', 
default=False, nargs='*',
help='run-tests-by  ')
 group.add_argument('--list-tests-by', required=False, 
dest='list_tests_by', default=False, nargs='*',
@@ -369,7 +372,7 @@ def list_tags():
 
 print 'Tags:\t%s' % ', '.join(str(x) for x in tags)
 
-def coverage_setup(run_tests, run_all_tests):
+def coverage_setup(run_tests, run_all_tests, coverage_source, 
coverage_include, coverage_omit):
 """ Set up the coverage measurement for the testcases to be run """
 builddir = os.environ.get("BUILDDIR")
 coveragerc = "%s/.coveragerc" % builddir
@@ -384,10 +387,25 @@ def coverage_setup(run_tests, run_all_tests):
 cps.write("branch = True\n")
 # Measure just BBLAYERS, scripts and bitbake folders
 cps.write("source = \n")
-for layer in get_bb_var('BBLAYERS').split():
-cps.write("%s\n" % layer)
-cps.write("%s\n" % os.path.dirname(os.path.realpath(__file__)))
-cps.write("%s\n" % 
os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),'bitbake'))
+if coverage_source:
+for directory in coverage_source:
+if not os.path.isdir(directory):
+log.warn("Directory %s is not valid.", directory)
+cps.write("%s\n" % directory)
+else:
+for layer in get_bb_var('BBLAYERS').split():
+cps.write("%s\n" % layer)
+cps.write("%s\n" % os.path.dirname(os.path.realpath(__file__)))
+cps.write("%s\n" % 
os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),'bitbake'))
+
+if coverage_include:
+cps.write("include = \n")
+for pattern in coverage_include:
+cps.write("%s\n" % pattern)
+if coverage_omit:
+cps.write("omit = \n")
+for pattern in coverage_omit:
+cps.write("%s\n" % pattern)
 
 return coveragerc
 
@@ -550,7 +568,7 @@ def buildResultClass(args):
 
 def startTestRun(self):
 """ Setup coverage before running any testcase """
-if args.coverage:
+if args.coverage or args.coverage_source or args.coverage_include 
or args.coverage_omit:
 try:
 # check if user can do coverage
 import coverage
@@ -561,7 +579,7 @@ def buildResultClass(args):
 # value indicates where the coverage configuration file 
resides
 # More info on https://pypi.python.org/pypi/coverage
 if not os.environ.get('COVERAGE_PROCESS_ST

[OE-core] [PATCH v3 2/2] scripts/oe-selftest: Use site.USER_SITE to run coverage configuration code for sub-process

2016-02-19 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Coverage in oe-selftest currently requires to create or modify
a sitecustomize.py file according the coverage tool setup instructions
(http://coverage.readthedocs.org/). This file has to be located in
the system's python folder, which is not a good solution since this
folder is not accesible to non-privileged users.

The best solution so far is to create this file in the home directory.
This is implemented by creating the temporal file in the user site
default folder.

[Yocto #8930]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 46 ++
 1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index f3865e4..bd9cbe0 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -553,6 +553,7 @@ def main():
 
 def buildResultClass(args):
 """Build a Result Class to use in the testcase execution"""
+import site
 
 class StampedResult(unittest.TextTestResult):
 """
@@ -568,26 +569,41 @@ def buildResultClass(args):
 
 def startTestRun(self):
 """ Setup coverage before running any testcase """
+
+# variable holding the coverage configuration file allowing 
subprocess to be measured
+self.coveragepth = None
+
+# indicates the system if coverage is currently installed
+self.coverage_installed = True
+
 if args.coverage or args.coverage_source or args.coverage_include 
or args.coverage_omit:
 try:
 # check if user can do coverage
 import coverage
-log.info("Coverage is enabled")
-
-# In case the user has not set the variable 
COVERAGE_PROCESS_START,
-# create a default one and export it. The 
COVERAGE_PROCESS_START
-# value indicates where the coverage configuration file 
resides
-# More info on https://pypi.python.org/pypi/coverage
-if not os.environ.get('COVERAGE_PROCESS_START'):
-os.environ['COVERAGE_PROCESS_START'] = 
coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, 
args.coverage_include, args.coverage_omit)
-
-self.coverage_installed = True
 except:
 log.warn('\n'.join(["python coverage is not installed",
 "Make sure your coverage takes into account 
sub-process",
 "More info on https://pypi.python.org/pypi/coverage";]))
 self.coverage_installed = False
 
+if self.coverage_installed:
+log.info("Coverage is enabled")
+
+# In case the user has not set the variable 
COVERAGE_PROCESS_START,
+# create a default one and export it. The 
COVERAGE_PROCESS_START
+# value indicates where the coverage configuration file resides
+# More info on https://pypi.python.org/pypi/coverage
+if not os.environ.get('COVERAGE_PROCESS_START'):
+os.environ['COVERAGE_PROCESS_START'] = 
coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, 
args.coverage_include, args.coverage_omit)
+
+# Use default site.USER_SITE and write corresponding config 
file
+site.ENABLE_USER_SITE = True
+if not os.path.exists(site.USER_SITE):
+os.makedirs(site.USER_SITE)
+self.coveragepth = os.path.join(site.USER_SITE, "coverage.pth")
+with open(self.coveragepth, 'w') as cps:
+cps.write('import sys,site; 
sys.path.extend(site.getsitepackages()); import coverage; 
coverage.process_startup();')
+
 def stopTestRun(self):
 """ Report coverage data after the testcases are run """
 
@@ -599,8 +615,14 @@ def buildResultClass(args):
 
 log.info("Coverage Report")
 log.info("===")
-
-coverage_report()
+try:
+coverage_report()
+# remove the pth file
+finally:
+try:
+os.remove(self.coveragepth)
+except OSError:
+log.warn("Expected temporal file from coverage is 
missing, ignoring removal.")
 
 return StampedResult
 
-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH] scripts/oe-selftest: Add search expression matching to run/list options

2016-03-11 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

The oe-selftest script required an exact matching for the parameters
passed to its run-tests-by and list-tests-by options. Many tests
can be retrieved here and filtering is a must.

This patch add this filtering functionality by enabling the use
of wildcards such as "*".

[Yocto #8916]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 108 +---
 1 file changed, 44 insertions(+), 64 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index de98a6c..4c92f6d 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -243,93 +243,73 @@ def get_all_tests():
 testlist += get_tests_from_module(tmod)
 return testlist
 
-
-def create_testsuite_by(criteria, keyword):
-# Create a testsuite based on 'keyword'
-# criteria: name, class, module, id, tag
-# keyword: a list of tests, classes, modules, ids, tags
-# NOTE: globing would be nice?
-
-ts = set()
-all_tests = get_all_tests()
-
-if criteria == 'name':
-for tc in all_tests:
-if tc.tcname in keyword:
-ts.add(tc.fullpath)
-
-elif criteria == 'class':
-for tc in all_tests:
-if tc.tcclass in keyword:
-ts.add(tc.fullpath)
-
-elif criteria == 'module':
-for tc in all_tests:
-if tc.tcmodule in keyword:
-ts.add(tc.fullpath)
-elif criteria == 'id':
-for tc in all_tests:
-if str(tc.tcid) in keyword:
-ts.add(tc.fullpath)
-elif criteria == 'tag':
-for tc in all_tests:
-# tc can have multiple tags (as list or tuple) otherwise as str
-if isinstance(tc.tctag, (list, tuple)):
-for tag in tc.tctag:
-if str(tag) in keyword:
-ts.add(tc.fullpath)
-elif tc.tctag in keyword:
-ts.add(tc.fullpath)
-
-return sorted(list(ts))
-
-
 def get_testsuite_by(criteria, keyword):
 # Get a testsuite based on 'keyword'
 # criteria: name, class, module, id, tag
 # keyword: a list of tests, classes, modules, ids, tags
-# NOTE: globing would be nice?
-ts = set()
+
+import re
+import fnmatch
+
+ts = []
 all_tests = get_all_tests()
 
+def get_matches(values):
+# Get a items and return the ones that match with keyword(s)
+# values: the list of items (names, modules, classes...)
+result = []
+remaining = values[:]
+for key in keyword:
+if key in remaining:
+# Regular matching of exact item
+result.append(key)
+remaining.remove(key)
+else:
+# Wildcard matching
+pattern = re.compile(fnmatch.translate(r"%s" % key))
+added = [ x for x in remaining if pattern.match(x) ]
+result.extend(added)
+remaining = [ x for x in remaining if not x in added ]
+
+return result
+
 if criteria == 'name':
-for tc in all_tests:
-if tc.tcname in keyword:
-ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+names = get_matches([ tc.tcname for tc in all_tests ])
+ts = [ tc for tc in all_tests if tc.tcname in names ]
 
 elif criteria == 'class':
-for tc in all_tests:
-if tc.tcclass in keyword:
-ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+classes = get_matches([ tc.tcclass for tc in all_tests ])
+ts = [ tc for tc in all_tests if tc.tcclass in classes ]
 
 elif criteria == 'module':
-for tc in all_tests:
-if tc.tcmodule in keyword:
-ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+modules = get_matches([ tc.tcmodule for tc in all_tests ])
+ts = [ tc for tc in all_tests if tc.tcmodule in modules ]
+
 elif criteria == 'id':
-for tc in all_tests:
-if str(tc.tcid) in keyword:
-ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+ids = get_matches([ str(tc.tcid) for tc in all_tests ])
+ts = [ tc for tc in all_tests if str(tc.tcid) in ids ]
+
 elif criteria == 'tag':
+values = set()
 for tc in all_tests:
 # tc can have multiple tags (as list or tuple) otherwise as str
 if isinstance(tc.tctag, (list, tuple)):
-for tag in tc.tctag:
-if str(tag) in keyword:
-ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, 
tc.tcmodule))
-elif str(tc.tctag) in keyword:
-ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+values |= { str(tag) for tag in tc.tctag }
+else:
+values.add(str(tc.tctag))
+
+tags = get_matches(list(values))
+  

[OE-core] [PATCH] scripts/oe-selftest: Add short names to most common options

2016-03-11 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Add short names to most common options in oe-selftest. The options
changed were --run-tests, --run-all-tests, --list-tests and
--list-modules.

[Yocto #9079]

Signed-off-by: Humberto Ibarra 
---
 scripts/oe-selftest | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index de98a6c..f13b1bd 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -73,9 +73,9 @@ def get_args_parser():
 description = "Script that runs unit tests agains bitbake and other Yocto 
related tools. The goal is to validate tools functionality and metadata 
integrity. Refer to https://wiki.yoctoproject.org/wiki/Oe-selftest for more 
information."
 parser = argparse_oe.ArgumentParser(description=description)
 group = parser.add_mutually_exclusive_group(required=True)
-group.add_argument('--run-tests', required=False, action='store', 
nargs='*', dest="run_tests", default=None, help='Select what tests to run 
(modules, classes or test methods). Format should be: 
..')
-group.add_argument('--run-all-tests', required=False, action="store_true", 
dest="run_all_tests", default=False, help='Run all (unhidden) tests')
-group.add_argument('--list-modules', required=False, action="store_true", 
dest="list_modules", default=False, help='List all available test modules.')
+group.add_argument('-r', '--run-tests', required=False, action='store', 
nargs='*', dest="run_tests", default=None, help='Select what tests to run 
(modules, classes or test methods). Format should be: 
..')
+group.add_argument('-a', '--run-all-tests', required=False, 
action="store_true", dest="run_all_tests", default=False, help='Run all 
(unhidden) tests')
+group.add_argument('-m', '--list-modules', required=False, 
action="store_true", dest="list_modules", default=False, help='List all 
available test modules.')
 group.add_argument('--list-classes', required=False, action="store_true", 
dest="list_allclasses", default=False, help='List all available test classes.')
 parser.add_argument('--coverage', action="store_true", help="Run code 
coverage when testing")
 parser.add_argument('--coverage-source', dest="coverage_source", 
nargs="+", help="Specifiy the directories to take coverage from")
@@ -85,7 +85,7 @@ def get_args_parser():
help='run-tests-by  ')
 group.add_argument('--list-tests-by', required=False, 
dest='list_tests_by', default=False, nargs='*',
help='list-tests-by  ')
-group.add_argument('--list-tests', required=False,  action="store_true", 
dest="list_tests", default=False,
+group.add_argument('-l', '--list-tests', required=False,  
action="store_true", dest="list_tests", default=False,
help='List all available tests.')
 group.add_argument('--list-tags', required=False, dest='list_tags', 
default=False, action="store_true",
help='List all tags that have been set to test cases.')
-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH] scripts/lib/bsp/help.py: Add missing options to yocto-bsp help and usage

2016-03-14 Thread humberto . ibarra . lopez
From: Humberto Ibarra 

Add the options --codedump and --skip-git-check to the yocto-bsp help and
yocto-bsp usage, since they are currently missing.

[YOCTO #8322]

Signed-off-by: Humberto Ibarra 
---
 scripts/lib/bsp/help.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/lib/bsp/help.py b/scripts/lib/bsp/help.py
index bbb7b31..2b4ed06 100644
--- a/scripts/lib/bsp/help.py
+++ b/scripts/lib/bsp/help.py
@@ -103,6 +103,7 @@ yocto_bsp_create_usage = """
 
  usage: yocto-bsp create   [-o  | --outdir ]
 [-i  | --infile ]
+[-c | --codedump] [-s | --skip-git-check]
 
  This command creates a Yocto BSP based on the specified parameters.
  The new BSP will be a new Yocto BSP layer contained by default within
@@ -131,6 +132,7 @@ NAME
 SYNOPSIS
 yocto-bsp create   [-o  | --outdir ]
 [-i  | --infile ]
+[-c | --codedump] [-s | --skip-git-check]
 
 DESCRIPTION
 This command creates a Yocto BSP based on the specified
-- 
1.9.1

-- 
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core