//go:build linux package main import ( "os" "syscall" "testing" ) func TestPgidOfAndTheGuardRecognisesOurHostEngines(t *testing.T) { if got := pgidOf(os.Getpid()); got != syscall.Getpgrp() { t.Fatalf("pgidOf(self) = %d, want %d", got, syscall.Getpgrp()) } if pgidOf(0x7ffffff0) != 0 { t.Error("a process that does not exist has no group") } host.Lock() host.procs = map[string]*hostProc{"comfyui": {pgid: syscall.Getpgrp(), done: make(chan struct{})}} host.Unlock() defer func() { host.Lock(); host.procs = map[string]*hostProc{}; host.Unlock() }() if !inOurHostEngine(os.Getpid()) { t.Error("a process in the engine's group is ours") } // the guard must not take our own engine for the owner's work got := otherGPUProcs([]gpuProc{{PID: os.Getpid(), Name: "python"}}, func(int) string { return "" }) if len(got) != 0 { t.Errorf("our engine counted as foreign: %v", got) } host.Lock() host.procs["comfyui"].pgid = 1 host.Unlock() if inOurHostEngine(os.Getpid()) { t.Error("a process outside the engine's group is not ours") } if got := otherGPUProcs([]gpuProc{{PID: os.Getpid(), Name: "python"}}, func(int) string { return "" }); len(got) != 1 { t.Errorf("another program on the GPU must still count: %v", got) } }