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