diff mbox series

[2/2] oeqa/selftest/devtool: fail if non-selfest workspace layer present

Message ID 20231007174701.1890063-2-chris.laplante@agilent.com
State New
Headers show
Series [1/2] recipetool: use context manager for tinfoil to avoid hang | expand

Commit Message

chris.laplante@agilent.com Oct. 7, 2023, 5:47 p.m. UTC
The tests will fail anyway (since you will have two 'workspacelayer'
layers), so might as well make it fail faster and be clear.

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
---
 meta/lib/oeqa/selftest/cases/devtool.py | 36 ++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

Comments

Julien Stephan Oct. 9, 2023, 7:50 a.m. UTC | #1
Le sam. 7 oct. 2023 à 19:47, Chris Laplante via lists.openembedded.org
<chris.laplante=agilent.com@lists.openembedded.org> a écrit :
>
> The tests will fail anyway (since you will have two 'workspacelayer'
> layers), so might as well make it fail faster and be clear.
>

Hi Chris,

FYI I also sent a patch to fix this issue the day just before you :)
You can find it here:
https://lists.openembedded.org/g/openembedded-core/message/188767

I do a check directly on the setUpModule. I also noticed that
devtool.DevtoolAddTests.test_devtool_add just hangs
if there is a local workspace but I didn't investigate it ;)

Cheers
Julien

> Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
> ---
>  meta/lib/oeqa/selftest/cases/devtool.py | 36 ++++++++++++++++++++++---
>  1 file changed, 33 insertions(+), 3 deletions(-)
>
> diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py
> index b577f6d62a..2c38eeca17 100644
> --- a/meta/lib/oeqa/selftest/cases/devtool.py
> +++ b/meta/lib/oeqa/selftest/cases/devtool.py
> @@ -3,7 +3,7 @@
>  #
>  # SPDX-License-Identifier: MIT
>  #
> -
> +import dataclasses
>  import os
>  import re
>  import shutil
> @@ -11,6 +11,7 @@ import tempfile
>  import glob
>  import fnmatch
>  import unittest
> +from typing import List
>
>  from oeqa.selftest.case import OESelftestTestCase
>  from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer
> @@ -90,6 +91,12 @@ def tearDownModule():
>          bb.utils.edit_bblayers_conf(bblayers_conf, None, None, bblayers_edit_cb)
>      shutil.rmtree(templayerdir)
>
> +@dataclasses.dataclass
> +class BBLayerConfEntry:
> +    layer: str
> +    path: str
> +    priority: int
> +
>  class DevtoolTestCase(OESelftestTestCase):
>
>      def setUp(self):
> @@ -100,6 +107,29 @@ class DevtoolTestCase(OESelftestTestCase):
>                          'This test cannot be run with a workspace directory '
>                          'under the build directory')
>
> +        # Ensure there is no actual workspace dir enabled
> +        self.assertFalse(self.is_external_workspace_layer_enabled(),
> +                         "This test cannot be run with a workspace layer in bblayers.conf")
> +
> +    def is_selftest_workspace_layer_enabled(self):
> +        """Returns true if the selftest workspace layer is enabled in bblayers.conf"""
> +        return any([layer for layer in self._read_bblayers() if
> +                    layer.layer == "workspacelayer" and layer.path == self.workspacedir])
> +
> +    def is_external_workspace_layer_enabled(self):
> +        """Returns true if a workspace layer (that wasn't installed by selftest) is enabled in bblayers.conf"""
> +        return any([layer for layer in self._read_bblayers() if
> +                    layer.layer == "workspacelayer" and layer.path != self.workspacedir])
> +
> +    def _read_bblayers(self) -> List[BBLayerConfEntry]:
> +        """Call bitbake-layers show-layers and return list of layers"""
> +        ret = []
> +        for line in runCmd('bitbake-layers show-layers').output.splitlines():
> +            line = line.strip()
> +            if match := re.match(r'^(\S+) +([^\n]*?) +(\d+)$', line):
> +                ret.append(BBLayerConfEntry(match[1], match[2], match[3]))
> +        return ret
> +
>      def _check_src_repo(self, repo_dir):
>          """Check srctree git repository"""
>          self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')),
> @@ -327,8 +357,8 @@ class DevtoolTests(DevtoolBase):
>
>      def test_create_workspace(self):
>          # Check preconditions
> -        result = runCmd('bitbake-layers show-layers')
> -        self.assertTrue('\nworkspace' not in result.output, 'This test cannot be run with a workspace layer in bblayers.conf')
> +        self.assertFalse(self.is_selftest_workspace_layer_enabled(),
> +                         "This test cannot be run with the selftest workspace layer in bblayers.conf")
>          # remove conf/devtool.conf to avoid it corrupting tests
>          devtoolconf = os.path.join(self.builddir, 'conf', 'devtool.conf')
>          self.track_for_cleanup(devtoolconf)
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#188798): https://lists.openembedded.org/g/openembedded-core/message/188798
> Mute This Topic: https://lists.openembedded.org/mt/101820643/4356723
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [jstephan@baylibre.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
chris.laplante@agilent.com Oct. 9, 2023, 2:46 p.m. UTC | #2
> FYI I also sent a patch to fix this issue the day just before you :) You can find it
> here:
> https://lists.op/
> enembedded.org%2Fg%2Fopenembedded-
> core%2Fmessage%2F188767&data=05%7C01%7Cchris.laplante%40agilent.com
> %7C34ce8f731f6f4590172108dbc89c6739%7Ca9c0bc098b46420693512ba12fb
> 4a5c0%7C0%7C0%7C638324346300462677%7CUnknown%7CTWFpbGZsb3d8e
> yJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%
> 7C3000%7C%7C%7C&sdata=X3V9v4pUxmNJh%2Fb0w9OVdzgvqiDXgfjQYB8iUb
> 904BU%3D&reserved=0
>
> I do a check directly on the setUpModule. I also noticed that
> devtool.DevtoolAddTests.test_devtool_add just hangs if there is a local
> workspace but I didn't investigate it ;)
>
> Cheers
> Julien

Ah, very nice :). It was really frustrating me (plus it was a Friday) which is why I spent the time to debug it.

Thanks,
Chris
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py
index b577f6d62a..2c38eeca17 100644
--- a/meta/lib/oeqa/selftest/cases/devtool.py
+++ b/meta/lib/oeqa/selftest/cases/devtool.py
@@ -3,7 +3,7 @@ 
 #
 # SPDX-License-Identifier: MIT
 #
-
+import dataclasses
 import os
 import re
 import shutil
@@ -11,6 +11,7 @@  import tempfile
 import glob
 import fnmatch
 import unittest
+from typing import List
 
 from oeqa.selftest.case import OESelftestTestCase
 from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer
@@ -90,6 +91,12 @@  def tearDownModule():
         bb.utils.edit_bblayers_conf(bblayers_conf, None, None, bblayers_edit_cb)
     shutil.rmtree(templayerdir)
 
+@dataclasses.dataclass
+class BBLayerConfEntry:
+    layer: str
+    path: str
+    priority: int
+
 class DevtoolTestCase(OESelftestTestCase):
 
     def setUp(self):
@@ -100,6 +107,29 @@  class DevtoolTestCase(OESelftestTestCase):
                         'This test cannot be run with a workspace directory '
                         'under the build directory')
 
+        # Ensure there is no actual workspace dir enabled
+        self.assertFalse(self.is_external_workspace_layer_enabled(),
+                         "This test cannot be run with a workspace layer in bblayers.conf")
+
+    def is_selftest_workspace_layer_enabled(self):
+        """Returns true if the selftest workspace layer is enabled in bblayers.conf"""
+        return any([layer for layer in self._read_bblayers() if
+                    layer.layer == "workspacelayer" and layer.path == self.workspacedir])
+
+    def is_external_workspace_layer_enabled(self):
+        """Returns true if a workspace layer (that wasn't installed by selftest) is enabled in bblayers.conf"""
+        return any([layer for layer in self._read_bblayers() if
+                    layer.layer == "workspacelayer" and layer.path != self.workspacedir])
+
+    def _read_bblayers(self) -> List[BBLayerConfEntry]:
+        """Call bitbake-layers show-layers and return list of layers"""
+        ret = []
+        for line in runCmd('bitbake-layers show-layers').output.splitlines():
+            line = line.strip()
+            if match := re.match(r'^(\S+) +([^\n]*?) +(\d+)$', line):
+                ret.append(BBLayerConfEntry(match[1], match[2], match[3]))
+        return ret
+
     def _check_src_repo(self, repo_dir):
         """Check srctree git repository"""
         self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')),
@@ -327,8 +357,8 @@  class DevtoolTests(DevtoolBase):
 
     def test_create_workspace(self):
         # Check preconditions
-        result = runCmd('bitbake-layers show-layers')
-        self.assertTrue('\nworkspace' not in result.output, 'This test cannot be run with a workspace layer in bblayers.conf')
+        self.assertFalse(self.is_selftest_workspace_layer_enabled(),
+                         "This test cannot be run with the selftest workspace layer in bblayers.conf")
         # remove conf/devtool.conf to avoid it corrupting tests
         devtoolconf = os.path.join(self.builddir, 'conf', 'devtool.conf')
         self.track_for_cleanup(devtoolconf)