196ff1984SBrad Bishop#
296ff1984SBrad Bishop# BitBake Tests for runqueue task processing
396ff1984SBrad Bishop#
496ff1984SBrad Bishop# Copyright (C) 2019 Richard Purdie
596ff1984SBrad Bishop#
696ff1984SBrad Bishop# SPDX-License-Identifier: GPL-2.0-only
796ff1984SBrad Bishop#
896ff1984SBrad Bishop
996ff1984SBrad Bishopimport unittest
1096ff1984SBrad Bishopimport os
1196ff1984SBrad Bishopimport tempfile
1296ff1984SBrad Bishopimport subprocess
13a34c030eSBrad Bishopimport sys
1400e122a7SBrad Bishopimport time
1596ff1984SBrad Bishop
1696ff1984SBrad Bishop#
1796ff1984SBrad Bishop# TODO:
1896ff1984SBrad Bishop# Add tests on task ordering (X happens before Y after Z)
1996ff1984SBrad Bishop#
2096ff1984SBrad Bishop
2196ff1984SBrad Bishopclass RunQueueTests(unittest.TestCase):
2296ff1984SBrad Bishop
2396ff1984SBrad Bishop    alltasks = ['package', 'fetch', 'unpack', 'patch', 'prepare_recipe_sysroot', 'configure',
2496ff1984SBrad Bishop                'compile', 'install', 'packagedata', 'package_qa', 'package_write_rpm', 'package_write_ipk',
2596ff1984SBrad Bishop                'populate_sysroot', 'build']
2696ff1984SBrad Bishop    a1_sstatevalid = "a1:do_package a1:do_package_qa a1:do_packagedata a1:do_package_write_ipk a1:do_package_write_rpm a1:do_populate_lic a1:do_populate_sysroot"
2796ff1984SBrad Bishop    b1_sstatevalid = "b1:do_package b1:do_package_qa b1:do_packagedata b1:do_package_write_ipk b1:do_package_write_rpm b1:do_populate_lic b1:do_populate_sysroot"
2896ff1984SBrad Bishop
2908902b01SBrad Bishop    def run_bitbakecmd(self, cmd, builddir, sstatevalid="", slowtasks="", extraenv=None, cleanup=False):
3096ff1984SBrad Bishop        env = os.environ.copy()
3196ff1984SBrad Bishop        env["BBPATH"] = os.path.realpath(os.path.join(os.path.dirname(__file__), "runqueue-tests"))
3296ff1984SBrad Bishop        env["BB_ENV_EXTRAWHITE"] = "SSTATEVALID SLOWTASKS"
3396ff1984SBrad Bishop        env["SSTATEVALID"] = sstatevalid
3496ff1984SBrad Bishop        env["SLOWTASKS"] = slowtasks
3596ff1984SBrad Bishop        if extraenv:
3696ff1984SBrad Bishop            for k in extraenv:
3796ff1984SBrad Bishop                env[k] = extraenv[k]
3896ff1984SBrad Bishop                env["BB_ENV_EXTRAWHITE"] = env["BB_ENV_EXTRAWHITE"] + " " + k
3996ff1984SBrad Bishop        try:
4096ff1984SBrad Bishop            output = subprocess.check_output(cmd, env=env, stderr=subprocess.STDOUT,universal_newlines=True, cwd=builddir)
4108902b01SBrad Bishop            print(output)
4296ff1984SBrad Bishop        except subprocess.CalledProcessError as e:
4396ff1984SBrad Bishop            self.fail("Command %s failed with %s" % (cmd, e.output))
4496ff1984SBrad Bishop        tasks = []
4508902b01SBrad Bishop        tasklog = builddir + "/task.log"
4608902b01SBrad Bishop        if os.path.exists(tasklog):
4708902b01SBrad Bishop            with open(tasklog, "r") as f:
4896ff1984SBrad Bishop                tasks = [line.rstrip() for line in f]
4908902b01SBrad Bishop            if cleanup:
5008902b01SBrad Bishop                os.remove(tasklog)
5196ff1984SBrad Bishop        return tasks
5296ff1984SBrad Bishop
5396ff1984SBrad Bishop    def test_no_setscenevalid(self):
5496ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
5596ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
5696ff1984SBrad Bishop            sstatevalid = ""
5796ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
5896ff1984SBrad Bishop            expected = ['a1:' + x for x in self.alltasks]
5996ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
6096ff1984SBrad Bishop
6196ff1984SBrad Bishop    def test_single_setscenevalid(self):
6296ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
6396ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
6496ff1984SBrad Bishop            sstatevalid = "a1:do_package"
6596ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
6696ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
6796ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_qa', 'a1:package_write_rpm', 'a1:package_write_ipk',
6896ff1984SBrad Bishop                        'a1:populate_sysroot', 'a1:build']
6996ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
7096ff1984SBrad Bishop
7196ff1984SBrad Bishop    def test_intermediate_setscenevalid(self):
7296ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
7396ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
7496ff1984SBrad Bishop            sstatevalid = "a1:do_package a1:do_populate_sysroot"
7596ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
7696ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:packagedata', 'a1:package_qa', 'a1:package_write_rpm', 'a1:package_write_ipk',
7796ff1984SBrad Bishop                        'a1:populate_sysroot_setscene', 'a1:build']
7896ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
7996ff1984SBrad Bishop
8096ff1984SBrad Bishop    def test_intermediate_notcovered(self):
8196ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
8296ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
8396ff1984SBrad Bishop            sstatevalid = "a1:do_package_qa a1:do_packagedata a1:do_package_write_ipk a1:do_package_write_rpm a1:do_populate_lic a1:do_populate_sysroot"
8496ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
8596ff1984SBrad Bishop            expected = ['a1:package_write_ipk_setscene', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
8696ff1984SBrad Bishop                        'a1:package_qa_setscene', 'a1:build', 'a1:populate_sysroot_setscene']
8796ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
8896ff1984SBrad Bishop
8996ff1984SBrad Bishop    def test_all_setscenevalid(self):
9096ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
9196ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
9296ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid
9396ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
9496ff1984SBrad Bishop            expected = ['a1:package_write_ipk_setscene', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
9596ff1984SBrad Bishop                        'a1:package_qa_setscene', 'a1:build', 'a1:populate_sysroot_setscene']
9696ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
9796ff1984SBrad Bishop
9896ff1984SBrad Bishop    def test_no_settasks(self):
9996ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
10096ff1984SBrad Bishop            cmd = ["bitbake", "a1", "-c", "patch"]
10196ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid
10296ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
10396ff1984SBrad Bishop            expected = ['a1:fetch', 'a1:unpack', 'a1:patch']
10496ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
10596ff1984SBrad Bishop
10696ff1984SBrad Bishop    def test_mix_covered_notcovered(self):
10796ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
10896ff1984SBrad Bishop            cmd = ["bitbake", "a1:do_patch", "a1:do_populate_sysroot"]
10996ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid
11096ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
11196ff1984SBrad Bishop            expected = ['a1:fetch', 'a1:unpack', 'a1:patch', 'a1:populate_sysroot_setscene']
11296ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
11396ff1984SBrad Bishop
11496ff1984SBrad Bishop
11596ff1984SBrad Bishop    # Test targets with intermediate setscene tasks alongside a target with no intermediate setscene tasks
11696ff1984SBrad Bishop    def test_mixed_direct_tasks_setscene_tasks(self):
11796ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
11896ff1984SBrad Bishop            cmd = ["bitbake", "c1:do_patch", "a1"]
11996ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid
12096ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
12196ff1984SBrad Bishop            expected = ['c1:fetch', 'c1:unpack', 'c1:patch', 'a1:package_write_ipk_setscene', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
12296ff1984SBrad Bishop                        'a1:package_qa_setscene', 'a1:build', 'a1:populate_sysroot_setscene']
12396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
12496ff1984SBrad Bishop
12596ff1984SBrad Bishop    # This test slows down the execution of do_package_setscene until after other real tasks have
12696ff1984SBrad Bishop    # started running which tests for a bug where tasks were being lost from the buildable list of real
12796ff1984SBrad Bishop    # tasks if they weren't in tasks_covered or tasks_notcovered
12896ff1984SBrad Bishop    def test_slow_setscene(self):
12996ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
13096ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
13196ff1984SBrad Bishop            sstatevalid = "a1:do_package"
13296ff1984SBrad Bishop            slowtasks = "a1:package_setscene"
13396ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, slowtasks)
13496ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
13596ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_qa', 'a1:package_write_rpm', 'a1:package_write_ipk',
13696ff1984SBrad Bishop                        'a1:populate_sysroot', 'a1:build']
13796ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
13896ff1984SBrad Bishop
13996ff1984SBrad Bishop    def test_setscenewhitelist(self):
14096ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
14196ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
14296ff1984SBrad Bishop            extraenv = {
14396ff1984SBrad Bishop                "BB_SETSCENE_ENFORCE" : "1",
14496ff1984SBrad Bishop                "BB_SETSCENE_ENFORCE_WHITELIST" : "a1:do_package_write_rpm a1:do_build"
14596ff1984SBrad Bishop            }
14696ff1984SBrad Bishop            sstatevalid = "a1:do_package a1:do_package_qa a1:do_packagedata a1:do_package_write_ipk a1:do_populate_lic a1:do_populate_sysroot"
14796ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv)
14896ff1984SBrad Bishop            expected = ['a1:packagedata_setscene', 'a1:package_qa_setscene', 'a1:package_write_ipk_setscene',
14996ff1984SBrad Bishop                        'a1:populate_sysroot_setscene', 'a1:package_setscene']
15096ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
15196ff1984SBrad Bishop
15296ff1984SBrad Bishop    # Tests for problems with dependencies between setscene tasks
15396ff1984SBrad Bishop    def test_no_setscenevalid_harddeps(self):
15496ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
15596ff1984SBrad Bishop            cmd = ["bitbake", "d1"]
15696ff1984SBrad Bishop            sstatevalid = ""
15796ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
15896ff1984SBrad Bishop            expected = ['a1:package', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
15996ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_write_rpm', 'a1:package_write_ipk',
16096ff1984SBrad Bishop                        'a1:populate_sysroot', 'd1:package', 'd1:fetch', 'd1:unpack', 'd1:patch', 'd1:prepare_recipe_sysroot', 'd1:configure',
16196ff1984SBrad Bishop                        'd1:compile', 'd1:install', 'd1:packagedata', 'd1:package_qa', 'd1:package_write_rpm', 'd1:package_write_ipk',
16296ff1984SBrad Bishop                        'd1:populate_sysroot', 'd1:build']
16396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
16496ff1984SBrad Bishop
16596ff1984SBrad Bishop    def test_no_setscenevalid_withdeps(self):
16696ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
16796ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
16896ff1984SBrad Bishop            sstatevalid = ""
16996ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
17096ff1984SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks]
17196ff1984SBrad Bishop            expected.remove('a1:build')
17296ff1984SBrad Bishop            expected.remove('a1:package_qa')
17396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
17496ff1984SBrad Bishop
17596ff1984SBrad Bishop    def test_single_a1_setscenevalid_withdeps(self):
17696ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
17796ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
17896ff1984SBrad Bishop            sstatevalid = "a1:do_package"
17996ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
18096ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
18196ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_write_rpm', 'a1:package_write_ipk',
18296ff1984SBrad Bishop                        'a1:populate_sysroot'] + ['b1:' + x for x in self.alltasks]
18396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
18496ff1984SBrad Bishop
18596ff1984SBrad Bishop    def test_single_b1_setscenevalid_withdeps(self):
18696ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
18796ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
18896ff1984SBrad Bishop            sstatevalid = "b1:do_package"
18996ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
19096ff1984SBrad Bishop            expected = ['a1:package', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
19196ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_write_rpm', 'a1:package_write_ipk',
19296ff1984SBrad Bishop                        'a1:populate_sysroot', 'b1:package_setscene'] + ['b1:' + x for x in self.alltasks]
19396ff1984SBrad Bishop            expected.remove('b1:package')
19496ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
19596ff1984SBrad Bishop
19696ff1984SBrad Bishop    def test_intermediate_setscenevalid_withdeps(self):
19796ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
19896ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
19996ff1984SBrad Bishop            sstatevalid = "a1:do_package a1:do_populate_sysroot b1:do_package"
20096ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
20196ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:packagedata', 'a1:package_write_rpm', 'a1:package_write_ipk',
20296ff1984SBrad Bishop                        'a1:populate_sysroot_setscene', 'b1:package_setscene'] + ['b1:' + x for x in self.alltasks]
20396ff1984SBrad Bishop            expected.remove('b1:package')
20496ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
20596ff1984SBrad Bishop
20696ff1984SBrad Bishop    def test_all_setscenevalid_withdeps(self):
20796ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
20896ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
20996ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid + " " + self.b1_sstatevalid
21096ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
21196ff1984SBrad Bishop            expected = ['a1:package_write_ipk_setscene', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
21296ff1984SBrad Bishop                        'b1:build', 'a1:populate_sysroot_setscene', 'b1:package_write_ipk_setscene', 'b1:package_write_rpm_setscene',
21396ff1984SBrad Bishop                        'b1:packagedata_setscene', 'b1:package_qa_setscene', 'b1:populate_sysroot_setscene']
21496ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
21596ff1984SBrad Bishop
21696ff1984SBrad Bishop    def test_multiconfig_setscene_optimise(self):
21796ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
21896ff1984SBrad Bishop            extraenv = {
21996ff1984SBrad Bishop                "BBMULTICONFIG" : "mc1 mc2",
22096ff1984SBrad Bishop                "BB_SIGNATURE_HANDLER" : "basic"
22196ff1984SBrad Bishop            }
22296ff1984SBrad Bishop            cmd = ["bitbake", "b1", "mc:mc1:b1", "mc:mc2:b1"]
22396ff1984SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
22496ff1984SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
22596ff1984SBrad Bishop            sstatevalid = ""
22696ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv)
22796ff1984SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks] + \
22896ff1984SBrad Bishop                       ['mc1:b1:' + x for x in setscenetasks] + ['mc1:a1:' + x for x in setscenetasks] + \
22996ff1984SBrad Bishop                       ['mc2:b1:' + x for x in setscenetasks] + ['mc2:a1:' + x for x in setscenetasks] + \
23096ff1984SBrad Bishop                       ['mc1:b1:build', 'mc2:b1:build']
23196ff1984SBrad Bishop            for x in ['mc1:a1:package_qa_setscene', 'mc2:a1:package_qa_setscene', 'a1:build', 'a1:package_qa']:
23296ff1984SBrad Bishop                expected.remove(x)
23396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
23496ff1984SBrad Bishop
235*5a43b434SAndrew Geissler    def test_multiconfig_bbmask(self):
236*5a43b434SAndrew Geissler        # This test validates that multiconfigs can independently mask off
237*5a43b434SAndrew Geissler        # recipes they do not want with BBMASK. It works by having recipes
238*5a43b434SAndrew Geissler        # that will fail to parse for mc1 and mc2, then making each multiconfig
239*5a43b434SAndrew Geissler        # build the one that does parse. This ensures that the recipes are in
240*5a43b434SAndrew Geissler        # each multiconfigs BBFILES, but each is masking only the one that
241*5a43b434SAndrew Geissler        # doesn't parse
242*5a43b434SAndrew Geissler        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
243*5a43b434SAndrew Geissler            extraenv = {
244*5a43b434SAndrew Geissler                "BBMULTICONFIG" : "mc1 mc2",
245*5a43b434SAndrew Geissler                "BB_SIGNATURE_HANDLER" : "basic",
246*5a43b434SAndrew Geissler                "EXTRA_BBFILES": "${COREBASE}/recipes/fails-mc/*.bb",
247*5a43b434SAndrew Geissler            }
248*5a43b434SAndrew Geissler            cmd = ["bitbake", "mc:mc1:fails-mc2", "mc:mc2:fails-mc1"]
249*5a43b434SAndrew Geissler            self.run_bitbakecmd(cmd, tempdir, "", extraenv=extraenv)
250*5a43b434SAndrew Geissler
251*5a43b434SAndrew Geissler    def test_multiconfig_mcdepends(self):
252*5a43b434SAndrew Geissler        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
253*5a43b434SAndrew Geissler            extraenv = {
254*5a43b434SAndrew Geissler                "BBMULTICONFIG" : "mc1 mc2",
255*5a43b434SAndrew Geissler                "BB_SIGNATURE_HANDLER" : "TestMulticonfigDepends",
256*5a43b434SAndrew Geissler                "EXTRA_BBFILES": "${COREBASE}/recipes/fails-mc/*.bb",
257*5a43b434SAndrew Geissler            }
258*5a43b434SAndrew Geissler            tasks = self.run_bitbakecmd(["bitbake", "mc:mc1:f1"], tempdir, "", extraenv=extraenv, cleanup=True)
259*5a43b434SAndrew Geissler            expected = ["mc1:f1:%s" % t for t in self.alltasks] + \
260*5a43b434SAndrew Geissler                       ["mc2:a1:%s" % t for t in self.alltasks]
261*5a43b434SAndrew Geissler            self.assertEqual(set(tasks), set(expected))
262*5a43b434SAndrew Geissler
263*5a43b434SAndrew Geissler            # A rebuild does nothing
264*5a43b434SAndrew Geissler            tasks = self.run_bitbakecmd(["bitbake", "mc:mc1:f1"], tempdir, "", extraenv=extraenv, cleanup=True)
265*5a43b434SAndrew Geissler            self.assertEqual(set(tasks), set())
266*5a43b434SAndrew Geissler
267*5a43b434SAndrew Geissler            # Test that a signature change in the dependent task causes
268*5a43b434SAndrew Geissler            # mcdepends to rebuild
269*5a43b434SAndrew Geissler            tasks = self.run_bitbakecmd(["bitbake", "mc:mc2:a1", "-c", "compile", "-f"], tempdir, "", extraenv=extraenv, cleanup=True)
270*5a43b434SAndrew Geissler            expected = ["mc2:a1:compile"]
271*5a43b434SAndrew Geissler            self.assertEqual(set(tasks), set(expected))
272*5a43b434SAndrew Geissler
273*5a43b434SAndrew Geissler            rerun_tasks = self.alltasks[:]
274*5a43b434SAndrew Geissler            for x in ("fetch", "unpack", "patch", "prepare_recipe_sysroot", "configure", "compile"):
275*5a43b434SAndrew Geissler                rerun_tasks.remove(x)
276*5a43b434SAndrew Geissler            tasks = self.run_bitbakecmd(["bitbake", "mc:mc1:f1"], tempdir, "", extraenv=extraenv, cleanup=True)
277*5a43b434SAndrew Geissler            expected = ["mc1:f1:%s" % t for t in rerun_tasks] + \
278*5a43b434SAndrew Geissler                       ["mc2:a1:%s" % t for t in rerun_tasks]
279*5a43b434SAndrew Geissler            self.assertEqual(set(tasks), set(expected))
28008902b01SBrad Bishop
281a34c030eSBrad Bishop    @unittest.skipIf(sys.version_info < (3, 5, 0), 'Python 3.5 or later required')
28208902b01SBrad Bishop    def test_hashserv_single(self):
28308902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
28408902b01SBrad Bishop            extraenv = {
285a34c030eSBrad Bishop                "BB_HASHSERVE" : "auto",
28608902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
28708902b01SBrad Bishop            }
28808902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1"]
28908902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
29008902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
29108902b01SBrad Bishop            sstatevalid = ""
29208902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
29308902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks]
29408902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
29508902b01SBrad Bishop            cmd = ["bitbake", "a1", "-c", "install", "-f"]
29608902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
29708902b01SBrad Bishop            expected = ['a1:install']
29808902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
29908902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1"]
30008902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
30108902b01SBrad Bishop            expected = ['a1:populate_sysroot', 'a1:package', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
30282c905dcSAndrew Geissler                        'a1:package_write_ipk_setscene', 'a1:package_qa_setscene', 'a1:build']
30308902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
30408902b01SBrad Bishop
30500e122a7SBrad Bishop            self.shutdown(tempdir)
30600e122a7SBrad Bishop
307a34c030eSBrad Bishop    @unittest.skipIf(sys.version_info < (3, 5, 0), 'Python 3.5 or later required')
30808902b01SBrad Bishop    def test_hashserv_double(self):
30908902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
31008902b01SBrad Bishop            extraenv = {
311a34c030eSBrad Bishop                "BB_HASHSERVE" : "auto",
31208902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
31308902b01SBrad Bishop            }
31408902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1", "e1"]
31508902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
31608902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
31708902b01SBrad Bishop            sstatevalid = ""
31808902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
31908902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks] + ['e1:' + x for x in self.alltasks]
32008902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
32108902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1", "-c", "install", "-fn"]
32208902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
32308902b01SBrad Bishop            cmd = ["bitbake", "e1"]
32408902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
32508902b01SBrad Bishop            expected = ['a1:package', 'a1:install', 'b1:package', 'b1:install', 'a1:populate_sysroot', 'b1:populate_sysroot',
32608902b01SBrad Bishop                        'a1:package_write_ipk_setscene', 'b1:packagedata_setscene', 'b1:package_write_rpm_setscene',
32708902b01SBrad Bishop                        'a1:package_write_rpm_setscene', 'b1:package_write_ipk_setscene', 'a1:packagedata_setscene']
32808902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
32908902b01SBrad Bishop
33000e122a7SBrad Bishop            self.shutdown(tempdir)
33108902b01SBrad Bishop
332a34c030eSBrad Bishop    @unittest.skipIf(sys.version_info < (3, 5, 0), 'Python 3.5 or later required')
33308902b01SBrad Bishop    def test_hashserv_multiple_setscene(self):
33408902b01SBrad Bishop        # Runs e1:do_package_setscene twice
33508902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
33608902b01SBrad Bishop            extraenv = {
337a34c030eSBrad Bishop                "BB_HASHSERVE" : "auto",
33808902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
33908902b01SBrad Bishop            }
34008902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1", "e1"]
34108902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
34208902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
34308902b01SBrad Bishop            sstatevalid = ""
34408902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
34508902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks] + ['e1:' + x for x in self.alltasks]
34608902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
34708902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1", "-c", "install", "-fn"]
34808902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
34908902b01SBrad Bishop            cmd = ["bitbake", "e1"]
35008902b01SBrad Bishop            sstatevalid = "e1:do_package"
35108902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True, slowtasks="a1:populate_sysroot b1:populate_sysroot")
35208902b01SBrad Bishop            expected = ['a1:package', 'a1:install', 'b1:package', 'b1:install', 'a1:populate_sysroot', 'b1:populate_sysroot',
35308902b01SBrad Bishop                        'a1:package_write_ipk_setscene', 'b1:packagedata_setscene', 'b1:package_write_rpm_setscene',
35408902b01SBrad Bishop                        'a1:package_write_rpm_setscene', 'b1:package_write_ipk_setscene', 'a1:packagedata_setscene',
35508902b01SBrad Bishop                        'e1:package_setscene']
35608902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
35708902b01SBrad Bishop            for i in expected:
35808902b01SBrad Bishop                self.assertEqual(tasks.count(i), 1, "%s not in task list once" % i)
35908902b01SBrad Bishop
36000e122a7SBrad Bishop            self.shutdown(tempdir)
36108902b01SBrad Bishop
36200e122a7SBrad Bishop    def shutdown(self, tempdir):
36300e122a7SBrad Bishop        # Wait for the hashserve socket to disappear else we'll see races with the tempdir cleanup
36400e122a7SBrad Bishop        while os.path.exists(tempdir + "/hashserve.sock"):
36500e122a7SBrad Bishop            time.sleep(0.5)
36608902b01SBrad Bishop
36708902b01SBrad Bishop
368