|
| 1 | +# documentation: https://help.github.com/en/articles/workflow-syntax-for-github-actions |
| 2 | +name: Test NVIDIA Host Libraries Linking |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '*-software.eessi.io' # Matches any branch ending with '-software.eessi.io' |
| 7 | + pull_request: |
| 8 | + paths: |
| 9 | + - 'scripts/gpu_support/nvidia/link_nvidia_host_libraries.sh' # PR changes only relevant for this specific file |
| 10 | + - '.github/workflows/tests_link_nvidia_host_libraries.yml' # Also test when changing the tests themselves |
| 11 | +permissions: |
| 12 | + contents: read # to fetch code (actions/checkout) |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + runs-on: ubuntu-24.04 |
| 16 | + steps: |
| 17 | + - name: checkout |
| 18 | + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 |
| 19 | + |
| 20 | + - name: Initialize EESSI |
| 21 | + uses: eessi/github-action-eessi@v3 |
| 22 | + |
| 23 | + - name: Setup mock NVIDIA libraries |
| 24 | + run: | |
| 25 | + # Run the script to create mock libraries |
| 26 | + chmod +x ./tests/nvidia-libs/mock-nvidia-libs.sh |
| 27 | + echo ">>> Running ./tests/nvidia-libs/mock-nvidia-libs.sh" |
| 28 | + ./tests/nvidia-libs/mock-nvidia-libs.sh |
| 29 | +
|
| 30 | + # Create symlink to override host's ldconfig, since the script tries to use /sbin/ldconfig first. |
| 31 | + echo "Symlinking ldconfig to /sbin/ldconfig" |
| 32 | + sudo ln -sf /tmp/ldconfig/ldconfig /sbin/ldconfig |
| 33 | + |
| 34 | + # Verify the symlink was created correctly |
| 35 | + ls -la /sbin/ldconfig |
| 36 | +
|
| 37 | + - name: Setup mock nvidia-smi |
| 38 | + run: | |
| 39 | + # Create directory for mock nvidia-smi |
| 40 | + mkdir -p /tmp/nvidia-bin |
| 41 | + |
| 42 | + # Copy the mock script |
| 43 | + chmod +x ./tests/nvidia-libs/mock-nvidia-smi.sh |
| 44 | + echo ">>> Copying ./tests/nvidia-libs/mock-nvidia-smi.sh" |
| 45 | + cp ./tests/nvidia-libs/mock-nvidia-smi.sh /tmp/nvidia-bin/nvidia-smi |
| 46 | + |
| 47 | + # Add to PATH |
| 48 | + echo "Updating PATH" |
| 49 | + echo "PATH=/tmp/nvidia-bin:$PATH" >> $GITHUB_ENV |
| 50 | +
|
| 51 | + - name: Test LD_PRELOAD mode |
| 52 | + run: | |
| 53 | + echo ">>> Testing LD_PRELOAD mode" |
| 54 | +
|
| 55 | + # Run the script with LD_PRELOAD option (shouldn't create symlinks) |
| 56 | + output=$(./scripts/gpu_support/nvidia/link_nvidia_host_libraries.sh --show-ld-preload || { echo "Script returned non-zero: $?"; echo $output; exit 1; }) |
| 57 | + |
| 58 | + echo "$output" |
| 59 | +
|
| 60 | + echo ">>> Running checks" |
| 61 | +
|
| 62 | + # Check for expected outputs |
| 63 | + echo "$output" | grep "export EESSI_GPU_COMPAT_LD_PRELOAD=" || { echo "EESSI_GPU_COMPAT_LD_PRELOAD not found in output"; exit 1; } |
| 64 | + echo "$output" | grep "export EESSI_GPU_LD_PRELOAD=" || { echo "EESSI_GPU_LD_PRELOAD not found in output"; exit 1; } |
| 65 | + echo "$output" | grep "export EESSI_OVERRIDE_GPU_CHECK=" || { echo "EESSI_OVERRIDE_GPU_CHECK not found in output"; exit 1; } |
| 66 | + |
| 67 | + # Verify that no symlinks were created |
| 68 | + if [ -e "/opt/eessi/nvidia/x86_64/host/driver_version.txt" ]; then |
| 69 | + echo "Error: symlinks were created in LD_PRELOAD mode" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + |
| 73 | + echo "LD_PRELOAD mode test passed." |
| 74 | +
|
| 75 | + - name: Test normal run (first time) |
| 76 | + run: | |
| 77 | + echo ">>> Testing normal run - first time" |
| 78 | +
|
| 79 | + # Run with verbose mode |
| 80 | + output=$(./scripts/gpu_support/nvidia/link_nvidia_host_libraries.sh --verbose || { echo "Script returned non-zero: $?"; echo $output; exit 1; }) |
| 81 | +
|
| 82 | + echo "$output" |
| 83 | +
|
| 84 | + echo ">>> Running checks" |
| 85 | + |
| 86 | + # Check if NVIDIA GPU was detected - Driver version and CUDA version are hardcoded in `tests/nvidia-libs/mock-nvidia-smi.sh` |
| 87 | + echo "$output" | grep "Found NVIDIA GPU driver version 535.129.03" || { echo "Failed to detect NVIDIA driver version"; exit 1; } |
| 88 | + echo "$output" | grep "Found host CUDA version 8.0" || { echo "Failed to detect CUDA version"; exit 1; } |
| 89 | + |
| 90 | + # Check if libraries were found |
| 91 | + echo "$output" | grep "Matched.*CUDA Libraries" || { echo "Failed to match CUDA libraries"; exit 1; } |
| 92 | + |
| 93 | + # Verify symlinks were created |
| 94 | + if [ ! -d "/opt/eessi/nvidia/x86_64/host" ]; then |
| 95 | + echo "Error: host directory wasn't created" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + |
| 99 | + # Check if version files were created |
| 100 | + if [ ! -f "/opt/eessi/nvidia/x86_64/host/driver_version.txt" ]; then |
| 101 | + echo "Error: driver_version.txt wasn't created" |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | + |
| 105 | + # Check driver version content |
| 106 | + grep "535.129.03" "/opt/eessi/nvidia/x86_64/host/driver_version.txt" || { echo "Incorrect driver version"; exit 1; } |
| 107 | + |
| 108 | + # Check if latest symlink was created |
| 109 | + if [ ! -L "/opt/eessi/nvidia/x86_64/latest" ]; then |
| 110 | + echo "Error: 'latest' symlink wasn't created" |
| 111 | + exit 1 |
| 112 | + fi |
| 113 | + |
| 114 | + # Check if latest points to host |
| 115 | + readlink "/opt/eessi/nvidia/x86_64/latest" | grep "host" || { echo "latest doesn't point to host"; exit 1; } |
| 116 | +
|
| 117 | + # Check if symlinks to libraries were created and point to correct files |
| 118 | + echo ">>> Checking library symlinks" |
| 119 | +
|
| 120 | + # List dir with libraries |
| 121 | + echo "Showing content of /tmp/nvidia_libs" |
| 122 | + echo "$(ls -l /tmp/nvidia_libs)" |
| 123 | + echo "Showing content of /opt/eessi/nvidia/x86_64/host" |
| 124 | + echo "$(ls -l /opt/eessi/nvidia/x86_64/host)" |
| 125 | +
|
| 126 | + # List expected library names - list of libraries is hardcoded in `tests/nvidia-libs/mock-nvidia-libs.sh` |
| 127 | + libraries=( |
| 128 | + "libcuda.so" |
| 129 | + "libcuda.so.1" |
| 130 | + "libnvidia-ml.so" |
| 131 | + "libnvidia-ml.so.1" |
| 132 | + "libnvidia-ptxjitcompiler.so" |
| 133 | + "libnvidia-ptxjitcompiler.so.1" |
| 134 | + "libcudadebugger.so" |
| 135 | + "libcudadebugger.so.1" |
| 136 | + ) |
| 137 | +
|
| 138 | + # Check each expected library symlink |
| 139 | + for lib in "${libraries[@]}"; do |
| 140 | + lib_path="/opt/eessi/nvidia/x86_64/host/$lib" |
| 141 | + |
| 142 | + # Check if the symlink exists |
| 143 | + if [ ! -L "$lib_path" ]; then |
| 144 | + echo "Error: Symlink for $lib was not created" |
| 145 | + exit 1 |
| 146 | + fi |
| 147 | + |
| 148 | + # Check if symlink target exists |
| 149 | + target=$(readlink "$lib_path") |
| 150 | + if [ ! -e "$target" ]; then |
| 151 | + echo "Error: Symlink $lib_path points to non-existent file: $target" |
| 152 | + exit 1 |
| 153 | + fi |
| 154 | + |
| 155 | + # Verify it points to our mock library in /tmp/nvidia_libs |
| 156 | + if [[ "$target" != "/tmp/nvidia_libs/$lib"* && "$target" != *"/tmp/nvidia_libs/"* ]]; then |
| 157 | + echo "Error: Symlink $lib_path points to $target, which is not in our mock directory" |
| 158 | + exit 1 |
| 159 | + fi |
| 160 | + |
| 161 | + echo ">>> Verified symlink: $lib -> $target" |
| 162 | + done |
| 163 | + |
| 164 | + echo "First normal run test passed" |
| 165 | +
|
| 166 | + - name: Test normal run (second time) |
| 167 | + run: | |
| 168 | + echo ">>> Testing normal run - second time - should be idempotent" |
| 169 | + # Remove all write permissions on /opt/eessi so any attempts to write files fail |
| 170 | + chmod -R a-w /opt/eessi |
| 171 | + |
| 172 | + # Store file timestamps before second run (ignoring access time) |
| 173 | + stat_before=$(stat --format="%n %s %y %U %G %m %i" "/opt/eessi/nvidia/x86_64/host/driver_version.txt") |
| 174 | + |
| 175 | + # Run script again |
| 176 | + output=$(./scripts/gpu_support/nvidia/link_nvidia_host_libraries.sh || { echo "Script returned non-zero: $?"; echo $output; exit 1; }) |
| 177 | + |
| 178 | + echo "$output" |
| 179 | +
|
| 180 | + echo ">>> Running checks" |
| 181 | +
|
| 182 | + # Store file timestamps after second run (ignoring access time) |
| 183 | + stat_after=$(stat --format="%n %s %y %U %G %m %i" "/opt/eessi/nvidia/x86_64/host/driver_version.txt") |
| 184 | + |
| 185 | + # Compare timestamps - should be the same (files shouldn't be modified) |
| 186 | + if [[ "$stat_before" != "$stat_after" ]]; then |
| 187 | + echo "Error: files were modified on second run when they shouldn't have been" |
| 188 | + echo "Before: $stat_before" |
| 189 | + echo "After: $stat_after" |
| 190 | + exit 1 |
| 191 | + fi |
| 192 | + |
| 193 | + # Check for message indicating that libraries are already linked |
| 194 | + echo "$output" | grep "have already been linked" || { echo "Missing 'already linked' message"; exit 1; } |
| 195 | + |
| 196 | + echo "Second normal run test passed" |
0 commit comments