Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
0d55d983
Commit
0d55d983
authored
May 02, 2012
by
Alex Brainman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
os/signal: run windows TestCtrlBreak during build
R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/6136054
parent
90626864
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
19 deletions
+70
-19
src/pkg/os/signal/signal_windows_test.go
src/pkg/os/signal/signal_windows_test.go
+61
-16
src/pkg/syscall/exec_windows.go
src/pkg/syscall/exec_windows.go
+5
-3
src/pkg/syscall/ztypes_windows.go
src/pkg/syscall/ztypes_windows.go
+4
-0
No files found.
src/pkg/os/signal/signal_windows_test.go
View file @
0d55d983
...
...
@@ -5,16 +5,16 @@
package
signal
import
(
"
flag
"
"
bytes
"
"os"
"os/exec"
"path/filepath"
"syscall"
"testing"
"time"
)
var
runCtrlBreakTest
=
flag
.
Bool
(
"run_ctlbrk_test"
,
false
,
"force to run Ctrl+Break test"
)
func
sendCtrlBreak
(
t
*
testing
.
T
)
{
func
sendCtrlBreak
(
t
*
testing
.
T
,
pid
int
)
{
d
,
e
:=
syscall
.
LoadDLL
(
"kernel32.dll"
)
if
e
!=
nil
{
t
.
Fatalf
(
"LoadDLL: %v
\n
"
,
e
)
...
...
@@ -23,29 +23,74 @@ func sendCtrlBreak(t *testing.T) {
if
e
!=
nil
{
t
.
Fatalf
(
"FindProc: %v
\n
"
,
e
)
}
r
,
_
,
e
:=
p
.
Call
(
0
,
0
)
r
,
_
,
e
:=
p
.
Call
(
syscall
.
CTRL_BREAK_EVENT
,
uintptr
(
pid
)
)
if
r
==
0
{
t
.
Fatalf
(
"GenerateConsoleCtrlEvent: %v
\n
"
,
e
)
}
}
func
TestCtrlBreak
(
t
*
testing
.
T
)
{
if
!*
runCtrlBreakTest
{
t
.
Logf
(
"test disabled; use -run_ctlbrk_test to enable"
)
return
}
go
func
()
{
time
.
Sleep
(
1
*
time
.
Second
)
sendCtrlBreak
(
t
)
}()
// create source file
const
source
=
`
package main
import (
"log"
"os"
"os/signal"
"time"
)
func main() {
c := make(chan os.Signal, 10)
Notify
(
c
)
signal.
Notify(c)
select {
case s := <-c:
if s != os.Interrupt {
t
.
Fatalf
(
"Wrong signal received: got %q, want %q
\n
"
,
s
,
os
.
Interrupt
)
log
.Fatalf("Wrong signal received: got %q, want %q\n", s, os.Interrupt)
}
case <-time.After(3 * time.Second):
t
.
Fatalf
(
"Timeout waiting for Ctrl+Break
\n
"
)
log.Fatalf("Timeout waiting for Ctrl+Break\n")
}
}
`
name
:=
filepath
.
Join
(
os
.
TempDir
(),
"ctlbreak"
)
src
:=
name
+
".go"
defer
os
.
Remove
(
src
)
f
,
err
:=
os
.
Create
(
src
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create %v: %v"
,
src
,
err
)
}
defer
f
.
Close
()
f
.
Write
([]
byte
(
source
))
// compile it
exe
:=
name
+
".exe"
defer
os
.
Remove
(
exe
)
o
,
err
:=
exec
.
Command
(
"go"
,
"build"
,
"-o"
,
exe
,
src
)
.
CombinedOutput
()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to compile: %v
\n
%v"
,
err
,
string
(
o
))
}
// run it
cmd
:=
exec
.
Command
(
exe
)
var
b
bytes
.
Buffer
cmd
.
Stdout
=
&
b
cmd
.
Stderr
=
&
b
cmd
.
SysProcAttr
=
&
syscall
.
SysProcAttr
{
CreationFlags
:
syscall
.
CREATE_NEW_PROCESS_GROUP
,
}
err
=
cmd
.
Start
()
if
err
!=
nil
{
t
.
Fatalf
(
"Start failed: %v"
,
err
)
}
go
func
()
{
time
.
Sleep
(
1
*
time
.
Second
)
sendCtrlBreak
(
t
,
cmd
.
Process
.
Pid
)
}()
err
=
cmd
.
Wait
()
if
err
!=
nil
{
t
.
Fatalf
(
"Program exited with error: %v
\n
%v"
,
err
,
string
(
b
.
Bytes
()))
}
}
src/pkg/syscall/exec_windows.go
View file @
0d55d983
...
...
@@ -227,6 +227,7 @@ type ProcAttr struct {
type
SysProcAttr
struct
{
HideWindow
bool
CmdLine
string
// used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
CreationFlags
uint32
}
var
zeroProcAttr
ProcAttr
...
...
@@ -313,7 +314,8 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
pi
:=
new
(
ProcessInformation
)
err
=
CreateProcess
(
argv0p
,
argvp
,
nil
,
nil
,
true
,
CREATE_UNICODE_ENVIRONMENT
,
createEnvBlock
(
attr
.
Env
),
dirp
,
si
,
pi
)
flags
:=
sys
.
CreationFlags
|
CREATE_UNICODE_ENVIRONMENT
err
=
CreateProcess
(
argv0p
,
argvp
,
nil
,
nil
,
true
,
flags
,
createEnvBlock
(
attr
.
Env
),
dirp
,
si
,
pi
)
if
err
!=
nil
{
return
0
,
0
,
err
}
...
...
src/pkg/syscall/ztypes_windows.go
View file @
0d55d983
...
...
@@ -146,6 +146,7 @@ const (
WAIT_OBJECT_0
=
0x00000000
WAIT_FAILED
=
0xFFFFFFFF
CREATE_NEW_PROCESS_GROUP
=
0x00000200
CREATE_UNICODE_ENVIRONMENT
=
0x00000400
PROCESS_QUERY_INFORMATION
=
0x00000400
...
...
@@ -162,6 +163,9 @@ const (
FILE_MAP_WRITE
=
0x02
FILE_MAP_READ
=
0x04
FILE_MAP_EXECUTE
=
0x20
CTRL_C_EVENT
=
0
CTRL_BREAK_EVENT
=
1
)
const
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment