summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2020-08-04 20:49:00 -0700
committerAdin Scannell <ascannell@google.com>2020-08-04 20:49:00 -0700
commitc5f5806fe69e8d4be99341318f20ce0acfd7be2a (patch)
treea67130ecf0cc3f404fd0952b9cb743f0854991e8
parentaf2f456735252b8412af676a3d6ff61690fdf9a7 (diff)
Enable "make packetimpact-tests" to work.
This required minor fixes to the bazel wrapper. The "dut_platform" is also changed to "native" to line-up with the system call tests and remove the hard-coded "linux" and "netstack" strings.
-rw-r--r--Makefile4
-rw-r--r--test/packetimpact/runner/defs.bzl22
-rw-r--r--test/packetimpact/runner/packetimpact_test.go18
-rw-r--r--test/packetimpact/testbench/testbench.go6
-rw-r--r--test/packetimpact/tests/tcp_reordering_test.go6
-rw-r--r--tools/bazel.mk13
6 files changed, 33 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 5a9367de8..dfd1b4abc 100644
--- a/Makefile
+++ b/Makefile
@@ -185,7 +185,6 @@ swgso-tests: load-basic-images
@$(call submake,install-test-runtime RUNTIME="swgso" ARGS="--software-gso=true --gso=false")
@$(call submake,test-runtime RUNTIME="swgso" TARGETS="$(INTEGRATION_TARGETS)")
.PHONY: swgso-tests
-
hostnet-tests: load-basic-images
@$(call submake,install-test-runtime RUNTIME="hostnet" ARGS="--network=host")
@$(call submake,test-runtime RUNTIME="hostnet" OPTIONS="--test_arg=-checkpoint=false" TARGETS="$(INTEGRATION_TARGETS)")
@@ -211,8 +210,9 @@ packetdrill-tests: load-packetdrill
.PHONY: packetdrill-tests
packetimpact-tests: load-packetimpact
+ @sudo modprobe iptable_filter ip6table_filter
@$(call submake,install-test-runtime RUNTIME="packetimpact")
- @$(call submake,test-runtime RUNTIME="packetimpact" TARGETS="$(shell $(MAKE) query TARGETS='attr(tags, packetimpact, tests(//...))')")
+ @$(call submake,test-runtime OPTIONS="--jobs=HOST_CPUS*3 --local_test_jobs=HOST_CPUS*3" RUNTIME="packetimpact" TARGETS="$(shell $(MAKE) query TARGETS='attr(tags, packetimpact, tests(//...))')")
.PHONY: packetimpact-tests
root-tests: load-basic-images
diff --git a/test/packetimpact/runner/defs.bzl b/test/packetimpact/runner/defs.bzl
index 79b3c9162..93a36c6c2 100644
--- a/test/packetimpact/runner/defs.bzl
+++ b/test/packetimpact/runner/defs.bzl
@@ -61,12 +61,12 @@ PACKETIMPACT_TAGS = [
"packetimpact",
]
-def packetimpact_linux_test(
+def packetimpact_native_test(
name,
testbench_binary,
expect_failure = False,
**kwargs):
- """Add a packetimpact test on linux.
+ """Add a native packetimpact test.
Args:
name: name of the test
@@ -76,9 +76,9 @@ def packetimpact_linux_test(
"""
expect_failure_flag = ["--expect_failure"] if expect_failure else []
_packetimpact_test(
- name = name + "_linux_test",
+ name = name + "_native_test",
testbench_binary = testbench_binary,
- flags = ["--dut_platform", "linux"] + expect_failure_flag,
+ flags = ["--native"] + expect_failure_flag,
tags = PACKETIMPACT_TAGS,
**kwargs
)
@@ -102,21 +102,21 @@ def packetimpact_netstack_test(
_packetimpact_test(
name = name + "_netstack_test",
testbench_binary = testbench_binary,
- # This is the default runtime unless
- # "--test_arg=--runtime=OTHER_RUNTIME" is used to override the value.
- flags = ["--dut_platform", "netstack", "--runtime=runsc-d"] + expect_failure_flag,
+ # Note that a distinct runtime must be provided in the form
+ # --test_arg=--runtime=other when invoking bazel.
+ flags = expect_failure_flag,
tags = PACKETIMPACT_TAGS,
**kwargs
)
-def packetimpact_go_test(name, size = "small", pure = True, expect_linux_failure = False, expect_netstack_failure = False, **kwargs):
+def packetimpact_go_test(name, size = "small", pure = True, expect_native_failure = False, expect_netstack_failure = False, **kwargs):
"""Add packetimpact tests written in go.
Args:
name: name of the test
size: size of the test
pure: make a static go binary
- expect_linux_failure: the test must fail for Linux
+ expect_native_failure: the test must fail natively
expect_netstack_failure: the test must fail for Netstack
**kwargs: all the other args, forwarded to go_test
"""
@@ -131,9 +131,9 @@ def packetimpact_go_test(name, size = "small", pure = True, expect_linux_failure
],
**kwargs
)
- packetimpact_linux_test(
+ packetimpact_native_test(
name = name,
- expect_failure = expect_linux_failure,
+ expect_failure = expect_native_failure,
testbench_binary = testbench_binary,
)
packetimpact_netstack_test(
diff --git a/test/packetimpact/runner/packetimpact_test.go b/test/packetimpact/runner/packetimpact_test.go
index 74e1e6def..e8c183977 100644
--- a/test/packetimpact/runner/packetimpact_test.go
+++ b/test/packetimpact/runner/packetimpact_test.go
@@ -50,7 +50,7 @@ func (l *stringList) Set(value string) error {
}
var (
- dutPlatform = flag.String("dut_platform", "", "either \"linux\" or \"netstack\"")
+ native = flag.Bool("native", false, "whether the test should be run natively")
testbenchBinary = flag.String("testbench_binary", "", "path to the testbench binary")
tshark = flag.Bool("tshark", false, "use more verbose tshark in logs instead of tcpdump")
extraTestArgs = stringList{}
@@ -84,17 +84,9 @@ func (l logger) Logf(format string, args ...interface{}) {
func TestOne(t *testing.T) {
flag.Var(&extraTestArgs, "extra_test_arg", "extra arguments to pass to the testbench")
flag.Parse()
- if *dutPlatform != "linux" && *dutPlatform != "netstack" {
- t.Fatal("--dut_platform should be either linux or netstack")
- }
if *testbenchBinary == "" {
t.Fatal("--testbench_binary is missing")
}
- if *dutPlatform == "netstack" {
- if _, err := dockerutil.RuntimePath(); err != nil {
- t.Fatal("--runtime is missing or invalid with --dut_platform=netstack:", err)
- }
- }
dockerutil.EnsureSupportedDockerVersion()
ctx := context.Background()
@@ -140,9 +132,11 @@ func TestOne(t *testing.T) {
const testOutputDir = "/tmp/testoutput"
// Create the Docker container for the DUT.
- dut := dockerutil.MakeContainer(ctx, logger("dut"))
- if *dutPlatform == "linux" {
+ var dut *dockerutil.Container
+ if *native {
dut = dockerutil.MakeNativeContainer(ctx, logger("dut"))
+ } else {
+ dut = dockerutil.MakeContainer(ctx, logger("dut"))
}
runOpts := dockerutil.RunOpts{
@@ -307,7 +301,7 @@ func TestOne(t *testing.T) {
"--remote_mac", remoteMAC.String(),
"--remote_interface_id", fmt.Sprintf("%d", dutDeviceInfo.ID),
"--device", testNetDev,
- "--dut_type", *dutPlatform,
+ fmt.Sprintf("--native=%t", *native),
)
testbenchLogs, err := testbench.Exec(ctx, dockerutil.ExecOpts{}, testArgs...)
if (err != nil) != *expectFailure {
diff --git a/test/packetimpact/testbench/testbench.go b/test/packetimpact/testbench/testbench.go
index 242464e3a..e3629e1f3 100644
--- a/test/packetimpact/testbench/testbench.go
+++ b/test/packetimpact/testbench/testbench.go
@@ -27,8 +27,8 @@ import (
)
var (
- // DUTType is the type of device under test.
- DUTType = ""
+ // Native indicates that the test is being run natively.
+ Native = false
// Device is the local device on the test network.
Device = ""
@@ -81,7 +81,7 @@ func RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(&RemoteIPv6, "remote_ipv6", RemoteIPv6, "remote IPv6 address for test packets")
fs.StringVar(&RemoteMAC, "remote_mac", RemoteMAC, "remote mac address for test packets")
fs.StringVar(&Device, "device", Device, "local device for test packets")
- fs.StringVar(&DUTType, "dut_type", DUTType, "type of device under test")
+ fs.BoolVar(&Native, "native", Native, "whether the test is running natively")
fs.Uint64Var(&RemoteInterfaceID, "remote_interface_id", RemoteInterfaceID, "remote interface ID for test packets")
}
diff --git a/test/packetimpact/tests/tcp_reordering_test.go b/test/packetimpact/tests/tcp_reordering_test.go
index 8742819ca..b4aeaab57 100644
--- a/test/packetimpact/tests/tcp_reordering_test.go
+++ b/test/packetimpact/tests/tcp_reordering_test.go
@@ -54,13 +54,13 @@ func TestReorderingWindow(t *testing.T) {
acceptFd, _ := dut.Accept(t, listenFd)
defer dut.Close(t, acceptFd)
- if tb.DUTType == "linux" {
+ if tb.Native {
// Linux has changed its handling of reordering, force the old behavior.
dut.SetSockOpt(t, acceptFd, unix.IPPROTO_TCP, unix.TCP_CONGESTION, []byte("reno"))
}
pls := dut.GetSockOptInt(t, acceptFd, unix.IPPROTO_TCP, unix.TCP_MAXSEG)
- if tb.DUTType == "netstack" {
+ if !tb.Native {
// netstack does not impliment TCP_MAXSEG correctly. Fake it
// here. Netstack uses the max SACK size which is 32. The MSS
// option is 8 bytes, making the total 36 bytes.
@@ -141,7 +141,7 @@ func TestReorderingWindow(t *testing.T) {
}
}
- if tb.DUTType == "netstack" {
+ if !tb.Native {
// The window should now be halved, so we should receive any
// more, even if we send them.
dut.Send(t, acceptFd, payload, 0)
diff --git a/tools/bazel.mk b/tools/bazel.mk
index 82fe11a03..3e27af7d1 100644
--- a/tools/bazel.mk
+++ b/tools/bazel.mk
@@ -33,8 +33,8 @@ GCLOUD_CONFIG := $(shell readlink -m ~/.config/gcloud/)
DOCKER_SOCKET := /var/run/docker.sock
# Bazel flags.
-OPTIONS += --test_output=errors --keep_going --verbose_failures=true
BAZEL := bazel $(STARTUP_OPTIONS)
+OPTIONS += --color=no --curses=no
# Basic options.
UID := $(shell id -u ${USER})
@@ -143,12 +143,13 @@ bazel-server: ## Ensures that the server exists. Used as an internal target.
@docker exec $(FULL_DOCKER_EXEC_OPTIONS) $(DOCKER_NAME) true || $(MAKE) bazel-server-start
.PHONY: bazel-server
-build_cmd = docker exec $(FULL_DOCKER_EXEC_OPTIONS) $(DOCKER_NAME) sh -o pipefail -c '$(BAZEL) build $(OPTIONS) $(TARGETS)'
+build_cmd = docker exec $(FULL_DOCKER_EXEC_OPTIONS) $(DOCKER_NAME) sh -o pipefail -c '$(BAZEL) build $(OPTIONS) "$(TARGETS)"'
build_paths = $(build_cmd) 2>&1 \
| tee /proc/self/fd/2 \
| grep -E "^ bazel-bin/" \
- | awk "{print $$1;}" \
+ | tr -d '\r' \
+ | awk '{$$1=$$1};1' \
| xargs -n 1 -I {} sh -c "$(1)"
build: bazel-server
@@ -169,10 +170,12 @@ sudo: bazel-server
@$(call build_paths,sudo -E {} $(ARGS))
.PHONY: sudo
+test: OPTIONS += --test_output=errors --keep_going --verbose_failures=true
test: bazel-server
@docker exec $(FULL_DOCKER_EXEC_OPTIONS) $(DOCKER_NAME) $(BAZEL) test $(OPTIONS) $(TARGETS)
.PHONY: test
-query: bazel-server
- @docker exec $(FULL_DOCKER_EXEC_OPTIONS) $(DOCKER_NAME) $(BAZEL) query $(OPTIONS) '$(TARGETS)'
+query:
+ @$(MAKE) bazel-server >&2 # If we need to start, ensure stdout is not polluted.
+ @docker exec $(FULL_DOCKER_EXEC_OPTIONS) $(DOCKER_NAME) sh -o pipefail -c '$(BAZEL) query $(OPTIONS) "$(TARGETS)" 2>/dev/null'
.PHONY: query