servicetest_windows_test.go 891 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2016 Lawrence Woodman <[email protected]>
  2. // Use of this source code is governed by a zlib-style
  3. // license that can be found in the LICENSE file.
  4. package service_test
  5. import (
  6. "os"
  7. "syscall"
  8. "testing"
  9. )
  10. func interruptProcess(t *testing.T) {
  11. dll, err := syscall.LoadDLL("kernel32.dll")
  12. if err != nil {
  13. t.Fatalf("LoadDLL(\"kernel32.dll\") err: %s", err)
  14. }
  15. p, err := dll.FindProc("GenerateConsoleCtrlEvent")
  16. if err != nil {
  17. t.Fatalf("FindProc(\"GenerateConsoleCtrlEvent\") err: %s", err)
  18. }
  19. // Send the CTRL_BREAK_EVENT to a console process group that shares
  20. // the console associated with the calling process.
  21. // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683155(v=vs.85).aspx
  22. pid := os.Getpid()
  23. r1, _, err := p.Call(syscall.CTRL_BREAK_EVENT, uintptr(pid))
  24. if r1 == 0 {
  25. t.Fatalf("Call(CTRL_BREAK_EVENT, %d) err: %s", pid, err)
  26. }
  27. }