xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/selftest/cases/lic_checksum.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#
2# SPDX-License-Identifier: MIT
3#
4
5import os
6import tempfile
7import urllib
8
9from oeqa.selftest.case import OESelftestTestCase
10from oeqa.utils.commands import bitbake
11
12class LicenseTests(OESelftestTestCase):
13
14    def test_checksum_with_space(self):
15        bitbake_cmd = '-c populate_lic emptytest'
16
17        lic_file, lic_path = tempfile.mkstemp(" -afterspace")
18        os.close(lic_file)
19        #self.track_for_cleanup(lic_path)
20
21        self.write_config("INHERIT:remove = \"report-error\"")
22
23        self.write_recipeinc('emptytest', """
24INHIBIT_DEFAULT_DEPS = "1"
25LIC_FILES_CHKSUM = "file://%s;md5=d41d8cd98f00b204e9800998ecf8427e"
26SRC_URI = "file://%s;md5=d41d8cd98f00b204e9800998ecf8427e"
27""" % (urllib.parse.quote(lic_path), urllib.parse.quote(lic_path)))
28        result = bitbake(bitbake_cmd)
29        self.delete_recipeinc('emptytest')
30
31
32    # Verify that changing a license file that has an absolute path causes
33    # the license qa to fail due to a mismatched md5sum.
34    def test_nonmatching_checksum(self):
35        bitbake_cmd = '-c populate_lic emptytest'
36        error_msg = 'emptytest: The new md5 checksum is 8d777f385d3dfec8815d20f7496026dc'
37
38        lic_file, lic_path = tempfile.mkstemp()
39        os.close(lic_file)
40        self.track_for_cleanup(lic_path)
41
42        self.write_config("INHERIT:remove = \"report-error\"")
43
44        self.write_recipeinc('emptytest', """
45INHIBIT_DEFAULT_DEPS = "1"
46LIC_FILES_CHKSUM = "file://%s;md5=d41d8cd98f00b204e9800998ecf8427e"
47SRC_URI = "file://%s;md5=d41d8cd98f00b204e9800998ecf8427e"
48""" % (lic_path, lic_path))
49        result = bitbake(bitbake_cmd)
50
51        with open(lic_path, "w") as f:
52            f.write("data")
53
54        result = bitbake(bitbake_cmd, ignore_status=True)
55        self.delete_recipeinc('emptytest')
56        if error_msg not in result.output:
57            raise AssertionError(result.output)
58