summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/util/ld_so_conf.py
blob: b4352191a62eb727bf0d8a9bfca157e06d3dd7eb (plain) (blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os

import spack.util.ld_so_conf as ld_so_conf


def test_ld_so_conf_parsing(tmpdir):
    cwd = os.getcwd()
    tmpdir.ensure("subdir", dir=True)

    # Entrypoint config file
    with open(str(tmpdir.join("main.conf")), "wb") as f:
        f.write(b"  \n")
        f.write(b"include subdir/*.conf\n")
        f.write(b"include non-existent/file\n")
        f.write(b"include #nope\n")
        f.write(b"include     \n")
        f.write(b"include\t\n")
        f.write(b"include\n")
        f.write(b"/main.conf/lib # and a comment\n")
        f.write(b"relative/path\n\n")
        f.write(b"#/skip/me\n")

    # Should be parsed: subdir/first.conf
    with open(str(tmpdir.join("subdir", "first.conf")), "wb") as f:
        f.write(b"/first.conf/lib")

    # Should be parsed: subdir/second.conf
    with open(str(tmpdir.join("subdir", "second.conf")), "wb") as f:
        f.write(b"/second.conf/lib")

    # Not matching subdir/*.conf
    with open(str(tmpdir.join("subdir", "third")), "wb") as f:
        f.write(b"/third/lib")

    paths = ld_so_conf.parse_ld_so_conf(str(tmpdir.join("main.conf")))

    assert len(paths) == 3
    assert "/main.conf/lib" in paths
    assert "/first.conf/lib" in paths
    assert "/second.conf/lib" in paths

    # Make sure globbing didn't change the working dir
    assert os.getcwd() == cwd


def test_host_dynamic_linker_search_paths():
    assert {"/usr/lib", "/usr/lib64", "/lib", "/lib64"}.issubset(
        ld_so_conf.host_dynamic_linker_search_paths()
    )