summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Rosen <jeremy.rosen@smile.fr>2023-10-10 15:49:29 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-10-15 09:11:47 +0100
commit18bd65d241d2ca2d14541b9c6dd0d9f3f1cdba35 (patch)
tree5c8bbc56372d8152648da79e94f690f437b10f63
parent5330065f51fc0dcc2b74360220b2c97c4b80e622 (diff)
downloadpoky-18bd65d241d2ca2d14541b9c6dd0d9f3f1cdba35.tar.gz
insane: Detect python and perl based tests
match_line_in_files will look for a regex in all files matching a glob. we use iglob to avoid a complete, recursive scan of all source. iglob is based on python iterators and will scan as we walk through the directories pytest are detected by looking for "import pytest" or "from pytest" in any python file. perl Test:: is detetected by looking for any t/*.t in the toplevel source directory. (From OE-Core rev: 00d64ac38ae4af6193fae3b02375a16b1821f29e) Signed-off-by: Jérémy Rosen <jeremy.rosen@smile.fr> Reviewed-by: Yoann Congal <yoann.congal@smile.fr> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-global/insane.bbclass22
1 files changed, 22 insertions, 0 deletions
diff --git a/meta/classes-global/insane.bbclass b/meta/classes-global/insane.bbclass
index c40bae7e3d..99b8faccf5 100644
--- a/meta/classes-global/insane.bbclass
+++ b/meta/classes-global/insane.bbclass
@@ -1351,12 +1351,34 @@ python do_qa_patch() {
1351 ########################################################################### 1351 ###########################################################################
1352 # Check for missing ptests 1352 # Check for missing ptests
1353 ########################################################################### 1353 ###########################################################################
1354 def match_line_in_files(toplevel, filename_glob, line_regex):
1355 import pathlib
1356 toppath = pathlib.Path(toplevel)
1357 for entry in toppath.glob(filename_glob):
1358 try:
1359 with open(entry, 'r', encoding='utf-8', errors='ignore') as f:
1360 for line in f.readlines():
1361 if re.match(line_regex, line):
1362 return True
1363 except FileNotFoundError:
1364 # Broken symlink in source
1365 pass
1366 return False
1367
1354 srcdir = d.getVar('S') 1368 srcdir = d.getVar('S')
1355 if not bb.utils.contains('DISTRO_FEATURES', 'ptest', True, False, d): 1369 if not bb.utils.contains('DISTRO_FEATURES', 'ptest', True, False, d):
1356 pass 1370 pass
1357 elif bb.data.inherits_class('ptest', d): 1371 elif bb.data.inherits_class('ptest', d):
1358 bb.note("Package %s QA: skipping unimplemented-ptest: ptest implementation detected" % d.getVar('PN')) 1372 bb.note("Package %s QA: skipping unimplemented-ptest: ptest implementation detected" % d.getVar('PN'))
1359 1373
1374 # Detect perl Test:: based tests
1375 elif os.path.exists(os.path.join(srcdir, "t")) and any(filename.endswith('.t') for filename in os.listdir(os.path.join(srcdir, 't'))):
1376 oe.qa.handle_error("unimplemented-ptest", "%s: perl Test:: based tests detected" % d.getVar('PN'), d)
1377
1378 # Detect pytest-based tests
1379 elif match_line_in_files(srcdir, "**/*.py", r'\s*(?:import\s*pytest|from\s*pytest)'):
1380 oe.qa.handle_error("unimplemented-ptest", "%s: pytest-based tests detected" % d.getVar('PN'), d)
1381
1360 oe.qa.exit_if_errors(d) 1382 oe.qa.exit_if_errors(d)
1361} 1383}
1362 1384