Skip to content

Commit 2d92ccb

Browse files
committed
fix all XDC&ETH tests and enable it in CI
1 parent 74a54ca commit 2d92ccb

34 files changed

+1079
-979
lines changed

.travis.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ jobs:
1515
script:
1616
- go run build/ci.go lint
1717

18+
- stage: build
19+
os: linux
20+
dist: bionic
21+
go: 1.15.x
22+
env:
23+
- GO111MODULE=auto
24+
script:
25+
- go run build/ci.go test -coverage $TEST_PACKAGES
26+
1827
# These builders run the tests
1928
# - stage: build
2029
# os: linux
@@ -24,13 +33,4 @@ jobs:
2433
# env:
2534
# - GO111MODULE=auto
2635
# script:
27-
# - go run build/ci.go test -coverage $TEST_PACKAGES
28-
29-
# - stage: build
30-
# os: linux
31-
# dist: bionic
32-
# go: 1.15.x
33-
# env:
34-
# - GO111MODULE=auto
35-
# script:
3636
# - go run build/ci.go test -coverage $TEST_PACKAGES

accounts/keystore/plain_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,6 @@ func loadKeyStoreTestV1(file string, t *testing.T) map[string]KeyStoreTestV1 {
245245
return tests
246246
}
247247

248-
func TestKeyForDirectICAP(t *testing.T) {
249-
t.Parallel()
250-
key := NewKeyForDirectICAP(rand.Reader)
251-
if !strings.HasPrefix(key.Address.Hex(), "0x00") {
252-
t.Errorf("Expected first address byte to be zero, have: %s", key.Address.Hex())
253-
}
254-
}
255-
256248
func TestV3_31_Byte_Key(t *testing.T) {
257249
t.Parallel()
258250
tests := loadKeyStoreTestV3("testdata/v3_test_vector.json", t)

build/ci.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@
1818

1919
/*
2020
The ci command is called from Continuous Integration scripts.
21-
2221
Usage: go run build/ci.go <command> <command flags/arguments>
23-
2422
Available commands are:
25-
2623
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
2724
test [ -coverage ] [ packages... ] -- runs the tests
2825
lint -- runs certain pre-selected linters
2926
importkeys -- imports signing keys from env
3027
xgo [ -alltools ] [ options ] -- cross builds according to options
31-
3228
For all commands, -n prevents execution of external programs (dry run mode).
33-
3429
*/
3530
package main
3631

@@ -60,11 +55,11 @@ var (
6055
executablePath("geth"),
6156
executablePath("puppeth"),
6257
executablePath("rlpdump"),
58+
executablePath("swarm"),
6359
executablePath("wnode"),
6460
}
6561

66-
// Packages to be cross-compiled by the xgo command
67-
allCrossCompiledArchiveFiles = allToolsArchiveFiles
62+
dlgoVersion = "1.16.4"
6863
)
6964

7065
var GOBIN, _ = filepath.Abs(filepath.Join("build", "bin"))
@@ -214,27 +209,39 @@ func goToolArch(arch string, cc string, subcmd string, args ...string) *exec.Cmd
214209
// Running The Tests
215210
//
216211
// "tests" also includes static analysis tools such as vet.
217-
218212
func doTest(cmdline []string) {
219-
coverage := flag.Bool("coverage", false, "Whether to record code coverage")
213+
var (
214+
dlgo = flag.Bool("dlgo", false, "Download Go and build with it")
215+
arch = flag.String("arch", "", "Run tests for given architecture")
216+
cc = flag.String("cc", "", "Sets C compiler binary")
217+
coverage = flag.Bool("coverage", false, "Whether to record code coverage")
218+
verbose = flag.Bool("v", false, "Whether to log verbosely")
219+
)
220220
flag.CommandLine.Parse(cmdline)
221-
env := build.Env()
222-
223-
packages := []string{"./..."}
224-
if len(flag.CommandLine.Args()) > 0 {
225-
packages = flag.CommandLine.Args()
221+
fmt.Printf("Running tests with command line %v \n", cmdline)
222+
// Configure the toolchain.
223+
tc := build.GoToolchain{GOARCH: *arch, CC: *cc}
224+
if *dlgo {
225+
csdb := build.MustLoadChecksums("build/checksums.txt")
226+
tc.Root = build.DownloadGo(csdb, dlgoVersion)
226227
}
227-
packages = build.ExpandPackagesNoVendor(packages)
228+
gotest := tc.Go("test")
228229

229-
// Run the actual tests.
230230
// Test a single package at a time. CI builders are slow
231231
// and some tests run into timeouts under load.
232-
gotest := goTool("test", buildFlags(env)...)
233-
gotest.Args = append(gotest.Args, "-p", "1", "-timeout", "5m")
232+
gotest.Args = append(gotest.Args, "-p", "1")
234233
if *coverage {
235234
gotest.Args = append(gotest.Args, "-covermode=atomic", "-cover")
236235
}
236+
if *verbose {
237+
gotest.Args = append(gotest.Args, "-v")
238+
}
237239

240+
packages := []string{"./..."}
241+
if len(flag.CommandLine.Args()) > 0 {
242+
packages = flag.CommandLine.Args()
243+
}
244+
fmt.Printf("Running tests for %v \n", packages)
238245
gotest.Args = append(gotest.Args, packages...)
239246
build.MustRun(gotest)
240247
}
@@ -245,7 +252,6 @@ func doLint(cmdline []string) {
245252
cachedir = flag.String("cachedir", "./build/cache", "directory for caching golangci-lint binary.")
246253
)
247254
flag.CommandLine.Parse(cmdline)
248-
249255
packages := []string{"./..."}
250256
if len(flag.CommandLine.Args()) > 0 {
251257
packages = flag.CommandLine.Args()
@@ -255,7 +261,6 @@ func doLint(cmdline []string) {
255261
lflags := []string{"run", "--config", ".golangci.yml"}
256262
build.MustRunCommand(linter, append(lflags, packages...)...)
257263
fmt.Println("You have achieved perfection.")
258-
259264
}
260265

261266
// downloadLinter downloads and unpacks golangci-lint.
@@ -293,7 +298,7 @@ func doXgo(cmdline []string) {
293298

294299
if *alltools {
295300
args = append(args, []string{"--dest", GOBIN}...)
296-
for _, res := range allCrossCompiledArchiveFiles {
301+
for _, res := range allToolsArchiveFiles {
297302
if strings.HasPrefix(res, GOBIN) {
298303
// Binary tool found, cross build it explicitly
299304
args = append(args, "./"+filepath.Join("cmd", filepath.Base(res)))

crypto/ecies/ecies_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var dumpEnc bool
4747

4848
func init() {
4949
flDump := flag.Bool("dump", false, "write encrypted test message to file")
50-
flag.Parse()
50+
// flag.Parse()
5151
dumpEnc = *flDump
5252
}
5353

internal/build/gotool.go

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright 2021 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package build
18+
19+
import (
20+
"fmt"
21+
"log"
22+
"os"
23+
"os/exec"
24+
"path/filepath"
25+
"runtime"
26+
"strings"
27+
)
28+
29+
type GoToolchain struct {
30+
Root string // GOROOT
31+
32+
// Cross-compilation variables. These are set when running the go tool.
33+
GOARCH string
34+
GOOS string
35+
CC string
36+
}
37+
38+
// Go creates an invocation of the go command.
39+
func (g *GoToolchain) Go(command string, args ...string) *exec.Cmd {
40+
tool := g.goTool(command, args...)
41+
42+
// Configure environment for cross build.
43+
if g.GOARCH != "" && g.GOARCH != runtime.GOARCH {
44+
tool.Env = append(tool.Env, "CGO_ENABLED=1")
45+
tool.Env = append(tool.Env, "GOARCH="+g.GOARCH)
46+
}
47+
if g.GOOS != "" && g.GOOS != runtime.GOOS {
48+
tool.Env = append(tool.Env, "GOOS="+g.GOOS)
49+
}
50+
// Configure C compiler.
51+
if g.CC != "" {
52+
tool.Env = append(tool.Env, "CC="+g.CC)
53+
} else if os.Getenv("CC") != "" {
54+
tool.Env = append(tool.Env, "CC="+os.Getenv("CC"))
55+
}
56+
return tool
57+
}
58+
59+
// Install creates an invocation of 'go install'. The command is configured to output
60+
// executables to the given 'gobin' directory.
61+
//
62+
// This can be used to install auxiliary build tools without modifying the local go.mod and
63+
// go.sum files. To install tools which are not required by go.mod, ensure that all module
64+
// paths in 'args' contain a module version suffix (e.g. "...@latest").
65+
func (g *GoToolchain) Install(gobin string, args ...string) *exec.Cmd {
66+
if !filepath.IsAbs(gobin) {
67+
panic("GOBIN must be an absolute path")
68+
}
69+
tool := g.goTool("install")
70+
tool.Env = append(tool.Env, "GOBIN="+gobin)
71+
tool.Args = append(tool.Args, "-mod=readonly")
72+
tool.Args = append(tool.Args, args...)
73+
74+
// Ensure GOPATH is set because go install seems to absolutely require it. This uses
75+
// 'go env' because it resolves the default value when GOPATH is not set in the
76+
// environment. Ignore errors running go env and leave any complaining about GOPATH to
77+
// the install command.
78+
pathTool := g.goTool("env", "GOPATH")
79+
output, _ := pathTool.Output()
80+
tool.Env = append(tool.Env, "GOPATH="+string(output))
81+
return tool
82+
}
83+
84+
func (g *GoToolchain) goTool(command string, args ...string) *exec.Cmd {
85+
if g.Root == "" {
86+
g.Root = runtime.GOROOT()
87+
}
88+
tool := exec.Command(filepath.Join(g.Root, "bin", "go"), command)
89+
tool.Args = append(tool.Args, args...)
90+
tool.Env = append(tool.Env, "GOROOT="+g.Root)
91+
92+
// Forward environment variables to the tool, but skip compiler target settings.
93+
// TODO: what about GOARM?
94+
skip := map[string]struct{}{"GOROOT": {}, "GOARCH": {}, "GOOS": {}, "GOBIN": {}, "CC": {}}
95+
for _, e := range os.Environ() {
96+
if i := strings.IndexByte(e, '='); i >= 0 {
97+
if _, ok := skip[e[:i]]; ok {
98+
continue
99+
}
100+
}
101+
tool.Env = append(tool.Env, e)
102+
}
103+
return tool
104+
}
105+
106+
// DownloadGo downloads the Go binary distribution and unpacks it into a temporary
107+
// directory. It returns the GOROOT of the unpacked toolchain.
108+
func DownloadGo(csdb *ChecksumDB, version string) string {
109+
// Shortcut: if the Go version that runs this script matches the
110+
// requested version exactly, there is no need to download anything.
111+
activeGo := strings.TrimPrefix(runtime.Version(), "go")
112+
if activeGo == version {
113+
log.Printf("-dlgo version matches active Go version %s, skipping download.", activeGo)
114+
return runtime.GOROOT()
115+
}
116+
117+
ucache, err := os.UserCacheDir()
118+
if err != nil {
119+
log.Fatal(err)
120+
}
121+
122+
// For Arm architecture, GOARCH includes ISA version.
123+
os := runtime.GOOS
124+
arch := runtime.GOARCH
125+
if arch == "arm" {
126+
arch = "armv6l"
127+
}
128+
file := fmt.Sprintf("go%s.%s-%s", version, os, arch)
129+
if os == "windows" {
130+
file += ".zip"
131+
} else {
132+
file += ".tar.gz"
133+
}
134+
url := "https://golang.org/dl/" + file
135+
dst := filepath.Join(ucache, file)
136+
if err := csdb.DownloadFile(url, dst); err != nil {
137+
log.Fatal(err)
138+
}
139+
140+
godir := filepath.Join(ucache, fmt.Sprintf("geth-go-%s-%s-%s", version, os, arch))
141+
if err := ExtractArchive(dst, godir); err != nil {
142+
log.Fatal(err)
143+
}
144+
goroot, err := filepath.Abs(filepath.Join(godir, "go"))
145+
if err != nil {
146+
log.Fatal(err)
147+
}
148+
return goroot
149+
}

0 commit comments

Comments
 (0)