Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce VPP integration tests #75

Merged
merged 9 commits into from Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/ci.yaml
@@ -1,6 +1,5 @@
---
name: ci

name: CI
on:
push:
tags:
Expand Down Expand Up @@ -41,10 +40,14 @@ jobs:
go-version: ${{ matrix.go }}
- name: Checkout
uses: actions/checkout@v3
- name: Check go mod
- name: Run go mod tidy
run: go mod tidy -v
- name: Check go.mod
run: |
go mod tidy
git diff --exit-code go.mod
- name: Check go.sum
run: |
git diff --exit-code go.sum

build-test:
strategy:
Expand Down Expand Up @@ -73,7 +76,7 @@ jobs:
uses: guyarb/golang-test-annotations@v0.6.0
with:
test-results: test.json

golangci:
strategy:
matrix:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/test.yaml
@@ -0,0 +1,31 @@
---
name: Test
on:
push:
branches:
- master
pull_request:
# Allows running this workflow manually
workflow_dispatch:

jobs:
integration:
name: "VPP Integration ${{ matrix.version }}"
runs-on: ubuntu-latest
env:
VPP_REPO: ${{ matrix.version }}
strategy:
fail-fast: false
matrix:
version: [ '2210', '2206', '2202' ]

steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: "Run Tests"
run: |
make test-integration
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -40,6 +40,8 @@ ifeq ($(V),1)
GO_BUILD_ARGS += -v
endif

# Package cloud repo for VPP.
VPP_REPO ?= release
# VPP Docker image to use for api generation (gen-binapi-docker)
VPP_IMG ?= ligato/vpp-base:22.06-release
# Local VPP directory used for binary api generation (gen-binapi-from-code)
Expand Down Expand Up @@ -80,7 +82,7 @@ test: ## Run unit tests
.PHONY: test-integration
test-integration: ## Run integration tests
@echo "# running integration tests"
go test -tags="integration ${GO_BUILD_TAGS}" ./test/integration
VPP_REPO=$(VPP_REPO) ./test/run_integration.sh

.PHONY: lint ## Run code linter
lint:
Expand Down
4 changes: 2 additions & 2 deletions examples/multi-vpp/multi_vpp.go
Expand Up @@ -58,10 +58,10 @@ func main() {

// since sockets default to the same value
if *binapiSockAddrVpp1 == *binapiSockAddrVpp2 {
log.Fatalln("ERROR: identical VPP binapi sockets defined, set at least one of them to a non-default path")
log.Println("ERROR: identical VPP binapi sockets defined, set at least one of them to a non-default path")
ondrej-fabry marked this conversation as resolved.
Show resolved Hide resolved
}
if *statsSockAddrVpp1 == *statsSockAddrVpp2 {
log.Fatalln("ERROR: identical VPP stats sockets defined, set at least one of them to a non-default path")
log.Println("ERROR: identical VPP stats sockets defined, set at least one of them to a non-default path")
}
var name1, name2 = "vpp1", "vpp2"
ch1, statsConn1, disconnect1 := connectVPP(name1, *binapiSockAddrVpp1, *statsSockAddrVpp1)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -7,6 +7,7 @@ require (
github.com/fsnotify/fsnotify v1.4.9
github.com/ftrvxmtrx/fd v0.0.0-20150925145434-c6d800382fff
github.com/lunixbochs/struc v0.0.0-20200521075829-a4cb8d33dbbe
github.com/mitchellh/go-ps v1.0.0
github.com/onsi/gomega v1.19.0
github.com/pkg/profile v1.2.1
github.com/sirupsen/logrus v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -15,6 +15,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lunixbochs/struc v0.0.0-20200521075829-a4cb8d33dbbe h1:ewr1srjRCmcQogPQ/NCx6XCk6LGVmsVCc9Y3vvPZj+Y=
github.com/lunixbochs/struc v0.0.0-20200521075829-a4cb8d33dbbe/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/onsi/ginkgo/v2 v2.1.3 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
Expand Down
58 changes: 58 additions & 0 deletions test/build/Dockerfile.integration
@@ -0,0 +1,58 @@
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
curl \
git \
gnupg \
iproute2 \
iputils-ping \
make \
nano \
sudo \
wget \
&& rm -rf /var/lib/apt/lists/*

ARG GOTESTSUM_VERSION=1.8.2
RUN curl -fsSL https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz -o gotestsum.tar.gz \
&& tar -xf gotestsum.tar.gz gotestsum \
&& mv gotestsum /usr/local/bin/gotestsum \
&& rm gotestsum.tar.gz

# Install Go
ENV GOLANG_VERSION 1.18.3

RUN set -eux; \
dpkgArch="$(dpkg --print-architecture)"; \
case "${dpkgArch##*-}" in \
amd64) goRelArch='linux-amd64'; ;; \
armhf) goRelArch='linux-armv6l'; ;; \
arm64) goRelArch='linux-arm64'; ;; \
esac; \
wget -nv -O go.tgz "https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz;

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

ARG VPP_REPO=release

# Install VPP
RUN set -eux; \
apt-get update; \
curl -fsSL https://packagecloud.io/install/repositories/fdio/${VPP_REPO}/script.deb.sh | bash; \
apt-get update && apt-get install -V -y \
vpp \
vpp-plugin-core \
; \
rm -rf /var/lib/apt/lists/*

COPY vpp.conf /etc/vpp/vpp.conf

WORKDIR /src

CMD ["/usr/bin/vpp", "-c", "/etc/vpp/vpp.conf"]
21 changes: 21 additions & 0 deletions test/build/vpp.conf
@@ -0,0 +1,21 @@
unix {
nodaemon
log /var/log/vpp.log
cli-listen /run/vpp/cli.sock
cli-no-pager
full-coredump
pidfile /run/vpp/vpp.pid
}
api-trace {
on
}
socksvr {
socket-name /run/vpp/api.sock
}
statseg {
socket-name /run/vpp/stats.sock
per-node-counters on
}
plugins {
plugin dpdk_plugin.so { disable }
}
39 changes: 39 additions & 0 deletions test/integration/binapi_test.go
@@ -0,0 +1,39 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// 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 integration

import (
"context"
"testing"

"go.fd.io/govpp/binapi/vpe"
"go.fd.io/govpp/test/vpptesting"
)

func TestVersion(t *testing.T) {
test := vpptesting.SetupVPP(t)

vpeRPC := vpe.NewServiceClient(test.Conn)

versionInfo, err := vpeRPC.ShowVersion(context.Background(), &vpe.ShowVersion{})
if err != nil {
t.Fatalf("getting version failed: %v", err)
}

t.Logf("VPP version: %v", versionInfo.Version)
if versionInfo.Version == "" {
t.Fatal("expected VPP version to not be empty")
}
}
50 changes: 50 additions & 0 deletions test/integration/examples_test.go
@@ -0,0 +1,50 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// 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 integration

import (
"io/fs"
"os/exec"
"path/filepath"
"testing"

"go.fd.io/govpp/test/vpptesting"
)

func TestExamples(t *testing.T) {
if err := filepath.WalkDir("./examples", func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() || filepath.Base(d.Name()) == "examples" {
return nil
}
example := filepath.Base(d.Name())
t.Run(example, func(tt *testing.T) {
testExample(tt, example)
})
return nil
}); err != nil {
t.Fatal(err)
}
}

func testExample(t *testing.T, example string) {
vpptesting.SetupVPP(t)

cmd := exec.Command("go", "run", "./examples/"+example)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("%s command failed: %+v\n%s", cmd, err, out)
}
t.Logf("out: %s", out)
}
28 changes: 28 additions & 0 deletions test/integration/main_test.go
@@ -0,0 +1,28 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// 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 integration contains tests against running VPP instance.
// The test cases are only executed if env contains TEST=integration.
package integration

import (
"os"
"testing"
)

func TestMain(m *testing.M) {
if os.Getenv("TEST") == "integration" {
os.Exit(m.Run())
}
}