diff --git a/.github/workflows/go-compatible.yml b/.github/workflows/go-compatible.yml index 9c2c1eb0..1a4e33e8 100644 --- a/.github/workflows/go-compatible.yml +++ b/.github/workflows/go-compatible.yml @@ -26,4 +26,4 @@ jobs: go-version: '${{ matrix.go }}' - name: Test - run: go run ./script/run-test --reset-instrument --debug -v \ No newline at end of file + run: go run ./script/run-test --install-xgo --reset-instrument --debug -v \ No newline at end of file diff --git a/.github/workflows/go-next.yml b/.github/workflows/go-next.yml index 31742e78..0e50ffa4 100644 --- a/.github/workflows/go-next.yml +++ b/.github/workflows/go-next.yml @@ -24,9 +24,10 @@ jobs: run: | curl -fsSL -o go.tar.gz "https://go.dev/dl/go${{matrix.go}}.linux-amd64.tar.gz" mkdir setup + mkdir setup/gopath tar -C setup -xzf go.tar.gz ls setup GOROOT=$PWD/setup/go PATH=$PWD/setup/go/bin:$PATH go version - name: Test - run: GOROOT=$PWD/setup/go PATH=$PWD/setup/go/bin:$PATH go run ./script/run-test --reset-instrument --debug -v \ No newline at end of file + run: GOROOT=$PWD/setup/go GOPATH=$PWD/setup/gopath PATH=$PWD/setup/go/bin:$PWD/setup/gopath/bin:$PATH go run ./script/run-test --install-xgo --reset-instrument --debug -v \ No newline at end of file diff --git a/.github/workflows/go-windows.yml b/.github/workflows/go-windows.yml index 7e601b21..9a6dddeb 100644 --- a/.github/workflows/go-windows.yml +++ b/.github/workflows/go-windows.yml @@ -26,4 +26,4 @@ jobs: go-version: '${{ matrix.go }}' - name: Test - run: go run ./script/run-test --reset-instrument --debug -v \ No newline at end of file + run: go run ./script/run-test --install-xgo --reset-instrument --debug -v \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 01e22e9f..cce5996e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -26,7 +26,7 @@ jobs: go-version: '${{ matrix.go }}' - name: Test - run: go run ./script/run-test --reset-instrument --debug -v -cover -coverpkg github.com/xhd2015/xgo/runtime/... -coverprofile cover.out + run: go run ./script/run-test --install-xgo --reset-instrument --debug -v -cover -coverpkg github.com/xhd2015/xgo/runtime/... -coverprofile cover.out - name: Merge Coverages run: go run ./cmd/go-tool-coverage merge ./cover-runtime.out ./cover-runtime-sub.out -o cover-runtime-merged.out --exclude-prefix github.com/xhd2015/xgo/runtime/test diff --git a/cmd/xgo/exec_tool/debug.go b/cmd/xgo/exec_tool/debug.go index ed6cf5ac..d506a006 100644 --- a/cmd/xgo/exec_tool/debug.go +++ b/cmd/xgo/exec_tool/debug.go @@ -46,6 +46,11 @@ func getDebugEnvList(xgoCompilerEnableEnv string) [][2]string { {XGO_DEBUG_DUMP_AST_FILE, os.Getenv(XGO_DEBUG_DUMP_AST_FILE)}, {XGO_MAIN_MODULE, os.Getenv(XGO_MAIN_MODULE)}, {XGO_COMPILE_PKG_DATA_DIR, os.Getenv(XGO_COMPILE_PKG_DATA_DIR)}, + + // strace + {XGO_STACK_TRACE, os.Getenv(XGO_STACK_TRACE)}, + {XGO_STACK_TRACE_DIR, os.Getenv(XGO_STACK_TRACE_DIR)}, + {XGO_STD_LIB_TRAP_DEFAULT_ALLOW, os.Getenv(XGO_STD_LIB_TRAP_DEFAULT_ALLOW)}, {XGO_DEBUG_COMPILE_PKG, os.Getenv(XGO_DEBUG_COMPILE_PKG)}, {XGO_DEBUG_COMPILE_LOG_FILE, os.Getenv(XGO_DEBUG_COMPILE_LOG_FILE)}, diff --git a/cmd/xgo/exec_tool/env.go b/cmd/xgo/exec_tool/env.go index 20bf9964..68d7e207 100644 --- a/cmd/xgo/exec_tool/env.go +++ b/cmd/xgo/exec_tool/env.go @@ -14,6 +14,12 @@ const XGO_TOOLCHAIN_VERSION_NUMBER = "XGO_TOOLCHAIN_VERSION_NUMBER" const XGO_MAIN_MODULE = "XGO_MAIN_MODULE" +// --strace +const XGO_STACK_TRACE = "XGO_STACK_TRACE" + +// --strace-dir +const XGO_STACK_TRACE_DIR = "XGO_STACK_TRACE_DIR" + const XGO_COMPILE_PKG_DATA_DIR = "XGO_COMPILE_PKG_DATA_DIR" const XGO_STD_LIB_TRAP_DEFAULT_ALLOW = "XGO_STD_LIB_TRAP_DEFAULT_ALLOW" diff --git a/cmd/xgo/main.go b/cmd/xgo/main.go index e4f806be..3c94358c 100644 --- a/cmd/xgo/main.go +++ b/cmd/xgo/main.go @@ -165,6 +165,7 @@ func handleBuild(cmd string, args []string) error { dumpIR := opts.dumpIR dumpAST := opts.dumpAST stackTrace := opts.stackTrace + stackTraceDir := opts.stackTraceDir trapStdlib := opts.trapStdlib if cmdExec && len(remainArgs) == 0 { @@ -272,6 +273,22 @@ func handleBuild(cmd string, args []string) error { h.Write(optionsFromFileContent) buildCacheSuffix += "-" + hex.EncodeToString(h.Sum(nil)) } + if stackTrace == "on" || stackTrace == "true" { + v := stackTrace + if v == "true" { + v = "on" + } else if v == "false" { + v = "off" + } + buildCacheSuffix += "-strace_" + v + } + if stackTraceDir != "" && stackTraceDir != "." && stackTraceDir != "./" { + // this affects the flags package + h := md5.New() + h.Write([]byte(stackTraceDir)) + buildCacheSuffix += "-" + hex.EncodeToString(h.Sum(nil)) + } + buildCacheDir := filepath.Join(instrumentDir, "build-cache"+buildCacheSuffix) revisionFile := filepath.Join(instrumentDir, "xgo-revision.txt") fullSyncRecord := filepath.Join(instrumentDir, "full-sync-record.txt") @@ -601,7 +618,7 @@ func handleBuild(cmd string, args []string) error { if vscodeDebugFile != "" { xgoDebugVscode = vscodeDebugFile + vscodeDebugFileSuffix } - execCmd.Env = append(execCmd.Env, "XGO_DEBUG_VSCODE="+xgoDebugVscode) + execCmd.Env = append(execCmd.Env, exec_tool.XGO_DEBUG_VSCODE+"="+xgoDebugVscode) // debug compile package execCmd.Env = append(execCmd.Env, exec_tool.XGO_DEBUG_COMPILE_PKG+"="+debugCompilePkg) @@ -609,7 +626,10 @@ func handleBuild(cmd string, args []string) error { // stack trace if stackTrace != "" { - execCmd.Env = append(execCmd.Env, "XGO_STACK_TRACE="+stackTrace) + execCmd.Env = append(execCmd.Env, exec_tool.XGO_STACK_TRACE+"="+stackTrace) + } + if stackTraceDir != "" { + execCmd.Env = append(execCmd.Env, exec_tool.XGO_STACK_TRACE_DIR+"="+stackTraceDir) } // trap stdlib @@ -617,7 +637,7 @@ func handleBuild(cmd string, args []string) error { if trapStdlib { trapStdlibEnv = "true" } - execCmd.Env = append(execCmd.Env, "XGO_STD_LIB_TRAP_DEFAULT_ALLOW="+trapStdlibEnv) + execCmd.Env = append(execCmd.Env, exec_tool.XGO_STD_LIB_TRAP_DEFAULT_ALLOW+"="+trapStdlibEnv) // compiler options (make abs) var absOptionsFromFile string diff --git a/cmd/xgo/option.go b/cmd/xgo/option.go index ea80da74..4c88fbe5 100644 --- a/cmd/xgo/option.go +++ b/cmd/xgo/option.go @@ -70,7 +70,13 @@ type options struct { // --strace, --strace=on, --strace=off // --stack-stackTrace, --stack-stackTrace=off, --stack-stackTrace=on // to be used in test mode + // the parsed value is either on or off, mapping: + // "",true, on => on + // false, off => off + // other => error stackTrace string + // --strace-dir + stackTraceDir string remainArgs []string @@ -120,6 +126,7 @@ func parseOptions(cmd string, args []string) (*options, error) { var overlay string var modfile string var stackTrace string + var stackTraceDir string var trapStdlib bool var remainArgs []string @@ -314,6 +321,22 @@ func parseOptions(cmd string, args []string) (*options, error) { continue } + // strace dir + stackTraceDirVal, ok, err := tryParseRequiredValue("--strace-dir", args, &i) + if err != nil { + return nil, err + } + if !ok { + stackTraceDirVal, ok, err = tryParseRequiredValue("--stack-trace-dir", args, &i) + if err != nil { + return nil, err + } + } + if ok { + stackTraceDir = stackTraceDirVal + continue + } + argVal, ok := parseStackTraceFlag(arg) if ok { stackTrace = argVal @@ -419,18 +442,20 @@ func parseOptions(cmd string, args []string) (*options, error) { // default true syncWithLink: syncWithLink == nil || *syncWithLink, - mod: mod, - gcflags: gcflags, - overlay: overlay, - modfile: modfile, - stackTrace: stackTrace, - trapStdlib: trapStdlib, + mod: mod, + gcflags: gcflags, + overlay: overlay, + modfile: modfile, + stackTrace: stackTrace, + stackTraceDir: stackTraceDir, + trapStdlib: trapStdlib, remainArgs: remainArgs, testArgs: testArgs, }, nil } +// parse: --opt=x, --opt x, --opt, but not --opt -x func tryParseOption(flag string, args []string, i *int) (string, bool) { v, j, ok := tryParseOptionalValue(flag, args, *i) if !ok { @@ -440,23 +465,49 @@ func tryParseOption(flag string, args []string, i *int) (string, bool) { return v, true } -// parse: --opt=x, --opt x, but not --opt -x +// parse: --opt=x, --opt x, even --opt -x +func tryParseRequiredValue(flag string, args []string, i *int) (string, bool, error) { + v, j, ok, err := tryParseValue(flag, args, *i, false) + if err != nil { + return "", false, err + } + if !ok { + return "", false, nil + } + *i = j + return v, true, nil +} + func tryParseOptionalValue(flag string, args []string, i int) (string, int, bool) { + val, i, ok, err := tryParseValue(flag, args, i, true) + if err != nil { + panic(err) + } + return val, i, ok +} + +func tryParseValue(flag string, args []string, i int, optional bool) (string, int, bool, error) { arg := args[i] if !strings.HasPrefix(arg, flag) { - return "", i, false + return "", i, false, nil } - suffix := strings.TrimPrefix(arg, flag) + suffix := arg[len(flag):] if suffix == "" { - if i >= len(args) || strings.HasPrefix(args[i], "-") { - return "", i, true + if optional { + if i >= len(args) || strings.HasPrefix(args[i], "-") { + return "", i, true, nil + } + } else { + if i >= len(args) { + return "", i, false, fmt.Errorf("%s: requires value", flag) + } } - return args[i+1], i + 1, true + return args[i+1], i + 1, true, nil } if !strings.HasPrefix(suffix, "=") { - return "", i, false + return "", i, false, nil } - return suffix[1:], i, true + return suffix[1:], i, true, nil } func parseStackTraceFlag(arg string) (string, bool) { @@ -476,10 +527,10 @@ func parseStackTraceFlag(arg string) (string, bool) { return "", false } val := arg[len(stackTracePrefix)+1:] - if val == "" || val == "on" { + if val == "" || val == "on" || val == "true" { return "on", true } - if val == "off" { + if val == "off" || val == "false" { return "off", true } panic(fmt.Errorf("unrecognized value %s: %s, expects on|off", arg, val)) diff --git a/cmd/xgo/runtime_gen/trace/trace.go b/cmd/xgo/runtime_gen/trace/trace.go index e6bdbe82..56bf9658 100755 --- a/cmd/xgo/runtime_gen/trace/trace.go +++ b/cmd/xgo/runtime_gen/trace/trace.go @@ -13,28 +13,17 @@ import ( "github.com/xhd2015/xgo/runtime/core" "github.com/xhd2015/xgo/runtime/trap" + "github.com/xhd2015/xgo/runtime/trap/flags" ) // hold goroutine stacks, keyed by goroutine ptr var stackMap sync.Map // uintptr(goroutine) -> *Root var testInfoMapping sync.Map // uintptr(goroutine) -> *testInfo -// persist the --strace flag when invoking xgo test -// stack trace options: -// -// on: automatically collect when test starts and ends -const __xgo_injected_StraceFlag = "" - -// options: -// -// true: stdlib is by default allowed -const __xgo_injected_StdlibTrapDefaultAllow = "" - -var skipStdlibTraceByDefault = __xgo_injected_StdlibTrapDefaultAllow == "true" +var skipStdlibTraceByDefault = flags.TRAP_STDLIB == "true" type testInfo struct { - name string - + name string onFinish func() } @@ -49,7 +38,7 @@ func init() { name: name, } testInfoMapping.LoadOrStore(key, tInfo) - if __xgo_injected_StraceFlag == "on" { + if flags.STRACE == "on" || flags.STRACE == "true" { tInfo.onFinish = Begin() } }) diff --git a/cmd/xgo/runtime_gen/trap/flags/build_cache.go b/cmd/xgo/runtime_gen/trap/flags/build_cache.go new file mode 100755 index 00000000..c85f7f74 --- /dev/null +++ b/cmd/xgo/runtime_gen/trap/flags/build_cache.go @@ -0,0 +1,5 @@ +package flags + +// if any flag changed, this file should be replaced to +// cause rebuild +const _ = "__BUILD_CACHE__" diff --git a/cmd/xgo/runtime_gen/trap/flags/flags.go b/cmd/xgo/runtime_gen/trap/flags/flags.go new file mode 100755 index 00000000..b3aaf24e --- /dev/null +++ b/cmd/xgo/runtime_gen/trap/flags/flags.go @@ -0,0 +1,31 @@ +package flags + +// flag: --strace +// env: XGO_STACK_TRACE +// description: +// +// persist the --strace flag when invoking xgo test, +// if the value is on or true, trace will be automatically +// collected when test starts and ends +// +// values: +// +// on,true => --strace, --strace=on, --strace=true +// off,false,empty string => --strace=off, --strace=false +const STRACE = "" + +// flag: --strace-dir +// env: XGO_STACK_TRACE_DIR +// values: +// +// directory, default current dir +const STRACE_DIR = "" + +// flag: --trap-stdlib +// env: XGO_STD_LIB_TRAP_DEFAULT_ALLOW +// description: if true, stdlib trap is by default allowed +// values: +// +// true - default with test +// empty string and any other value - --trap-stdlib=false +const TRAP_STDLIB = "" diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index 3a2ec466..e9e9cb67 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -4,8 +4,8 @@ import "fmt" // auto updated const VERSION = "1.0.47" -const REVISION = "2b5b421d4069bcde6b70e76b157e98e39634672c+1" -const NUMBER = 301 +const REVISION = "6bd25c22e0175d3a73dde9e55151b32fbf80c67d+1" +const NUMBER = 302 // manually updated const CORE_VERSION = "1.0.47" diff --git a/patch/ctxt/ctx.go b/patch/ctxt/ctx.go index 0f0c9e43..c9808935 100644 --- a/patch/ctxt/ctx.go +++ b/patch/ctxt/ctx.go @@ -9,6 +9,7 @@ const XgoModule = "github.com/xhd2015/xgo" const XgoRuntimePkg = XgoModule + "/runtime" const XgoRuntimeCorePkg = XgoModule + "/runtime/core" const XgoRuntimeTracePkg = XgoModule + "/runtime/trace" +const XgoRuntimeFlagsPkg = XgoRuntimePkg + "/trap/flags" const XgoLinkTrapVarForGenerated = "__xgo_link_trap_var_for_generated" diff --git a/patch/syntax/syntax.go b/patch/syntax/syntax.go index 1fe22559..0ad01b2b 100644 --- a/patch/syntax/syntax.go +++ b/patch/syntax/syntax.go @@ -32,10 +32,22 @@ const XGO_NUMBER = "XGO_NUMBER" // --strace const XGO_STACK_TRACE = "XGO_STACK_TRACE" +const XGO_STACK_TRACE_DIR = "XGO_STACK_TRACE_DIR" const XGO_STD_LIB_TRAP_DEFAULT_ALLOW = "XGO_STD_LIB_TRAP_DEFAULT_ALLOW" + +// Deprecated: use flag_STRACE,.. instead const straceFlagConstName = "__xgo_injected_StraceFlag" const trapStdlibFlagConstName = "__xgo_injected_StdlibTrapDefaultAllow" +const ( + // --strace + flag_STRACE = "STRACE" + // --strace-dir + flag_STRACE_DIR = "STRACE_DIR" + // --trap-stdlib + flag_TRAP_STDLIB = "TRAP_STDLIB" +) + // this link function is considered safe as we do not allow user // to define such one,there will be no abuse const XgoLinkGeneratedRegisterFunc = "__xgo_link_generated_register_func" @@ -335,9 +347,12 @@ func registerAndTrapFuncs(fileList []*syntax.File, addFile func(name string, r i func injectXgoFlags(fileList []*syntax.File) { pkgPath := xgo_ctxt.GetPkgPath() switch pkgPath { + case xgo_ctxt.XgoRuntimeFlagsPkg: + injectXgoGeneralFlags(fileList) case xgo_ctxt.XgoRuntimeCorePkg: patchXgoRuntimeCoreVersions(fileList) case xgo_ctxt.XgoRuntimeTracePkg: + // Deprecated, left here only for compatible purpose injectXgoStraceFlag(fileList) } } @@ -408,6 +423,7 @@ func forEachConst(declList []syntax.Decl, fn func(constDecl *syntax.ConstDecl) b } } +// Deprecated: use injectXgoGeneralFlags instead func injectXgoStraceFlag(fileList []*syntax.File) { straceFlag := os.Getenv(XGO_STACK_TRACE) trapStdlibFlag := os.Getenv(XGO_STD_LIB_TRAP_DEFAULT_ALLOW) @@ -433,6 +449,24 @@ func injectXgoStraceFlag(fileList []*syntax.File) { }) } +func injectXgoGeneralFlags(fileList []*syntax.File) { + for _, file := range fileList { + forEachConst(file.DeclList, func(constDecl *syntax.ConstDecl) bool { + for _, name := range constDecl.NameList { + switch name.Value { + case flag_STRACE: + constDecl.Values = newStringLit(os.Getenv(XGO_STACK_TRACE)) + case flag_STRACE_DIR: + constDecl.Values = newStringLit(os.Getenv(XGO_STACK_TRACE_DIR)) + case flag_TRAP_STDLIB: + constDecl.Values = newStringLit(os.Getenv(XGO_STD_LIB_TRAP_DEFAULT_ALLOW)) + } + } + return false + }) + } +} + func getFileIndexMapping(files []*syntax.File) map[*syntax.File]int { m := make(map[*syntax.File]int, len(files)) for i, file := range files { diff --git a/runtime/test/trap/flags/persistent_after_build/persistent.go b/runtime/test/trap/flags/persistent_after_build/persistent.go new file mode 100644 index 00000000..a344a4e5 --- /dev/null +++ b/runtime/test/trap/flags/persistent_after_build/persistent.go @@ -0,0 +1 @@ +package persistent_after_build diff --git a/runtime/test/trap/flags/persistent_after_build/persistent_test.go b/runtime/test/trap/flags/persistent_after_build/persistent_test.go new file mode 100644 index 00000000..559752e9 --- /dev/null +++ b/runtime/test/trap/flags/persistent_after_build/persistent_test.go @@ -0,0 +1,40 @@ +//go:build unix +// +build unix + +package persistent_after_build + +import ( + "os" + "strings" + "testing" + + "github.com/xhd2015/xgo/support/cmd" +) + +func TestPersistentAfterBuild(t *testing.T) { + var xgoCmd string + var args []string + + testCmd := os.Getenv("XGO_TEST_COMMAND") + if testCmd != "" { + cmds := strings.Split(testCmd, " ") + xgoCmd = cmds[0] + args = cmds[1:] + } else { + xgoCmd = "xgo" + } + + args = append(args, "test", "-c", "-o", "test.bin", "--strace", "--strace-dir", "/tmp") + + // build + err := cmd.Debug().Dir("./testdata").Run(xgoCmd, args...) + if err != nil { + t.Error(err) + return + } + err = cmd.Debug().Dir("./testdata").Run("./test.bin", "-test.v") + if err != nil { + t.Error(err) + return + } +} diff --git a/runtime/test/trap/flags/persistent_after_build/testdata/flags_test.go b/runtime/test/trap/flags/persistent_after_build/testdata/flags_test.go new file mode 100644 index 00000000..9b8ef19b --- /dev/null +++ b/runtime/test/trap/flags/persistent_after_build/testdata/flags_test.go @@ -0,0 +1,23 @@ +package main + +import ( + "testing" + + "github.com/xhd2015/xgo/runtime/trap/flags" +) + +// go run -tags dev ./cmd/xgo test -v --project-dir runtime/test/trap/flags/persistent_after_build/testdata --strace --strace-dir /tmp ./ + +// separate: +// +// go run -tags dev ./cmd/xgo test -c --project-dir runtime/test/trap/flags/persistent_after_build/testdata --strace --strace-dir /tmp -o test.bin +// +// ./test.bin -test.v +func TestFlags(t *testing.T) { + if flags.STRACE != "on" { + t.Errorf("STRACE expect: %s, actual: %s", "on", flags.STRACE) + } + if flags.STRACE_DIR != "/tmp" { + t.Errorf("STRACE_DIR expect: %s, actual: %s", "/tmp", flags.STRACE_DIR) + } +} diff --git a/runtime/test/trap/flags/persistent_after_build/testdata/go.mod b/runtime/test/trap/flags/persistent_after_build/testdata/go.mod new file mode 100644 index 00000000..53c811a4 --- /dev/null +++ b/runtime/test/trap/flags/persistent_after_build/testdata/go.mod @@ -0,0 +1,7 @@ +module github.com/xhd2015/xgo/runtime/test/trap/flags/persistent_after_build/testdata + +go 1.14 + +require github.com/xhd2015/xgo/runtime v1.0.0 + +replace github.com/xhd2015/xgo/runtime => ../../../../.. diff --git a/runtime/trace/trace.go b/runtime/trace/trace.go index e6bdbe82..56bf9658 100644 --- a/runtime/trace/trace.go +++ b/runtime/trace/trace.go @@ -13,28 +13,17 @@ import ( "github.com/xhd2015/xgo/runtime/core" "github.com/xhd2015/xgo/runtime/trap" + "github.com/xhd2015/xgo/runtime/trap/flags" ) // hold goroutine stacks, keyed by goroutine ptr var stackMap sync.Map // uintptr(goroutine) -> *Root var testInfoMapping sync.Map // uintptr(goroutine) -> *testInfo -// persist the --strace flag when invoking xgo test -// stack trace options: -// -// on: automatically collect when test starts and ends -const __xgo_injected_StraceFlag = "" - -// options: -// -// true: stdlib is by default allowed -const __xgo_injected_StdlibTrapDefaultAllow = "" - -var skipStdlibTraceByDefault = __xgo_injected_StdlibTrapDefaultAllow == "true" +var skipStdlibTraceByDefault = flags.TRAP_STDLIB == "true" type testInfo struct { - name string - + name string onFinish func() } @@ -49,7 +38,7 @@ func init() { name: name, } testInfoMapping.LoadOrStore(key, tInfo) - if __xgo_injected_StraceFlag == "on" { + if flags.STRACE == "on" || flags.STRACE == "true" { tInfo.onFinish = Begin() } }) diff --git a/runtime/trap/flags/build_cache.go b/runtime/trap/flags/build_cache.go new file mode 100644 index 00000000..c85f7f74 --- /dev/null +++ b/runtime/trap/flags/build_cache.go @@ -0,0 +1,5 @@ +package flags + +// if any flag changed, this file should be replaced to +// cause rebuild +const _ = "__BUILD_CACHE__" diff --git a/runtime/trap/flags/flags.go b/runtime/trap/flags/flags.go new file mode 100644 index 00000000..b3aaf24e --- /dev/null +++ b/runtime/trap/flags/flags.go @@ -0,0 +1,31 @@ +package flags + +// flag: --strace +// env: XGO_STACK_TRACE +// description: +// +// persist the --strace flag when invoking xgo test, +// if the value is on or true, trace will be automatically +// collected when test starts and ends +// +// values: +// +// on,true => --strace, --strace=on, --strace=true +// off,false,empty string => --strace=off, --strace=false +const STRACE = "" + +// flag: --strace-dir +// env: XGO_STACK_TRACE_DIR +// values: +// +// directory, default current dir +const STRACE_DIR = "" + +// flag: --trap-stdlib +// env: XGO_STD_LIB_TRAP_DEFAULT_ALLOW +// description: if true, stdlib trap is by default allowed +// values: +// +// true - default with test +// empty string and any other value - --trap-stdlib=false +const TRAP_STDLIB = "" diff --git a/script/run-test/main.go b/script/run-test/main.go index b19f9e21..580ca56d 100644 --- a/script/run-test/main.go +++ b/script/run-test/main.go @@ -93,6 +93,11 @@ var extraSubTests = []*TestCase{ flags: []string{"--strace"}, windowsFlags: []string{"--trap-stdlib=false", "--strace"}, }, + // trap + { + name: "trap_flags_persistent", + dir: "runtime/test/trap/flags/persistent_after_build", + }, { name: "trap_with_overlay", dir: "runtime/test/trap_with_overlay", @@ -207,6 +212,8 @@ func main() { var xgoRuntimeSubTestOnly bool var xgoDefaultTestOnly bool + var installXgo bool + var debug bool var cover bool var coverpkgs []string @@ -292,6 +299,10 @@ func main() { debug = true continue } + if arg == "--install-xgo" { + installXgo = true + continue + } if arg == "--" { if i+1 < n { remainArgs = append(remainArgs, args[i+1:]...) @@ -366,6 +377,14 @@ func main() { fmt.Fprintf(os.Stderr, "no go select\n") os.Exit(1) } + + if installXgo { + err := cmd.Run("go", "install", "./cmd/xgo") + if err != nil { + fmt.Fprintf(os.Stderr, "install xgo: %v\n", err) + os.Exit(1) + } + } for _, goroot := range goroots { begin := time.Now() fmt.Fprintf(os.Stdout, "TEST %s\n", goroot) @@ -703,7 +722,6 @@ func doRunTest(goroot string, kind testKind, usePlainGo bool, dir string, args [ testArgs = append(testArgs, globalFlags...) testArgs = append(testArgs, args...) testArgs = append(testArgs, tests...) - } // remove extra xgo flags