scripts/oe-selftest: isolate oe-selftest execution
PATCH v2 1/2 scripts/oe-selftest: isolate oe-selftest execution
From: Leonardo Sandoval <[email protected]>
The main idea is to isolate the oe-selftest execution so neither the current build directory, configuration nor environment is use when executing the selftests.
The approach uses 'oe-selftest' as a wrapper scripts with once all isolation setup is done, it calls 'scripts/lib/oe-selftest-internal',
the latter is exactly what it is used to be oe-selftest. By isolation in this context, we mean the following: creation of a unique directory (base on PID), re-initializes the environment (re-sources oe-init-build-env)
and finally launches the the internal oe-selftest script.
The new build directory (created by oe-init-build-env, on top of the isolated dir) has the same configuration data (local.conf, auto.conf, site.conf) as the current one. Also, the variables DL_DIR and SSTATE_DIR are passed to the new environment, effectively reusing these two directories and not impacting performance.
This new wrapper allows to launch multiple 'oe-selftest -r XXX' jobs, each running a certain module/class/unittest, easily allowing tools like GNU parallel to run jobs in parallel (see scripts/contrib/parallel-oe-selftest.sh)
[YOCTO #11429]
--- scripts/lib/oe-selftest-internal | 75 +++++++++++++++++++++++++++++++ scripts/oe-selftest | 97 ++++++++++++++++++++-------------------- 2 files changed, 124 insertions(+), 48 deletions(-) create mode 100755 scripts/lib/oe-selftest-internal
scripts/lib/oe-selftest-internal new file +75 -0
@@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2013-2017 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# DESCRIPTION +# This script runs tests defined in meta/lib/oeqa/selftest/ +# It's purpose is to automate the testing of different bitbake tools. +# To use it you just need to source your build environment setup script and +# add the meta-selftest layer to your BBLAYERS. +# Call the script as: "oe-selftest -a" to run all the tests in meta/lib/oeqa/selftest/ +# Call the script as: "oe-selftest -r <module>.<Class>.<method>" to run just a single test +# E.g: "oe-selftest -r bblayers.BitbakeLayers" will run just the BitbakeLayers class from meta/lib/oeqa/selftest/bblayers.py + + + +import os +import sys +import argparse +import logging + +scripts_path = os.path.dirname(os.path.realpath(__file__)) +lib_path = scripts_path + '/lib' +sys.path = sys.path + [lib_path] +import argparse_oe +import scriptutils +import scriptpath +scriptpath.add_oe_lib_path() +scriptpath.add_bitbake_lib_path() + +from oeqa.utils import load_test_components +from oeqa.core.exception import OEQAPreRun + +logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout) + +def main(): + description = "Script that runs unit tests against 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(prog='oe-selftest', description=description) + + comp_name, comp = load_test_components(logger, 'oe-selftest').popitem() + comp.register_commands(logger, parser) + + try: + args = parser.parse_args() + results = args.func(logger, args) + ret = 0 if results.wasSuccessful() else 1 + except SystemExit as err: + if err.code != 0: + raise err + ret = err.code + except OEQAPreRun as pr: + ret = 1 + + return ret + +if __name__ == '__main__': + try: + ret = main() + except Exception: + ret = 1 + import traceback + traceback.print_exc() + sys.exit(ret)
scripts/oe-selftest +49 -48
116 lines not on this page · raw message
Signature · 1 line
2.12.3
PATCH v2 2/2 parallel-oe-selftest.sh: runs oe-selftest in parallel
From: Leonardo Sandoval <[email protected]>
Parallelize oe-selftest execution using GNU/Parallel: for each test defined, a job will be launched and at any time at maximun of jobs will be executing (defaults to 4).
1. Run all modules
parallel-oe-selftest.sh
2. Run certaing modules and print results in order (see parallel man page for more info)
parallel-oe-selftest.sh wic bblayers
--- scripts/contrib/parallel-oe-selftest.sh | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 scripts/contrib/parallel-oe-selftest.sh
scripts/contrib/parallel-oe-selftest.sh new file +80 -0
@@ -0,0 +1,80 @@ +#!/bin/sh + +# paralell-oe-selftest: executes oe-selftest in 'parallel'. The tests (modules, clases or test methods, same +# as oe-selftest --run-tests) to be executed can be piped to this script; if this is not the case, all modules +# are executed +# +# Copyright (c) 2013-2017 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# Before anything else, check oe-core environment +if [ -z "$BUILDDIR" ]; then + echo "Please initialize the OE-Core environment through oe-init-build-env script" + exit 1 +fi + +usage() { +CMD=$(basename $0) +cat <<EOM +Usage: $CMD [-h] [-j jobs] [test1 test2 ..] + -j jobs Number of jobs to be running concurrently + -h Display this help message + + Examples: + # run all found testcases + $CMD + + # just run wic and bblayers + $CMD wic bblayers + +EOM +} + +JOBS=4 +# Parse and validate arguments +while getopts "hj:" OPT; do + case $OPT in + j) + JOBS="$OPTARG" + ;; + h) + usage + exit 0 + ;; + --) + shift + break + ;; + esac +done + + +shift "$((OPTIND - 1))" +TESTCASES="$@" + +# Parallelization is done through GNU/Paralell, so it must be present in host machine +which parallel 2>&1 >/dev/null || { echo "Please install GNU/Parallel"; exit 1; } + +# no test cases given, running all found +if [ -z "$TESTCASES" ]; then + TESTCASES="$(oe-selftest -m | awk '{ print $NF } ' | grep -v ':')" +fi + +if [ -z "$TESTCASES" ]; then + echo $TESTCASES | time parallel --keep-order --progress --jobs $JOBS oe-selftest -r +else + time parallel -d ' ' --keep-order --progress --jobs $JOBS oe-selftest -r ::: $TESTCASES +fi
Signature · 1 line
2.12.3
Re: [PATCH v2 2/2] parallel-oe-selftest.sh: runs oe-selftest in parallel
Quoted 4 lines · On Mon, Dec 18, 2017 at 9:43 AM, <[email protected]>…
From: Leonardo Sandoval <[email protected]>
Parallelize oe-selftest execution using GNU/Parallel: for each test defined, a job will be launched and at any time at maximun of jobs will
Typo.
Quoted 7 lines
be executing (defaults to 4).
1. Run all modules
parallel-oe-selftest.sh2. Run certaing modules and print results in order (see parallel man page for
Typo.
Quoted 16 lines
more info)
parallel-oe-selftest.shwic bblayersSigned-off-by Leonardo Sandoval <[email protected]>--- scripts/contrib/parallel-oe-selftest.sh | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 scripts/contrib/parallel-oe-selftest.shscripts/contrib/parallel-oe-selftest.sh new file +0
-0
scripts/contrib/parallel-oe-selftest.sh line 3
Quoted 3 lines
scripts/contrib/parallel-oe-selftest.sh new file +3
-0@@ -0,0 +1,80 @@ +#!/bin/sh + +# paralell-oe-selftest: executes oe-selftest in 'parallel'. The tests (modules, clases or test methods, same
Two typos.
Quoted 55 lines
scripts/contrib/parallel-oe-selftest.sh new file +55
-0+# as oe-selftest --run-tests) to be executed can be piped to this script; if this is not the case, all modules +# are executed +# +# Copyright (c) 2013-2017 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# Before anything else, check oe-core environment +if [ -z "$BUILDDIR" ]; then + echo "Please initialize the OE-Core environment through oe-init-build-env script" + exit 1 +fi + +usage() { +CMD=$(basename $0) +cat <<EOM +Usage: $CMD [-h] [-j jobs] [test1 test2 ..] + -j jobs Number of jobs to be running concurrently + -h Display this help message + + Examples: + # run all found testcases + $CMD + + # just run wic and bblayers + $CMD wic bblayers + +EOM +} + +JOBS=4 +# Parse and validate arguments +while getopts "hj:" OPT; do + case $OPT in + j) + JOBS="$OPTARG" + ;; + h) + usage + exit 0 + ;; + --) + shift
scripts/contrib/parallel-oe-selftest.sh line 68
Quoted 10 lines
scripts/contrib/parallel-oe-selftest.sh new file +10
-0+ break + ;; + esac +done + + +shift "$((OPTIND - 1))" +TESTCASES="$@" + +# Parallelization is done through GNU/Paralell, so it must be present in host machine
Typo.
scripts/contrib/parallel-oe-selftest.sh line 77
Quoted 9 lines
scripts/contrib/parallel-oe-selftest.sh new file +9
-0+which parallel 2>&1 >/dev/null || { echo "Please install GNU/Parallel"; exit 1; } + +# no test cases given, running all found +if [ -z "$TESTCASES" ]; then + TESTCASES="$(oe-selftest -m | awk '{ print $NF } ' | grep -v ':')" +fi + +if [ -z "$TESTCASES" ]; then + echo $TESTCASES | time parallel --keep-order --progress --jobs $JOBS oe-selftest -r
Since $TESTCASES is an empty variable here, why echo it?
Quoted 11 lines
scripts/contrib/parallel-oe-selftest.sh new file +3
-1+else + time parallel -d ' ' --keep-order --progress --jobs $JOBS oe-selftest -r ::: $TESTCASES +fi --2.12.3
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Re: [PATCH v2 2/2] parallel-oe-selftest.sh: runs oe-selftest in parallel
Quoted 109 lines · On Mon, 18 Dec 2017 12:26:32 -0800 Andre McCurdy <[email protected]> wrote:
Quoted 4 lines · On Mon, Dec 18, 2017 at 9:43 AM, <[email protected]>…
From: Leonardo Sandoval <[email protected]>
Parallelize oe-selftest execution using GNU/Parallel: for each test defined, a job will be launched and at any time at maximun of jobs will
Typo.
Quoted 7 lines
be executing (defaults to 4).
1. Run all modules
parallel-oe-selftest.sh2. Run certaing modules and print results in order (see parallel man page for
Typo.
Quoted 16 lines
more info)
parallel-oe-selftest.shwic bblayersSigned-off-by Leonardo Sandoval <[email protected]>--- scripts/contrib/parallel-oe-selftest.sh | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 scripts/contrib/parallel-oe-selftest.shscripts/contrib/parallel-oe-selftest.sh new file +0
-0scripts/contrib/parallel-oe-selftest.sh line 3
Quoted 3 lines
scripts/contrib/parallel-oe-selftest.sh new file +3
-0@@ -0,0 +1,80 @@ +#!/bin/sh + +# paralell-oe-selftest: executes oe-selftest in 'parallel'. The tests (modules, clases or test methods, sameTwo typos.
Quoted 55 lines
scripts/contrib/parallel-oe-selftest.sh new file +55
-0+# as oe-selftest --run-tests) to be executed can be piped to this script; if this is not the case, all modules +# are executed +# +# Copyright (c) 2013-2017 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# Before anything else, check oe-core environment +if [ -z "$BUILDDIR" ]; then + echo "Please initialize the OE-Core environment through oe-init-build-env script" + exit 1 +fi + +usage() { +CMD=$(basename $0) +cat <<EOM +Usage: $CMD [-h] [-j jobs] [test1 test2 ..] + -j jobs Number of jobs to be running concurrently + -h Display this help message + + Examples: + # run all found testcases + $CMD + + # just run wic and bblayers + $CMD wic bblayers + +EOM +} + +JOBS=4 +# Parse and validate arguments +while getopts "hj:" OPT; do + case $OPT in + j) + JOBS="$OPTARG" + ;; + h) + usage + exit 0 + ;; + --) + shiftscripts/contrib/parallel-oe-selftest.sh line 68
Quoted 10 lines
scripts/contrib/parallel-oe-selftest.sh new file +10
-0+ break + ;; + esac +done + + +shift "$((OPTIND - 1))" +TESTCASES="$@" + +# Parallelization is done through GNU/Paralell, so it must be present in host machineTypo.
Quoted 11 lines
scripts/contrib/parallel-oe-selftest.sh line 77
Quoted 9 lines
scripts/contrib/parallel-oe-selftest.sh new file +9
-0+which parallel 2>&1 >/dev/null || { echo "Please install GNU/Parallel"; exit 1; } + +# no test cases given, running all found +if [ -z "$TESTCASES" ]; then + TESTCASES="$(oe-selftest -m | awk '{ print $NF } ' | grep -v ':')" +fi + +if [ -z "$TESTCASES" ]; then + echo $TESTCASES | time parallel --keep-order --progress --jobs $JOBS oe-selftest -rSince $TESTCASES is an empty variable here, why echo it?
you are right. Sending a v3. also, I will enable my flyspell-mode in emacs!
Leo
Quoted 12 lines
Quoted 12 lines
scripts/contrib/parallel-oe-selftest.sh new file +3
-1+else + time parallel -d ' ' --keep-order --progress --jobs $JOBS oe-selftest -r ::: $TESTCASES +fi --2.12.3
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core