Skip to content

Commit 4061d34

Browse files
committed
syscall: rewrite handle inheritance test to use C rather than Powershell
In CL 327210, we disabled this test on arm platforms, because the powershell shipped with those systems isn't native, which means it'd refuse to load native DLLs. This commit rewrites the test to simply not use Powershell, and instead compiles a trivial C program that tests for the same thing. Reverting CL 316269 makes this test fail, as desired, while applying it makes this test succeed. Fixes #46701 Change-Id: If39612c57bf74c63adf58e2c49b5cb739b461fe5 Reviewed-on: https://go-review.googlesource.com/c/go/+/327969 Trust: Jason A. Donenfeld <[email protected]> Trust: Alex Brainman <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent cf4e3e3 commit 4061d34

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/syscall/syscall_windows_test.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"os"
1111
"os/exec"
1212
"path/filepath"
13-
"runtime"
1413
"strings"
1514
"syscall"
1615
"testing"
@@ -80,9 +79,6 @@ func TestTOKEN_ALL_ACCESS(t *testing.T) {
8079
func TestStdioAreInheritable(t *testing.T) {
8180
testenv.MustHaveGoBuild(t)
8281
testenv.MustHaveExecPath(t, "gcc")
83-
if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" {
84-
t.Skip("Powershell is not native on ARM; see golang.org/issues/46701")
85-
}
8682

8783
tmpdir := t.TempDir()
8884

@@ -114,18 +110,28 @@ func main() {}
114110
t.Fatalf("failed to build go library: %s\n%s", err, out)
115111
}
116112

117-
// run powershell script
118-
psscript := fmt.Sprintf(`
119-
hostname;
120-
$signature = " [DllImport("%q")] public static extern void HelloWorld(); ";
121-
Add-Type -MemberDefinition $signature -Name World -Namespace Hello;
122-
[Hello.World]::HelloWorld();
123-
hostname;
124-
`, dll)
125-
psscript = strings.ReplaceAll(psscript, "\n", "")
126-
out, err = exec.Command("powershell", "-Command", psscript).CombinedOutput()
113+
// build c exe
114+
const exetext = `
115+
#include <stdlib.h>
116+
#include <windows.h>
117+
int main(int argc, char *argv[])
118+
{
119+
system("hostname");
120+
((void(*)(void))GetProcAddress(LoadLibraryA(%q), "HelloWorld"))();
121+
system("hostname");
122+
return 0;
123+
}
124+
`
125+
exe := filepath.Join(tmpdir, "helloworld.exe")
126+
cmd = exec.Command("gcc", "-o", exe, "-xc", "-")
127+
cmd.Stdin = strings.NewReader(fmt.Sprintf(exetext, dll))
128+
out, err = testenv.CleanCmdEnv(cmd).CombinedOutput()
129+
if err != nil {
130+
t.Fatalf("failed to build c executable: %s\n%s", err, out)
131+
}
132+
out, err = exec.Command(exe).CombinedOutput()
127133
if err != nil {
128-
t.Fatalf("Powershell command failed: %v: %v", err, string(out))
134+
t.Fatalf("c program execution failed: %v: %v", err, string(out))
129135
}
130136

131137
hostname, err := os.Hostname()
@@ -137,6 +143,6 @@ hostname;
137143
have = strings.ReplaceAll(have, "\r", "")
138144
want := fmt.Sprintf("%sHello World%s", hostname, hostname)
139145
if have != want {
140-
t.Fatalf("Powershell command output is wrong: got %q, want %q", have, want)
146+
t.Fatalf("c program output is wrong: got %q, want %q", have, want)
141147
}
142148
}

0 commit comments

Comments
 (0)