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