diff options
Diffstat (limited to 'test/runtimes/python')
-rw-r--r-- | test/runtimes/python/BUILD | 1 | ||||
-rw-r--r-- | test/runtimes/python/Dockerfile | 6 | ||||
-rw-r--r-- | test/runtimes/python/proctor-python.go | 89 |
3 files changed, 28 insertions, 68 deletions
diff --git a/test/runtimes/python/BUILD b/test/runtimes/python/BUILD index 501f77d63..37fd6a0f2 100644 --- a/test/runtimes/python/BUILD +++ b/test/runtimes/python/BUILD @@ -5,4 +5,5 @@ package(licenses = ["notice"]) go_binary( name = "proctor-python", srcs = ["proctor-python.go"], + deps = ["//test/runtimes/common"], ) diff --git a/test/runtimes/python/Dockerfile b/test/runtimes/python/Dockerfile index 811f48f8a..5ae328890 100644 --- a/test/runtimes/python/Dockerfile +++ b/test/runtimes/python/Dockerfile @@ -26,6 +26,8 @@ WORKDIR ${LANG_DIR} RUN ./configure --with-pydebug RUN make -s -j2 -COPY proctor-python.go ${LANG_DIR} +COPY common /root/go/src/gvisor.dev/gvisor/test/runtimes/common/common +COPY python/proctor-python.go ${LANG_DIR} +RUN ["/root/go/bin/go", "build", "-o", "/root/go/bin/proctor", "proctor-python.go"] -ENTRYPOINT ["/root/go/bin/go", "run", "proctor-python.go"] +ENTRYPOINT ["/root/go/bin/proctor"] diff --git a/test/runtimes/python/proctor-python.go b/test/runtimes/python/proctor-python.go index 73c8deb49..35e28a7df 100644 --- a/test/runtimes/python/proctor-python.go +++ b/test/runtimes/python/proctor-python.go @@ -16,93 +16,50 @@ package main import ( - "flag" "fmt" "log" "os" "os/exec" "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") - testRegEx = regexp.MustCompile(`^test_.+\.py$`) + dir = os.Getenv("LANG_DIR") ) -func main() { - flag.Parse() +type pythonRunner 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("Python version: ", os.Getenv("LANG_VER"), " is installed.") - return - } - if *test != "" { - runTest(*test) - return +func main() { + if err := common.LaunchFunc(pythonRunner{}); err != nil { + log.Fatalf("Failed to start: %v", err) } - runAllTests() } -func listTests() ([]string, error) { - var testSlice []string - root := filepath.Join(dir, "Lib/test") - - err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - name := filepath.Base(path) - - if info.IsDir() || !testRegEx.MatchString(name) { - return nil - } - - relPath, err := filepath.Rel(root, path) - if err != nil { - return err - } - testSlice = append(testSlice, relPath) - return nil - }) - +func (p pythonRunner) ListTests() ([]string, error) { + args := []string{"-m", "test", "--list-tests"} + cmd := exec.Command(filepath.Join(dir, "python"), args...) + cmd.Stderr = os.Stderr + out, err := cmd.Output() if err != nil { - return nil, fmt.Errorf("walking %q: %v", root, err) + return nil, fmt.Errorf("failed to list: %v", err) } - - return testSlice, nil + var toolSlice []string + for _, test := range strings.Split(string(out), "\n") { + toolSlice = append(toolSlice, test) + } + return toolSlice, nil } -func runTest(test string) { +func (p pythonRunner) RunTest(test string) error { args := []string{"-m", "test", test} cmd := exec.Command(filepath.Join(dir, "python"), args...) cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr if err := cmd.Run(); err != nil { - log.Fatalf("Failed to run: %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("failed to run: %v", err) } + return nil } |