Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add check for dynamic linking on linux #2386

Merged
merged 8 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed tests/tests/dupes.bson
Binary file not shown.
63 changes: 63 additions & 0 deletions tests/tests/test_smoke.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import pathlib
import subprocess

import pytest
import psycopg2

from fixtures.glaredb import glaredb_connection, release_path, debug_path
Expand All @@ -24,3 +26,64 @@ def test_start(
):
with glaredb_connection.cursor() as cur:
cur.execute("SELECT 1;")


@pytest.mark.skipif(not sys.platform.startswith("linux"), reason="linux version of the test")
def test_expected_linking_linux(debug_path: pathlib.Path):
out = [
ll
for cell in [
item
for item in [
line.split(" ")
for line in str(subprocess.check_output(["ldd", debug_path.absolute()], text=True))
.replace("\t", "")
.split("\n")
]
]
for ll in cell
if not (
ll == "=>"
or ll == ""
or ll.startswith("(0x00")
or ll.startswith("/usr/lib")
or ll.startswith("/lib")
)
]
expected_prefix = ["libc.so", "libm.so", "linux-vdso"]
possible_libs = ["liblzma", "libbz", "libgcc"]
pending_removal = ["libcrypto", "libssl"]
expected = 0
possible = 0
pending = 0
for lib in out:
for prefix in expected_prefix:
if lib.startswith(prefix):
expected += 1

for prefix in possible_libs:
if lib.startswith(prefix):
possible += 1

for prefix in pending_removal:
if lib.startswith(prefix):
pending += 1

assert expected == 3, f"missing expected library {expected_prefix} in:\n" + "\n".join(out)

# this is hella gross, but this number will change any time we add
# a new library, this assertion will fail.
#
# it's two numbers because this is different on different distros;
# as long as we don't have two numbers next to eachother this is fine;
# presently: (ubuntu2004, archlinux)
assert len(out) == (expected + possible + pending), "unexpected library in:\n" + "\n".join(out)

# TODO: currently we link (open) libssl, which means the first time it
# changes uncomment the first assertion in the loop below and
# remove this comment:

for lib in out:
# assert not ("ssl" in lib)
assert not ("libc++" in lib)
assert not ("libstdc++" in lib)