Bugs fixed in production code: - compare.sh: Python truthiness on 0.0 — `if b_val` was False for 0.0 t/s, displaying it as a dash instead of "0.0". Fixed with `is not None` checks. - compare.sh: ZeroDivisionError when computing delta % with 0.0 baseline. Test improvements (review findings): - detect.bats: kernel param tests now use real detect_kernel_param logic pattern (not a separate reimplementation). Added non-GiB-aligned RAM test, device ID without 0x prefix, empty firmware version, llama-bench detection, detect_total_physical_ram_kb tests. - benchmark_compare.bats: assert delta percentages (+20.0%, -25.0%, 0.0%), test 0.0 t/s edge case, test per-directory error messages, test config change detection with specific field assertions. - log_metrics.bats: add assert_success, --help test, timestamp format validation. Remove unused mock sysfs setup. - common.bats: fix data_dir test, remove redundant assertion, add cleanup. - test_helper.sh: remove unused FIXTURES_DIR. - Remove empty tests/fixtures/ directory. 94 tests, all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
89 lines
2.9 KiB
Bash
89 lines
2.9 KiB
Bash
#!/usr/bin/env bats
|
|
# Tests for scripts/monitor/log-metrics.sh — metric collection
|
|
|
|
load test_helper.sh
|
|
|
|
setup() {
|
|
source_lib common.sh
|
|
OUTPUT_FILE="$(mktemp)"
|
|
}
|
|
|
|
teardown() {
|
|
rm -f "$OUTPUT_FILE"
|
|
}
|
|
|
|
@test "log-metrics: produces CSV with correct header" {
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" \
|
|
--duration 2 --interval 1 --output "$OUTPUT_FILE"
|
|
assert_success
|
|
head -1 "$OUTPUT_FILE" | grep -q "timestamp,gpu_busy_pct,vram_used_mib,gtt_used_mib,gpu_temp_c,gpu_power_w,cpu_pct,ram_used_mib"
|
|
}
|
|
|
|
@test "log-metrics: produces at least 1 data row in 3 seconds" {
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" \
|
|
--duration 3 --interval 1 --output "$OUTPUT_FILE"
|
|
assert_success
|
|
local lines
|
|
lines=$(wc -l < "$OUTPUT_FILE")
|
|
(( lines >= 2 )) # header + at least 1 data row
|
|
}
|
|
|
|
@test "log-metrics: data rows have 8 comma-separated fields" {
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" \
|
|
--duration 3 --interval 1 --output "$OUTPUT_FILE"
|
|
assert_success
|
|
local row
|
|
row=$(sed -n '2p' "$OUTPUT_FILE")
|
|
[ -n "$row" ] # ensure a data row exists
|
|
local field_count
|
|
field_count=$(echo "$row" | awk -F, '{print NF}')
|
|
[ "$field_count" -eq 8 ]
|
|
}
|
|
|
|
@test "log-metrics: rejects non-numeric interval" {
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" \
|
|
--interval abc --duration 1 --output "$OUTPUT_FILE"
|
|
assert_failure
|
|
assert_output --partial "positive integer"
|
|
}
|
|
|
|
@test "log-metrics: rejects non-numeric duration" {
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" \
|
|
--duration abc --interval 1 --output "$OUTPUT_FILE"
|
|
assert_failure
|
|
assert_output --partial "positive integer"
|
|
}
|
|
|
|
@test "log-metrics: creates output file in specified path" {
|
|
local custom_dir
|
|
custom_dir="$(mktemp -d)"
|
|
local custom_output="$custom_dir/custom-metrics.csv"
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" \
|
|
--duration 2 --interval 1 --output "$custom_output"
|
|
assert_success
|
|
[ -f "$custom_output" ]
|
|
rm -rf "$custom_dir"
|
|
}
|
|
|
|
@test "log-metrics: warns on unknown argument" {
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" \
|
|
--bogus-flag --duration 1 --interval 1 --output "$OUTPUT_FILE"
|
|
assert_success # script continues despite unknown arg
|
|
assert_output --partial "Unknown argument"
|
|
}
|
|
|
|
@test "log-metrics: shows help with --help" {
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" --help
|
|
assert_success
|
|
assert_output --partial "Usage"
|
|
}
|
|
|
|
@test "log-metrics: timestamp column has valid datetime format" {
|
|
run bash "$PROJECT_ROOT/scripts/monitor/log-metrics.sh" \
|
|
--duration 2 --interval 1 --output "$OUTPUT_FILE"
|
|
assert_success
|
|
local ts
|
|
ts=$(sed -n '2p' "$OUTPUT_FILE" | cut -d, -f1)
|
|
[[ "$ts" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}$ ]]
|
|
}
|