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 bb
1196ff1984SBrad Bishopimport os
1296ff1984SBrad Bishopimport tempfile
1396ff1984SBrad Bishopimport subprocess
1496ff1984SBrad Bishop
1596ff1984SBrad Bishop#
1696ff1984SBrad Bishop# TODO:
1796ff1984SBrad Bishop# Add tests on task ordering (X happens before Y after Z)
1896ff1984SBrad Bishop#
1996ff1984SBrad Bishop
2096ff1984SBrad Bishopclass RunQueueTests(unittest.TestCase):
2196ff1984SBrad Bishop
2296ff1984SBrad Bishop    alltasks = ['package', 'fetch', 'unpack', 'patch', 'prepare_recipe_sysroot', 'configure',
2396ff1984SBrad Bishop                'compile', 'install', 'packagedata', 'package_qa', 'package_write_rpm', 'package_write_ipk',
2496ff1984SBrad Bishop                'populate_sysroot', 'build']
2596ff1984SBrad 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"
2696ff1984SBrad 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"
2796ff1984SBrad Bishop
28*08902b01SBrad Bishop    def run_bitbakecmd(self, cmd, builddir, sstatevalid="", slowtasks="", extraenv=None, cleanup=False):
2996ff1984SBrad Bishop        env = os.environ.copy()
3096ff1984SBrad Bishop        env["BBPATH"] = os.path.realpath(os.path.join(os.path.dirname(__file__), "runqueue-tests"))
3196ff1984SBrad Bishop        env["BB_ENV_EXTRAWHITE"] = "SSTATEVALID SLOWTASKS"
3296ff1984SBrad Bishop        env["SSTATEVALID"] = sstatevalid
3396ff1984SBrad Bishop        env["SLOWTASKS"] = slowtasks
3496ff1984SBrad Bishop        if extraenv:
3596ff1984SBrad Bishop            for k in extraenv:
3696ff1984SBrad Bishop                env[k] = extraenv[k]
3796ff1984SBrad Bishop                env["BB_ENV_EXTRAWHITE"] = env["BB_ENV_EXTRAWHITE"] + " " + k
3896ff1984SBrad Bishop        try:
3996ff1984SBrad Bishop            output = subprocess.check_output(cmd, env=env, stderr=subprocess.STDOUT,universal_newlines=True, cwd=builddir)
40*08902b01SBrad Bishop            print(output)
4196ff1984SBrad Bishop        except subprocess.CalledProcessError as e:
4296ff1984SBrad Bishop            self.fail("Command %s failed with %s" % (cmd, e.output))
4396ff1984SBrad Bishop        tasks = []
44*08902b01SBrad Bishop        tasklog = builddir + "/task.log"
45*08902b01SBrad Bishop        if os.path.exists(tasklog):
46*08902b01SBrad Bishop            with open(tasklog, "r") as f:
4796ff1984SBrad Bishop                tasks = [line.rstrip() for line in f]
48*08902b01SBrad Bishop            if cleanup:
49*08902b01SBrad Bishop                os.remove(tasklog)
5096ff1984SBrad Bishop        return tasks
5196ff1984SBrad Bishop
5296ff1984SBrad Bishop    def test_no_setscenevalid(self):
5396ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
5496ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
5596ff1984SBrad Bishop            sstatevalid = ""
5696ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
5796ff1984SBrad Bishop            expected = ['a1:' + x for x in self.alltasks]
5896ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
5996ff1984SBrad Bishop
6096ff1984SBrad Bishop    def test_single_setscenevalid(self):
6196ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
6296ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
6396ff1984SBrad Bishop            sstatevalid = "a1:do_package"
6496ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
6596ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
6696ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_qa', 'a1:package_write_rpm', 'a1:package_write_ipk',
6796ff1984SBrad Bishop                        'a1:populate_sysroot', 'a1:build']
6896ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
6996ff1984SBrad Bishop
7096ff1984SBrad Bishop    def test_intermediate_setscenevalid(self):
7196ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
7296ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
7396ff1984SBrad Bishop            sstatevalid = "a1:do_package a1:do_populate_sysroot"
7496ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
7596ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:packagedata', 'a1:package_qa', 'a1:package_write_rpm', 'a1:package_write_ipk',
7696ff1984SBrad Bishop                        'a1:populate_sysroot_setscene', 'a1:build']
7796ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
7896ff1984SBrad Bishop
7996ff1984SBrad Bishop    def test_intermediate_notcovered(self):
8096ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
8196ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
8296ff1984SBrad 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"
8396ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
8496ff1984SBrad Bishop            expected = ['a1:package_write_ipk_setscene', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
8596ff1984SBrad Bishop                        'a1:package_qa_setscene', 'a1:build', 'a1:populate_sysroot_setscene']
8696ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
8796ff1984SBrad Bishop
8896ff1984SBrad Bishop    def test_all_setscenevalid(self):
8996ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
9096ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
9196ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid
9296ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
9396ff1984SBrad Bishop            expected = ['a1:package_write_ipk_setscene', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
9496ff1984SBrad Bishop                        'a1:package_qa_setscene', 'a1:build', 'a1:populate_sysroot_setscene']
9596ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
9696ff1984SBrad Bishop
9796ff1984SBrad Bishop    def test_no_settasks(self):
9896ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
9996ff1984SBrad Bishop            cmd = ["bitbake", "a1", "-c", "patch"]
10096ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid
10196ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
10296ff1984SBrad Bishop            expected = ['a1:fetch', 'a1:unpack', 'a1:patch']
10396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
10496ff1984SBrad Bishop
10596ff1984SBrad Bishop    def test_mix_covered_notcovered(self):
10696ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
10796ff1984SBrad Bishop            cmd = ["bitbake", "a1:do_patch", "a1:do_populate_sysroot"]
10896ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid
10996ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
11096ff1984SBrad Bishop            expected = ['a1:fetch', 'a1:unpack', 'a1:patch', 'a1:populate_sysroot_setscene']
11196ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
11296ff1984SBrad Bishop
11396ff1984SBrad Bishop
11496ff1984SBrad Bishop    # Test targets with intermediate setscene tasks alongside a target with no intermediate setscene tasks
11596ff1984SBrad Bishop    def test_mixed_direct_tasks_setscene_tasks(self):
11696ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
11796ff1984SBrad Bishop            cmd = ["bitbake", "c1:do_patch", "a1"]
11896ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid
11996ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
12096ff1984SBrad Bishop            expected = ['c1:fetch', 'c1:unpack', 'c1:patch', 'a1:package_write_ipk_setscene', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
12196ff1984SBrad Bishop                        'a1:package_qa_setscene', 'a1:build', 'a1:populate_sysroot_setscene']
12296ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
12396ff1984SBrad Bishop
12496ff1984SBrad Bishop    # This test slows down the execution of do_package_setscene until after other real tasks have
12596ff1984SBrad Bishop    # started running which tests for a bug where tasks were being lost from the buildable list of real
12696ff1984SBrad Bishop    # tasks if they weren't in tasks_covered or tasks_notcovered
12796ff1984SBrad Bishop    def test_slow_setscene(self):
12896ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
12996ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
13096ff1984SBrad Bishop            sstatevalid = "a1:do_package"
13196ff1984SBrad Bishop            slowtasks = "a1:package_setscene"
13296ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, slowtasks)
13396ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
13496ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_qa', 'a1:package_write_rpm', 'a1:package_write_ipk',
13596ff1984SBrad Bishop                        'a1:populate_sysroot', 'a1:build']
13696ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
13796ff1984SBrad Bishop
13896ff1984SBrad Bishop    def test_setscenewhitelist(self):
13996ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
14096ff1984SBrad Bishop            cmd = ["bitbake", "a1"]
14196ff1984SBrad Bishop            extraenv = {
14296ff1984SBrad Bishop                "BB_SETSCENE_ENFORCE" : "1",
14396ff1984SBrad Bishop                "BB_SETSCENE_ENFORCE_WHITELIST" : "a1:do_package_write_rpm a1:do_build"
14496ff1984SBrad Bishop            }
14596ff1984SBrad 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"
14696ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv)
14796ff1984SBrad Bishop            expected = ['a1:packagedata_setscene', 'a1:package_qa_setscene', 'a1:package_write_ipk_setscene',
14896ff1984SBrad Bishop                        'a1:populate_sysroot_setscene', 'a1:package_setscene']
14996ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
15096ff1984SBrad Bishop
15196ff1984SBrad Bishop    # Tests for problems with dependencies between setscene tasks
15296ff1984SBrad Bishop    def test_no_setscenevalid_harddeps(self):
15396ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
15496ff1984SBrad Bishop            cmd = ["bitbake", "d1"]
15596ff1984SBrad Bishop            sstatevalid = ""
15696ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
15796ff1984SBrad Bishop            expected = ['a1:package', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
15896ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_write_rpm', 'a1:package_write_ipk',
15996ff1984SBrad Bishop                        'a1:populate_sysroot', 'd1:package', 'd1:fetch', 'd1:unpack', 'd1:patch', 'd1:prepare_recipe_sysroot', 'd1:configure',
16096ff1984SBrad Bishop                        'd1:compile', 'd1:install', 'd1:packagedata', 'd1:package_qa', 'd1:package_write_rpm', 'd1:package_write_ipk',
16196ff1984SBrad Bishop                        'd1:populate_sysroot', 'd1:build']
16296ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
16396ff1984SBrad Bishop
16496ff1984SBrad Bishop    def test_no_setscenevalid_withdeps(self):
16596ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
16696ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
16796ff1984SBrad Bishop            sstatevalid = ""
16896ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
16996ff1984SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks]
17096ff1984SBrad Bishop            expected.remove('a1:build')
17196ff1984SBrad Bishop            expected.remove('a1:package_qa')
17296ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
17396ff1984SBrad Bishop
17496ff1984SBrad Bishop    def test_single_a1_setscenevalid_withdeps(self):
17596ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
17696ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
17796ff1984SBrad Bishop            sstatevalid = "a1:do_package"
17896ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
17996ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
18096ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_write_rpm', 'a1:package_write_ipk',
18196ff1984SBrad Bishop                        'a1:populate_sysroot'] + ['b1:' + x for x in self.alltasks]
18296ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
18396ff1984SBrad Bishop
18496ff1984SBrad Bishop    def test_single_b1_setscenevalid_withdeps(self):
18596ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
18696ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
18796ff1984SBrad Bishop            sstatevalid = "b1:do_package"
18896ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
18996ff1984SBrad Bishop            expected = ['a1:package', 'a1:fetch', 'a1:unpack', 'a1:patch', 'a1:prepare_recipe_sysroot', 'a1:configure',
19096ff1984SBrad Bishop                        'a1:compile', 'a1:install', 'a1:packagedata', 'a1:package_write_rpm', 'a1:package_write_ipk',
19196ff1984SBrad Bishop                        'a1:populate_sysroot', 'b1:package_setscene'] + ['b1:' + x for x in self.alltasks]
19296ff1984SBrad Bishop            expected.remove('b1:package')
19396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
19496ff1984SBrad Bishop
19596ff1984SBrad Bishop    def test_intermediate_setscenevalid_withdeps(self):
19696ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
19796ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
19896ff1984SBrad Bishop            sstatevalid = "a1:do_package a1:do_populate_sysroot b1:do_package"
19996ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
20096ff1984SBrad Bishop            expected = ['a1:package_setscene', 'a1:packagedata', 'a1:package_write_rpm', 'a1:package_write_ipk',
20196ff1984SBrad Bishop                        'a1:populate_sysroot_setscene', 'b1:package_setscene'] + ['b1:' + x for x in self.alltasks]
20296ff1984SBrad Bishop            expected.remove('b1:package')
20396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
20496ff1984SBrad Bishop
20596ff1984SBrad Bishop    def test_all_setscenevalid_withdeps(self):
20696ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
20796ff1984SBrad Bishop            cmd = ["bitbake", "b1"]
20896ff1984SBrad Bishop            sstatevalid = self.a1_sstatevalid + " " + self.b1_sstatevalid
20996ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid)
21096ff1984SBrad Bishop            expected = ['a1:package_write_ipk_setscene', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
21196ff1984SBrad Bishop                        'b1:build', 'a1:populate_sysroot_setscene', 'b1:package_write_ipk_setscene', 'b1:package_write_rpm_setscene',
21296ff1984SBrad Bishop                        'b1:packagedata_setscene', 'b1:package_qa_setscene', 'b1:populate_sysroot_setscene']
21396ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
21496ff1984SBrad Bishop
21596ff1984SBrad Bishop    def test_multiconfig_setscene_optimise(self):
21696ff1984SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
21796ff1984SBrad Bishop            extraenv = {
21896ff1984SBrad Bishop                "BBMULTICONFIG" : "mc1 mc2",
21996ff1984SBrad Bishop                "BB_SIGNATURE_HANDLER" : "basic"
22096ff1984SBrad Bishop            }
22196ff1984SBrad Bishop            cmd = ["bitbake", "b1", "mc:mc1:b1", "mc:mc2:b1"]
22296ff1984SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
22396ff1984SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
22496ff1984SBrad Bishop            sstatevalid = ""
22596ff1984SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv)
22696ff1984SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks] + \
22796ff1984SBrad Bishop                       ['mc1:b1:' + x for x in setscenetasks] + ['mc1:a1:' + x for x in setscenetasks] + \
22896ff1984SBrad Bishop                       ['mc2:b1:' + x for x in setscenetasks] + ['mc2:a1:' + x for x in setscenetasks] + \
22996ff1984SBrad Bishop                       ['mc1:b1:build', 'mc2:b1:build']
23096ff1984SBrad Bishop            for x in ['mc1:a1:package_qa_setscene', 'mc2:a1:package_qa_setscene', 'a1:build', 'a1:package_qa']:
23196ff1984SBrad Bishop                expected.remove(x)
23296ff1984SBrad Bishop            self.assertEqual(set(tasks), set(expected))
23396ff1984SBrad Bishop
234*08902b01SBrad Bishop
235*08902b01SBrad Bishop    def test_hashserv_single(self):
236*08902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
237*08902b01SBrad Bishop            extraenv = {
238*08902b01SBrad Bishop                "BB_HASHSERVE" : "localhost:0",
239*08902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
240*08902b01SBrad Bishop            }
241*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1"]
242*08902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
243*08902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
244*08902b01SBrad Bishop            sstatevalid = ""
245*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
246*08902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks]
247*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
248*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "-c", "install", "-f"]
249*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
250*08902b01SBrad Bishop            expected = ['a1:install']
251*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
252*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1"]
253*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
254*08902b01SBrad Bishop            expected = ['a1:populate_sysroot', 'a1:package', 'a1:package_write_rpm_setscene', 'a1:packagedata_setscene',
255*08902b01SBrad Bishop                        'a1:package_write_ipk_setscene', 'a1:package_qa_setscene']
256*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
257*08902b01SBrad Bishop
258*08902b01SBrad Bishop    def test_hashserv_double(self):
259*08902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
260*08902b01SBrad Bishop            extraenv = {
261*08902b01SBrad Bishop                "BB_HASHSERVE" : "localhost:0",
262*08902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
263*08902b01SBrad Bishop            }
264*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1", "e1"]
265*08902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
266*08902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
267*08902b01SBrad Bishop            sstatevalid = ""
268*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
269*08902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks] + ['e1:' + x for x in self.alltasks]
270*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
271*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1", "-c", "install", "-fn"]
272*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
273*08902b01SBrad Bishop            cmd = ["bitbake", "e1"]
274*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
275*08902b01SBrad Bishop            expected = ['a1:package', 'a1:install', 'b1:package', 'b1:install', 'a1:populate_sysroot', 'b1:populate_sysroot',
276*08902b01SBrad Bishop                        'a1:package_write_ipk_setscene', 'b1:packagedata_setscene', 'b1:package_write_rpm_setscene',
277*08902b01SBrad Bishop                        'a1:package_write_rpm_setscene', 'b1:package_write_ipk_setscene', 'a1:packagedata_setscene']
278*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
279*08902b01SBrad Bishop
280*08902b01SBrad Bishop
281*08902b01SBrad Bishop    def test_hashserv_multiple_setscene(self):
282*08902b01SBrad Bishop        # Runs e1:do_package_setscene twice
283*08902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
284*08902b01SBrad Bishop            extraenv = {
285*08902b01SBrad Bishop                "BB_HASHSERVE" : "localhost:0",
286*08902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
287*08902b01SBrad Bishop            }
288*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1", "e1"]
289*08902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
290*08902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
291*08902b01SBrad Bishop            sstatevalid = ""
292*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
293*08902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks] + ['e1:' + x for x in self.alltasks]
294*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
295*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1", "-c", "install", "-fn"]
296*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
297*08902b01SBrad Bishop            cmd = ["bitbake", "e1"]
298*08902b01SBrad Bishop            sstatevalid = "e1:do_package"
299*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True, slowtasks="a1:populate_sysroot b1:populate_sysroot")
300*08902b01SBrad Bishop            expected = ['a1:package', 'a1:install', 'b1:package', 'b1:install', 'a1:populate_sysroot', 'b1:populate_sysroot',
301*08902b01SBrad Bishop                        'a1:package_write_ipk_setscene', 'b1:packagedata_setscene', 'b1:package_write_rpm_setscene',
302*08902b01SBrad Bishop                        'a1:package_write_rpm_setscene', 'b1:package_write_ipk_setscene', 'a1:packagedata_setscene',
303*08902b01SBrad Bishop                        'e1:package_setscene']
304*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
305*08902b01SBrad Bishop            for i in expected:
306*08902b01SBrad Bishop                if i in ["e1:package_setscene"]:
307*08902b01SBrad Bishop                    self.assertEqual(tasks.count(i), 4, "%s not in task list four times" % i)
308*08902b01SBrad Bishop                else:
309*08902b01SBrad Bishop                    self.assertEqual(tasks.count(i), 1, "%s not in task list once" % i)
310*08902b01SBrad Bishop
311*08902b01SBrad Bishop    def test_hashserv_partial_match(self):
312*08902b01SBrad Bishop        # e1:do_package matches initial built but not second hash value
313*08902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
314*08902b01SBrad Bishop            extraenv = {
315*08902b01SBrad Bishop                "BB_HASHSERVE" : "localhost:0",
316*08902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
317*08902b01SBrad Bishop            }
318*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1"]
319*08902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
320*08902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
321*08902b01SBrad Bishop            sstatevalid = ""
322*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
323*08902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks]
324*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
325*08902b01SBrad Bishop            with open(tempdir + "/stamps/a1.do_install.taint", "w") as f:
326*08902b01SBrad Bishop               f.write("d460a29e-903f-4b76-a96b-3bcc22a65994")
327*08902b01SBrad Bishop            with open(tempdir + "/stamps/b1.do_install.taint", "w") as f:
328*08902b01SBrad Bishop               f.write("ed36d46a-2977-458a-b3de-eef885bc1817")
329*08902b01SBrad Bishop            cmd = ["bitbake", "e1"]
330*08902b01SBrad Bishop            sstatevalid = "e1:do_package:685e69a026b2f029483fdefe6a11e1e06641dd2a0f6f86e27b9b550f8f21229d"
331*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
332*08902b01SBrad Bishop            expected = ['a1:package', 'a1:install', 'b1:package', 'b1:install', 'a1:populate_sysroot', 'b1:populate_sysroot',
333*08902b01SBrad Bishop                        'a1:package_write_ipk_setscene', 'b1:packagedata_setscene', 'b1:package_write_rpm_setscene',
334*08902b01SBrad Bishop                        'a1:package_write_rpm_setscene', 'b1:package_write_ipk_setscene', 'a1:packagedata_setscene',
335*08902b01SBrad Bishop                        'e1:package_setscene'] + ['e1:' + x for x in self.alltasks]
336*08902b01SBrad Bishop            expected.remove('e1:package')
337*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
338*08902b01SBrad Bishop
339*08902b01SBrad Bishop    def test_hashserv_partial_match2(self):
340*08902b01SBrad Bishop        # e1:do_package + e1:do_populate_sysroot matches initial built but not second hash value
341*08902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
342*08902b01SBrad Bishop            extraenv = {
343*08902b01SBrad Bishop                "BB_HASHSERVE" : "localhost:0",
344*08902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
345*08902b01SBrad Bishop            }
346*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1"]
347*08902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
348*08902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
349*08902b01SBrad Bishop            sstatevalid = ""
350*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
351*08902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks]
352*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
353*08902b01SBrad Bishop            with open(tempdir + "/stamps/a1.do_install.taint", "w") as f:
354*08902b01SBrad Bishop               f.write("d460a29e-903f-4b76-a96b-3bcc22a65994")
355*08902b01SBrad Bishop            with open(tempdir + "/stamps/b1.do_install.taint", "w") as f:
356*08902b01SBrad Bishop               f.write("ed36d46a-2977-458a-b3de-eef885bc1817")
357*08902b01SBrad Bishop            cmd = ["bitbake", "e1"]
358*08902b01SBrad Bishop            sstatevalid = "e1:do_package:685e69a026b2f029483fdefe6a11e1e06641dd2a0f6f86e27b9b550f8f21229d e1:do_populate_sysroot:ef7dc0e2dd55d0534e75cba50731ff42f949818b6f29a65d72bc05856e56711d"
359*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
360*08902b01SBrad Bishop            expected = ['a1:package', 'a1:install', 'b1:package', 'b1:install', 'a1:populate_sysroot', 'b1:populate_sysroot',
361*08902b01SBrad Bishop                        'a1:package_write_ipk_setscene', 'b1:packagedata_setscene', 'b1:package_write_rpm_setscene',
362*08902b01SBrad Bishop                        'a1:package_write_rpm_setscene', 'b1:package_write_ipk_setscene', 'a1:packagedata_setscene',
363*08902b01SBrad Bishop                        'e1:package_setscene', 'e1:populate_sysroot_setscene', 'e1:build', 'e1:package_qa', 'e1:package_write_rpm', 'e1:package_write_ipk', 'e1:packagedata']
364*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
365*08902b01SBrad Bishop
366*08902b01SBrad Bishop    def test_hashserv_partial_match3(self):
367*08902b01SBrad Bishop        # e1:do_package is valid for a1 but not after b1
368*08902b01SBrad Bishop        # In former buggy code, this triggered e1:do_fetch, then e1:do_populate_sysroot to run
369*08902b01SBrad Bishop        # with none of the intermediate tasks which is a serious bug
370*08902b01SBrad Bishop        with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir:
371*08902b01SBrad Bishop            extraenv = {
372*08902b01SBrad Bishop                "BB_HASHSERVE" : "localhost:0",
373*08902b01SBrad Bishop                "BB_SIGNATURE_HANDLER" : "TestEquivHash"
374*08902b01SBrad Bishop            }
375*08902b01SBrad Bishop            cmd = ["bitbake", "a1", "b1"]
376*08902b01SBrad Bishop            setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene',
377*08902b01SBrad Bishop                             'populate_sysroot_setscene', 'package_qa_setscene']
378*08902b01SBrad Bishop            sstatevalid = ""
379*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True)
380*08902b01SBrad Bishop            expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks]
381*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
382*08902b01SBrad Bishop            with open(tempdir + "/stamps/a1.do_install.taint", "w") as f:
383*08902b01SBrad Bishop               f.write("d460a29e-903f-4b76-a96b-3bcc22a65994")
384*08902b01SBrad Bishop            with open(tempdir + "/stamps/b1.do_install.taint", "w") as f:
385*08902b01SBrad Bishop               f.write("ed36d46a-2977-458a-b3de-eef885bc1817")
386*08902b01SBrad Bishop            cmd = ["bitbake", "e1", "-DD"]
387*08902b01SBrad Bishop            sstatevalid = "e1:do_package:af056eae12a733a6a8c4f4da8c6757e588e13565852c94e2aad4d953a3989c13 e1:do_package:a3677703db82b22d28d57c1820a47851dd780104580863f5bd32e66e003a779d"
388*08902b01SBrad Bishop            tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv, cleanup=True, slowtasks="e1:fetch b1:install")
389*08902b01SBrad Bishop            expected = ['a1:package', 'a1:install', 'b1:package', 'b1:install', 'a1:populate_sysroot', 'b1:populate_sysroot',
390*08902b01SBrad Bishop                        'a1:package_write_ipk_setscene', 'b1:packagedata_setscene', 'b1:package_write_rpm_setscene',
391*08902b01SBrad Bishop                        'a1:package_write_rpm_setscene', 'b1:package_write_ipk_setscene', 'a1:packagedata_setscene',
392*08902b01SBrad Bishop                        'e1:package_setscene']  + ['e1:' + x for x in self.alltasks]
393*08902b01SBrad Bishop            expected.remove('e1:package')
394*08902b01SBrad Bishop            self.assertEqual(set(tasks), set(expected))
395*08902b01SBrad Bishop
396*08902b01SBrad Bishop
397