Rewrite: improve process handling and restoration
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseMemSize(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
want uint64
|
||||
bad bool
|
||||
}{
|
||||
{"512M", 512 * 1024 * 1024, false},
|
||||
{" 1g ", 1024 * 1024 * 1024, false},
|
||||
{"0", 0, false},
|
||||
{"18446744073709551615", math.MaxUint64, false},
|
||||
{"17179869183G", 17179869183 * 1024 * 1024 * 1024, false},
|
||||
{"17179869184G", 0, true},
|
||||
{"", 0, true},
|
||||
{"G", 0, true},
|
||||
{"1GB", 0, true},
|
||||
{"1.5G", 0, true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
got, err := parseMemSize(tt.input)
|
||||
if (err != nil) != tt.bad || got != tt.want {
|
||||
t.Fatalf("parseMemSize(%q) = %d, %v; want %d, bad=%v", tt.input, got, err, tt.want, tt.bad)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDesiredPriority(t *testing.T) {
|
||||
const mem = 512 * 1024 * 1024
|
||||
tests := []struct {
|
||||
name string
|
||||
rss uint64
|
||||
current uint32
|
||||
gameMode, isGame bool
|
||||
want uint32
|
||||
}{
|
||||
{"promote heavy", mem, PriorityClassNormal, false, false, PriorityClassHigh},
|
||||
{"keep heavy high", mem, PriorityClassHigh, false, false, PriorityClassHigh},
|
||||
{"demote light high", mem - 1, PriorityClassHigh, false, false, PriorityClassNormal},
|
||||
{"demote light realtime", mem - 1, PriorityClassRealtime, false, false, PriorityClassNormal},
|
||||
{"keep light normal", mem - 1, PriorityClassNormal, false, false, 0},
|
||||
{"boost game", 1, PriorityClassIdle, true, true, PriorityClassHigh},
|
||||
{"idle non-game", mem * 10, PriorityClassHigh, true, false, PriorityClassIdle},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := desiredPriority(tt.rss, mem, tt.current, tt.gameMode, tt.isGame); got != tt.want {
|
||||
t.Fatalf("desiredPriority() = %#x, want %#x", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user