Skip to contentSkip to conversation

oeqa/sdk: clarify ELF assertion message

PATCH New Ross Burton 1 participant 5 messages Dec 11, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/5 oeqa/sdk: clarify ELF assertion message

For example, instead of saying "3 != 62", say "Binary was x86-64 but expected i586".

---
 meta/lib/oeqa/sdk/case.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
meta/lib/oeqa/sdk/case.py +12 -5
index ea15d6a107e..d8611c8b308 100644
@@ -1,6 +1,7 @@
 # Copyright (C) 2016 Intel Corporation
 # Released under the MIT license (see COPYING.MIT)
 
+import os
 import subprocess
 
 from oeqa.core.case import OETestCase
@@ -26,11 +27,13 @@ class OESDKTestCase(OETestCase):
         return tarball
 
     def check_elf(self, path, target_os=None, target_arch=None):
+        """
+        Verify that the ELF binary $path matches the specified target
+        OS/architecture, or if not specified the currently configured MACHINE's
+        OS/architecture.
+        """
         import oe.qa, oe.elf
 
-        elf = oe.qa.ELFFile(path)
-        elf.open()
-
         if not target_os or not target_arch:
             output = self._run("echo $OECORE_TARGET_OS:$OECORE_TARGET_ARCH")
             target_os, target_arch = output.strip().split(":")
@@ -38,7 +41,11 @@ class OESDKTestCase(OETestCase):
         machine_data = oe.elf.machine_dict(None)[target_os][target_arch]
         (machine, osabi, abiversion, endian, bits) = machine_data
 
-        self.assertEqual(machine, elf.machine())
+        elf = oe.qa.ELFFile(path)
+        elf.open()
+
+        self.assertEqual(machine, elf.machine(),
+                         "Binary was %s but expected %s" %
+                         (oe.qa.elf_machine_to_string(elf.machine()), oe.qa.elf_machine_to_string(machine)))
         self.assertEqual(bits, elf.abiSize())
         self.assertEqual(endian, elf.isLittleEndian())
-
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 2/5 oeqa/sdk: show output if run() fails

Use oeqa.utils.subprocesstweak to monkey-patch the subprocess exception so that any output is shown, and remove any explicit try/catch handling that would have hidden this.

---
 meta/lib/oeqa/sdk/cases/buildcpio.py  |  3 +++
 meta/lib/oeqa/sdk/cases/buildlzip.py  |  2 ++
 meta/lib/oeqa/sdk/cases/gcc.py        |  3 +++
 meta/lib/oeqa/sdk/cases/perl.py       | 12 ++++++------
 meta/lib/oeqa/sdk/cases/python.py     | 21 +++++++++------------
 meta/lib/oeqa/sdkext/cases/devtool.py |  3 +++
 6 files changed, 26 insertions(+), 18 deletions(-)
meta/lib/oeqa/sdk/cases/buildcpio.py +3 -0
index f348ac5d909..6697b12de29 100644
@@ -2,6 +2,9 @@ import unittest
 from oeqa.sdk.case import OESDKTestCase
 from oeqa.sdk.utils.sdkbuildproject import SDKBuildProject
 
+from oeqa.utils.subprocesstweak import errors_have_output
+errors_have_output()
+
 class BuildCpioTest(OESDKTestCase):
     td_vars = ['DATETIME']
 
meta/lib/oeqa/sdk/cases/buildlzip.py +2 -0
index 9d137f30ebf..b57fbbece7f 100644
@@ -2,6 +2,8 @@ import unittest
 from oeqa.sdk.case import OESDKTestCase
 from oeqa.sdk.utils.sdkbuildproject import SDKBuildProject
 
+from oeqa.utils.subprocesstweak import errors_have_output
+errors_have_output()
 
 class BuildLzipTest(OESDKTestCase):
     td_vars = ['DATETIME']
meta/lib/oeqa/sdk/cases/gcc.py +3 -0
index b32b01fc241..54c6fc488bc 100644
@@ -5,6 +5,9 @@ import unittest
 from oeqa.core.utils.path import remove_safe
 from oeqa.sdk.case import OESDKTestCase
 
+from oeqa.utils.subprocesstweak import errors_have_output
+errors_have_output()
+
 class GccCompileTest(OESDKTestCase):
     td_vars = ['MACHINE']
 
meta/lib/oeqa/sdk/cases/perl.py +6 -6
index e1d2bc159a0..b8adc5ac72d 100644
@@ -1,6 +1,9 @@
 import unittest
 from oeqa.sdk.case import OESDKTestCase
 
+from oeqa.utils.subprocesstweak import errors_have_output
+errors_have_output()
+
 class PerlTest(OESDKTestCase):
     def setUp(self):
         if not (self.tc.hasHostPackage("nativesdk-perl") or
@@ -8,9 +11,6 @@ class PerlTest(OESDKTestCase):
             raise unittest.SkipTest("No perl package in the SDK")
 
     def test_perl(self):
-        try:
-            cmd = "perl -e '$_=\"Uryyb, jbeyq\"; tr/a-zA-Z/n-za-mN-ZA-M/;print'"
-            output = self._run(cmd)
-            self.assertEqual(output, "Hello, world")
-        except subprocess.CalledProcessError as e:
-            self.fail("Unexpected exit %d (output %s)" % (e.returncode, e.output))
+        cmd = "perl -e '$_=\"Uryyb, jbeyq\"; tr/a-zA-Z/n-za-mN-ZA-M/;print'"
+        output = self._run(cmd)
+        self.assertEqual(output, "Hello, world")
meta/lib/oeqa/sdk/cases/python.py +9 -12
index 2254867d455..b9174fadbaa 100644
@@ -1,6 +1,9 @@
 import subprocess, unittest
 from oeqa.sdk.case import OESDKTestCase
 
+from oeqa.utils.subprocesstweak import errors_have_output
+errors_have_output()
+
 class Python2Test(OESDKTestCase):
     def setUp(self):
         if not (self.tc.hasHostPackage("nativesdk-python-core") or
@@ -8,12 +11,9 @@ class Python2Test(OESDKTestCase):
             raise unittest.SkipTest("No python package in the SDK")
 
     def test_python2(self):
-        try:
-            cmd = "python -c \"import codecs; print(codecs.encode('Uryyb, jbeyq', 'rot13'))\""
-            output = self._run(cmd)
-            self.assertEqual(output, "Hello, world\n")
-        except subprocess.CalledProcessError as e:
-            self.fail("Unexpected exit %d (output %s)" % (e.returncode, e.output))
+        cmd = "python -c \"import codecs; print(codecs.encode('Uryyb, jbeyq', 'rot13'))\""
+        output = self._run(cmd)
+        self.assertEqual(output, "Hello, world\n")
 
 class Python3Test(OESDKTestCase):
     def setUp(self):
@@ -22,9 +22,6 @@ class Python3Test(OESDKTestCase):
             raise unittest.SkipTest("No python3 package in the SDK")
 
     def test_python3(self):
-        try:
-            cmd = "python3 -c \"import codecs; print(codecs.encode('Uryyb, jbeyq', 'rot13'))\""
-            output = self._run(cmd)
-            self.assertEqual(output, "Hello, world\n")
-        except subprocess.CalledProcessError as e:
-            self.fail("Unexpected exit %d (output %s)" % (e.returncode, e.output))
+        cmd = "python3 -c \"import codecs; print(codecs.encode('Uryyb, jbeyq', 'rot13'))\""
+        output = self._run(cmd)
+        self.assertEqual(output, "Hello, world\n")
meta/lib/oeqa/sdkext/cases/devtool.py +3 -0
index 0860e8d17cf..d322f86c73e 100644
@@ -9,6 +9,9 @@ from oeqa.sdkext.case import OESDKExtTestCase
 from oeqa.core.decorator.oeid import OETestID
 from oeqa.utils.httpserver import HTTPService
 
+from oeqa.utils.subprocesstweak import errors_have_output
+errors_have_output()
+
 class DevtoolTest(OESDKExtTestCase):
     @classmethod
     def setUpClass(cls):
Signature · 1 line
2.11.0
#2 lore raw

PATCH v2 3/5 oeqa/sdk: clean up galculator test

In reply to Ross Burton

Drop redundant imports and variables, and use os.makedirs() instead of bb.utils.mkdirhier().

---
 meta/lib/oeqa/sdk/cases/buildgalculator.py | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
meta/lib/oeqa/sdk/cases/buildgalculator.py +4 -7
index 7beb55884d3..164a695637a 100644
@@ -3,17 +3,14 @@ import subprocess
 import tempfile
 import unittest
 
-import bb
-
 from oeqa.sdk.case import OESDKTestCase
-from oeqa.sdk.utils.sdkbuildproject import SDKBuildProject
-
 from oeqa.utils.subprocesstweak import errors_have_output
 errors_have_output()
 
 class GalculatorTest(OESDKTestCase):
-    td_vars = ['DATETIME']
-
+    """
+    Test that autotools and GTK+ 3 compiles correctly.
+    """
     def setUp(self):
         if not (self.tc.hasTargetPackage("gtk+3", multilib=True) or \
                 self.tc.hasTargetPackage("libgtk-3.0", multilib=True)):
@@ -33,8 +30,8 @@ class GalculatorTest(OESDKTestCase):
 
             subprocess.check_output(["tar", "xf", tarball, "-C", testdir])
             self.assertTrue(os.path.isdir(dirs["source"]))
+            os.makedirs(dirs["build"])
 
-            bb.utils.mkdirhier(dirs["build"])
             self._run("cd {source} && autoreconf -i -f -I $OECORE_TARGET_SYSROOT/usr/share/aclocal -I m4".format(**dirs))
             self._run("cd {build} && {source}/configure $CONFIGURE_FLAGS".format(**dirs))
             self._run("cd {build} && make -j".format(**dirs))
Signature · 1 line
2.11.0
#3 lore raw

PATCH v2 4/5 oeqa/sdk: rewrite lzip test

In reply to Ross Burton

Don't use the helper class as it gets in the way more than it helps, exercise the out-of-tree paths, and verify the installed files match the expected architecture.

---
 meta/lib/oeqa/sdk/cases/buildlzip.py | 61 +++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 33 deletions(-)
meta/lib/oeqa/sdk/cases/buildlzip.py +28 -33
index b57fbbece7f..a7ca239fb49 100644
@@ -1,39 +1,34 @@
-import unittest
+import os, tempfile, subprocess, unittest
 from oeqa.sdk.case import OESDKTestCase
-from oeqa.sdk.utils.sdkbuildproject import SDKBuildProject
-
 from oeqa.utils.subprocesstweak import errors_have_output
 errors_have_output()
 
 class BuildLzipTest(OESDKTestCase):
-    td_vars = ['DATETIME']
-
-    @classmethod
-    def setUpClass(self):
-        dl_dir = self.td.get('DL_DIR', None)
-
-        self.project = SDKBuildProject(self.tc.sdk_dir + "/lzip/", self.tc.sdk_env,
-                        "http://downloads.yoctoproject.org/mirror/sources/lzip-1.19.tar.gz",
-                        self.tc.sdk_dir, self.td['DATETIME'], dl_dir=dl_dir)
-        self.project.download_archive()
-
-    def setUp(self):
-        machine = self.td.get("MACHINE")
-
-        if not (self.tc.hasHostPackage("packagegroup-cross-canadian-%s" % machine) or
-                self.tc.hasHostPackage("^gcc-", regex=True)):
-            raise unittest.SkipTest("SDK doesn't contain a cross-canadian toolchain")
-
+    """
+    Test that "plain" compilation works, using just $CC $CFLAGS etc.
+    """
     def test_lzip(self):
-        self.assertEqual(self.project.run_configure(), 0,
-                        msg="Running configure failed")
-
-        self.assertEqual(self.project.run_make(), 0,
-                        msg="Running make failed")
-
-        self.assertEqual(self.project.run_install(), 0,
-                        msg="Running make install failed")
-
-    @classmethod
-    def tearDownClass(self):
-        self.project.clean()
+        with tempfile.TemporaryDirectory(prefix="lzip", dir=self.tc.sdk_dir) as testdir:
+            dl_dir = self.td.get('DL_DIR', None)
+            tarball = self.fetch(testdir, dl_dir, "http://downloads.yoctoproject.org/mirror/sources/lzip-1.19.tar.gz")
+
+            dirs = {}
+            dirs["source"] = os.path.join(testdir, "lzip-1.19")
+            dirs["build"] = os.path.join(testdir, "build")
+            dirs["install"] = os.path.join(testdir, "install")
+
+            subprocess.check_output(["tar", "xf", tarball, "-C", testdir])
+            self.assertTrue(os.path.isdir(dirs["source"]))
+            os.makedirs(dirs["build"])
+
+            cmd = """cd {build} && \
+                     {source}/configure --srcdir {source} \
+                     CXX="$CXX" \
+                     CPPFLAGS="$CPPFLAGS" \
+                     CXXFLAGS="$CXXFLAGS" \
+                     LDFLAGS="$LDFLAGS" \
+                  """
+            self._run(cmd.format(**dirs))
+            self._run("cd {build} && make -j".format(**dirs))
+            self._run("cd {build} && make install DESTDIR={install}".format(**dirs))
+            self.check_elf(os.path.join(dirs["install"], "usr", "local", "bin", "lzip"))
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 5/5 oeqa/sdk: rewrite cpio test

In reply to Ross Burton

Don't use the helper class as it gets in the way more than it helps, exercise the out-of-tree paths, and verify the installed files match the expected architecture.

---
 meta/lib/oeqa/sdk/cases/buildcpio.py | 49 ++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 27 deletions(-)
meta/lib/oeqa/sdk/cases/buildcpio.py +22 -27
index 6697b12de29..ff3e1347d37 100644
@@ -1,37 +1,32 @@
+import os
+import tempfile
+import subprocess
 import unittest
-from oeqa.sdk.case import OESDKTestCase
-from oeqa.sdk.utils.sdkbuildproject import SDKBuildProject
 
+from oeqa.sdk.case import OESDKTestCase
 from oeqa.utils.subprocesstweak import errors_have_output
 errors_have_output()
 
 class BuildCpioTest(OESDKTestCase):
-    td_vars = ['DATETIME']
-
-    @classmethod
-    def setUpClass(self):
-        dl_dir = self.td.get('DL_DIR', None)
-
-        self.project = SDKBuildProject(self.tc.sdk_dir + "/cpio/", self.tc.sdk_env,
-                        "https://ftp.gnu.org/gnu/cpio/cpio-2.12.tar.gz",
-                        self.tc.sdk_dir, self.td['DATETIME'], dl_dir=dl_dir)
-        self.project.download_archive()
-
-    def setUp(self):
-        machine = self.td.get("MACHINE")
-        if not self.tc.hasHostPackage("packagegroup-cross-canadian-%s" % machine):
-            raise unittest.SkipTest("SDK doesn't contain a cross-canadian toolchain")
-
+    """
+    Check that autotools will cross-compile correctly.
+    """
     def test_cpio(self):
-        self.assertEqual(self.project.run_configure(), 0,
-                        msg="Running configure failed")
+        with tempfile.TemporaryDirectory(prefix="cpio-", dir=self.tc.sdk_dir) as testdir:
+            dl_dir = self.td.get('DL_DIR', None)
+            tarball = self.fetch(testdir, dl_dir, "https://ftp.gnu.org/gnu/cpio/cpio-2.12.tar.gz")
+
+            dirs = {}
+            dirs["source"] = os.path.join(testdir, "cpio-2.12")
+            dirs["build"] = os.path.join(testdir, "build")
+            dirs["install"] = os.path.join(testdir, "install")
 
-        self.assertEqual(self.project.run_make(), 0,
-                        msg="Running make failed")
+            subprocess.check_output(["tar", "xf", tarball, "-C", testdir])
+            self.assertTrue(os.path.isdir(dirs["source"]))
+            os.makedirs(dirs["build"])
 
-        self.assertEqual(self.project.run_install(), 0,
-                        msg="Running make install failed")
+            self._run("cd {build} && {source}/configure $CONFIGURE_FLAGS".format(**dirs))
+            self._run("cd {build} && make -j".format(**dirs))
+            self._run("cd {build} && make install DESTDIR={install}".format(**dirs))
 
-    @classmethod
-    def tearDownClass(self):
-        self.project.clean()
+            self.check_elf(os.path.join(dirs["install"], "usr", "local", "bin", "cpio"))
Signature · 1 line
2.11.0