summaryrefslogtreecommitdiffhomepage
path: root/test/runtimes/go
diff options
context:
space:
mode:
Diffstat (limited to 'test/runtimes/go')
-rw-r--r--test/runtimes/go/BUILD1
-rw-r--r--test/runtimes/go/proctor-go.go76
2 files changed, 18 insertions, 59 deletions
diff --git a/test/runtimes/go/BUILD b/test/runtimes/go/BUILD
index c34f49ea6..ce971ee9d 100644
--- a/test/runtimes/go/BUILD
+++ b/test/runtimes/go/BUILD
@@ -5,4 +5,5 @@ package(licenses = ["notice"])
go_binary(
name = "proctor-go",
srcs = ["proctor-go.go"],
+ deps = ["//test/runtimes/common"],
)
diff --git a/test/runtimes/go/proctor-go.go b/test/runtimes/go/proctor-go.go
index c5387e21d..eae8b5e55 100644
--- a/test/runtimes/go/proctor-go.go
+++ b/test/runtimes/go/proctor-go.go
@@ -21,7 +21,6 @@
package main
import (
- "flag"
"fmt"
"log"
"os"
@@ -29,14 +28,13 @@ import (
"path/filepath"
"regexp"
"strings"
+
+ "gvisor.dev/gvisor/test/runtimes/common"
)
var (
- list = flag.Bool("list", false, "list all available tests")
- test = flag.String("test", "", "run a single test from the list of available tests")
- version = flag.Bool("v", false, "print out the version of node that is installed")
-
dir = os.Getenv("LANG_DIR")
+ goBin = filepath.Join(dir, "bin/go")
testDir = filepath.Join(dir, "test")
testRegEx = regexp.MustCompile(`^.+\.go$`)
@@ -45,35 +43,16 @@ var (
exclDirs = regexp.MustCompile(`^.+\/(bench|stress)\/.+$|^.+\.dir.+$`)
)
-func main() {
- flag.Parse()
+type goRunner struct {
+}
- if *list && *test != "" {
- flag.PrintDefaults()
- os.Exit(1)
- }
- if *list {
- tests, err := listTests()
- if err != nil {
- log.Fatalf("Failed to list tests: %v", err)
- }
- for _, test := range tests {
- fmt.Println(test)
- }
- return
- }
- if *version {
- fmt.Println("Go version: ", os.Getenv("LANG_VER"), " is installed.")
- return
- }
- if *test != "" {
- runTest(*test)
- return
+func main() {
+ if err := common.LaunchFunc(goRunner{}); err != nil {
+ log.Fatalf("Failed to start: %v", err)
}
- runAllTests()
}
-func listTests() ([]string, error) {
+func (g goRunner) ListTests() ([]string, error) {
// Go tool dist test tests.
args := []string{"tool", "dist", "test", "-list"}
cmd := exec.Command(filepath.Join(dir, "bin/go"), args...)
@@ -112,50 +91,29 @@ func listTests() ([]string, error) {
return testSlice, nil
}
-func runTest(test string) {
- toolArgs := []string{
- "tool",
- "dist",
- "test",
- }
- diskArgs := []string{
- "run",
- "run.go",
- "-v",
- }
+func (g goRunner) RunTest(test string) error {
// Check if test exists on disk by searching for file of the same name.
// This will determine whether or not it is a Go test on disk.
if _, err := os.Stat(test); err == nil {
relPath, err := filepath.Rel(testDir, test)
if err != nil {
- log.Fatalf("Failed to get rel path: %v", err)
+ return fmt.Errorf("failed to get rel path: %v", err)
}
- diskArgs = append(diskArgs, "--", relPath)
- cmd := exec.Command(filepath.Join(dir, "bin/go"), diskArgs...)
+ cmd := exec.Command(goBin, "run", "run.go", "-v", "--", relPath)
cmd.Dir = testDir
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
- log.Fatalf("Failed to run: %v", err)
+ return fmt.Errorf("failed to run test: %v", err)
}
} else if os.IsNotExist(err) {
// File was not found, try running as Go tool test.
- toolArgs = append(toolArgs, "-run", test)
- cmd := exec.Command(filepath.Join(dir, "bin/go"), toolArgs...)
+ cmd := exec.Command(goBin, "tool", "dist", "test", "-run", test)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
- log.Fatalf("Failed to run: %v", err)
+ return fmt.Errorf("failed to run test: %v", err)
}
} else {
- log.Fatalf("Error searching for test: %v", err)
- }
-}
-
-func runAllTests() {
- tests, err := listTests()
- if err != nil {
- log.Fatalf("Failed to list tests: %v", err)
- }
- for _, test := range tests {
- runTest(test)
+ return fmt.Errorf("error searching for test: %v", err)
}
+ return nil
}