public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: "'Clara Kowalsky' via isar-users" <isar-users@googlegroups.com>
To: isar-users@googlegroups.com
Cc: felix.moessbauer@siemens.com,
	Clara Kowalsky <clara.kowalsky@siemens.com>
Subject: [PATCH v2 4/4] testsuite: add rootfs-add-files unittest
Date: Mon, 26 Oct 2026 11:10:18 +0100	[thread overview]
Message-ID: <20261026101018.276241-4-clara.kowalsky@siemens.com> (raw)
In-Reply-To: <20261026101018.276241-1-clara.kowalsky@siemens.com>

Run rootfs_add_files and verify the removal command targets ROOTFSDIR
before the replacement is copied. Cover schroot and unshare commands,
including the unshare ownership.

Signed-off-by: Clara Kowalsky <clara.kowalsky@siemens.com>
---
 testsuite/unittests/test_rootfs_add_files.py | 80 ++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 testsuite/unittests/test_rootfs_add_files.py

diff --git a/testsuite/unittests/test_rootfs_add_files.py b/testsuite/unittests/test_rootfs_add_files.py
new file mode 100644
index 00000000..1ef7c4a8
--- /dev/null
+++ b/testsuite/unittests/test_rootfs_add_files.py
@@ -0,0 +1,80 @@
+# This software is a part of Isar.
+# Copyright (C) Siemens AG, 2026
+#
+# SPDX-License-Identifier: MIT
+
+from rootfs import TemporaryRootfs
+
+import os
+import sys
+import unittest
+from unittest.mock import patch
+from typing import Tuple
+
+sys.path.append(os.path.join(os.path.dirname(__file__), '../../bitbake/lib'))
+
+from bb import process
+from bb.build import exec_func
+from bb.data_smart import DataSmart
+from bb.data import init
+from bb.parse import handle
+
+file_name = 'meta/classes-recipe/rootfs-add-files.bbclass'
+
+
+class TestRootfsAddFiles(unittest.TestCase):
+    def assert_remove_targets_rootfs(self, run_mock, rootfs_file):
+        command = run_mock.call_args_list[0].args[0]
+        if isinstance(command, str):
+            command = command.split()
+        self.assertEqual(
+            command[-3:], ['/usr/bin/rm', '-f', rootfs_file],
+            'Expected the existing destination to be removed from ROOTFSDIR.',
+        )
+
+    def setup(self, chroot_mode: str,
+              destination: str = 'install/payload'
+              ) -> Tuple[DataSmart, TemporaryRootfs]:
+        rootfs = TemporaryRootfs()
+        rootfs.create_file('/source', 'payload')
+        rootfs.create_file('/install/payload', 'old payload')
+
+        d = handle(
+            os.path.join(os.path.dirname(__file__), '../..', file_name),
+            init(),
+        )
+        d.setVar('T', f'{rootfs.path()}/temp')
+        d.setVar('ROOTFSDIR', rootfs.path())
+        d.setVar('ROOTFS_ADDITIONAL_FILES', 'payload')
+        d.setVar('RUN_PRIVILEGED_CMD', 'unshare --mount --user'
+                 if chroot_mode == 'unshare' else 'sudo -E')
+        d.setVar('ISAR_CHROOT_MODE', chroot_mode)
+        d.setVarFlag('ROOTFS_ADDITIONAL_FILE_payload', 'source',
+                     f'{rootfs.path()}/source')
+        d.setVarFlag('ROOTFS_ADDITIONAL_FILE_payload', 'destination',
+                     destination)
+        return (d, rootfs)
+
+    def test_replace_existing_file(self):
+        for destination in ('install/payload', '/install/payload'):
+            with self.subTest(destination=destination):
+                d, rootfs = self.setup('schroot', destination)
+                rootfs_file = f'{rootfs.path()}/{destination}'
+
+                with patch.object(process, 'run') as run_mock:
+                    exec_func('rootfs_add_files', d)
+
+                self.assert_remove_targets_rootfs(run_mock, rootfs_file)
+
+    def test_replace_existing_file_unshare(self):
+        d, rootfs = self.setup('unshare')
+        rootfs_file = f'{rootfs.path()}/install/payload'
+
+        with patch.object(process, 'run') as run_mock:
+            exec_func('rootfs_add_files', d)
+
+        self.assert_remove_targets_rootfs(run_mock, rootfs_file)
+
+
+if __name__ == '__main__':
+    unittest.main()
-- 
2.55.0

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20261026101018.276241-4-clara.kowalsky%40siemens.com.

  parent reply	other threads:[~2026-10-26 10:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 10:10 [PATCH v2 1/4] rootfs-add-files: correctly remove files in ROOTFSDIR 'Clara Kowalsky' via isar-users
2026-10-26 10:10 ` [PATCH v2 2/4] rootfs-add-files: use privileged execution helper for rootless builds 'Clara Kowalsky' via isar-users
2026-10-26 10:10 ` [PATCH v2 3/4] testsuite: add installer build test for rootfs-add-files 'Clara Kowalsky' via isar-users
2026-10-26 10:10 ` 'Clara Kowalsky' via isar-users [this message]
2026-10-28 16:44 ` [PATCH v2 1/4] rootfs-add-files: correctly remove files in ROOTFSDIR Zhihang Wei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261026101018.276241-4-clara.kowalsky@siemens.com \
    --to=isar-users@googlegroups.com \
    --cc=clara.kowalsky@siemens.com \
    --cc=felix.moessbauer@siemens.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox