Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos m2 兼容性问题 #150

Open
wangwenfan opened this issue Dec 7, 2023 · 6 comments
Open

macos m2 兼容性问题 #150

wangwenfan opened this issue Dec 7, 2023 · 6 comments

Comments

@wangwenfan
Copy link

v2.11.0 版本可以使用打桩,权限报错消失了,但在一个测试方法中,进行多个成员方法打桩,除第一个,其他的打桩不生效,测试后Intel 的 mac 没有问题,M 系统的 mac 会 有这个问题。
代码 demo:

	patches := gomonkey.ApplyMethodSeq(reflect.TypeOf(groupFactory), "MethodA", outputs)
	defer patches.Reset()
	patches = gomonkey.ApplyMethodSeq(reflect.TypeOf(groupFactory), "MethodB", outputs2)

MethodB不会生效

@agiledragon
Copy link
Owner

Can you post the complete program?

@leojin
Copy link

leojin commented Jan 12, 2024

  1. Environment:
  • Apple M1
  • go1.20.12
  • github.com/agiledragon/gomonkey/v2@v2.11.0
  1. Function Codes
package main

func main() {
	_, _, _ = Execute()
}

func Execute() (int, int, int) {
	s := S{}
	return F1(), F2(), s.F3()
}

func F1() int {
	return 1
}

func F2() int {
	return 2
}

type S struct {
}

func (*S) F3() int {
	return 3
}
  1. Works with one patch
package main_test

import (
	"github.com/agiledragon/gomonkey/v2"
	"github.com/go-playground/assert/v2"
	"gomonkey_arm64"
	"testing"
)

func TestExecute(t *testing.T) {
	rst1Expect := 11
	gomonkey.
		ApplyFunc(main.F1, func() int {
			return rst1Expect
		})
	rst1, _, _ := main.Execute()
	assert.Equal(t, rst1Expect, rst1)
}
  1. Fail with multi ApplyFunc/Method

It can work with the env GOARCH=amd64

package main_test

import (
	"github.com/agiledragon/gomonkey/v2"
	"github.com/go-playground/assert/v2"
	"gomonkey_arm64"
	"reflect"
	"testing"
)

func TestExecute(t *testing.T) {
	s := main.S{}
	rst1Expect := 11
	rst2Expect := 12
	rst3Expect := 13
	gomonkey.
		ApplyFunc(main.F1, func() int {
			return rst1Expect
		}).
		ApplyFunc(main.F2, func() int {
			return rst2Expect
		}).
		ApplyMethod(reflect.TypeOf(&s), "F3", func(_ *main.S) int {
			return rst3Expect
		})
	rst1, rst2, rst3 := main.Execute()
	assert.Equal(t, rst1Expect, rst1)
	assert.Equal(t, rst2Expect, rst2)
	assert.Equal(t, rst3Expect, rst3)
}
/Users/jinzheng/go/go1.20.12/bin/go tool test2json -t /Users/jinzheng/Library/Caches/JetBrains/GoLand2023.3/tmp/GoLand/___1TestExecute_in_gomonkey_arm64.test -test.v -test.paniconexit0 -test.run ^\QTestExecute\E$
=== RUN   TestExecute
unexpected fault address 0x10052fa08
fatal error: fault
[signal SIGBUS: bus error code=0x1 addr=0x10052fa08 pc=0x10052fa08]

goroutine 6 [running]:
runtime.throw({0x100531d07?, 0x10052dde8?})
	/Users/jinzheng/go/go1.20.12/src/runtime/panic.go:1047 +0x40 fp=0x14000070c50 sp=0x14000070c20 pc=0x1003f4100
runtime.sigpanic()
	/Users/jinzheng/go/go1.20.12/src/runtime/signal_unix.go:838 +0x10c fp=0x14000070c80 sp=0x14000070c50 pc=0x10040af1c
github.com/agiledragon/gomonkey/v2.write(0x10052da50, 0x1400001a120, 0x18, 0x10052c000, 0x4000, 0x5)
	/Users/jinzheng/go/pkg/mod/github.com/agiledragon/gomonkey/v2@v2.11.0/write_darwin_arm64.s:36 +0x1028 fp=0x14000070cc0 sp=0x14000070c90 pc=0x10052fa08
github.com/agiledragon/gomonkey/v2.modifyBinary(0x18?, {0x1400001a120, 0x18, 0x18})
	/Users/jinzheng/go/pkg/mod/github.com/agiledragon/gomonkey/v2@v2.11.0/modify_binary_darwin.go:16 +0x78 fp=0x14000070d30 sp=0x14000070cc0 pc=0x10052dee8
github.com/agiledragon/gomonkey/v2.replace(0x100567d40?, 0x14000016340?)
	/Users/jinzheng/go/pkg/mod/github.com/agiledragon/gomonkey/v2@v2.11.0/patch.go:269 +0x74 fp=0x14000070da0 sp=0x14000070d30 pc=0x10052e874
github.com/agiledragon/gomonkey/v2.(*Patches).ApplyCore(0x1400000c0d8, {0x100567d40?, 0x1005a2ac0?, 0x140000745d0?}, {0x100567d40, 0x14000016340, 0x13})
	/Users/jinzheng/go/pkg/mod/github.com/agiledragon/gomonkey/v2@v2.11.0/patch.go:213 +0x74 fp=0x14000070e20 sp=0x14000070da0 pc=0x10052e314
github.com/agiledragon/gomonkey/v2.(*Patches).ApplyFunc(0x14000070ec8?, {0x100567d40?, 0x1005a2ac0?}, {0x100567d40, 0x14000016340})
	/Users/jinzheng/go/pkg/mod/github.com/agiledragon/gomonkey/v2@v2.11.0/patch.go:83 +0x70 fp=0x14000070e90 sp=0x14000070e20 pc=0x10052e110
github.com/agiledragon/gomonkey/v2.ApplyFunc({0x100567d40, 0x1005a2ac0}, {0x100567d40, 0x14000016340})
	/Users/jinzheng/go/pkg/mod/github.com/agiledragon/gomonkey/v2@v2.11.0/patch.go:25 +0x40 fp=0x14000070ed0 sp=0x14000070e90 pc=0x10052dfb0
gomonkey_arm64_test.TestExecute(0x0?)
	/Users/jinzheng/Projects/Personal/gomonkey_test/main_test.go:17 +0x5c fp=0x14000070f60 sp=0x14000070ed0 pc=0x1005310ac
testing.tRunner(0x14000003a00, 0x1005a2ad0)
	/Users/jinzheng/go/go1.20.12/src/testing/testing.go:1576 +0x114 fp=0x14000070fb0 sp=0x14000070f60 pc=0x1004b4554
testing.(*T).Run.func1()
	/Users/jinzheng/go/go1.20.12/src/testing/testing.go:1629 +0x2c fp=0x14000070fd0 sp=0x14000070fb0 pc=0x1004b525c
runtime.goexit()
	/Users/jinzheng/go/go1.20.12/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000070fd0 sp=0x14000070fd0 pc=0x100427b04
created by testing.(*T).Run
	/Users/jinzheng/go/go1.20.12/src/testing/testing.go:1629 +0x340

goroutine 1 [chan receive]:
runtime.gopark(0x1005a2d30, 0x1400005e138, 0xe, 0x17, 0x2)
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:381 +0xd8 fp=0x14000105aa0 sp=0x14000105a70 pc=0x1003f6938
runtime.chanrecv(0x1400005e0e0, 0x14000105baf, 0x1)
	/Users/jinzheng/go/go1.20.12/src/runtime/chan.go:583 +0x29c fp=0x14000105b30 sp=0x14000105aa0 pc=0x1003c208c
runtime.chanrecv1(0x10059f5c0?, 0x100569480?)
	/Users/jinzheng/go/go1.20.12/src/runtime/chan.go:442 +0x14 fp=0x14000105b60 sp=0x14000105b30 pc=0x1003c1db4
testing.(*T).Run(0x14000003860, {0x100533366, 0xb}, 0x1005a2ad0)
	/Users/jinzheng/go/go1.20.12/src/testing/testing.go:1630 +0x354 fp=0x14000105c20 sp=0x14000105b60 pc=0x1004b5124
testing.runTests.func1(0x14000105c01?)
	/Users/jinzheng/go/go1.20.12/src/testing/testing.go:2036 +0x48 fp=0x14000105c70 sp=0x14000105c20 pc=0x1004b6e18
testing.tRunner(0x14000003860, 0x14000105d68)
	/Users/jinzheng/go/go1.20.12/src/testing/testing.go:1576 +0x114 fp=0x14000105cc0 sp=0x14000105c70 pc=0x1004b4554
testing.runTests(0x1400010e0a0?, {0x1006b6720, 0x1, 0x1}, {0x100534642?, 0xf?, 0x0?})
	/Users/jinzheng/go/go1.20.12/src/testing/testing.go:2034 +0x334 fp=0x14000105d90 sp=0x14000105cc0 pc=0x1004b6d24
testing.(*M).Run(0x1400010e0a0)
	/Users/jinzheng/go/go1.20.12/src/testing/testing.go:1906 +0x458 fp=0x14000105ef0 sp=0x14000105d90 pc=0x1004b5b48
main.main()
	_testmain.go:49 +0x80 fp=0x14000105f70 sp=0x14000105ef0 pc=0x100531380
runtime.main()
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:250 +0x21c fp=0x14000105fd0 sp=0x14000105f70 pc=0x1003f64fc
runtime.goexit()
	/Users/jinzheng/go/go1.20.12/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000105fd0 sp=0x14000105fd0 pc=0x100427b04

goroutine 2 [force gc (idle)]:
runtime.gopark(0x1005a2f28, 0x1006bf100, 0x11, 0x14, 0x1)
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:381 +0xd8 fp=0x14000046f70 sp=0x14000046f40 pc=0x1003f6938
runtime.goparkunlock(0x0?, 0x0?, 0x0?, 0x0?)
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:387 +0x34 fp=0x14000046fa0 sp=0x14000046f70 pc=0x1003f69c4
runtime.forcegchelper()
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:305 +0xb4 fp=0x14000046fd0 sp=0x14000046fa0 pc=0x1003f6754
runtime.goexit()
	/Users/jinzheng/go/go1.20.12/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000046fd0 sp=0x14000046fd0 pc=0x100427b04
created by runtime.init.6
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:293 +0x24

goroutine 3 [GC sweep wait]:
runtime.gopark(0x1005a2f28, 0x1006bf520, 0xc, 0x14, 0x1)
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:381 +0xd8 fp=0x14000047740 sp=0x14000047710 pc=0x1003f6938
runtime.goparkunlock(0x0?, 0x0?, 0x0?, 0x0?)
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:387 +0x34 fp=0x14000047770 sp=0x14000047740 pc=0x1003f69c4
runtime.bgsweep(0x0?)
	/Users/jinzheng/go/go1.20.12/src/runtime/mgcsweep.go:278 +0xa0 fp=0x140000477b0 sp=0x14000047770 pc=0x1003e05c0
runtime.gcenable.func1()
	/Users/jinzheng/go/go1.20.12/src/runtime/mgc.go:178 +0x28 fp=0x140000477d0 sp=0x140000477b0 pc=0x1003d56b8
runtime.goexit()
	/Users/jinzheng/go/go1.20.12/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140000477d0 sp=0x140000477d0 pc=0x100427b04
created by runtime.gcenable
	/Users/jinzheng/go/go1.20.12/src/runtime/mgc.go:178 +0x74

goroutine 4 [GC scavenge wait]:
runtime.gopark(0x1005a2f28, 0x1006bf6c0, 0xd, 0x14, 0x2)
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:381 +0xd8 fp=0x14000047f20 sp=0x14000047ef0 pc=0x1003f6938
runtime.goparkunlock(0x1400005e000?, 0x78?, 0xcf?, 0x1?)
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:387 +0x34 fp=0x14000047f50 sp=0x14000047f20 pc=0x1003f69c4
runtime.(*scavengerState).park(0x1006bf6c0)
	/Users/jinzheng/go/go1.20.12/src/runtime/mgcscavenge.go:400 +0x4c fp=0x14000047f80 sp=0x14000047f50 pc=0x1003de2ac
runtime.bgscavenge(0x0?)
	/Users/jinzheng/go/go1.20.12/src/runtime/mgcscavenge.go:628 +0x44 fp=0x14000047fb0 sp=0x14000047f80 pc=0x1003de7f4
runtime.gcenable.func2()
	/Users/jinzheng/go/go1.20.12/src/runtime/mgc.go:179 +0x28 fp=0x14000047fd0 sp=0x14000047fb0 pc=0x1003d5658
runtime.goexit()
	/Users/jinzheng/go/go1.20.12/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000047fd0 sp=0x14000047fd0 pc=0x100427b04
created by runtime.gcenable
	/Users/jinzheng/go/go1.20.12/src/runtime/mgc.go:179 +0xb8

goroutine 5 [finalizer wait]:
runtime.gopark(0x1005a2d98, 0x1006f3498, 0x10, 0x14, 0x1)
	/Users/jinzheng/go/go1.20.12/src/runtime/proc.go:381 +0xd8 fp=0x14000046580 sp=0x14000046550 pc=0x1003f6938
runtime.runfinq()
	/Users/jinzheng/go/go1.20.12/src/runtime/mfinal.go:193 +0xf4 fp=0x140000467d0 sp=0x14000046580 pc=0x1003d4874
runtime.goexit()
	/Users/jinzheng/go/go1.20.12/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140000467d0 sp=0x140000467d0 pc=0x100427b04
created by runtime.createfing
	/Users/jinzheng/go/go1.20.12/src/runtime/mfinal.go:163 +0x4c

@mwindson
Copy link

same problem

@shubham-dogra-pingsafe
Copy link

same problem vv2.11.0, processor: m3pro

@wustrong
Copy link

same problem vv2.11.0, processor: m3pro

+1

@xhd2015
Copy link

xhd2015 commented Apr 16, 2024

same problem vv2.11.0, processor: m3pro

+1

@wustrong @shubham-dogra-pingsafe 已经有项目用xgo验证可以兼容M2,M3,参考: kilianc/base-golang#3

xgo使用:https://github.com/xhd2015/xgo .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants