xgo icon indicating copy to clipboard operation
xgo copied to clipboard

run test failed in WSL

Open WAY29 opened this issue 1 year ago • 26 comments

I download xgo by install.sh

curl -fsSL https://github.com/xhd2015/xgo/raw/master/install.sh | bash

And when I run:

xgo test -run TestMethodMock ./mock_tcp_conn

I got error:

fork/exec /Users/xhd2015/installed/go1.21.7/bin/go: no such file or directory

Maybe something wrong with build-release

WAY29 avatar Mar 25 '24 00:03 WAY29

Okey I'll test it using docker later. Can you build it using --local and try again?

xhd2015 avatar Mar 25 '24 00:03 xhd2015

got another error:

# cmd/compile/internal/xgo_rewrite_internal/patch
internal/xgo_rewrite_internal/patch/trap.go:96:22: invalid operation: cannot index fn.Type().Params() (value of type *types.Type)
exit status 1

WAY29 avatar Mar 25 '24 00:03 WAY29

Seems a regression.Can you try it with go1.22.1? I'll deliver a fix later

xhd2015 avatar Mar 25 '24 00:03 xhd2015

I seems I wrote some wrong code, Not it work well in both 1.20.5 and 1.22.1

WAY29 avatar Mar 25 '24 00:03 WAY29

Sounds good, thanks for your feedback!

xhd2015 avatar Mar 25 '24 00:03 xhd2015

Maybe should fix install script or build-release

WAY29 avatar Mar 25 '24 00:03 WAY29

cmd/compile/internal/xgo_rewrite_internal/patch

internal/xgo_rewrite_internal/patch/trap.go:96:22: invalid operation: cannot index fn.Type().Params() (value of type *types.Type) exit status 1

I can reproduce this error with go1.19, it should be easy to fix.

xhd2015 avatar Mar 25 '24 04:03 xhd2015

I got error: fork/exec /Users/xhd2015/installed/go1.21.7/bin/go: no such file or directory Maybe something wrong with build-release

As for this, I cannot reproduce. I just tested the example in README.md in a refresh docker container. The test passed.

Not sure if it is related to windows or WSL.

xhd2015 avatar Mar 25 '24 05:03 xhd2015

I got error: fork/exec /Users/xhd2015/installed/go1.21.7/bin/go: no such file or directory Maybe something wrong with build-release

As for this, I cannot reproduce. I just tested the example in README.md in a refresh docker container. The test passed.

Not sure if it is related to windows or WSL.

Are you use curl -fsSL https://github.com/xhd2015/xgo/raw/master/install.sh | bash to download xgo?

WAY29 avatar Mar 25 '24 05:03 WAY29

Are you use curl -fsSL https://github.com/xhd2015/xgo/raw/master/install.sh | bash to download xgo?

Yes.

xhd2015 avatar Mar 25 '24 05:03 xhd2015

Steps to reproduce a successful installation on Linux:

curl -fsSL https://github.com/xhd2015/xgo/raw/master/install.sh | bash
export PATH=~/.xgo/bin:$PATH

git clone https://github.com/xhd2015/xgo
cd xgo

# this may take a while for initial setup
xgo test -v ./test/xgo_test/...

Output:

=== RUN   TestTrapSet
--- PASS: TestTrapSet (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/link_on_init_finished      0.046s
=== RUN   TestMemEqual
--- PASS: TestMemEqual (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/mem_equal  0.003s
=== RUN   TestMethodShouldHaveFMSuffix
--- PASS: TestMethodShouldHaveFMSuffix (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/method_fm_suffix   0.002s
=== RUN   TestMethodRecvValueShouldBeCopied
--- PASS: TestMethodRecvValueShouldBeCopied (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/method_recv_value  0.024s
=== RUN   TestMethodValueCompare
--- PASS: TestMethodValueCompare (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/method_value_cmp   0.003s
=== RUN   TestRewriteChallenge
--- PASS: TestRewriteChallenge (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/rewrite_challenge  0.023s
=== RUN   TestTrapSet
--- PASS: TestTrapSet (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/trap_set   0.023s

xhd2015 avatar Mar 25 '24 06:03 xhd2015

Steps to reproduce a successful installation on Linux:

curl -fsSL https://github.com/xhd2015/xgo/raw/master/install.sh | bash
export PATH=~/.xgo/bin:$PATH

git clone https://github.com/xhd2015/xgo
cd xgo

# this may take a while for initial setup
xgo test -v ./test/xgo_test/...

Output:

=== RUN   TestTrapSet
--- PASS: TestTrapSet (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/link_on_init_finished      0.046s
=== RUN   TestMemEqual
--- PASS: TestMemEqual (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/mem_equal  0.003s
=== RUN   TestMethodShouldHaveFMSuffix
--- PASS: TestMethodShouldHaveFMSuffix (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/method_fm_suffix   0.002s
=== RUN   TestMethodRecvValueShouldBeCopied
--- PASS: TestMethodRecvValueShouldBeCopied (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/method_recv_value  0.024s
=== RUN   TestMethodValueCompare
--- PASS: TestMethodValueCompare (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/method_value_cmp   0.003s
=== RUN   TestRewriteChallenge
--- PASS: TestRewriteChallenge (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/rewrite_challenge  0.023s
=== RUN   TestTrapSet
--- PASS: TestTrapSet (0.00s)
PASS
ok      github.com/xhd2015/xgo/test/xgo_test/trap_set   0.023s

I try this in another WSL and got same error, maybe WSL problem?

WAY29 avatar Mar 25 '24 07:03 WAY29

WSL may be a slightly different linux, I'll test this tonight.

xhd2015 avatar Mar 25 '24 07:03 xhd2015

And may also test on cygwin (windows is kind of complex...)

xhd2015 avatar Mar 25 '24 07:03 xhd2015

curl -fsSL https://github.com/xhd2015/xgo/raw/master/install.sh | bash
export PATH=~/.xgo/bin:$PATH

git clone https://github.com/xhd2015/xgo
cd xgo

# this may take a while for initial setup
xgo test -v ./test/xgo_test/...

Hello @WAY29 , I tried on WSL , and again, everything works fine.

You can also run xgo test --log-debug -v ./test/xgo_test/... to see what will happen.

P.S. The build script seems fine.

xhd2015 avatar Mar 25 '24 14:03 xhd2015

got another error by install script xgo:

❯ xgo test --log-debug -v ./test/xgo_test/...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x64194b]

goroutine 1 [running]:
os/exec.(*ExitError).Error(...)
        /home/xhd2015/installed/go1.22.1/src/os/exec/exec.go:869
main.main()
        /tmp/xgo2556559935/src/cmd/xgo/main.go:99 +0x6ab

However go run ./script/build-release --local build xgo is work fine.

WAY29 avatar Mar 26 '24 01:03 WAY29

I think your xgo release should not be compiled on the local machine but should use github action to prevent some compilation information (such as username xhd2015) from appearing.

WAY29 avatar Mar 26 '24 01:03 WAY29

routine 1 [running]: os/exec.(*ExitError).Error(...) /home/xhd2015/installed/go1.22.1/src/os/exec/exec.go:869 main.main() /tmp/xgo255

For this one, do you have the debug.log?

xhd2015 avatar Mar 26 '24 01:03 xhd2015

I think your xgo release should not be compiled on the local machine but should use github action to prevent some compilation information (such as username xhd2015) from appearing.

I have created the issue https://github.com/xhd2015/xgo/issues/10 to follow on this

xhd2015 avatar Mar 26 '24 01:03 xhd2015

I think your xgo release should not be compiled on the local machine but should use github action to prevent some compilation information (such as username xhd2015) from appearing.

Now build-release includes a -trimpath flag, see https://github.com/xhd2015/xgo/commit/c16fef5bf0691ecb53ce936332a854debd48d8f8.

It's output will look like:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x123171d]

goroutine 1 [running]:
os/exec.(*ExitError).Error(...)
        os/exec/exec.go:862
main.main()
        github.com/xhd2015/xgo/cmd/xgo/main.go:44 +0xbd

The go doc at https://pkg.go.dev/cmd/go#:~:text=trimpath says:

-trimpath
	remove all file system paths from the resulting executable.
	Instead of absolute file system paths, the recorded file names
	will begin either a module path@version (when using modules),
	or a plain import path (when using the standard library, or GOPATH).

xhd2015 avatar Mar 26 '24 04:03 xhd2015

I re-run above steps and all work fine.

However it seems new version of xgo need to SET GOROOT ENV or set --with-goroot option manually? Can't it get GOROOT by go env GOROOT?

WAY29 avatar Mar 26 '24 12:03 WAY29

However it seems new version of xgo need to SET GOROOT ENV or set --with-goroot option manually? Can't it get GOROOT by go env GOROOT?

Can you run with --log-debug to see what's the env in the log? Because it actually init GOROOT from runtime, if that not found, then it will ask for the --with-goroot option.

xhd2015 avatar Mar 26 '24 13:03 xhd2015

However it seems new version of xgo need to SET GOROOT ENV or set --with-goroot option manually? Can't it get GOROOT by go env GOROOT?

Can you run with --log-debug to see what's the env in the log? Because it actually init GOROOT from runtime, if that not found, then it will ask for the --with-goroot option.

I run with --log-debug and no debug.log created.Just got message: requires GOROOT or --with-goroot

WAY29 avatar Mar 26 '24 13:03 WAY29

Ok that should be simple to reproduce. I think the situation should be that, you have go on your PATH variable, but does not have set GOROOT. So $GOROOT is empty, however go env GOROOT is fine.

Can you verify that on your machine?

xhd2015 avatar Mar 26 '24 14:03 xhd2015

Ok that should be simple to reproduce. I think the situation should be that, you have go on your PATH variable, but does not have set GOROOT. So $GOROOT is empty, however go env GOROOT is fine.

Can you verify that on your machine?

Yes, as you say.

WAY29 avatar Mar 26 '24 14:03 WAY29

This has been fixed in v1.0.8

xhd2015 avatar Mar 29 '24 00:03 xhd2015