summaryrefslogtreecommitdiffstats
path: root/scripts/oe-selftest
diff options
context:
space:
mode:
authorHumberto Ibarra <humberto.ibarra.lopez@intel.com>2016-02-19 15:29:32 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-28 11:32:57 +0000
commit3f7aa6fc5d018747e8d3bc8d6038215c36c9ef54 (patch)
tree158ce8b4a8b38b5a440f8b86504368a00501e325 /scripts/oe-selftest
parent1c6c76e1df605507c0aaab9e92d9335b2629055c (diff)
downloadpoky-3f7aa6fc5d018747e8d3bc8d6038215c36c9ef54.tar.gz
scripts/oe-selftest: Use site.USER_SITE to run coverage configuration code for sub-process
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] (From OE-Core rev: 3f9b1658d745b536eff1017b2c74a9dff46b6f4a) Signed-off-by: Humberto Ibarra <humberto.ibarra.lopez@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/oe-selftest')
-rwxr-xr-xscripts/oe-selftest46
1 files changed, 34 insertions, 12 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index f3865e4e81..bd9cbe0826 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -553,6 +553,7 @@ def main():
553 553
554def buildResultClass(args): 554def buildResultClass(args):
555 """Build a Result Class to use in the testcase execution""" 555 """Build a Result Class to use in the testcase execution"""
556 import site
556 557
557 class StampedResult(unittest.TextTestResult): 558 class StampedResult(unittest.TextTestResult):
558 """ 559 """
@@ -568,26 +569,41 @@ def buildResultClass(args):
568 569
569 def startTestRun(self): 570 def startTestRun(self):
570 """ Setup coverage before running any testcase """ 571 """ Setup coverage before running any testcase """
572
573 # variable holding the coverage configuration file allowing subprocess to be measured
574 self.coveragepth = None
575
576 # indicates the system if coverage is currently installed
577 self.coverage_installed = True
578
571 if args.coverage or args.coverage_source or args.coverage_include or args.coverage_omit: 579 if args.coverage or args.coverage_source or args.coverage_include or args.coverage_omit:
572 try: 580 try:
573 # check if user can do coverage 581 # check if user can do coverage
574 import coverage 582 import coverage
575 log.info("Coverage is enabled")
576
577 # In case the user has not set the variable COVERAGE_PROCESS_START,
578 # create a default one and export it. The COVERAGE_PROCESS_START
579 # value indicates where the coverage configuration file resides
580 # More info on https://pypi.python.org/pypi/coverage
581 if not os.environ.get('COVERAGE_PROCESS_START'):
582 os.environ['COVERAGE_PROCESS_START'] = coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, args.coverage_include, args.coverage_omit)
583
584 self.coverage_installed = True
585 except: 583 except:
586 log.warn('\n'.join(["python coverage is not installed", 584 log.warn('\n'.join(["python coverage is not installed",
587 "Make sure your coverage takes into account sub-process", 585 "Make sure your coverage takes into account sub-process",
588 "More info on https://pypi.python.org/pypi/coverage"])) 586 "More info on https://pypi.python.org/pypi/coverage"]))
589 self.coverage_installed = False 587 self.coverage_installed = False
590 588
589 if self.coverage_installed:
590 log.info("Coverage is enabled")
591
592 # In case the user has not set the variable COVERAGE_PROCESS_START,
593 # create a default one and export it. The COVERAGE_PROCESS_START
594 # value indicates where the coverage configuration file resides
595 # More info on https://pypi.python.org/pypi/coverage
596 if not os.environ.get('COVERAGE_PROCESS_START'):
597 os.environ['COVERAGE_PROCESS_START'] = coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, args.coverage_include, args.coverage_omit)
598
599 # Use default site.USER_SITE and write corresponding config file
600 site.ENABLE_USER_SITE = True
601 if not os.path.exists(site.USER_SITE):
602 os.makedirs(site.USER_SITE)
603 self.coveragepth = os.path.join(site.USER_SITE, "coverage.pth")
604 with open(self.coveragepth, 'w') as cps:
605 cps.write('import sys,site; sys.path.extend(site.getsitepackages()); import coverage; coverage.process_startup();')
606
591 def stopTestRun(self): 607 def stopTestRun(self):
592 """ Report coverage data after the testcases are run """ 608 """ Report coverage data after the testcases are run """
593 609
@@ -599,8 +615,14 @@ def buildResultClass(args):
599 615
600 log.info("Coverage Report") 616 log.info("Coverage Report")
601 log.info("===============") 617 log.info("===============")
602 618 try:
603 coverage_report() 619 coverage_report()
620 # remove the pth file
621 finally:
622 try:
623 os.remove(self.coveragepth)
624 except OSError:
625 log.warn("Expected temporal file from coverage is missing, ignoring removal.")
604 626
605 return StampedResult 627 return StampedResult
606 628