summaryrefslogtreecommitdiffhomepage
path: root/test/runtimes
diff options
context:
space:
mode:
Diffstat (limited to 'test/runtimes')
-rw-r--r--test/runtimes/README.md2
-rw-r--r--test/runtimes/common/BUILD20
-rw-r--r--test/runtimes/common/common.go114
-rw-r--r--test/runtimes/common/common_test.go128
-rw-r--r--test/runtimes/go/BUILD1
-rw-r--r--test/runtimes/go/Dockerfile8
-rw-r--r--test/runtimes/go/proctor-go.go122
-rw-r--r--test/runtimes/java/BUILD1
-rw-r--r--test/runtimes/java/Dockerfile46
-rw-r--r--test/runtimes/java/proctor-java.go58
-rw-r--r--test/runtimes/nodejs/BUILD1
-rw-r--r--test/runtimes/nodejs/Dockerfile6
-rw-r--r--test/runtimes/nodejs/proctor-nodejs.go78
-rw-r--r--test/runtimes/php/BUILD1
-rw-r--r--test/runtimes/php/Dockerfile6
-rw-r--r--test/runtimes/php/proctor-php.go75
-rw-r--r--test/runtimes/python/BUILD1
-rw-r--r--test/runtimes/python/Dockerfile6
-rw-r--r--test/runtimes/python/proctor-python.go89
-rw-r--r--test/runtimes/runtimes_test.go36
20 files changed, 430 insertions, 369 deletions
diff --git a/test/runtimes/README.md b/test/runtimes/README.md
index 4e5a950bc..34d3507be 100644
--- a/test/runtimes/README.md
+++ b/test/runtimes/README.md
@@ -16,7 +16,7 @@ The following runtimes are currently supported:
1) [Install and configure Docker](https://docs.docker.com/install/)
-2) Build each Docker container:
+2) Build each Docker container from the runtimes directory:
```bash
$ docker build -f $LANG/Dockerfile [-t $NAME] .
diff --git a/test/runtimes/common/BUILD b/test/runtimes/common/BUILD
new file mode 100644
index 000000000..1b39606b8
--- /dev/null
+++ b/test/runtimes/common/BUILD
@@ -0,0 +1,20 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+
+package(licenses = ["notice"])
+
+go_library(
+ name = "common",
+ srcs = ["common.go"],
+ importpath = "gvisor.dev/gvisor/test/runtimes/common",
+ visibility = ["//:sandbox"],
+)
+
+go_test(
+ name = "common_test",
+ size = "small",
+ srcs = ["common_test.go"],
+ deps = [
+ ":common",
+ "//runsc/test/testutil",
+ ],
+)
diff --git a/test/runtimes/common/common.go b/test/runtimes/common/common.go
new file mode 100644
index 000000000..0ff87fa8b
--- /dev/null
+++ b/test/runtimes/common/common.go
@@ -0,0 +1,114 @@
+// Copyright 2019 The gVisor Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package common executes functions for proctor binaries.
+package common
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "path/filepath"
+ "regexp"
+)
+
+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")
+)
+
+// TestRunner is an interface to be implemented in each proctor binary.
+type TestRunner interface {
+ // ListTests returns a string slice of tests available to run.
+ ListTests() ([]string, error)
+
+ // RunTest runs a single test.
+ RunTest(test string) error
+}
+
+// LaunchFunc parses flags passed by a proctor binary and calls the requested behavior.
+func LaunchFunc(tr TestRunner) error {
+ flag.Parse()
+
+ if *list && *test != "" {
+ flag.PrintDefaults()
+ return fmt.Errorf("cannot specify 'list' and 'test' flags simultaneously")
+ }
+ if *list {
+ tests, err := tr.ListTests()
+ if err != nil {
+ return fmt.Errorf("failed to list tests: %v", err)
+ }
+ for _, test := range tests {
+ fmt.Println(test)
+ }
+ return nil
+ }
+ if *version {
+ fmt.Println(os.Getenv("LANG_NAME"), "version:", os.Getenv("LANG_VER"), "is installed.")
+ return nil
+ }
+ if *test != "" {
+ if err := tr.RunTest(*test); err != nil {
+ return fmt.Errorf("test %q failed to run: %v", *test, err)
+ }
+ return nil
+ }
+
+ if err := runAllTests(tr); err != nil {
+ return fmt.Errorf("error running all tests: %v", err)
+ }
+ return nil
+}
+
+// Search uses filepath.Walk to perform a search of the disk for test files
+// and returns a string slice of tests.
+func Search(root string, testFilter *regexp.Regexp) ([]string, error) {
+ var testSlice []string
+
+ err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
+ name := filepath.Base(path)
+
+ if info.IsDir() || !testFilter.MatchString(name) {
+ return nil
+ }
+
+ relPath, err := filepath.Rel(root, path)
+ if err != nil {
+ return err
+ }
+ testSlice = append(testSlice, relPath)
+ return nil
+ })
+
+ if err != nil {
+ return nil, fmt.Errorf("walking %q: %v", root, err)
+ }
+
+ return testSlice, nil
+}
+
+func runAllTests(tr TestRunner) error {
+ tests, err := tr.ListTests()
+ if err != nil {
+ return fmt.Errorf("failed to list tests: %v", err)
+ }
+ for _, test := range tests {
+ if err := tr.RunTest(test); err != nil {
+ return fmt.Errorf("test %q failed to run: %v", test, err)
+ }
+ }
+ return nil
+}
diff --git a/test/runtimes/common/common_test.go b/test/runtimes/common/common_test.go
new file mode 100644
index 000000000..4fb1e482a
--- /dev/null
+++ b/test/runtimes/common/common_test.go
@@ -0,0 +1,128 @@
+// Copyright 2019 The gVisor Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package common_test
+
+import (
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "reflect"
+ "regexp"
+ "strings"
+ "testing"
+
+ "gvisor.dev/gvisor/runsc/test/testutil"
+ "gvisor.dev/gvisor/test/runtimes/common"
+)
+
+func touch(t *testing.T, name string) {
+ t.Helper()
+ f, err := os.Create(name)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := f.Close(); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestSearchEmptyDir(t *testing.T) {
+ td, err := ioutil.TempDir(testutil.TmpDir(), "searchtest")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(td)
+
+ var want []string
+
+ testFilter := regexp.MustCompile(`^test-[^-].+\.tc$`)
+ got, err := common.Search(td, testFilter)
+ if err != nil {
+ t.Errorf("Search error: %v", err)
+ }
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("Found %#v; want %#v", got, want)
+ }
+}
+
+func TestSearch(t *testing.T) {
+ td, err := ioutil.TempDir(testutil.TmpDir(), "searchtest")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(td)
+
+ // Creating various files similar to the test filter regex.
+ files := []string{
+ "emp/",
+ "tee/",
+ "test-foo.tc",
+ "test-foo.tc",
+ "test-bar.tc",
+ "test-sam.tc",
+ "Test-que.tc",
+ "test-brett",
+ "test--abc.tc",
+ "test---xyz.tc",
+ "test-bool.TC",
+ "--test-gvs.tc",
+ " test-pew.tc",
+ "dir/test_baz.tc",
+ "dir/testsnap.tc",
+ "dir/test-luk.tc",
+ "dir/nest/test-ok.tc",
+ "dir/dip/diz/goog/test-pack.tc",
+ "dir/dip/diz/wobble/thud/test-cas.e",
+ "dir/dip/diz/wobble/thud/test-cas.tc",
+ }
+ want := []string{
+ "dir/dip/diz/goog/test-pack.tc",
+ "dir/dip/diz/wobble/thud/test-cas.tc",
+ "dir/nest/test-ok.tc",
+ "dir/test-luk.tc",
+ "test-bar.tc",
+ "test-foo.tc",
+ "test-sam.tc",
+ }
+
+ for _, item := range files {
+ if strings.HasSuffix(item, "/") {
+ // This item is a directory, create it.
+ if err := os.MkdirAll(filepath.Join(td, item), 0755); err != nil {
+ t.Fatal(err)
+ }
+ } else {
+ // This item is a file, create the directory and touch file.
+ // Create directory in which file should be created
+ fullDirPath := filepath.Join(td, filepath.Dir(item))
+ if err := os.MkdirAll(fullDirPath, 0755); err != nil {
+ t.Fatal(err)
+ }
+ // Create file with full path to file.
+ touch(t, filepath.Join(td, item))
+ }
+ }
+
+ testFilter := regexp.MustCompile(`^test-[^-].+\.tc$`)
+ got, err := common.Search(td, testFilter)
+ if err != nil {
+ t.Errorf("Search error: %v", err)
+ }
+
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("Found %#v; want %#v", got, want)
+ }
+}
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/Dockerfile b/test/runtimes/go/Dockerfile
index cd55608cd..2d3477392 100644
--- a/test/runtimes/go/Dockerfile
+++ b/test/runtimes/go/Dockerfile
@@ -23,9 +23,13 @@ ENV LANG_DIR=${GOROOT}
WORKDIR ${LANG_DIR}/src
RUN ./make.bash
+# Pre-compile the tests for faster execution
+RUN ["/root/go/bin/go", "tool", "dist", "test", "-compile-only"]
WORKDIR ${LANG_DIR}
-COPY proctor-go.go ${LANG_DIR}
+COPY common /root/go/src/gvisor.dev/gvisor/test/runtimes/common/common
+COPY go/proctor-go.go ${LANG_DIR}
+RUN ["/root/go/bin/go", "build", "-o", "/root/go/bin/proctor", "proctor-go.go"]
-ENTRYPOINT ["/root/go/bin/go", "run", "proctor-go.go"]
+ENTRYPOINT ["/root/go/bin/proctor"]
diff --git a/test/runtimes/go/proctor-go.go b/test/runtimes/go/proctor-go.go
index c5387e21d..3eb24576e 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,133 +28,78 @@ 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$`)
// Directories with .dir contain helper files for tests.
// Exclude benchmarks and stress tests.
- exclDirs = regexp.MustCompile(`^.+\/(bench|stress)\/.+$|^.+\.dir.+$`)
+ dirFilter = 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...)
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
- log.Fatalf("Failed to list: %v", err)
+ return nil, fmt.Errorf("failed to list: %v", err)
}
- var testSlice []string
+ var toolSlice []string
for _, test := range strings.Split(string(out), "\n") {
- testSlice = append(testSlice, test)
+ toolSlice = append(toolSlice, test)
}
// Go tests on disk.
- if err := filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error {
- name := filepath.Base(path)
-
- if info.IsDir() {
- return nil
- }
-
- if !testRegEx.MatchString(name) {
- return nil
- }
-
- if exclDirs.MatchString(path) {
- return nil
+ diskSlice, err := common.Search(testDir, testRegEx)
+ if err != nil {
+ return nil, err
+ }
+ // Remove items from /bench/, /stress/ and .dir files
+ diskFiltered := diskSlice[:0]
+ for _, file := range diskSlice {
+ if !dirFilter.MatchString(file) {
+ diskFiltered = append(diskFiltered, file)
}
-
- testSlice = append(testSlice, path)
- return nil
- }); err != nil {
- return nil, fmt.Errorf("walking %q: %v", testDir, err)
}
- return testSlice, nil
+ return append(toolSlice, diskFiltered...), 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)
- }
- diskArgs = append(diskArgs, "--", relPath)
- cmd := exec.Command(filepath.Join(dir, "bin/go"), diskArgs...)
+ if strings.HasSuffix(test, ".go") {
+ // Test has suffix ".go" which indicates a disk test, run it as such.
+ cmd := exec.Command(goBin, "run", "run.go", "-v", "--", test)
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...)
+ } else {
+ // No ".go" suffix, run as a tool test.
+ 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 nil
}
diff --git a/test/runtimes/java/BUILD b/test/runtimes/java/BUILD
index 7e2808ece..8c39d39ec 100644
--- a/test/runtimes/java/BUILD
+++ b/test/runtimes/java/BUILD
@@ -5,4 +5,5 @@ package(licenses = ["notice"])
go_binary(
name = "proctor-java",
srcs = ["proctor-java.go"],
+ deps = ["//test/runtimes/common"],
)
diff --git a/test/runtimes/java/Dockerfile b/test/runtimes/java/Dockerfile
index e162d7218..1a61d9d8f 100644
--- a/test/runtimes/java/Dockerfile
+++ b/test/runtimes/java/Dockerfile
@@ -1,25 +1,16 @@
FROM ubuntu:bionic
# This hash is associated with a specific JDK release and needed for ensuring
# the same version is downloaded every time.
-ENV LANG_HASH=af47e0398606
-ENV LANG_VER=11u-dev
+ENV LANG_HASH=76072a077ee1
+ENV LANG_VER=11
ENV LANG_NAME=Java
RUN apt-get update && apt-get install -y \
autoconf \
build-essential \
- curl\
- file \
- libasound2-dev \
- libcups2-dev \
- libfontconfig1-dev \
- libx11-dev \
- libxext-dev \
- libxrandr-dev \
- libxrender-dev \
- libxt-dev \
- libxtst-dev \
+ curl \
make \
+ openjdk-${LANG_VER}-jdk \
unzip \
zip
@@ -27,26 +18,19 @@ WORKDIR /root
RUN curl -o go.tar.gz https://dl.google.com/go/go1.12.6.linux-amd64.tar.gz
RUN tar -zxf go.tar.gz
-# Use curl instead of ADD to prevent redownload every time.
-RUN curl -o jdk.tar.gz http://hg.openjdk.java.net/jdk-updates/jdk${LANG_VER}/archive/${LANG_HASH}.tar.gz
-# Download Java version N-1 to be used as the Boot JDK to build Java version N.
-RUN curl -o bootjdk.tar.gz https://download.java.net/openjdk/jdk10/ri/openjdk-10+44_linux-x64_bin_ri.tar.gz
-
-RUN tar -zxf jdk.tar.gz
-RUN tar -zxf bootjdk.tar.gz
-
-# Specify the JDK to be used by jtreg.
-ENV JT_JAVA=/root/jdk${LANG_VER}-${LANG_HASH}/build/linux-x86_64-normal-server-release/jdk
-ENV LANG_DIR=/root/jdk${LANG_VER}-${LANG_HASH}
-
-WORKDIR ${LANG_DIR}
+# Download the JDK test library.
+RUN set -ex \
+ && curl -fsSL --retry 10 -o /tmp/jdktests.tar.gz http://hg.openjdk.java.net/jdk/jdk${LANG_VER}/archive/${LANG_HASH}.tar.gz/test \
+ && tar -xzf /tmp/jdktests.tar.gz -C /root \
+ && rm -f /tmp/jdktests.tar.gz
RUN curl -o jtreg.tar.gz https://ci.adoptopenjdk.net/view/Dependencies/job/jtreg/lastSuccessfulBuild/artifact/jtreg-4.2.0-tip.tar.gz
RUN tar -xzf jtreg.tar.gz
-RUN bash configure --with-boot-jdk=/root/jdk-10 --with-jtreg=${LANG_DIR}/jtreg
-RUN make clean
-RUN make images
-COPY proctor-java.go ${LANG_DIR}
+ENV LANG_DIR=/root
+
+COPY common /root/go/src/gvisor.dev/gvisor/test/runtimes/common/common
+COPY java/proctor-java.go ${LANG_DIR}
+RUN ["/root/go/bin/go", "build", "-o", "/root/go/bin/proctor", "proctor-java.go"]
-ENTRYPOINT ["/root/go/bin/go", "run", "proctor-java.go"]
+ENTRYPOINT ["/root/go/bin/proctor"]
diff --git a/test/runtimes/java/proctor-java.go b/test/runtimes/java/proctor-java.go
index 0177f421d..7f6a66f4f 100644
--- a/test/runtimes/java/proctor-java.go
+++ b/test/runtimes/java/proctor-java.go
@@ -16,7 +16,6 @@
package main
import (
- "flag"
"fmt"
"log"
"os"
@@ -24,49 +23,29 @@ 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")
+ hash = os.Getenv("LANG_HASH")
jtreg = filepath.Join(dir, "jtreg/bin/jtreg")
exclDirs = regexp.MustCompile(`(^(sun\/security)|(java\/util\/stream)|(java\/time)| )`)
)
-func main() {
- flag.Parse()
+type javaRunner 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("Java version: ", os.Getenv("LANG_VER"), " is installed.")
- return
- }
- if *test != "" {
- runTest(*test)
- return
+func main() {
+ if err := common.LaunchFunc(javaRunner{}); err != nil {
+ log.Fatalf("Failed to start: %v", err)
}
- runAllTests()
}
-func listTests() ([]string, error) {
+func (j javaRunner) ListTests() ([]string, error) {
args := []string{
- "-dir:test/jdk",
+ "-dir:/root/jdk11-" + hash + "/test/jdk",
"-ignore:quiet",
"-a",
"-listtests",
@@ -90,21 +69,12 @@ func listTests() ([]string, error) {
return testSlice, nil
}
-func runTest(test string) {
- args := []string{"-dir:test/jdk/", test}
+func (j javaRunner) RunTest(test string) error {
+ args := []string{"-noreport", "-dir:/root/jdk11-" + hash + "/test/jdk", test}
cmd := exec.Command(jtreg, 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
}
diff --git a/test/runtimes/nodejs/BUILD b/test/runtimes/nodejs/BUILD
index 0fe5ff83e..0594c250b 100644
--- a/test/runtimes/nodejs/BUILD
+++ b/test/runtimes/nodejs/BUILD
@@ -5,4 +5,5 @@ package(licenses = ["notice"])
go_binary(
name = "proctor-nodejs",
srcs = ["proctor-nodejs.go"],
+ deps = ["//test/runtimes/common"],
)
diff --git a/test/runtimes/nodejs/Dockerfile b/test/runtimes/nodejs/Dockerfile
index b2416cce8..ce2943af8 100644
--- a/test/runtimes/nodejs/Dockerfile
+++ b/test/runtimes/nodejs/Dockerfile
@@ -22,8 +22,10 @@ RUN ./configure
RUN make
RUN make test-build
-COPY proctor-nodejs.go ${LANG_DIR}
+COPY common /root/go/src/gvisor.dev/gvisor/test/runtimes/common/common
+COPY nodejs/proctor-nodejs.go ${LANG_DIR}
+RUN ["/root/go/bin/go", "build", "-o", "/root/go/bin/proctor", "proctor-nodejs.go"]
# Including dumb-init emulates the Linux "init" process, preventing the failure
# of tests involving worker processes.
-ENTRYPOINT ["/usr/bin/dumb-init", "/root/go/bin/go", "run", "proctor-nodejs.go"]
+ENTRYPOINT ["/usr/bin/dumb-init", "/root/go/bin/proctor"]
diff --git a/test/runtimes/nodejs/proctor-nodejs.go b/test/runtimes/nodejs/proctor-nodejs.go
index 8ddfb67fe..0624f6a0d 100644
--- a/test/runtimes/nodejs/proctor-nodejs.go
+++ b/test/runtimes/nodejs/proctor-nodejs.go
@@ -16,93 +16,45 @@
package main
import (
- "flag"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
+
+ "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-.+\.js$`)
+ testDir = filepath.Join(dir, "test")
+ testRegEx = regexp.MustCompile(`^test-[^-].+\.js$`)
)
-func main() {
- flag.Parse()
+type nodejsRunner 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("Node.js version: ", os.Getenv("LANG_VER"), " is installed.")
- return
- }
- if *test != "" {
- runTest(*test)
- return
+func main() {
+ if err := common.LaunchFunc(nodejsRunner{}); err != nil {
+ log.Fatalf("Failed to start: %v", err)
}
- runAllTests()
}
-func listTests() ([]string, error) {
- var testSlice []string
- root := filepath.Join(dir, "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 (n nodejsRunner) ListTests() ([]string, error) {
+ testSlice, err := common.Search(testDir, testRegEx)
if err != nil {
- return nil, fmt.Errorf("walking %q: %v", root, err)
+ return nil, err
}
-
return testSlice, nil
}
-func runTest(test string) {
+func (n nodejsRunner) RunTest(test string) error {
args := []string{filepath.Join(dir, "tools", "test.py"), test}
cmd := exec.Command("/usr/bin/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
}
diff --git a/test/runtimes/php/BUILD b/test/runtimes/php/BUILD
index 22aef7ba4..31799b77a 100644
--- a/test/runtimes/php/BUILD
+++ b/test/runtimes/php/BUILD
@@ -5,4 +5,5 @@ package(licenses = ["notice"])
go_binary(
name = "proctor-php",
srcs = ["proctor-php.go"],
+ deps = ["//test/runtimes/common"],
)
diff --git a/test/runtimes/php/Dockerfile b/test/runtimes/php/Dockerfile
index 1f8959b50..d79babe58 100644
--- a/test/runtimes/php/Dockerfile
+++ b/test/runtimes/php/Dockerfile
@@ -24,6 +24,8 @@ WORKDIR ${LANG_DIR}
RUN ./configure
RUN make
-COPY proctor-php.go ${LANG_DIR}
+COPY common /root/go/src/gvisor.dev/gvisor/test/runtimes/common/common
+COPY php/proctor-php.go ${LANG_DIR}
+RUN ["/root/go/bin/go", "build", "-o", "/root/go/bin/proctor", "proctor-php.go"]
-ENTRYPOINT ["/root/go/bin/go", "run", "proctor-php.go"]
+ENTRYPOINT ["/root/go/bin/proctor"]
diff --git a/test/runtimes/php/proctor-php.go b/test/runtimes/php/proctor-php.go
index 9dfb33b04..e6c5fabdf 100644
--- a/test/runtimes/php/proctor-php.go
+++ b/test/runtimes/php/proctor-php.go
@@ -16,92 +16,43 @@
package main
import (
- "flag"
"fmt"
"log"
"os"
"os/exec"
- "path/filepath"
"regexp"
+
+ "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(`^.+\.phpt$`)
)
-func main() {
- flag.Parse()
+type phpRunner 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("PHP version: ", os.Getenv("LANG_VER"), " is installed.")
- return
- }
- if *test != "" {
- runTest(*test)
- return
+func main() {
+ if err := common.LaunchFunc(phpRunner{}); err != nil {
+ log.Fatalf("Failed to start: %v", err)
}
- runAllTests()
}
-func listTests() ([]string, error) {
- var testSlice []string
-
- err := filepath.Walk(dir, 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(dir, path)
- if err != nil {
- return err
- }
- testSlice = append(testSlice, relPath)
- return nil
- })
-
+func (p phpRunner) ListTests() ([]string, error) {
+ testSlice, err := common.Search(dir, testRegEx)
if err != nil {
- return nil, fmt.Errorf("walking %q: %v", dir, err)
+ return nil, err
}
-
return testSlice, nil
}
-func runTest(test string) {
+func (p phpRunner) RunTest(test string) error {
args := []string{"test", "TESTS=" + test}
cmd := exec.Command("make", 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
}
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
}
diff --git a/test/runtimes/runtimes_test.go b/test/runtimes/runtimes_test.go
index 6bf954e78..9421021a1 100644
--- a/test/runtimes/runtimes_test.go
+++ b/test/runtimes/runtimes_test.go
@@ -22,8 +22,16 @@ import (
"gvisor.dev/gvisor/runsc/test/testutil"
)
-func TestNodeJS(t *testing.T) {
- const img = "gcr.io/gvisor-proctor/nodejs"
+// Wait time for each test to run.
+const timeout = 180 * time.Second
+
+// Helper function to execute the docker container associated with the
+// language passed. Captures the output of the list function and executes
+// each test individually, supplying any errors recieved.
+func testLang(t *testing.T, lang string) {
+ t.Helper()
+
+ img := "gcr.io/gvisor-presubmit/" + lang
if err := testutil.Pull(img); err != nil {
t.Fatalf("docker pull failed: %v", err)
}
@@ -41,15 +49,13 @@ func TestNodeJS(t *testing.T) {
for _, tc := range tests {
tc := tc
t.Run(tc, func(t *testing.T) {
- t.Parallel()
-
d := testutil.MakeDocker("gvisor-test")
if err := d.Run(img, "--test", tc); err != nil {
t.Fatalf("docker test %q failed to run: %v", tc, err)
}
defer d.CleanUp()
- status, err := d.Wait(60 * time.Second)
+ status, err := d.Wait(timeout)
if err != nil {
t.Fatalf("docker test %q failed to wait: %v", tc, err)
}
@@ -65,3 +71,23 @@ func TestNodeJS(t *testing.T) {
})
}
}
+
+func TestGo(t *testing.T) {
+ testLang(t, "go")
+}
+
+func TestJava(t *testing.T) {
+ testLang(t, "java")
+}
+
+func TestNodejs(t *testing.T) {
+ testLang(t, "nodejs")
+}
+
+func TestPhp(t *testing.T) {
+ testLang(t, "php")
+}
+
+func TestPython(t *testing.T) {
+ testLang(t, "python")
+}