Skip to contentSkip to conversation

Enable installation of packages in DUT

PATCH New [email protected] 1 participant 9 messages Jun 6, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover Enable installation of packages in DUT

From: Mariano Lopez <[email protected]>

This series enable the functionality to install packages in the DUT during runtime testing. Such packages must had been build previously by bitbake and the packages are specified using a JSON file. This functionality works with testimage and with testexport.

This address the concer of adding a task to extract the packages, instead the extraction was added to the testimage and testexport tasks.

This also includes the use of an SDK package for systems with missing dependencies in the testing system.

This address several bugs:
- 7850
- 8694
- 8481

Changes in v2:

- Fix testexport for python3
- Fix import form other layers with python3
- Made changes to use with python3

This also address more bugs:
- 9702
- 9705

The following changes since commit 6c5d7f1fb276cbe0a461ece6c8f0ca17a478fa8c:

lib/oe/package_manager: adapt for Python 3 (2016-06-05 23:39:47 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib mariano/bug7850v3
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=mariano/bug7850v3

Mariano Lopez (7):
oe/lib/pacakge_manager.py: Update missing pipeline decoding lib/oeqa/otest.py: Fix import tests from other layers with python3 oetest.py: Add install/uninstall functionality for DUTs testimage.bbclass: Make dependency of cpio when using RPMs testexport-tarball.bb: Add recipe
testexport.bbclass: Add support for testexport-tarball testexport.bbclass: Create tarballs for easy release

 meta/classes/testexport.bbclass              | 86 +++++++++++++++++++++++++---
 meta/classes/testimage.bbclass               | 20 +++++++
 meta/lib/oe/package_manager.py               |  4 +-
 meta/lib/oeqa/__init__.py                    |  0
 meta/lib/oeqa/oetest.py                      | 79 ++++++++++++++++++++++++-
 meta/lib/oeqa/runexported.py                 | 35 ++++++++++-
 meta/lib/oeqa/runtime/__init__.py            |  3 -
 meta/recipes-core/meta/testexport-tarball.bb | 56 ++++++++++++++++++
 8 files changed, 265 insertions(+), 18 deletions(-)
 delete mode 100644 meta/lib/oeqa/__init__.py
 delete mode 100644 meta/lib/oeqa/runtime/__init__.py
 create mode 100644 meta/recipes-core/meta/testexport-tarball.bb
Signature · 1 line
2.6.6
#1 lore raw

PATCH v2 1/7 oe/lib/pacakge_manager.py: Update missing pipeline decoding

From: Mariano Lopez <[email protected]>

Adds decoding needed by some commands output later used as strings.

[YOCTO #9702]

---
 meta/lib/oe/package_manager.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/oe/package_manager.py +2 -2
index 3b1d24f..4aaff8c 100644
@@ -1411,7 +1411,7 @@ class RpmPM(PackageManager):
     def package_info(self, pkg):
         cmd = "%s %s info --urls %s" % (self.smart_cmd, self.smart_opt, pkg)
         try:
-            output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
+            output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8")
         except subprocess.CalledProcessError as e:
             bb.fatal("Unable to list available packages. Command '%s' "
                      "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8")))
@@ -1506,7 +1506,7 @@ class OpkgDpkgPM(PackageManager):
     def package_info(self, pkg, cmd):
 
         try:
-            output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
+            output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8")
         except subprocess.CalledProcessError as e:
             bb.fatal("Unable to list available packages. Command '%s' "
                      "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8")))
Signature · 1 line
2.6.6
#2 lore raw

PATCH v2 2/7 lib/oeqa/otest.py: Fix import tests from other layers with python3

In reply to [email protected]

From: Mariano Lopez <[email protected]>

In python3 the functionality to import modules has been changed and this broke the capability to add runtime tests from other layers.

This commit returns this capability to testimage and testexport.

[YOCTO #9705]

---
 meta/classes/testexport.bbclass   | 10 ++++++----
 meta/lib/oeqa/__init__.py         |  0
 meta/lib/oeqa/oetest.py           |  5 ++---
 meta/lib/oeqa/runtime/__init__.py |  3 ---
 4 files changed, 8 insertions(+), 10 deletions(-)
 delete mode 100644 meta/lib/oeqa/__init__.py
 delete mode 100644 meta/lib/oeqa/runtime/__init__.py
meta/classes/testexport.bbclass +6 -4
index 51b7d93..c86eaac 100644
@@ -96,11 +96,13 @@ def exportTests(d,tc):
                         shutil.copytree(foldername, target_folder)
         if not isfolder:
             shutil.copy2(mod.path, os.path.join(exportpath, "oeqa/runtime"))
-    # copy __init__.py files
-    oeqadir = os.path.dirname(pkgutil.get_loader("oeqa").path)
-    shutil.copy2(os.path.join(oeqadir, "__init__.py"), os.path.join(exportpath, "oeqa"))
-    shutil.copy2(os.path.join(oeqadir, "runtime/__init__.py"), os.path.join(exportpath, "oeqa/runtime"))
+    # Get meta layer
+    for layer in d.getVar("BBLAYERS", True).split():
+        if os.path.basename(layer) == "meta":
+            meta_layer = layer
+            break
     # copy oeqa/oetest.py and oeqa/runexported.py
+    oeqadir = os.path.join(meta_layer, "lib/oeqa")
     shutil.copy2(os.path.join(oeqadir, "oetest.py"), os.path.join(exportpath, "oeqa"))
     shutil.copy2(os.path.join(oeqadir, "runexported.py"), exportpath)
     # copy oeqa/utils/*.py
meta/lib/oeqa/__init__.py deleted +0 -0
deleted file mode 100644
index e69de29..0000000
meta/lib/oeqa/oetest.py +2 -3
index b4cf34b..819f959 100644
@@ -203,8 +203,7 @@ class TestContext(object):
         self.testslist = self._get_tests_list(path, extrapath)
         self.testsrequired = self._get_test_suites_required()
 
-        self.filesdir = os.path.join(os.path.dirname(os.path.abspath(
-            oeqa.runtime.__file__)), "files")
+        self.filesdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "runtime/files")
         self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split()
         self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split()
 
@@ -460,7 +459,7 @@ class RuntimeTestContext(TestContext):
         Returns the path of the JSON file for a module, empty if doesn't exitst.
         """
 
-        module_file = module.filename
+        module_file = module.path
         json_file = "%s.json" % module_file.rsplit(".", 1)[0]
         if os.path.isfile(module_file) and os.path.isfile(json_file):
             return json_file
meta/lib/oeqa/runtime/__init__.py deleted +0 -3
deleted file mode 100644
index 4cf3fa7..0000000
@@ -1,3 +0,0 @@
-# Enable other layers to have tests in the same named directory
-from pkgutil import extend_path
-__path__ = extend_path(__path__, __name__)
Signature · 1 line
2.6.6
#3 lore raw

PATCH v2 3/7 oetest.py: Add install/uninstall functionality for DUTs

In reply to [email protected]

From: Mariano Lopez <[email protected]>

Add the functionality to install/unistall packages in the DUTs without the use of the package manager. This is possible with the extraction introduced in package manager class.

testimage and testexport bbclasses has been modified in order to support this new feature.

[YOCTO #8694]

---
 meta/classes/testexport.bbclass | 33 +++++++++++++++---
 meta/classes/testimage.bbclass  | 18 ++++++++++
 meta/lib/oeqa/oetest.py         | 74 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 120 insertions(+), 5 deletions(-)
meta/classes/testexport.bbclass +28 -5
index c86eaac..8046e29 100644
@@ -16,6 +16,9 @@
 
 TEST_LOG_DIR ?= "${WORKDIR}/testexport"
 TEST_EXPORT_DIR ?= "${TMPDIR}/testexport/${PN}"
+TEST_EXPORT_PACKAGED_DIR ?= "packages/packaged"
+TEST_EXPORT_EXTRACTED_DIR ?= "packages/extracted"
+
 TEST_TARGET ?= "simpleremote"
 TEST_TARGET_IP ?= ""
 TEST_SERVER_IP ?= ""
@@ -28,9 +31,9 @@ python do_testexport() {
 }
 
 addtask testexport
-do_testimage[nostamp] = "1"
-do_testimage[depends] += "${TEST_EXPORT_DEPENDS}"
-do_testimage[lockfiles] += "${TEST_EXPORT_LOCK}"
+do_testexport[nostamp] = "1"
+do_testexport[depends] += "${TEST_EXPORT_DEPENDS} ${TESTIMAGEDEPENDS}"
+do_testexport[lockfiles] += "${TEST_EXPORT_LOCK}"
 
 def exportTests(d,tc):
     import json
@@ -96,6 +99,9 @@ def exportTests(d,tc):
                         shutil.copytree(foldername, target_folder)
         if not isfolder:
             shutil.copy2(mod.path, os.path.join(exportpath, "oeqa/runtime"))
+            json_file = "%s.json" % mod.path.rsplit(".", 1)[0]
+            if os.path.isfile(json_file):
+                shutil.copy2(json_file, os.path.join(exportpath, "oeqa/runtime"))
     # Get meta layer
     for layer in d.getVar("BBLAYERS", True).split():
         if os.path.basename(layer) == "meta":
@@ -115,6 +121,20 @@ def exportTests(d,tc):
         for f in files:
             shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/runtime/files"))
 
+    # Copy packages needed for runtime testing
+    export_pkg_dir = os.path.join(d.getVar("TEST_EXPORT_DIR", True), "packages")
+    test_pkg_dir = d.getVar("TEST_NEEDED_PACKAGES_DIR", True)
+    for root, subdirs, files in os.walk(test_pkg_dir):
+        for subdir in subdirs:
+            tmp_dir = os.path.join(root.replace(test_pkg_dir, "").lstrip("/"), subdir)
+            new_dir = os.path.join(export_pkg_dir, tmp_dir)
+            bb.utils.mkdirhier(new_dir)
+
+        for f in files:
+            src_f = os.path.join(root, f)
+            dst_f = os.path.join(export_pkg_dir, root.replace(test_pkg_dir, "").lstrip("/"), f)
+            shutil.copy2(src_f, dst_f)
+
     bb.plain("Exported tests to: %s" % exportpath)
 
 def testexport_main(d):
@@ -122,9 +142,11 @@ def testexport_main(d):
     from oeqa.targetcontrol import get_target_controller
     from oeqa.utils.dump import get_host_dumper
 
+    test_create_extract_dirs(d)
+    export_dir = d.getVar("TEST_EXPORT_DIR", True)
     bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
-    bb.utils.remove(d.getVar("TEST_EXPORT_DIR", True), recurse=True)
-    bb.utils.mkdirhier(d.getVar("TEST_EXPORT_DIR", True))
+    bb.utils.remove(export_dir, recurse=True)
+    bb.utils.mkdirhier(export_dir)
 
     # the robot dance
     target = get_target_controller(d)
@@ -141,6 +163,7 @@ def testexport_main(d):
         import traceback
         bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
 
+    tc.extract_packages()
     exportTests(d,tc)
 
 testexport_main[vardepsexclude] =+ "BB_ORIGENV"
meta/classes/testimage.bbclass +18 -0
index a2e13df..a70d3a8 100644
@@ -30,6 +30,10 @@
 TEST_LOG_DIR ?= "${WORKDIR}/testimage"
 
 TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}"
+TEST_INSTALL_TMP_DIR ?= "${WORKDIR}/testimage/install_tmp"
+TEST_NEEDED_PACKAGES_DIR ?= "${WORKDIR}/testimage/packages"
+TEST_EXTRACTED_DIR ?= "${TEST_NEEDED_PACKAGES_DIR}/extracted"
+TEST_PACKAGED_DIR ?= "${TEST_NEEDED_PACKAGES_DIR}/packaged"
 
 RPMTESTSUITE = "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'smart rpm', '', d)}"
 MINTESTSUITE = "ping"
@@ -100,6 +104,7 @@ testimage_dump_host () {
 python do_testimage() {
     testimage_main(d)
 }
+
 addtask testimage
 do_testimage[nostamp] = "1"
 do_testimage[depends] += "${TESTIMAGEDEPENDS}"
@@ -117,6 +122,7 @@ def testimage_main(d):
 
     pn = d.getVar("PN", True)
     bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
+    test_create_extract_dirs(d)
 
     # we need the host dumper in test context
     host_dumper = get_host_dumper(d)
@@ -136,6 +142,7 @@ def testimage_main(d):
         import traceback
         bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
 
+    tc.extract_packages()
     target.deploy()
     try:
         target.start()
@@ -155,6 +162,17 @@ def testimage_main(d):
         signal.signal(signal.SIGTERM, tc.origsigtermhandler)
         target.stop()
 
+def test_create_extract_dirs(d):
+    install_path = d.getVar("TEST_INSTALL_TMP_DIR", True)
+    package_path = d.getVar("TEST_PACKAGED_DIR", True)
+    extracted_path = d.getVar("TEST_EXTRACTED_DIR", True)
+    bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
+    bb.utils.remove(package_path, recurse=True)
+    bb.utils.mkdirhier(install_path)
+    bb.utils.mkdirhier(package_path)
+    bb.utils.mkdirhier(extracted_path)
+
+
 testimage_main[vardepsexclude] =+ "BB_ORIGENV"
 
 inherit testsdk
meta/lib/oeqa/oetest.py +74 -0

109 lines not on this page · raw message

Signature · 1 line
2.6.6
#4 lore raw

PATCH v2 4/7 testimage.bbclass: Make dependency of cpio when using RPMs

In reply to [email protected]

From: Mariano Lopez <[email protected]>

Exctraction of RPMs needs cpio, not all distros include cpio by default, so we need to build it.

[YOCTO #8694]

(From OE-Core rev: 95cd427b3887b087533fba11c67ef9bc173f9aa5)

---
 meta/classes/testexport.bbclass | 1 +
 meta/classes/testimage.bbclass  | 2 ++
 2 files changed, 3 insertions(+)
meta/classes/testexport.bbclass +1 -0
index 8046e29..a320880 100644
@@ -24,6 +24,7 @@ TEST_TARGET_IP ?= ""
 TEST_SERVER_IP ?= ""
 
 TEST_EXPORT_DEPENDS = ""
+TEST_EXPORT_DEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
 TEST_EXPORT_LOCK = "${TMPDIR}/testimage.lock"
 
 python do_testexport() {
meta/classes/testimage.bbclass +2 -0
index a70d3a8..7fd0f62 100644
@@ -68,6 +68,8 @@ TEST_TARGET ?= "qemu"
 
 TESTIMAGEDEPENDS = ""
 TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot"
+TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
+TESTIMAGEDEPENDS_qemuall += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
 
 TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
 TESTIMAGELOCK_qemuall = ""
Signature · 1 line
2.6.6
#5 lore raw

PATCH v2 5/7 testexport-tarball.bb: Add recipe

In reply to [email protected]

From: Mariano Lopez <[email protected]>

This new recipe is used when exporting runtime test outside packages that won't be installed in the testing system but are required for the runtime testing.

This new recipe is almost identical to buildtools-tarball, but is able to define the SDK packages in local.conf.

[YOCTO #7850]

(From OE-Core rev: fbcd1f9ed6144a76ff6a556d23af30f04c39bfa0)

---
 meta/recipes-core/meta/testexport-tarball.bb | 56 ++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 meta/recipes-core/meta/testexport-tarball.bb
meta/recipes-core/meta/testexport-tarball.bb new file +56 -0
new file mode 100644
index 0000000..951d3be
@@ -0,0 +1,56 @@
+DESCRIPTION = "SDK type target for standalone tarball containing packages defined by TEST_EXPORT_TOOLS. The \
+               tarball can be used to run missing programs on testing systems which don't have such tools.\
+               This recipe is almost the same as buildtools-tarball"
+SUMMARY = "Standalone tarball for test systems with missing software"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
+                    file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+TOOLCHAIN_TARGET_TASK ?= ""
+
+TOOLCHAIN_HOST_TASK ?= "${TEST_EXPORT_SDK_PACKAGES}"
+
+SDK_PACKAGE_ARCHS += "tesexport-tools-${SDKPKGSUFFIX}"
+
+TOOLCHAIN_OUTPUTNAME ?= "${TEST_EXPORT_SDK_NAME}"
+
+SDK_TITLE = "Testexport tools"
+
+RDEPENDS = "${TOOLCHAIN_HOST_TASK}"
+
+EXCLUDE_FROM_WORLD = "1"
+
+inherit meta
+inherit populate_sdk
+inherit toolchain-scripts
+
+create_sdk_files_append () {
+	rm -f ${SDK_OUTPUT}/${SDKPATH}/site-config-*
+	rm -f ${SDK_OUTPUT}/${SDKPATH}/environment-setup-*
+	rm -f ${SDK_OUTPUT}/${SDKPATH}/version-*
+
+	# Generate new (mini) sdk-environment-setup file
+	script=${1:-${SDK_OUTPUT}/${SDKPATH}/environment-setup-${SDK_SYS}}
+	touch $script
+	echo 'export PATH=${SDKPATHNATIVE}${bindir_nativesdk}:$PATH' >> $script
+	# In order for the self-extraction script to correctly extract and set up things,
+	# we need a 'OECORE_NATIVE_SYSROOT=xxx' line in environment setup script.
+	# However, testexport-tarball is inherently a tool set instead of a fully functional SDK,
+	# so instead of exporting the variable, we use a comment here.
+	echo '#OECORE_NATIVE_SYSROOT="${SDKPATHNATIVE}"' >> $script
+	toolchain_create_sdk_version ${SDK_OUTPUT}/${SDKPATH}/version-${SDK_SYS}
+
+	echo 'export GIT_SSL_CAINFO="${SDKPATHNATIVE}${sysconfdir}/ssl/certs/ca-certificates.crt"' >>$script
+
+	if [ "${SDKMACHINE}" = "i686" ]; then
+		echo 'export NO32LIBS="0"' >>$script
+		echo 'echo "$BB_ENV_EXTRAWHITE" | grep -q "NO32LIBS"' >>$script
+		echo '[ $? != 0 ] && export BB_ENV_EXTRAWHITE="NO32LIBS $BB_ENV_EXTRAWHITE"' >>$script
+	fi
+}
+
+# testexport-tarball doesn't need config site
+TOOLCHAIN_NEED_CONFIGSITE_CACHE = ""
+
+# The recipe doesn't need any default deps
+INHIBIT_DEFAULT_DEPS = "1"
Signature · 1 line
2.6.6
#6 lore raw

PATCH v2 6/7 testexport.bbclass: Add support for testexport-tarball

In reply to [email protected]

From: Mariano Lopez <[email protected]>

Add support to export the SDK tarball needed when a test system doesn't have the required software to perform runtime tests.

The support is when exporting the test and when running the test on a remote system. The user of this feature just need to set TEST_EXPORT_SDK_ENABLED to "1" and declare the sdk packages in TEST_EXPORT_SDK_PACKAGES.

[YOCTO #7850]

(From OE-Core rev: a6041f81b81baa7564e4c712fc88de2b997e52e4)

---
 meta/classes/testexport.bbclass | 16 ++++++++++++++++
 meta/lib/oeqa/runexported.py    | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 1 deletion(-)
meta/classes/testexport.bbclass +16 -0
index a320880..6009349 100644
@@ -23,8 +23,14 @@ TEST_TARGET ?= "simpleremote"
 TEST_TARGET_IP ?= ""
 TEST_SERVER_IP ?= ""
 
+TEST_EXPORT_SDK_PACKAGES ?= ""
+TEST_EXPORT_SDK_ENABLED ?= "0"
+TEST_EXPORT_SDK_NAME ?= "testexport-tools-nativesdk"
+TEST_EXPORT_SDK_DIR ?= "sdk"
+
 TEST_EXPORT_DEPENDS = ""
 TEST_EXPORT_DEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
+TEST_EXPORT_DEPENDS += "${@bb.utils.contains('TEST_EXPORT_SDK_ENABLED', '1', 'testexport-tarball:do_populate_sdk', '', d)}"
 TEST_EXPORT_LOCK = "${TMPDIR}/testimage.lock"
 
 python do_testexport() {
@@ -136,6 +142,16 @@ def exportTests(d,tc):
             dst_f = os.path.join(export_pkg_dir, root.replace(test_pkg_dir, "").lstrip("/"), f)
             shutil.copy2(src_f, dst_f)
 
+    # Copy SDK
+    if d.getVar("TEST_EXPORT_SDK_ENABLED", True) == "1":
+        sdk_deploy = d.getVar("SDK_DEPLOY", True)
+        tarball_name = "%s.sh" % d.getVar("TEST_EXPORT_SDK_NAME", True)
+        tarball_path = os.path.join(sdk_deploy, tarball_name)
+        export_sdk_dir = os.path.join(d.getVar("TEST_EXPORT_DIR", True),
+                                      d.getVar("TEST_EXPORT_SDK_DIR", True))
+        bb.utils.mkdirhier(export_sdk_dir)
+        shutil.copy2(tarball_path, export_sdk_dir)
+
     bb.plain("Exported tests to: %s" % exportpath)
 
 def testexport_main(d):
meta/lib/oeqa/runexported.py +34 -1
index f1366a6..5886739 100755
@@ -31,8 +31,8 @@ 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.sshcontrol import SSHControl
-from oeqa.utils.dump import get_host_dumper
 
 # this isn't pretty but we need a fake target object
 # for running the tests externally as we don't care
@@ -107,6 +107,8 @@ def main():
         if not os.path.isdir(d["DEPLOY_DIR"]):
             print("WARNING: The path to DEPLOY_DIR does not exist: %s" % d["DEPLOY_DIR"])
 
+    extract_sdk(d)
+
     target = FakeTarget(d)
     for key in loaded["target"].keys():
         setattr(target, key, loaded["target"][key])
@@ -118,6 +120,37 @@ def main():
 
     return 0
 
+def extract_sdk(d):
+    """
+    Extract SDK if needed
+    """
+
+    export_dir = os.path.dirname(os.path.realpath(__file__))
+    tools_dir = d.getVar("TEST_EXPORT_SDK_DIR", True)
+    tarball_name = "%s.sh" % d.getVar("TEST_EXPORT_SDK_NAME", True)
+    tarball_path = os.path.join(export_dir, tools_dir, tarball_name)
+    extract_path = os.path.join(export_dir, "sysroot")
+    if os.path.isfile(tarball_path):
+        print ("Found SDK tarball %s. Extracting..." % tarball_path)
+        result = runCmd("%s -y -d %s" % (tarball_path, extract_path))
+        for f in os.listdir(extract_path):
+            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
+
 if __name__ == "__main__":
     try:
         ret = main()
Signature · 1 line
2.6.6
#7 lore raw

PATCH v2 7/7 testexport.bbclass: Create tarballs for easy release

In reply to [email protected]

From: Mariano Lopez <[email protected]>

This create tarballs in the testexport directory in order to make easier to distribute the test in another systems.

There are three tarballs, one for the metadata that is not arch dependant, another for packages needed by the DUT (this depends of target MACHINE), and the last one for the SDK needed by the systems that perform the tests.

[YOCTO #8481]

(From OE-Core rev: f8a0456e100b07a966cc24a78f197400c5a2ccab)

---
 meta/classes/testexport.bbclass | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
meta/classes/testexport.bbclass +26 -0
index 6009349..99602a3 100644
@@ -128,6 +128,9 @@ def exportTests(d,tc):
         for f in files:
             shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/runtime/files"))
 
+    # Create tar file for common parts of testexport
+    create_tarball(d, "testexport.tar.gz", d.getVar("TEST_EXPORT_DIR", True))
+
     # Copy packages needed for runtime testing
     export_pkg_dir = os.path.join(d.getVar("TEST_EXPORT_DIR", True), "packages")
     test_pkg_dir = d.getVar("TEST_NEEDED_PACKAGES_DIR", True)
@@ -142,6 +145,9 @@ def exportTests(d,tc):
             dst_f = os.path.join(export_pkg_dir, root.replace(test_pkg_dir, "").lstrip("/"), f)
             shutil.copy2(src_f, dst_f)
 
+    # Create tar file for packages needed by the DUT
+    create_tarball(d, "testexport_packages_%s.tar.gz" % d.getVar("MACHINE", True), export_pkg_dir)
+
     # Copy SDK
     if d.getVar("TEST_EXPORT_SDK_ENABLED", True) == "1":
         sdk_deploy = d.getVar("SDK_DEPLOY", True)
@@ -152,6 +158,9 @@ def exportTests(d,tc):
         bb.utils.mkdirhier(export_sdk_dir)
         shutil.copy2(tarball_path, export_sdk_dir)
 
+    # Create tar file for the sdk
+    create_tarball(d, "testexport_sdk_%s.tar.gz" % d.getVar("SDK_ARCH", True), export_sdk_dir)
+
     bb.plain("Exported tests to: %s" % exportpath)
 
 def testexport_main(d):
@@ -183,6 +192,23 @@ def testexport_main(d):
     tc.extract_packages()
     exportTests(d,tc)
 
+def create_tarball(d, tar_name, src_dir):
+
+    import tarfile
+
+    tar_path = os.path.join(d.getVar("TEST_EXPORT_DIR", True), tar_name)
+    current_dir = os.getcwd()
+    src_dir = src_dir.rstrip('/')
+    dir_name = os.path.dirname(src_dir)
+    base_name = os.path.basename(src_dir)
+
+    os.chdir(dir_name)
+    tar = tarfile.open(tar_path, "w:gz")
+    tar.add(base_name)
+    tar.close()
+    os.chdir(current_dir)
+
+
 testexport_main[vardepsexclude] =+ "BB_ORIGENV"
 
 inherit testimage
Signature · 1 line
2.6.6
#8 lore raw

PATCH v3 7/7 testexport.bbclass: Create tarballs for easy release

From: Mariano Lopez <[email protected]>

This create tarballs in the testexport directory in order to make easier to distribute the test in another systems.

There are three tarballs, one for the metadata that is not arch dependant, another for packages needed by the DUT (this depends of target MACHINE), and the last one for the SDK needed by the systems that perform the tests.

This also create only the tarballs that are needed.

[YOCTO #8481]

(From OE-Core rev: f8a0456e100b07a966cc24a78f197400c5a2ccab)

---
 meta/classes/testexport.bbclass | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
meta/classes/testexport.bbclass +32 -0
index 6009349..15fa470 100644
@@ -128,9 +128,13 @@ def exportTests(d,tc):
         for f in files:
             shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/runtime/files"))
 
+    # Create tar file for common parts of testexport
+    create_tarball(d, "testexport.tar.gz", d.getVar("TEST_EXPORT_DIR", True))
+
     # Copy packages needed for runtime testing
     export_pkg_dir = os.path.join(d.getVar("TEST_EXPORT_DIR", True), "packages")
     test_pkg_dir = d.getVar("TEST_NEEDED_PACKAGES_DIR", True)
+    need_pkg_dir = False
     for root, subdirs, files in os.walk(test_pkg_dir):
         for subdir in subdirs:
             tmp_dir = os.path.join(root.replace(test_pkg_dir, "").lstrip("/"), subdir)
@@ -138,10 +142,18 @@ def exportTests(d,tc):
             bb.utils.mkdirhier(new_dir)
 
         for f in files:
+            need_pkg_dir = True
             src_f = os.path.join(root, f)
             dst_f = os.path.join(export_pkg_dir, root.replace(test_pkg_dir, "").lstrip("/"), f)
             shutil.copy2(src_f, dst_f)
 
+    if need_pkg_dir:
+        # Create tar file for packages needed by the DUT
+        create_tarball(d, "testexport_packages_%s.tar.gz" % d.getVar("MACHINE", True), export_pkg_dir)
+    else:
+        # Remov packages dir from exported test
+        bb.utils.remove(export_pkg_dir, True)
+
     # Copy SDK
     if d.getVar("TEST_EXPORT_SDK_ENABLED", True) == "1":
         sdk_deploy = d.getVar("SDK_DEPLOY", True)
@@ -152,6 +164,9 @@ def exportTests(d,tc):
         bb.utils.mkdirhier(export_sdk_dir)
         shutil.copy2(tarball_path, export_sdk_dir)
 
+        # Create tar file for the sdk
+        create_tarball(d, "testexport_sdk_%s.tar.gz" % d.getVar("SDK_ARCH", True), export_sdk_dir)
+
     bb.plain("Exported tests to: %s" % exportpath)
 
 def testexport_main(d):
@@ -183,6 +198,23 @@ def testexport_main(d):
     tc.extract_packages()
     exportTests(d,tc)
 
+def create_tarball(d, tar_name, src_dir):
+
+    import tarfile
+
+    tar_path = os.path.join(d.getVar("TEST_EXPORT_DIR", True), tar_name)
+    current_dir = os.getcwd()
+    src_dir = src_dir.rstrip('/')
+    dir_name = os.path.dirname(src_dir)
+    base_name = os.path.basename(src_dir)
+
+    os.chdir(dir_name)
+    tar = tarfile.open(tar_path, "w:gz")
+    tar.add(base_name)
+    tar.close()
+    os.chdir(current_dir)
+
+
 testexport_main[vardepsexclude] =+ "BB_ORIGENV"
 
 inherit testimage
Signature · 1 line
2.6.6