CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
133 lines
4.2 KiB
Python
133 lines
4.2 KiB
Python
#!/usr/bin/env python
|
|
# Copyright Advanced Micro Devices, Inc.
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
import os
|
|
import platform
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from _therock_utils.exe_stub_gen import (
|
|
POSIX_EXE_STUB_TEMPLATE,
|
|
generate_exe_link_stub,
|
|
)
|
|
|
|
|
|
IS_WINDOWS = platform.system() == "Windows"
|
|
IS_LINUX = platform.system() == "Linux"
|
|
|
|
|
|
def _require_cc():
|
|
cc = os.getenv("CC", "cc")
|
|
if not shutil.which(cc):
|
|
raise unittest.SkipTest(f"C compiler not found: {cc}")
|
|
return cc
|
|
|
|
|
|
def _write_target(target: Path):
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text("#!/bin/sh\nprintf 'target ran:%s\\n' \"$1\"\n")
|
|
target.chmod(0o755)
|
|
|
|
|
|
def _compile_stub_source(output_file: Path, relative_link_to: str, source: str):
|
|
cc = _require_cc()
|
|
source_file = output_file.with_suffix(".c")
|
|
source_file.write_text(source.replace("@EXEC_RELPATH@", relative_link_to))
|
|
subprocess.check_call(
|
|
[cc, "-fPIE", "-o", str(output_file), str(source_file), "-ldl"]
|
|
)
|
|
|
|
|
|
@unittest.skipIf(IS_WINDOWS, "exe stubs are not implemented on Windows")
|
|
class ExeStubGenTest(unittest.TestCase):
|
|
def test_invokes_target_by_absolute_path(self):
|
|
_require_cc()
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
tmp = Path(tmpdir)
|
|
stub = tmp / "pkg" / "wrappers" / "tool"
|
|
target = tmp / "pkg" / "bin" / "target"
|
|
stub.parent.mkdir(parents=True)
|
|
_write_target(target)
|
|
|
|
generate_exe_link_stub(stub, "../bin/target")
|
|
|
|
result = subprocess.run(
|
|
[str(stub), "absolute"],
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
self.assertEqual(result.returncode, 0)
|
|
self.assertEqual(result.stdout, "target ran:absolute\n")
|
|
self.assertEqual(result.stderr, "")
|
|
|
|
@unittest.skipUnless(IS_LINUX, "PATH lookup regression is Linux-specific")
|
|
def test_invokes_system_target_by_path_lookup(self):
|
|
_require_cc()
|
|
echo = Path("/bin/echo")
|
|
if not echo.exists():
|
|
raise unittest.SkipTest("/bin/echo not found")
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
tmp = Path(tmpdir)
|
|
stub = tmp / "tool"
|
|
|
|
generate_exe_link_stub(stub, os.path.relpath(echo, stub.parent))
|
|
|
|
env = os.environ.copy()
|
|
env["PATH"] = str(stub.parent)
|
|
result = subprocess.run(
|
|
["tool", "path"],
|
|
env=env,
|
|
cwd=tmp,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
self.assertEqual(result.returncode, 0)
|
|
self.assertEqual(result.stdout, "path\n")
|
|
self.assertEqual(result.stderr, "")
|
|
|
|
def test_invocation_through_symlink_uses_real_stub_location(self):
|
|
_require_cc()
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
tmp = Path(tmpdir)
|
|
stub = tmp / "pkg" / "wrappers" / "tool"
|
|
target = tmp / "pkg" / "bin" / "target"
|
|
link = tmp / "path" / "tool"
|
|
stub.parent.mkdir(parents=True)
|
|
link.parent.mkdir()
|
|
_write_target(target)
|
|
|
|
generate_exe_link_stub(stub, "../bin/target")
|
|
link.symlink_to(stub)
|
|
|
|
result = subprocess.check_output([str(link), "symlink"], cwd=tmp, text=True)
|
|
self.assertEqual(result, "target ran:symlink\n")
|
|
|
|
def test_dladdr_fallback_is_available_without_proc_self_exe(self):
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
tmp = Path(tmpdir)
|
|
stub = tmp / "pkg" / "wrappers" / "tool"
|
|
target = tmp / "pkg" / "bin" / "target"
|
|
stub.parent.mkdir(parents=True)
|
|
_write_target(target)
|
|
|
|
source = POSIX_EXE_STUB_TEMPLATE.replace(
|
|
"#include <unistd.h>\n",
|
|
"#include <unistd.h>\n#undef __linux__\n#undef __CYGWIN__\n",
|
|
1,
|
|
)
|
|
_compile_stub_source(stub, "../bin/target", source)
|
|
|
|
result = subprocess.check_output(
|
|
[str(stub), "fallback"], cwd=tmp, text=True
|
|
)
|
|
self.assertEqual(result, "target ran:fallback\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|