Skip to content

Commit

Permalink
test #194
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Jun 7, 2024
1 parent ceb96b7 commit 7b0e452
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 19 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This workflow is mainly used to debug some tricky bugs that cannot be
# easily setup on my local machine, for example, arm64-related bugs
# (because by the time writing I don't have an M1 or M2 mac)
# And it's hard to setup qemu.

name: Custom Test

on:
push:
branches: [ "nothing" ]
workflow_dispatch:
inputs:
dummy:
default: nothing

# 'gin-gonic/gin' ok
# 'fatedier/frp' cannot pass even with go? need to verify
#
# NOTE: use serially job to avoid 'Job Cancelled' which could
# possible be due to memory exhaust
jobs:

test-with-xgo:
runs-on: macos-latest
timeout-minutes: 360
steps:
- uses: actions/checkout@v4
with:
path: xgo

- name: Prepare Utility Scripts
run: |
cat > util.sh <<'EOF'
function record_exit_code {
local exit_code=$?
echo "exit code: $exit_code"
echo "$exit_code" > test-exit-code.txt
}
trap 'record_exit_code' EXIT
EOF
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Install Xgo Locally
run: |
cd xgo
go install ./cmd/xgo
xgo exec --reset-instrument --log-debug go version
xgo revision
- name: Dep check
run: |
go install github.com/xhd2015/go-inspect/cmd/depcheck@latest
cd xgo/runtime/test/issue_194_asm_func/demo
depcheck ./
- name: Test with go
continue-on-error: true
run: |
source util.sh
cd xgo/runtime/test/issue_194_asm_func/demo
go test -v
- name: Test with xgo
continue-on-error: true
run: |
source util.sh
cd xgo/runtime/test/issue_194_asm_func/demo
xgo test -v
4 changes: 2 additions & 2 deletions cmd/xgo/runtime_gen/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.39"
const REVISION = "b2c3ae1e20700a8710d719b492b6db9e60fc4800+1"
const NUMBER = 263
const REVISION = "ceb96b726f89731a8f2bda8239af7c1810e44294+1"
const NUMBER = 264

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.39"
const REVISION = "b2c3ae1e20700a8710d719b492b6db9e60fc4800+1"
const NUMBER = 263
const REVISION = "ceb96b726f89731a8f2bda8239af7c1810e44294+1"
const NUMBER = 264

func getRevision() string {
revSuffix := ""
Expand Down
4 changes: 4 additions & 0 deletions patch/syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ func extractFuncDecls(fileIndex int, f *syntax.File, file string, decl syntax.De
}

func getFuncDeclInfo(fileIndex int, f *syntax.File, file string, fn *syntax.FuncDecl) *DeclInfo {
if fn.Body == nil {
// see bug https://github.com/xhd2015/xgo/issues/202
return nil
}
line := fn.Pos().Line()
fnName := fn.Name.Value
// there are cases where fnName is _
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.39"
const REVISION = "b2c3ae1e20700a8710d719b492b6db9e60fc4800+1"
const NUMBER = 263
const REVISION = "ceb96b726f89731a8f2bda8239af7c1810e44294+1"
const NUMBER = 264

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
16 changes: 3 additions & 13 deletions runtime/test/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,15 @@
// failing code
//
// usage:
// go run -tags dev ./cmd/xgo test --debug-compile --project-dir runtime/test/debug
// go run -tags dev ./cmd/xgo test --project-dir runtime/test/debug
// go run -tags dev ./cmd/xgo test --debug-compile --project-dir runtime/test/debug

package debug

import (
"testing"
)

const userNsLength = (1 << 16)
const (
minimumMappingUID = userNsLength
mappingLen = userNsLength * 2000
)

// see bug https://github.com/xhd2015/xgo/issues/176
func TestUntypedUnknownConstShouldCompile(t *testing.T) {
var allocated uint32

if allocated > minimumMappingUID+mappingLen-userNsLength {
t.Fatalf("allocated is greater?")
}
func TestNodef(t *testing.T) {
}
3 changes: 3 additions & 0 deletions runtime/test/issue_194_asm_func/asm_func.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package asm_func

func AsmFunc()
9 changes: 9 additions & 0 deletions runtime/test/issue_194_asm_func/asm_func_amd64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build !noasm,amd64
//go:build !noasm && amd64

#include "go_asm.h"
#include "funcdata.h"
#include "textflag.h"

TEXT ·AsmFunc2(SB), NOSPLIT, $0-0
RET
18 changes: 18 additions & 0 deletions runtime/test/issue_194_asm_func/asm_func_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !noasm && amd64
// +build !noasm,amd64

package asm_func

import (
"testing"
)

// see bug https://github.com/xhd2015/xgo/issues/202
func TestAsmFunc(t *testing.T) {
// no panic
// don't really call it, go can omit
// this function.
// but prior to fixing this bug, xgo
// registers it, so the linkers failed
// AsmFunc()
}
15 changes: 15 additions & 0 deletions runtime/test/issue_194_asm_func/demo/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module test

go 1.21

require github.com/bytedance/sonic v1.11.8

require (
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
)
35 changes: 35 additions & 0 deletions runtime/test/issue_194_asm_func/demo/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
github.com/bytedance/sonic v1.11.8 h1:Zw/j1KfiS+OYTi9lyB3bb0CFxPJVkM17k1wyDG32LRA=
github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
16 changes: 16 additions & 0 deletions runtime/test/issue_194_asm_func/demo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"github.com/bytedance/sonic"
)

func main() {
unmarshal(nil, nil)
}

func unmarshal(body []byte, u interface{}) {
if body == nil {
return
}
sonic.Unmarshal(body, u)
}
9 changes: 9 additions & 0 deletions runtime/test/issue_194_asm_func/demo/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"testing"
)

func TestUnmarshal(t *testing.T) {
unmarshal(nil, nil)
}
10 changes: 10 additions & 0 deletions script/run-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ var extraSubTests = []*TestCase{
flags: []string{},
windowsFlags: []string{"--trap-stdlib=false"},
},
{
// see https://github.com/xhd2015/xgo/issues/202
name: "asm_func",
dir: "runtime/test/issue_194_asm_func",
},
{
// see https://github.com/xhd2015/xgo/issues/194
name: "asm_func_sonic",
dir: "runtime/test/issue_194_asm_func/demo",
},
{
// see https://github.com/xhd2015/xgo/issues/142
name: "trace_panic_peek",
Expand Down

0 comments on commit 7b0e452

Please sign in to comment.