package main import ( "os" "testing" ) // spec:26174-planctl-context-tokens/R1.2+D§3.3 func TestPpidOf_selfParent(t *testing.T) { got := ppidOf(os.Getpid()) want := os.Getppid() if got != want { t.Errorf("ppidOf(getpid()) = %d, want getppid()=%d", got, want) } } // spec:26174-planctl-context-tokens/R6.3+D§3.3 func TestProcessAlive_self(t *testing.T) { if !processAlive(os.Getpid()) { t.Error("processAlive(self) returned false") } } // spec:26174-planctl-context-tokens/R6.3+D§3.3 func TestProcessAlive_zeroOrNegative(t *testing.T) { if processAlive(0) { t.Error("processAlive(0) should be false") } if processAlive(-1) { t.Error("processAlive(-1) should be false") } } // spec:26174-planctl-context-tokens/R6.3+D§3.3+D§4.1 func TestProcessStartTimeSec_selfNonZero(t *testing.T) { stamp, err := processStartTimeSec(os.Getpid()) if err != nil { t.Fatalf("processStartTimeSec(self): %v", err) } if stamp <= 0 { t.Errorf("expected positive stamp, got %d", stamp) } } // spec:26174-planctl-context-tokens/R6.3+D§3.3 // ppidOf of a very unlikely PID (huge number) should return 0 (not panic). func TestPpidOf_nonexistent(t *testing.T) { got := ppidOf(999_999_999) if got != 0 { t.Errorf("ppidOf(nonexistent) = %d, want 0", got) } }