-
Notifications
You must be signed in to change notification settings - Fork 326
/
main.go
97 lines (82 loc) · 2.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Tetragon
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"strconv"
"github.com/cilium/tetragon/pkg/vmtests"
)
var (
tetragonDir = "."
goTestsDir = filepath.Join(tetragonDir, "go-tests")
outDir = filepath.Join(tetragonDir, "tests", "vmtests")
)
func splitProgs(n int, blacklist []vmtests.GoTest) error {
tests, err := vmtests.ListTests(goTestsDir, false, blacklist)
if err != nil || len(tests) == 0 {
return fmt.Errorf("no tests found (err:%w). Is %s accesible? Did you run `make test-compile`?", err, goTestsDir)
}
files := make([]*os.File, n)
for i := 0; i < n; i++ {
fname := filepath.Join(outDir, fmt.Sprintf("test-group-%d", i))
files[i], err = os.Create(fname)
if err != nil {
return err
}
defer files[i].Close()
}
// NB: Some programs take longer than others. We allocate them
// one-by-one in groups hoping that this will lead to a decent
// load-balance between the groups.
i := 0
for _, test := range tests {
fmt.Fprintf(files[i%n], "%s\n", test.ToString())
i++
}
return nil
}
var CiBlacklist = []vmtests.GoTest{
// pkg.exporter has a rate limit test, which is time-dependent. There
// was a previous attempt to fix the test, but failed. Ignore it for
// now.
{PackageProg: "pkg.exporter"},
// pkg.grpc.exec relies on sleep() calls in order to wait for the
// eventcache to run. Running them on heavily loaded VM cause flakes.
// As they are not kernel-dependant, let's run them only as part of
// gotests.
{PackageProg: "pkg.grpc.exec"},
}
func usage() {
fmt.Fprintf(
flag.CommandLine.Output(),
"Usage: %s [flags] <ngroups> -- split tests in <ngroups> groups. Output is %s/test-group-X.\n",
os.Args[0], outDir,
)
flag.PrintDefaults()
}
func main() {
var cirun bool
flag.BoolVar(&cirun, "ci-run", false, "This option enables CI blacklist for tests")
flag.Parse()
if flag.NArg() != 1 {
usage()
os.Exit(0)
}
n, err := strconv.Atoi(flag.Arg(0))
if err != nil {
usage()
os.Exit(1)
}
var blacklist []vmtests.GoTest
if cirun {
blacklist = CiBlacklist
}
err = splitProgs(n, blacklist)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
}