Skip to content

Add unit test coverage for RPATH correctness #5114

@ScottTodd

Description

@ScottTodd

Forking from #5108 (comment)


Original report (from Claude Code): https://github.com/ScottTodd/claude-rocm-workspace/blob/main/reviews/pr_TheRock_5108.md#unit-test-coverage-for-rpath-correctness

Current state

There is no automated validation of RPATH correctness. The existing
therock_test_validate_shared_lib / validate_shared_library.py only checks
that a .so can be dlopen'd — it doesn't verify executable RPATH entries.

Proposed: RPATH validation script

A post-build validation script could catch these issues at CI time rather than
waiting for runtime failures. Approach:

# build_tools/validate_rpath.py
# Walk dist/<subproject>/stage/, find all ELF executables/shared libs,
# read RUNPATH via readelf/pyelftools, verify each $ORIGIN-relative
# path resolves to a directory that actually exists in the stage tree.

This could be wired up similar to therock_test_validate_shared_lib:

# cmake/therock_testing.cmake
function(therock_test_validate_rpath)
  # For each ELF binary in the dist tree, verify RPATH entries resolve
  add_test(
    NAME therock-validate-rpath-${subproject}
    COMMAND "${Python3_EXECUTABLE}"
      "${THEROCK_SOURCE_DIR}/build_tools/validate_rpath.py"
      "${dist_path}"
  )
endfunction()

Alternative: CMake-time validation

A lighter approach: add validation in therock_global_post_subproject.cmake
that compares the target's actual install destination (from RUNTIME_OUTPUT_DIRECTORY
or the install() command) against the computed origin. This is tricky because
CMake doesn't reliably expose the install destination as a target property at
configure time — it's set in the install() command, which is a separate
code path.

Recommendation

The script approach is more practical. It could run as a CTest after
ninja install and would catch:

  1. Missing THEROCK_INSTALL_RPATH_ORIGIN for non-standard install locations
  2. Missing INSTALL_RPATH_DIRS for non-standard lib directories
  3. Stale RPATH entries pointing to nonexistent directories

(back to my words)

The ctest after ninja install would just be the existing

- name: Test Packaging
run: |
ctest --test-dir ${BUILD_DIR} --output-on-failure

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    TODO

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions