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

Fix #229 - gpu probe regression #230

Merged
merged 1 commit into from
Jan 13, 2025
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
8 changes: 4 additions & 4 deletions src/ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@ fn do_create_snapshot(jobs: &mut dyn jobs::JobManager, opts: &PsOptions, timesta
let gpu_utilization: Vec<gpu::Process>;
let mut gpu_info: String = "".to_string();
match gpu::probe() {
None => {
gpu_status = GpuStatus::UnknownFailure;
}
None => {}
Some(mut gpu) => {
match gpu.get_card_utilization() {
Err(_) => {}
Err(_) => {
gpu_status = GpuStatus::UnknownFailure;
}
Ok(ref cards) => {
let mut s = "".to_string();
s = add_key(s, "fan%", cards, |c: &gpu::CardState| {
Expand Down
35 changes: 35 additions & 0 deletions tests/no-gpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
#
# First check that `sonar sysinfo` will detect no GPUs if there are no GPUs.
#
# Next check and that there are no GPU fields in the output from `sonar ps`.

# Requirement: the `jq` utility.

# Add other GPU types here when we add support for them, the tests below should start failing when
# that happens.
set -e
if [[ -e /sys/module/amdgpu || -e /sys/module/nvidia ]]; then
echo "GPUs detected"
exit 0
fi

( cd .. ; cargo build )

output=$(../target/debug/sonar sysinfo)
numcards=$(jq .gpu_cards <<< $output)
if (( $numcards != 0 )); then
echo "Bad output from jq: <$numcards> should be zero"
exit 1
fi

# TODO: Once we have JSON output, use that here! The CSV matching is very crude and there's a small
# chance that it will have a false positive on sufficiently perverse command names.

output=$(../target/debug/sonar ps --load)
if [[ $output =~ ,gpu[%a-z_-]+= ]]; then
echo "Bad output: unexpected GPU fields in output on non-gpu system"
exit 1
fi

echo "OK"
3 changes: 2 additions & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Primitive test runner.
# Primitive test runner, to run locally and on CI.

set -e

Expand All @@ -25,6 +25,7 @@ for test in amd-gpu \
load \
lockfile \
min-cpu-time \
no-gpu \
nvidia-gpu \
ps-syntax \
rollup \
Expand Down
Loading