(t *testing.T)
| 438 | } |
| 439 | |
| 440 | func TestQueryWorkingSetConcurrentCalls(t *testing.T) { |
| 441 | const pageSize = 4096 |
| 442 | addr, err := windows.VirtualAlloc(0, pageSize, windows.MEM_COMMIT|windows.MEM_RESERVE, windows.PAGE_READWRITE) |
| 443 | if err != nil { |
| 444 | t.Fatalf("VirtualAlloc failed: %v", err) |
| 445 | } |
| 446 | defer windows.VirtualFree(addr, 0, windows.MEM_RELEASE) |
| 447 | |
| 448 | var wg sync.WaitGroup |
| 449 | var successCount atomic.Int32 |
| 450 | |
| 451 | for i := 0; i < 30; i++ { |
| 452 | wg.Add(1) |
| 453 | go func() { |
| 454 | defer wg.Done() |
| 455 | ws := []sys.MemoryWorkingSetExInformation{{VirtualAddress: addr}} |
| 456 | if QueryWorkingSet(windows.CurrentProcess(), ws) != nil { |
| 457 | successCount.Add(1) |
| 458 | } |
| 459 | }() |
| 460 | } |
| 461 | |
| 462 | wg.Wait() |
| 463 | // with a pool of poolSize() workers, some calls will be dropped under |
| 464 | // contention but at least some must succeed |
| 465 | if successCount.Load() == 0 { |
| 466 | t.Error("all concurrent QueryWorkingSet calls failed") |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | func BenchmarkQueryWorkingSetSinglePage(b *testing.B) { |
| 471 | const pageSize = 4096 |
nothing calls this directly
no test coverage detected