On Tue, 2026-04-28 at 09:10 +0100, Sam Kent via lists.openembedded.org wrote:
> Add unit tests for the filename pre-filter logic, is_kernel_module(),
> and the is_kernel_module_signed() detection.
>
> Signed-off-by: Sam Kent <[email protected]>
> ---
> meta/lib/oe/tests/__init__.py | 0
> meta/lib/oe/tests/test_package.py | 121 ++++++++++++++++++++++++++++++
> 2 files changed, 121 insertions(+)
> create mode 100644 meta/lib/oe/tests/__init__.py
> create mode 100644 meta/lib/oe/tests/test_package.py
>
> +class TestIsKernelModule(unittest.TestCase):
> + """
> + is_kernel_module() detects kernel modules by searching for the
> + "vermagic=" string, which is always present in genuine .ko files.
> + """
> +
> + def _make_tmp(self, content: bytes) -> str:
> + f = tempfile.NamedTemporaryFile(delete=False, suffix=".ko")
> + f.write(content)
> + f.close()
> + return f.name
> +
> + def tearDown(self):
> + # Clean up any temp files created during the test.
> + for attr in ("_tmpfile",):
> + path = getattr(self, attr, None)
> + if path and os.path.exists(path):
> + os.unlink(path)
> +
> + def test_detects_vermagic(self):
> + self._tmpfile = self._make_tmp(b"\x7fELF\x00" * 10 +
> b"vermagic=5.15.0" + b"\x00" * 10)
> + self.assertTrue(is_kernel_module(self._tmpfile))
> +
> + def test_rejects_plain_elf(self):
> + self._tmpfile = self._make_tmp(b"\x7fELF\x00" * 50)
> + self.assertFalse(is_kernel_module(self._tmpfile))
Sorry about the delay in replying to this, I think we were all confused
about who was going to do it!
The code above is a little bit more complex than it needs to be. It can
be simplified to something like:
with NamedTemporaryFile(suffix=".ko") as f:
f.write(b"\x7fELF\x00" * 10 + b"vermagic=5.15.0" + b"\x00" * 10)
self.assertTrue(is_kernel_module(f.name))
which will self clean up. Could you make that tweak, then we should be
able to merge, thanks!
Cheers,
Richard
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#238129):
https://lists.openembedded.org/g/openembedded-core/message/238129
Mute This Topic: https://lists.openembedded.org/mt/119045161/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-