Skip to content

Commit

Permalink
Merge pull request #294 from kzys/run-tests-gha
Browse files Browse the repository at this point in the history
Run tests on GitHub Actions
  • Loading branch information
kzys committed May 14, 2021
2 parents 82a531b + b1febd1 commit f722ecf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Expand Up @@ -11,9 +11,9 @@ jobs:
build:
strategy:
matrix:
go: ['1.11', '1.12', '1.13', '1.14', '1.15']
go: ['1.11', '1.12', '1.13', '1.14', '1.15', '1.16']
os: ['ubuntu-20.04']

fail-fast: false
name: ${{ matrix.os }} / Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -25,5 +25,5 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: make build
- name: Test
run: make test EXTRAGOARGS=-v
8 changes: 2 additions & 6 deletions Makefile
Expand Up @@ -48,16 +48,12 @@ all: build

test: all-tests

unit-tests: check-kvm $(testdata_objects)
unit-tests: $(testdata_objects)
DISABLE_ROOT_TESTS=$(DISABLE_ROOT_TESTS) go test -short ./... $(EXTRAGOARGS)

all-tests: check-kvm $(testdata_objects)
all-tests: $(testdata_objects)
DISABLE_ROOT_TESTS=$(DISABLE_ROOT_TESTS) go test ./... $(EXTRAGOARGS)

check-kvm:
@test -w /dev/kvm || \
(echo "In order to run firecracker, $(shell whoami) must have write permission to /dev/kvm"; false)

generate build clean::
go $@ $(EXTRAGOARGS)

Expand Down
21 changes: 21 additions & 0 deletions fctesting/utils.go
Expand Up @@ -14,9 +14,13 @@
package fctesting

import (
"fmt"
"os"
"os/user"
"testing"

"golang.org/x/sys/unix"

log "github.com/sirupsen/logrus"
)

Expand All @@ -31,6 +35,23 @@ func init() {
}
}

func RequiresKVM(t testing.TB) {
accessErr := unix.Access("/dev/kvm", unix.W_OK)
if accessErr != nil {
var name string
u, err := user.Current()
if err == nil {
name = u.Name
}

// On GitHub Actions, user.Current() doesn't return an error, but the name is "".
if name == "" {
name = fmt.Sprintf("uid=%d", os.Getuid())
}
t.Skipf("/dev/kvm is not writable from %s: %s", name, accessErr)
}
}

// RequiresRoot will ensure that tests that require root access are actually
// root. In addition, this will skip root tests if the DISABLE_ROOT_TESTS is
// set to true
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -16,7 +16,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.0
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.6.1
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
golang.org/x/sys v0.0.0-20201117170446-d9b008d0a637
)
2 changes: 0 additions & 2 deletions go.sum
Expand Up @@ -271,8 +271,6 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
Expand Down
18 changes: 12 additions & 6 deletions machine_test.go
Expand Up @@ -122,9 +122,7 @@ func TestNewMachine(t *testing.T) {
}

func TestJailerMicroVMExecution(t *testing.T) {
if testing.Short() {
t.Skip()
}
fctesting.RequiresKVM(t)
fctesting.RequiresRoot(t)

logPath := filepath.Join(testDataLogPath, "TestJailerMicroVMExecution")
Expand Down Expand Up @@ -284,9 +282,7 @@ func TestJailerMicroVMExecution(t *testing.T) {
}

func TestMicroVMExecution(t *testing.T) {
if testing.Short() {
t.Skip()
}
fctesting.RequiresKVM(t)

var nCpus int64 = 2
cpuTemplate := models.CPUTemplate(models.CPUTemplateT2)
Expand Down Expand Up @@ -398,8 +394,11 @@ func TestMicroVMExecution(t *testing.T) {
}

func TestStartVMM(t *testing.T) {
fctesting.RequiresKVM(t)

socketPath, cleanup := makeSocketPath(t)
defer cleanup()

cfg := Config{
SocketPath: socketPath,
}
Expand Down Expand Up @@ -437,6 +436,8 @@ func TestStartVMM(t *testing.T) {
}

func TestLogAndMetrics(t *testing.T) {
fctesting.RequiresKVM(t)

tests := []struct {
logLevel string
quiet bool
Expand Down Expand Up @@ -523,6 +524,8 @@ func testLogAndMetrics(t *testing.T, logLevel string) string {
}

func TestStartVMMOnce(t *testing.T) {
fctesting.RequiresKVM(t)

socketPath, cleanup := makeSocketPath(t)
defer cleanup()

Expand Down Expand Up @@ -1252,6 +1255,7 @@ func TestCaptureFifoToFile_leak(t *testing.T) {
}

func TestWait(t *testing.T) {
fctesting.RequiresKVM(t)
fctesting.RequiresRoot(t)

cases := []struct {
Expand Down Expand Up @@ -1535,6 +1539,7 @@ func TestSignalForwarding(t *testing.T) {
}

func TestPauseResume(t *testing.T) {
fctesting.RequiresKVM(t)
fctesting.RequiresRoot(t)

dir, err := ioutil.TempDir("", t.Name())
Expand Down Expand Up @@ -1646,6 +1651,7 @@ func TestPauseResume(t *testing.T) {
}

func TestCreateSnapshot(t *testing.T) {
fctesting.RequiresKVM(t)
fctesting.RequiresRoot(t)

dir, err := ioutil.TempDir("", t.Name())
Expand Down

0 comments on commit f722ecf

Please sign in to comment.