Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'util/all_tests.go')
-rw-r--r--util/all_tests.go62
1 files changed, 54 insertions, 8 deletions
diff --git a/util/all_tests.go b/util/all_tests.go
index 566c3f70..d361651e 100644
--- a/util/all_tests.go
+++ b/util/all_tests.go
@@ -24,6 +24,7 @@ import (
"path"
"strconv"
"strings"
+ "sync"
"syscall"
"time"
)
@@ -32,8 +33,10 @@ import (
var (
useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
+ useCallgrind = flag.Bool("callgrind", false, "If true, run code under valgrind to generate callgrind traces.")
useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
buildDir = flag.String("build-dir", "build", "The build directory to run the tests from.")
+ numWorkers = flag.Int("num-workers", 1, "Runs the given number of workers when testing.")
jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask each test to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
@@ -41,6 +44,12 @@ var (
type test []string
+type result struct {
+ Test test
+ Passed bool
+ Error error
+}
+
// testOutput is a representation of Chromium's JSON test result format. See
// https://www.chromium.org/developers/the-json-test-results-format
type testOutput struct {
@@ -105,6 +114,14 @@ func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
return exec.Command("valgrind", valgrindArgs...)
}
+func callgrindOf(path string, args ...string) *exec.Cmd {
+ valgrindArgs := []string{"-q", "--tool=callgrind", "--dump-instr=yes", "--collect-jumps=yes", "--callgrind-out-file=" + *buildDir + "/callgrind/callgrind.out.%p"}
+ valgrindArgs = append(valgrindArgs, path)
+ valgrindArgs = append(valgrindArgs, args...)
+
+ return exec.Command("valgrind", valgrindArgs...)
+}
+
func gdbOf(path string, args ...string) *exec.Cmd {
xtermArgs := []string{"-e", "gdb", "--args"}
xtermArgs = append(xtermArgs, path)
@@ -127,6 +144,8 @@ func runTestOnce(test test, mallocNumToFail int64) (passed bool, err error) {
var cmd *exec.Cmd
if *useValgrind {
cmd = valgrindOf(false, prog, args...)
+ } else if *useCallgrind {
+ cmd = callgrindOf(prog, args...)
} else if *useGDB {
cmd = gdbOf(prog, args...)
} else {
@@ -225,28 +244,55 @@ func parseTestConfig(filename string) ([]test, error) {
return result, nil
}
+func worker(tests <-chan test, results chan<- result, done *sync.WaitGroup) {
+ defer done.Done()
+ for test := range tests {
+ passed, err := runTest(test)
+ results <- result{test, passed, err}
+ }
+}
+
func main() {
flag.Parse()
setWorkingDirectory()
- tests, err := parseTestConfig("util/all_tests.json")
+ testCases, err := parseTestConfig("util/all_tests.json")
if err != nil {
fmt.Printf("Failed to parse input: %s\n", err)
os.Exit(1)
}
+ var wg sync.WaitGroup
+ tests := make(chan test, *numWorkers)
+ results := make(chan result, *numWorkers)
+
+ for i := 0; i < *numWorkers; i++ {
+ wg.Add(1)
+ go worker(tests, results, &wg)
+ }
+
+ go func() {
+ for _, test := range testCases {
+ tests <- test
+ }
+ close(tests)
+
+ wg.Wait()
+ close(results)
+ }()
+
testOutput := newTestOutput()
var failed []test
- for _, test := range tests {
- fmt.Printf("%s\n", strings.Join([]string(test), " "))
+ for testResult := range results {
+ test := testResult.Test
+ fmt.Printf("%s\n", strings.Join([]string(test), " "))
name := shortTestName(test)
- passed, err := runTest(test)
- if err != nil {
- fmt.Printf("%s failed to complete: %s\n", test[0], err)
+ if testResult.Error != nil {
+ fmt.Printf("%s failed to complete: %s\n", test[0], testResult.Error)
failed = append(failed, test)
testOutput.addResult(name, "CRASHED")
- } else if !passed {
+ } else if !testResult.Passed {
fmt.Printf("%s failed to print PASS on the last line.\n", test[0])
failed = append(failed, test)
testOutput.addResult(name, "FAIL")
@@ -262,7 +308,7 @@ func main() {
}
if len(failed) > 0 {
- fmt.Printf("\n%d of %d tests failed:\n", len(failed), len(tests))
+ fmt.Printf("\n%d of %d tests failed:\n", len(failed), len(testCases))
for _, test := range failed {
fmt.Printf("\t%s\n", strings.Join([]string(test), " "))
}