* [PATCH] testsuite: Add source package contents test case
@ 2023-11-01 9:32 Anton Mikanovich
2023-11-10 8:32 ` Uladzimir Bely
0 siblings, 1 reply; 2+ messages in thread
From: Anton Mikanovich @ 2023-11-01 9:32 UTC (permalink / raw)
To: isar-users; +Cc: Anton Mikanovich
Add new test case for checking source package contents.
Two aspects are currently checking:
1) Source package content do not include .git files
2) Setting empty DPKG_SOURCE_EXTRA_ARGS makes package include new files
Also introduce some new APIs for test writters:
1) create_tmp_layer and cleanup_tmp_layer
Create and remove meta-tmp for temporary source changing.
Now we can put bbappend into it without touching meta and meta-isar.
2) getVars
API to retrieve one or more bitbake variables from repices.
Setting target value makes it parce multiconfig related variables.
3) get_tar_content
Obtain filenames from tar.* files.
Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
testsuite/cibase.py | 54 +++++++++++++++++++++++++++++++
testsuite/cibuilder.py | 73 ++++++++++++++++++++++++++++++++++++++++++
testsuite/citest.py | 15 +++++++++
3 files changed, 142 insertions(+)
diff --git a/testsuite/cibase.py b/testsuite/cibase.py
index d7010387..adeff205 100755
--- a/testsuite/cibase.py
+++ b/testsuite/cibase.py
@@ -212,3 +212,57 @@ class CIBaseTest(CIBuilder):
['do_rootfs_install_setscene', '!do_rootfs_install'])
]):
self.fail("Failed rebuild package and image")
+
+ def perform_source_test(self, targets, **kwargs):
+ def get_source_content(targets):
+ sfiles = dict()
+ for target in targets:
+ sfiles[target] = dict()
+ package = target.rsplit(':', 1)[-1]
+ isar_apt = self.getVars('REPO_ISAR_DB_DIR', target=target)
+ fpath = f'{package}/{package}*.tar.gz'
+ targz = set(glob.glob(f'{isar_apt}/../apt/*/pool/*/*/{fpath}'))
+ if len(targz) < 1:
+ self.fail('No source packages found')
+ for filename in targz:
+ sfiles[target][filename] = self.get_tar_content(filename)
+ return sfiles
+
+ self.configure(**kwargs)
+
+ tmp_layer_dir = self.create_tmp_layer()
+ try:
+ self.bitbake(targets, bitbake_cmd='do_deploy_source', **kwargs)
+
+ sfiles_before = get_source_content(targets)
+ for tdir in sfiles_before:
+ for filename in sfiles_before[tdir]:
+ for file in sfiles_before[tdir][filename]:
+ if os.path.basename(file).startswith('.git'):
+ self.fail('Found .git files')
+
+ package = targets[0].rsplit(':', 1)[-1]
+ tmp_layer_nested_dirs = os.path.join(tmp_layer_dir,
+ 'recipes-app', package)
+ os.makedirs(tmp_layer_nested_dirs, exist_ok=True)
+ bbappend_file = os.path.join(tmp_layer_nested_dirs,
+ package + '.bbappend')
+ with open(bbappend_file, 'w') as file:
+ file.write('DPKG_SOURCE_EXTRA_ARGS = ""')
+
+ self.bitbake(targets, bitbake_cmd='do_deploy_source', **kwargs)
+
+ sfiles_after = get_source_content(targets)
+
+ for tdir in sfiles_after:
+ for filename in sfiles_after[tdir]:
+ if not sfiles_before[tdir][filename]:
+ self.fail('Source filenames are different')
+ diff = []
+ for file in sfiles_after[tdir][filename]:
+ if file not in sfiles_before[tdir][filename]:
+ diff.append(file)
+ if len(diff) < 1:
+ self.fail('Source packages are equal')
+ finally:
+ self.cleanup_tmp_layer(tmp_layer_dir)
diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py
index 1ff77332..2b784ef9 100755
--- a/testsuite/cibuilder.py
+++ b/testsuite/cibuilder.py
@@ -8,6 +8,8 @@ import select
import shutil
import signal
import subprocess
+import sys
+import tarfile
import time
import tempfile
@@ -17,6 +19,11 @@ from avocado import Test
from avocado.utils import path
from avocado.utils import process
+sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/../bitbake/lib')
+
+import bb
+import bb.tinfoil
+
DEF_VM_TO_SEC = 600
isar_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
@@ -245,6 +252,72 @@ class CIBuilder(Test):
return env['LAYERDIR_' + layer].strip('"')
+ def getVars(self, *vars, target=None):
+ def fixStream(stream):
+ # fix stream objects to emulate _io.TextIOWrapper
+ stream.isatty = lambda: False
+ stream.fileno = lambda: False
+ stream.encoding = sys.getdefaultencoding()
+
+ sl = target is not None
+ fixStream(sys.stdout)
+ fixStream(sys.stderr)
+
+ lockfile = os.path.join(self.build_dir, 'bitbake.lock2')
+ checks = 0
+ while os.path.exists(lockfile) and checks < 5:
+ time.sleep(1)
+ checks += 1
+
+ with bb.tinfoil.Tinfoil(setup_logging=sl) as tinfoil:
+ values = ()
+ if target:
+ tinfoil.prepare(quiet=2)
+ d = tinfoil.parse_recipe(target)
+ for var in vars:
+ values = values + (d.getVar(var),)
+ else:
+ tinfoil.prepare(config_only=True, quiet=2)
+ for var in vars:
+ values = values + (tinfoil.config_data.getVar(var),)
+ return values if len(values) > 1 else values[0]
+
+ def create_tmp_layer(self):
+ tmp_layer_dir = os.path.join(isar_root, 'meta-tmp')
+
+ conf_dir = os.path.join(tmp_layer_dir, 'conf')
+ os.makedirs(conf_dir, exist_ok=True)
+ layer_conf_file = os.path.join(conf_dir, 'layer.conf')
+ with open(layer_conf_file, 'w') as file:
+ file.write('\
+BBPATH .= ":${LAYERDIR}"\
+\nBBFILES += "${LAYERDIR}/recipes-*/*/*.bbappend"\
+\nBBFILE_COLLECTIONS += "tmp"\
+\nBBFILE_PATTERN_tmp = "^${LAYERDIR}/"\
+\nBBFILE_PRIORITY_tmp = "5"\
+\nLAYERVERSION_tmp = "1"\
+\nLAYERSERIES_COMPAT_tmp = "v0.6"\
+')
+
+ bblayersconf_file = os.path.join(self.build_dir, 'conf',
+ 'bblayers.conf')
+ bb.utils.edit_bblayers_conf(bblayersconf_file, tmp_layer_dir, None)
+
+ return tmp_layer_dir
+
+ def cleanup_tmp_layer(self, tmp_layer_dir):
+ bblayersconf_file = os.path.join(self.build_dir, 'conf',
+ 'bblayers.conf')
+ bb.utils.edit_bblayers_conf(bblayersconf_file, None, tmp_layer_dir)
+ bb.utils.prunedir(tmp_layer_dir)
+
+ def get_tar_content(self, filename):
+ try:
+ tar = tarfile.open(filename)
+ return tar.getnames()
+ except Exception:
+ return []
+
def get_ssh_cmd_prefix(self, user, host, port, priv_key):
cmd_prefix = 'ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no '\
'-p %s -o IdentityFile=%s %s@%s ' \
diff --git a/testsuite/citest.py b/testsuite/citest.py
index 81bdeba5..7be2b86b 100755
--- a/testsuite/citest.py
+++ b/testsuite/citest.py
@@ -314,6 +314,21 @@ class SingleTest(CIBaseTest):
self.vm_start(machine.removeprefix('qemu'), distro,
stop_vm=True)
+class SourceTest(CIBaseTest):
+
+ """
+ Source contents test
+
+ :avocado: tags=source
+ """
+ def test_source(self):
+ targets = [
+ 'mc:qemuamd64-bookworm:libhello',
+ 'mc:qemuarm64-bookworm:libhello',
+ ]
+
+ self.init()
+ self.perform_source_test(targets)
class VmBootTestFast(CIBaseTest):
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] testsuite: Add source package contents test case
2023-11-01 9:32 [PATCH] testsuite: Add source package contents test case Anton Mikanovich
@ 2023-11-10 8:32 ` Uladzimir Bely
0 siblings, 0 replies; 2+ messages in thread
From: Uladzimir Bely @ 2023-11-10 8:32 UTC (permalink / raw)
To: Anton Mikanovich, isar-users
On Wed, 2023-11-01 at 11:32 +0200, Anton Mikanovich wrote:
> Add new test case for checking source package contents.
> Two aspects are currently checking:
> 1) Source package content do not include .git files
> 2) Setting empty DPKG_SOURCE_EXTRA_ARGS makes package include new
> files
>
> Also introduce some new APIs for test writters:
> 1) create_tmp_layer and cleanup_tmp_layer
> Create and remove meta-tmp for temporary source changing.
> Now we can put bbappend into it without touching meta and meta-isar.
> 2) getVars
> API to retrieve one or more bitbake variables from repices.
> Setting target value makes it parce multiconfig related variables.
> 3) get_tar_content
> Obtain filenames from tar.* files.
>
> Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
> ---
> testsuite/cibase.py | 54 +++++++++++++++++++++++++++++++
> testsuite/cibuilder.py | 73
> ++++++++++++++++++++++++++++++++++++++++++
> testsuite/citest.py | 15 +++++++++
> 3 files changed, 142 insertions(+)
>
Applied to next.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-10 8:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-01 9:32 [PATCH] testsuite: Add source package contents test case Anton Mikanovich
2023-11-10 8:32 ` Uladzimir Bely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox