From a1c74096a93bb2f0734cdf048152cddb31703581 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Wed, 31 May 2023 10:03:15 +0100 Subject: [PATCH] Add another test case for issue #77 --- jit/go.mod | 3 ++- jit/jit_test.go | 5 +++++ jit/testdata/common/common.go | 10 ++++++++++ jit/testdata/test_issue78/test.go | 9 +++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/jit/go.mod b/jit/go.mod index c8990b0d..1c730cd2 100644 --- a/jit/go.mod +++ b/jit/go.mod @@ -10,4 +10,5 @@ require ( require github.com/opentracing/opentracing-go v1.2.0 // indirect -//replace github.com/eh-steve/goloader => ../ +replace github.com/eh-steve/goloader => ../ +replace github.com/eh-steve/goloader/jit/testdata => ./testdata diff --git a/jit/jit_test.go b/jit/jit_test.go index 22ea112a..a1953a06 100644 --- a/jit/jit_test.go +++ b/jit/jit_test.go @@ -812,6 +812,11 @@ func TestIssue78(t *testing.T) { } test2 := symbols["Test2"].(func() int) fmt.Printf("Reported: 0x%x\n", test2()) + test3 := symbols["Test3"].(func() int) + val3 := test3() + if val3 != common.Val { + t.Fatalf("expected %d, got %d", common.Val, val3) + } err := module.Unload() if err != nil { t.Fatal(err) diff --git a/jit/testdata/common/common.go b/jit/testdata/common/common.go index 56b09574..e635bc25 100644 --- a/jit/testdata/common/common.go +++ b/jit/testdata/common/common.go @@ -5,6 +5,16 @@ import ( "sync" ) +var Val = 99 + +func Inc() { + Val += 1 +} + +func Dec() { + Val += 1 +} + type SomeStruct struct { Val1 interface{} Val2 map[string]interface{} diff --git a/jit/testdata/test_issue78/test.go b/jit/testdata/test_issue78/test.go index 505fe49c..8fd2ae8d 100644 --- a/jit/testdata/test_issue78/test.go +++ b/jit/testdata/test_issue78/test.go @@ -3,6 +3,7 @@ package test_issue78 import ( "context" "fmt" + "github.com/eh-steve/goloader/jit/testdata/common" "unsafe" ) @@ -32,3 +33,11 @@ func Test2() int { } return 99 } + +func Test3() (a int) { + a = common.Val + 1 + a = common.Val - 1 + common.Inc() + fmt.Println(common.Val) + return common.Val +}