summaryrefslogtreecommitdiff
path: root/.github/scripts/tests/test_armhf_sysroot_symlinks.py
blob: 42647345876b4f25f8941c16ba0d59b086c013bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import pathlib
import subprocess
import tempfile
import unittest


ROOT = pathlib.Path(__file__).resolve().parents[3]
NORMALIZER = ROOT / ".github/scripts/normalize-armhf-sysroot-symlinks.sh"


class ArmhfSysrootSymlinkTests(unittest.TestCase):
    def test_absolute_links_are_rebased_inside_sysroot(self):
        with tempfile.TemporaryDirectory() as temporary:
            sysroot = pathlib.Path(temporary)
            target = sysroot / "lib/arm-linux-gnueabihf/libm.so.6"
            target.parent.mkdir(parents=True)
            target.write_text("fixture\n", encoding="utf-8")
            link = sysroot / "usr/lib/arm-linux-gnueabihf/libm.so"
            link.parent.mkdir(parents=True)
            link.symlink_to("/lib/arm-linux-gnueabihf/libm.so.6")

            subprocess.run(["bash", str(NORMALIZER), str(sysroot)], check=True)

            self.assertFalse(os.readlink(link).startswith("/"))
            self.assertEqual(link.resolve(), target.resolve())

    def test_relative_links_remain_unchanged(self):
        with tempfile.TemporaryDirectory() as temporary:
            sysroot = pathlib.Path(temporary)
            directory = sysroot / "usr/lib"
            directory.mkdir(parents=True)
            link = directory / "libfixture.so"
            link.symlink_to("libfixture.so.1")

            subprocess.run(["bash", str(NORMALIZER), str(sysroot)], check=True)

            self.assertEqual(os.readlink(link), "libfixture.so.1")


if __name__ == "__main__":
    unittest.main()