Skip to content

Commit f722ecf

Browse files
authored
Merge pull request #294 from kzys/run-tests-gha
Run tests on GitHub Actions
2 parents 82a531b + b1febd1 commit f722ecf

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

.github/workflows/go.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
build:
1212
strategy:
1313
matrix:
14-
go: ['1.11', '1.12', '1.13', '1.14', '1.15']
14+
go: ['1.11', '1.12', '1.13', '1.14', '1.15', '1.16']
1515
os: ['ubuntu-20.04']
16-
16+
fail-fast: false
1717
name: ${{ matrix.os }} / Go ${{ matrix.go }}
1818
runs-on: ${{ matrix.os }}
1919
steps:
@@ -25,5 +25,5 @@ jobs:
2525
- name: Check out code into the Go module directory
2626
uses: actions/checkout@v2
2727

28-
- name: Build
29-
run: make build
28+
- name: Test
29+
run: make test EXTRAGOARGS=-v

Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,12 @@ all: build
4848

4949
test: all-tests
5050

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

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

57-
check-kvm:
58-
@test -w /dev/kvm || \
59-
(echo "In order to run firecracker, $(shell whoami) must have write permission to /dev/kvm"; false)
60-
6157
generate build clean::
6258
go $@ $(EXTRAGOARGS)
6359

fctesting/utils.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
package fctesting
1515

1616
import (
17+
"fmt"
1718
"os"
19+
"os/user"
1820
"testing"
1921

22+
"golang.org/x/sys/unix"
23+
2024
log "github.com/sirupsen/logrus"
2125
)
2226

@@ -31,6 +35,23 @@ func init() {
3135
}
3236
}
3337

38+
func RequiresKVM(t testing.TB) {
39+
accessErr := unix.Access("/dev/kvm", unix.W_OK)
40+
if accessErr != nil {
41+
var name string
42+
u, err := user.Current()
43+
if err == nil {
44+
name = u.Name
45+
}
46+
47+
// On GitHub Actions, user.Current() doesn't return an error, but the name is "".
48+
if name == "" {
49+
name = fmt.Sprintf("uid=%d", os.Getuid())
50+
}
51+
t.Skipf("/dev/kvm is not writable from %s: %s", name, accessErr)
52+
}
53+
}
54+
3455
// RequiresRoot will ensure that tests that require root access are actually
3556
// root. In addition, this will skip root tests if the DISABLE_ROOT_TESTS is
3657
// set to true

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/pkg/errors v0.9.1
1717
github.com/sirupsen/logrus v1.8.0
1818
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c
19-
github.com/stretchr/testify v1.7.0
19+
github.com/stretchr/testify v1.6.1
2020
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
2121
golang.org/x/sys v0.0.0-20201117170446-d9b008d0a637
2222
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
271271
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
272272
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
273273
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
274-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
275-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
276274
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
277275
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
278276
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=

machine_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ func TestNewMachine(t *testing.T) {
122122
}
123123

124124
func TestJailerMicroVMExecution(t *testing.T) {
125-
if testing.Short() {
126-
t.Skip()
127-
}
125+
fctesting.RequiresKVM(t)
128126
fctesting.RequiresRoot(t)
129127

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

286284
func TestMicroVMExecution(t *testing.T) {
287-
if testing.Short() {
288-
t.Skip()
289-
}
285+
fctesting.RequiresKVM(t)
290286

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

400396
func TestStartVMM(t *testing.T) {
397+
fctesting.RequiresKVM(t)
398+
401399
socketPath, cleanup := makeSocketPath(t)
402400
defer cleanup()
401+
403402
cfg := Config{
404403
SocketPath: socketPath,
405404
}
@@ -437,6 +436,8 @@ func TestStartVMM(t *testing.T) {
437436
}
438437

439438
func TestLogAndMetrics(t *testing.T) {
439+
fctesting.RequiresKVM(t)
440+
440441
tests := []struct {
441442
logLevel string
442443
quiet bool
@@ -523,6 +524,8 @@ func testLogAndMetrics(t *testing.T, logLevel string) string {
523524
}
524525

525526
func TestStartVMMOnce(t *testing.T) {
527+
fctesting.RequiresKVM(t)
528+
526529
socketPath, cleanup := makeSocketPath(t)
527530
defer cleanup()
528531

@@ -1252,6 +1255,7 @@ func TestCaptureFifoToFile_leak(t *testing.T) {
12521255
}
12531256

12541257
func TestWait(t *testing.T) {
1258+
fctesting.RequiresKVM(t)
12551259
fctesting.RequiresRoot(t)
12561260

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

15371541
func TestPauseResume(t *testing.T) {
1542+
fctesting.RequiresKVM(t)
15381543
fctesting.RequiresRoot(t)
15391544

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

16481653
func TestCreateSnapshot(t *testing.T) {
1654+
fctesting.RequiresKVM(t)
16491655
fctesting.RequiresRoot(t)
16501656

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

0 commit comments

Comments
 (0)