windows: add TestJobObjectInfo

Add test for CL 251197.

Updates golang/go#41001

Change-Id: I6317678057eb8b18a1f7564842a92682c0c9930f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/253097
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Alex Brainman
2020-09-05 00:46:54 +00:00
committed by Ian Lance Taylor
parent e0c6998df7
commit be1d3432aa
3 changed files with 51 additions and 0 deletions
+37
View File
@@ -14,6 +14,7 @@ import (
"strings"
"syscall"
"testing"
"unsafe"
"golang.org/x/sys/windows"
)
@@ -421,3 +422,39 @@ func TestProcessWorkingSetSizeEx(t *testing.T) {
t.Error(err)
}
}
func TestJobObjectInfo(t *testing.T) {
jo, err := windows.CreateJobObject(nil, nil)
if err != nil {
t.Fatalf("CreateJobObject failed: %v", err)
}
defer windows.CloseHandle(jo)
var info windows.JOBOBJECT_EXTENDED_LIMIT_INFORMATION
err = windows.QueryInformationJobObject(jo, windows.JobObjectExtendedLimitInformation,
uintptr(unsafe.Pointer(&info)), uint32(unsafe.Sizeof(info)), nil)
if err != nil {
t.Fatalf("QueryInformationJobObject failed: %v", err)
}
const wantMemLimit = 4 * 1024
info.BasicLimitInformation.LimitFlags |= windows.JOB_OBJECT_LIMIT_PROCESS_MEMORY
info.ProcessMemoryLimit = wantMemLimit
_, err = windows.SetInformationJobObject(jo, windows.JobObjectExtendedLimitInformation,
uintptr(unsafe.Pointer(&info)), uint32(unsafe.Sizeof(info)))
if err != nil {
t.Fatalf("SetInformationJobObject failed: %v", err)
}
err = windows.QueryInformationJobObject(jo, windows.JobObjectExtendedLimitInformation,
uintptr(unsafe.Pointer(&info)), uint32(unsafe.Sizeof(info)), nil)
if err != nil {
t.Fatalf("QueryInformationJobObject failed: %v", err)
}
if have := info.ProcessMemoryLimit; wantMemLimit != have {
t.Errorf("ProcessMemoryLimit is wrong: want %v have %v", wantMemLimit, have)
}
}