Add selftest to test testexport's SDK feature
cover Add selftest to test testexport's SDK feature
From: Mariano Lopez <[email protected]>
This adds a new selftest for testexport in the CI to avoid breaking SDK functionality.
This depends on:
http://lists.openembedded.org/pipermail/openembedded-core/2016-June/122785.html
The following changes since commit 242d70bf0af2eb56ed6da83d4ec7dce2172ebe70:
selftest/runtime-test.py: Add test for import test from other layers (2016-07-06 11:37:49 +0000)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib mariano/bug9765
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=mariano/bug9765
Mariano Lopez (2):
lib/oeqa/utils/commands.py: Move updateEnv() from runexported.py selftest/runtime-test.py: Add test for testexport SDK feature
meta/lib/oeqa/runexported.py | 16 ++------- meta/lib/oeqa/selftest/runtime-test.py | 60 +++++++++++++++++++++++++++++++++- meta/lib/oeqa/utils/commands.py | 31 ++++++++++++++++++ 3 files changed, 92 insertions(+), 15 deletions(-)
Signature · 1 line
2.6.6
PATCH 1/2 lib/oeqa/utils/commands.py: Move updateEnv() from runexported.py
From: Mariano Lopez <[email protected]>
updateEnv() can be used in other places so move the function to utils/commands.py
--- meta/lib/oeqa/runexported.py | 16 ++-------------- meta/lib/oeqa/utils/commands.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-)
meta/lib/oeqa/runexported.py +2 -14
@@ -31,7 +31,7 @@ except ImportError: sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "oeqa"))) from oeqa.oetest import ExportTestContext -from oeqa.utils.commands import runCmd +from oeqa.utils.commands import runCmd, updateEnv from oeqa.utils.sshcontrol import SSHControl # this isn't pretty but we need a fake target object
@@ -137,19 +137,7 @@ def extract_sdk(d): if f.startswith("environment-setup"): print("Setting up SDK environment...") env_file = os.path.join(extract_path, f) - update_env(env_file) - -def update_env(env_file): - """ - Source a file and update environment - """ - - cmd = ". %s; env -0" % env_file - result = runCmd(cmd) - - for line in result.output.split("\0"): - (key, _, value) = line.partition("=") - os.environ[key] = value + updateEnv(env_file) if __name__ == "__main__": try:
meta/lib/oeqa/utils/commands.py +12 -0
@@ -261,3 +261,15 @@ def runqemu(pn, ssh=True): qemu.stop() except: pass + +def updateEnv(env_file): + """ + Source a file and update environment. + """ + + cmd = ". %s; env -0" % env_file + result = runCmd(cmd) + + for line in result.output.split("\0"): + (key, _, value) = line.partition("=") + os.environ[key] = value
Signature · 1 line
2.6.6
PATCH 2/2 selftest/runtime-test.py: Add test for testexport SDK feature
In reply to [email protected]From: Mariano Lopez <[email protected]>
This adds test_testexport_sdk() to test the SDK feature of testexport in the CI in order to avoid breaking it.
[YOCTO #9765]
--- meta/lib/oeqa/selftest/runtime-test.py | 60 +++++++++++++++++++++++++++++++++- meta/lib/oeqa/utils/commands.py | 19 +++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/runtime-test.py +59 -1
@@ -1,5 +1,5 @@ from oeqa.selftest.base import oeSelfTest -from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu +from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu, updateEnv, restoreEnv from oeqa.utils.decorators import testcase import os
@@ -43,6 +43,64 @@ class TestExport(oeSelfTest): failure = True if 'FAIL' in result.output else False self.assertNotEqual(True, failure, 'ping test failed') + def test_testexport_sdk(self): + """ + Summary: Check sdk functionality for testexport. + Expected: 1. testexport directory must be created. + 2. SDK tarball must exists. + 3. Uncompressing of tarball must succeed. + 4. Check if the SDK directory is added to PATH. + 5. Run tar from the SDK directory. + Product: oe-core + Author: Mariano Lopez <[email protected]> + """ + + features = 'INHERIT += "testexport"\n' + # These aren't the actual IP addresses but testexport class needs something defined + features += 'TEST_SERVER_IP = "192.168.7.1"\n' + features += 'TEST_TARGET_IP = "192.168.7.1"\n' + features += 'TEST_SUITES = "ping"\n' + features += 'TEST_EXPORT_SDK_ENABLED = "1"\n' + features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n' + self.write_config(features) + + # Build tesexport for core-image-minimal + bitbake('core-image-minimal') + bitbake('-c testexport core-image-minimal') + + # Check for SDK + testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal') + sdk_dir = get_bb_var('TEST_EXPORT_SDK_DIR', 'core-image-minimal') + tarball_name = "%s.sh" % get_bb_var('TEST_EXPORT_SDK_NAME', 'core-image-minimal') + tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name) + self.assertEqual(os.path.isfile(tarball_path), True, "Couldn't find SDK tarball: %s" % tarball_path) + + # Uncompress SDK + extract_path = os.path.join(testexport_dir, "sysroot") + result = runCmd("%s -y -d %s" % (tarball_path, extract_path)) + + # Setting up environment + current_env = dict(os.environ) + for f in os.listdir(extract_path): + if f.startswith("environment-setup"): + env_file = os.path.join(extract_path, f) + updateEnv(env_file) + + # Check if the SDK directory was added to PATH + working_path = False + for path in os.environ['PATH'].split(":"): + if testexport_dir in path: + working_path = True + sdk_path = path + break + + self.assertEqual(working_path, True, "Couldn't find SDK path in PATH") + + # Execute tar from SDK path + cmd_tar = os.path.join(sdk_path, "tar") + result = runCmd("%s --version" % cmd_tar) + + restoreEnv(current_env) class TestImage(oeSelfTest):
meta/lib/oeqa/utils/commands.py +19 -0
@@ -273,3 +273,22 @@ def updateEnv(env_file): for line in result.output.split("\0"): (key, _, value) = line.partition("=") os.environ[key] = value + +def restoreEnv(old_env): + """ + Restore environment with os.environ. + + os.environ.clear() will throw an exception if there is + environment variable without any value, this function + will deal with such cases. + """ + + keys = list(os.environ.keys()) + + for var in keys: + if var: + if not os.environ[var]: + os.environ[var] = "tmp" + del os.environ[var] + + os.environ.update(old_env)
Signature · 1 line
2.6.6