1#
2# SPDX-License-Identifier: MIT
3#
4
5import os
6import tempfile
7
8from oeqa.selftest.case import OESelftestTestCase
9from oeqa.utils.commands import bitbake
10from oeqa.utils import CommandError
11
12class LicenseTests(OESelftestTestCase):
13
14    # Verify that changing a license file that has an absolute path causes
15    # the license qa to fail due to a mismatched md5sum.
16    def test_nonmatching_checksum(self):
17        bitbake_cmd = '-c populate_lic emptytest'
18        error_msg = 'emptytest: The new md5 checksum is 8d777f385d3dfec8815d20f7496026dc'
19
20        lic_file, lic_path = tempfile.mkstemp()
21        os.close(lic_file)
22        self.track_for_cleanup(lic_path)
23
24        self.write_config("INHERIT_remove = \"report-error\"")
25
26        self.write_recipeinc('emptytest', """
27INHIBIT_DEFAULT_DEPS = "1"
28LIC_FILES_CHKSUM = "file://%s;md5=d41d8cd98f00b204e9800998ecf8427e"
29SRC_URI = "file://%s;md5=d41d8cd98f00b204e9800998ecf8427e"
30""" % (lic_path, lic_path))
31        result = bitbake(bitbake_cmd)
32
33        with open(lic_path, "w") as f:
34            f.write("data")
35
36        result = bitbake(bitbake_cmd, ignore_status=True)
37        if error_msg not in result.output:
38            raise AssertionError(result.output)
39