- 重构 sysconf 为文档模型 INI Parser 与 Config Framework - 强化 hosts 解析、插入校验、写回与异常输入处理 - 完善 StarCmd 生命周期、等待 API、流式输出与 IO 重定向 - 扩展跨平台文件时间、文件锁、内存、进程与网络能力 - 将 Windows 进程适配更新到 b612.me/wincmd v0.1.0 - 移除本地 wincmd/win32api replace,改用发布版依赖 - 将最低 Go 版本提升到 1.18 - 补充 hosts、sysconf、FileLock、StarCmd 与平台适配回归测试
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
//go:build linux
|
|
// +build linux
|
|
|
|
package staros
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCPUUsageOverDurationGuardsZeroOrNegativeWindow(t *testing.T) {
|
|
if got := cpuUsageOverDuration(10, 0); got != 0 {
|
|
t.Fatalf("expected zero-window cpu usage to clamp to 0, got %v", got)
|
|
}
|
|
if got := cpuUsageOverDuration(10, -time.Millisecond); got != 0 {
|
|
t.Fatalf("expected negative-window cpu usage to clamp to 0, got %v", got)
|
|
}
|
|
if got := cpuUsageOverDuration(-1, time.Second); got != 0 {
|
|
t.Fatalf("expected negative delta cpu usage to clamp to 0, got %v", got)
|
|
}
|
|
if got := cpuUsageOverDuration(0.5, time.Second); got != 50 {
|
|
t.Fatalf("expected normal cpu usage calculation, got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestCPUUsagePercentGuardsInvalidSamples(t *testing.T) {
|
|
if got := cpuUsagePercent(1, 0); got != 0 {
|
|
t.Fatalf("expected zero total ticks to clamp to 0, got %v", got)
|
|
}
|
|
if got := cpuUsagePercent(-1, 4); got != 0 {
|
|
t.Fatalf("expected negative busy ticks to clamp to 0, got %v", got)
|
|
}
|
|
if got := cpuUsagePercent(1, 4); got != 25 {
|
|
t.Fatalf("expected normal cpu percent calculation, got %v", got)
|
|
}
|
|
}
|