Skip to content

Commit

Permalink
No bug: Basic sanity tests for sonar GPU logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars T Hansen committed Dec 12, 2024
1 parent fb7b203 commit 9db5716
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
26 changes: 26 additions & 0 deletions tests/amd-gpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
#
# Check that `sonar sysinfo` can detect an AMD GPU if it ought to (based on info from the file
# system). This test must be run on a node with such a device to have any effect, hence will not be
# effective in the github runner.
#
# Requirement: the `jq` utility.

set -e
if [[ ! -e /sys/module/amdgpu ]]; then
echo "No device"
exit 0
fi

( cd .. ; cargo build )
output=$(../target/debug/sonar sysinfo)
numcards=$(jq .gpu_cards <<< $output)
if [[ ! ( $numcards =~ ^[0-9]+$ ) ]]; then
echo "Bad output from jq: <$numcards>"
exit 1
fi
if (( $numcards == 0 )); then
echo "Number of cards should be nonzero"
exit 1
fi
echo "OK"
26 changes: 26 additions & 0 deletions tests/nvidia-gpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
#
# Check that `sonar sysinfo` can detect an NVIDIA GPU if it ought to (based on info from the file
# system). This test must be run on a node with such a device to have any effect, hence will not be
# effective in the github runner.
#
# Requirement: the `jq` utility.

set -e
if [[ ! -e /sys/module/nvidia ]]; then
echo "No device"
exit 0
fi

( cd .. ; cargo build )
output=$(../target/debug/sonar sysinfo)
numcards=$(jq .gpu_cards <<< $output)
if [[ ! ( $numcards =~ ^[0-9]+$ ) ]]; then
echo "Bad output from jq: <$numcards>"
exit 1
fi
if (( $numcards == 0 )); then
echo "Number of cards should be nonzero"
exit 1
fi
echo "OK"
4 changes: 3 additions & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ fi
# keep tests alphabetical
# later we could just iterate over all scripts that end with .sh
# and are not this script
for test in command-line \
for test in amd-gpu \
command-line \
exclude-commands \
exclude-system-jobs \
exclude-users \
Expand All @@ -24,6 +25,7 @@ for test in command-line \
load \
lockfile \
min-cpu-time \
nvidia-gpu \
ps-syntax \
rollup \
rollup2 \
Expand Down

0 comments on commit 9db5716

Please sign in to comment.