11a4b7ee2SBrad Bishop# 21a4b7ee2SBrad Bishop# BitBake Tests for cooker.py 31a4b7ee2SBrad Bishop# 4*c342db35SBrad Bishop# SPDX-License-Identifier: GPL-2.0-only 51a4b7ee2SBrad Bishop# 61a4b7ee2SBrad Bishop 71a4b7ee2SBrad Bishopimport unittest 81a4b7ee2SBrad Bishopimport tempfile 91a4b7ee2SBrad Bishopimport os 101a4b7ee2SBrad Bishopimport bb, bb.cooker 111a4b7ee2SBrad Bishopimport re 121a4b7ee2SBrad Bishopimport logging 131a4b7ee2SBrad Bishop 141a4b7ee2SBrad Bishop# Cooker tests 151a4b7ee2SBrad Bishopclass CookerTest(unittest.TestCase): 161a4b7ee2SBrad Bishop def setUp(self): 171a4b7ee2SBrad Bishop # At least one variable needs to be set 181a4b7ee2SBrad Bishop self.d = bb.data.init() 191a4b7ee2SBrad Bishop topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "testdata/cooker") 201a4b7ee2SBrad Bishop self.d.setVar('TOPDIR', topdir) 211a4b7ee2SBrad Bishop 221a4b7ee2SBrad Bishop def test_CookerCollectFiles_sublayers(self): 231a4b7ee2SBrad Bishop '''Test that a sublayer of an existing layer does not trigger 241a4b7ee2SBrad Bishop No bb files matched ...''' 251a4b7ee2SBrad Bishop 261a4b7ee2SBrad Bishop def append_collection(topdir, path, d): 271a4b7ee2SBrad Bishop collection = path.split('/')[-1] 281a4b7ee2SBrad Bishop pattern = "^" + topdir + "/" + path + "/" 291a4b7ee2SBrad Bishop regex = re.compile(pattern) 301a4b7ee2SBrad Bishop priority = 5 311a4b7ee2SBrad Bishop 321a4b7ee2SBrad Bishop d.setVar('BBFILE_COLLECTIONS', (d.getVar('BBFILE_COLLECTIONS') or "") + " " + collection) 331a4b7ee2SBrad Bishop d.setVar('BBFILE_PATTERN_%s' % (collection), pattern) 341a4b7ee2SBrad Bishop d.setVar('BBFILE_PRIORITY_%s' % (collection), priority) 351a4b7ee2SBrad Bishop 361a4b7ee2SBrad Bishop return (collection, pattern, regex, priority) 371a4b7ee2SBrad Bishop 381a4b7ee2SBrad Bishop topdir = self.d.getVar("TOPDIR") 391a4b7ee2SBrad Bishop 401a4b7ee2SBrad Bishop # Priorities: list of (collection, pattern, regex, priority) 411a4b7ee2SBrad Bishop bbfile_config_priorities = [] 421a4b7ee2SBrad Bishop # Order is important for this test, shortest to longest is typical failure case 431a4b7ee2SBrad Bishop bbfile_config_priorities.append( append_collection(topdir, 'first', self.d) ) 441a4b7ee2SBrad Bishop bbfile_config_priorities.append( append_collection(topdir, 'second', self.d) ) 451a4b7ee2SBrad Bishop bbfile_config_priorities.append( append_collection(topdir, 'second/third', self.d) ) 461a4b7ee2SBrad Bishop 471a4b7ee2SBrad Bishop pkgfns = [ topdir + '/first/recipes/sample1_1.0.bb', 481a4b7ee2SBrad Bishop topdir + '/second/recipes/sample2_1.0.bb', 491a4b7ee2SBrad Bishop topdir + '/second/third/recipes/sample3_1.0.bb' ] 501a4b7ee2SBrad Bishop 511a4b7ee2SBrad Bishop class LogHandler(logging.Handler): 521a4b7ee2SBrad Bishop def __init__(self): 531a4b7ee2SBrad Bishop logging.Handler.__init__(self) 541a4b7ee2SBrad Bishop self.logdata = [] 551a4b7ee2SBrad Bishop 561a4b7ee2SBrad Bishop def emit(self, record): 571a4b7ee2SBrad Bishop self.logdata.append(record.getMessage()) 581a4b7ee2SBrad Bishop 591a4b7ee2SBrad Bishop # Move cooker to use my special logging 601a4b7ee2SBrad Bishop logger = bb.cooker.logger 611a4b7ee2SBrad Bishop log_handler = LogHandler() 621a4b7ee2SBrad Bishop logger.addHandler(log_handler) 631a4b7ee2SBrad Bishop collection = bb.cooker.CookerCollectFiles(bbfile_config_priorities) 641a4b7ee2SBrad Bishop collection.collection_priorities(pkgfns, self.d) 651a4b7ee2SBrad Bishop logger.removeHandler(log_handler) 661a4b7ee2SBrad Bishop 671a4b7ee2SBrad Bishop # Should be empty (no generated messages) 681a4b7ee2SBrad Bishop expected = [] 691a4b7ee2SBrad Bishop 701a4b7ee2SBrad Bishop self.assertEqual(log_handler.logdata, expected) 71