From dbacef35c4559ce1cb8055279679ac2a449edb0b Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Tue, 16 Jun 2020 14:33:17 +0200 Subject: [PATCH] build: Update integration tests and add to build.go (#6744) --- build.go | 49 ++++++++++++++++++++++++++++++++++++++++++- test/h1/config.xml | 12 +++++++++-- test/h2/config.xml | 13 +++++++++++- test/h3/config.xml | 12 +++++++++-- test/usage_windows.go | 4 ++-- 5 files changed, 82 insertions(+), 8 deletions(-) diff --git a/build.go b/build.go index 1450519c5..ace772256 100644 --- a/build.go +++ b/build.go @@ -46,6 +46,8 @@ var ( installSuffix string pkgdir string cc string + run string + benchRun string debugBinary bool coverage bool timeout = "120s" @@ -301,6 +303,12 @@ func runCommand(cmd string, target target) { case "bench": bench("github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/...") + case "integration": + integration(false) + + case "integrationbench": + integration(true) + case "assets": rebuildAssets() @@ -367,6 +375,8 @@ func parseFlags() { flag.BoolVar(&debugBinary, "debug-binary", debugBinary, "Create unoptimized binary to use with delve, set -gcflags='-N -l' and omit -ldflags") flag.BoolVar(&coverage, "coverage", coverage, "Write coverage profile of tests to coverage.txt") flag.IntVar(&numVersions, "num-versions", numVersions, "Number of versions for changelog command") + flag.StringVar(&run, "run", "", "Specify which tests to run") + flag.StringVar(&benchRun, "bench", "", "Specify which benchmarks to run") flag.Parse() } @@ -386,12 +396,49 @@ func test(pkgs ...string) { args = append(args, "-covermode", "atomic", "-coverprofile", "coverage.txt", "-coverpkg", strings.Join(pkgs, ",")) } + args = append(args, runArgs()...) + runPrint(goCmd, append(args, pkgs...)...) } func bench(pkgs ...string) { lazyRebuildAssets() - runPrint(goCmd, append([]string{"test", "-run", "NONE", "-bench", "."}, pkgs...)...) + args := append([]string{"test", "-run", "NONE"}, benchArgs()...) + runPrint(goCmd, append(args, pkgs...)...) +} + +func integration(bench bool) { + lazyRebuildAssets() + args := []string{"test", "-v", "-timeout", "60m", "-tags"} + tags := "purego,integration" + if bench { + tags += ",benchmark" + } + args = append(args, tags) + args = append(args, runArgs()...) + if bench { + if run == "" { + args = append(args, "-run", "Benchmark") + } + args = append(args, benchArgs()...) + } + args = append(args, "./test") + fmt.Println(args) + runPrint(goCmd, args...) +} + +func runArgs() []string { + if run == "" { + return nil + } + return []string{"-run", run} +} + +func benchArgs() []string { + if benchRun == "" { + return []string{"-bench", "."} + } + return []string{"-bench", benchRun} } func install(target target, tags []string) { diff --git a/test/h1/config.xml b/test/h1/config.xml index 3875c1697..94ec05b6e 100644 --- a/test/h1/config.xml +++ b/test/h1/config.xml @@ -1,4 +1,4 @@ - + basic @@ -22,6 +22,9 @@ .stfolder false 0 + 0 + false + standard basic @@ -44,6 +47,9 @@ .stfolder false 0 + 0 + false + standard
tcp://127.0.0.1:22004
@@ -130,11 +136,13 @@ 0 ~ true - 0 + 0 https://crash.syncthing.net/newcrash true 180 20 default + auto + 0
diff --git a/test/h2/config.xml b/test/h2/config.xml index afa1821bb..cefafaea9 100644 --- a/test/h2/config.xml +++ b/test/h2/config.xml @@ -21,6 +21,9 @@ .stfolder false 0 + 0 + false + standard basic @@ -43,6 +46,9 @@ .stfolder false 0 + 0 + false + standard basic @@ -65,6 +71,9 @@ .stfolder false 0 + 0 + false + standard
tcp://127.0.0.1:22001
@@ -134,11 +143,13 @@ 0 ~ true - 0 + 0 https://crash.syncthing.net/newcrash true 180 20 default + auto + 0
diff --git a/test/h3/config.xml b/test/h3/config.xml index 7d2acfe46..8c711d94e 100644 --- a/test/h3/config.xml +++ b/test/h3/config.xml @@ -1,4 +1,4 @@ - + basic @@ -23,6 +23,9 @@ .stfolder false 0 + 0 + false + standard basic @@ -45,6 +48,9 @@ .stfolder false 0 + 0 + false + standard
tcp://127.0.0.1:22001
@@ -114,11 +120,13 @@ 0 ~ true - 0 + 0 https://crash.syncthing.net/newcrash true 180 20 default + auto + 0
diff --git a/test/usage_windows.go b/test/usage_windows.go index 728a387f9..52e24baac 100644 --- a/test/usage_windows.go +++ b/test/usage_windows.go @@ -23,7 +23,7 @@ func ftToDuration(ft *syscall.Filetime) time.Duration { func printUsage(name string, proc *os.ProcessState, total int64) { if rusage, ok := proc.SysUsage().(*syscall.Rusage); ok { mib := total / 1024 / 1024 - log.Printf("%s: Utime: %s / MiB", name, time.Duration(&rusage.UserTime/mib)) - log.Printf("%s: Stime: %s / MiB", name, time.Duration(&rusage.KernelTime/mib)) + log.Printf("%s: Utime: %s / MiB", name, time.Duration(rusage.UserTime.Nanoseconds()/mib)) + log.Printf("%s: Stime: %s / MiB", name, time.Duration(rusage.KernelTime.Nanoseconds()/mib)) } }