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

gha: add golangci-lint job, fix warnings; bump API version #46

Merged
merged 14 commits into from
Feb 17, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ jobs:
- name: checkout
uses: actions/checkout@v2

- name: install deps
- name: install criu
run: |
sudo apt-get install -y golint libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler protobuf-compiler python-protobuf libnl-3-dev libnet-dev libcap-dev
sudo make install.tools
sudo apt-get install -y libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler protobuf-compiler python-protobuf libnl-3-dev libnet-dev libcap-dev
git clone --single-branch -b ${{ matrix.criu_branch }} https://github.com/checkpoint-restore/criu.git
make -C criu
sudo make -C criu install-criu PREFIX=/usr
Expand All @@ -32,8 +31,7 @@ jobs:

- name: Run tests
run: |
sudo make lint build phaul test/test test/phaul test/piggie
# Run actual test as root as it uses CRIU.
sudo make test phaul-test
# This builds crit-go
sudo make -C crit-go/magic-gen lint build magicgen test
sudo make -C crit-go/magic-gen build magicgen test
24 changes: 24 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: verify
on: [ push, pull_request ]

jobs:
lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
with:
# must be specified without patch version
version: v1.36
# Only show new issues for a pull request.
only-new-issues: true

gomod:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: verify go.mod/go.sum
run: |
go mod tidy
(cd crit-go/magic-gen && go mod tidy)
git diff --exit-code
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test/test
test/piggie
test/piggie/piggie
test/phaul
image
rpc/rpc.proto
Expand Down
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
run:
skip_dirs:
- rpc
- stats

linters:
disable-all: false
presets:
- bugs
- performance
- unused
- format
65 changes: 28 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,46 @@
GO ?= go
CC ?= gcc
ifeq ($(GOPATH),)
export GOPATH := $(shell $(GO) env GOPATH)
endif
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
GOBIN := $(shell $(GO) env GOBIN)
ifeq ($(GOBIN),)
GOBIN := $(FIRST_GOPATH)/bin
endif

all: build test phaul phaul-test
all: build test phaul-test

lint:
@golint -set_exit_status . test phaul
golangci-lint run ./...
rst0git marked this conversation as resolved.
Show resolved Hide resolved

build:
@$(GO) build -v
$(GO) build -v ./...

test/piggie: test/piggie.c
@$(CC) $^ -o $@
TEST_BINARIES := test/test test/piggie/piggie test/phaul/phaul
test-bin: $(TEST_BINARIES)

test/test: test/main.go
@$(GO) build -v -o test/test test/main.go
test/piggie/piggie: test/piggie/piggie.c
$(CC) $^ -o $@

test: test/test test/piggie
mkdir -p image
test/piggie
test/test dump `pidof piggie` image
test/test restore image
pkill -9 piggie || :
test/test: test/*.go
$(GO) build -v -o $@ $^

phaul:
@cd phaul; go build -v
test: $(TEST_BINARIES)
mkdir -p image
PID=$$(test/piggie/piggie) && { \
test/test dump $$PID image && \
test/test restore image; \
pkill -9 piggie; \
}
rm -rf image

test/phaul: test/phaul-main.go
@$(GO) build -v -o test/phaul test/phaul-main.go
test/phaul/phaul: test/phaul/*.go
$(GO) build -v -o $@ $^

phaul-test: test/phaul test/piggie
phaul-test: $(TEST_BINARIES)
rm -rf image
test/piggie
test/phaul `pidof piggie`
pkill -9 piggie || :
PID=$$(test/piggie/piggie) && { \
test/phaul/phaul $$PID; \
pkill -9 piggie; \
}

clean:
@rm -f test/test test/piggie test/phaul
@rm -f $(TEST_BINARIES)
@rm -rf image
@rm -f rpc/rpc.proto

install.tools:
if [ ! -x "$(GOBIN)/golint" ]; then \
$(GO) get -u golang.org/x/lint/golint; \
fi
@rm -f rpc/rpc.proto stats/stats.proto

rpc/rpc.proto:
curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/rpc.proto -o $@
Expand All @@ -63,4 +54,4 @@ rpc/rpc.pb.go: rpc/rpc.proto
stats/stats.pb.go: stats/stats.proto
protoc --go_out=. $^

.PHONY: build test clean lint phaul
.PHONY: build test phaul-test test-bin clean lint
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![master](https://github.com/checkpoint-restore/go-criu/workflows/ci/badge.svg?branch=master)](https://github.com/checkpoint-restore/go-criu/actions)
[![test](https://github.com/checkpoint-restore/go-criu/workflows/ci/badge.svg?branch=master)](https://github.com/checkpoint-restore/go-criu/actions?query=workflow%3Aci)
[![verify](https://github.com/checkpoint-restore/go-criu/workflows/verify/badge.svg?branch=master)](https://github.com/checkpoint-restore/go-criu/actions?query=workflow%3Averify)

## go-criu -- Go bindings for [CRIU](https://criu.org/)

Expand Down
23 changes: 3 additions & 20 deletions crit-go/magic-gen/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
GO ?= go
CC ?= gcc
ifeq ($(GOPATH),)
export GOPATH := $(shell $(GO) env GOPATH)
endif
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
GOBIN := $(shell $(GO) env GOBIN)
ifeq ($(GOBIN),)
GOBIN := $(FIRST_GOPATH)/bin
endif

all: build test magicgen

lint:
@golint magic-gen.go

build:
@$(GO) build -v

test/magicgen: build
echo "#define TEST_MAGIC 0x12345678" > test_input
@rm -f test_output
@rm -f test_output
./magic-gen test_input test_output
cmp samplemagic test_output
if [ $$? -eq 0 ]; then \
Expand All @@ -29,8 +18,7 @@ test/magicgen: build
echo FAIL; \
exit 1; \
fi
@rm -f test_input
@rm -f test_output
@rm -f test_input test_output

test: test/magicgen

Expand All @@ -41,13 +29,8 @@ magicgen: build magic.h
./magic-gen magic.h magic.json
@rm -f magic.h

install.tools:
if [ ! -x "$(GOBIN)/golint" ]; then \
$(GO) get -u golang.org/x/lint/golint; \
fi

clean:
@rm -f testmagic.json
@rm -f test_output

.PHONY: build test clean lint magicgen
.PHONY: build test clean magicgen
5 changes: 5 additions & 0 deletions crit-go/magic-gen/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/thoas/go-funk v0.7.0 h1:GmirKrs6j6zJbhJIficOsz2aAI7700KsU/5YrdHRM1Y=
github.com/thoas/go-funk v0.7.0/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
5 changes: 3 additions & 2 deletions crit-go/magic-gen/magic-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bufio"
"encoding/json"
"fmt"
"github.com/thoas/go-funk"
"os"
"reflect"
"strconv"
"strings"

"github.com/thoas/go-funk"
)

func main() {
Expand All @@ -23,7 +24,7 @@ func main() {
infile, err := os.Open(magiccheader)
check(err)
defer infile.Close()
outfile, err := os.OpenFile(magicjson, os.O_CREATE|os.O_WRONLY, 0644)
outfile, err := os.OpenFile(magicjson, os.O_CREATE|os.O_WRONLY, 0o644)
check(err)
defer outfile.Close()
enc := json.NewEncoder(outfile)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/checkpoint-restore/go-criu/v4
module github.com/checkpoint-restore/go-criu/v5

go 1.13

Expand Down
27 changes: 14 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strconv"
"syscall"

"github.com/checkpoint-restore/go-criu/v4/rpc"
"github.com/golang/protobuf/proto"
"github.com/checkpoint-restore/go-criu/v5/rpc"
"google.golang.org/protobuf/proto"
)

// Criu struct
Expand Down Expand Up @@ -45,6 +45,7 @@ func (c *Criu) Prepare() error {
defer srv.Close()

args := []string{"swrk", strconv.Itoa(fds[1])}
// #nosec G204
cmd := exec.Command(c.swrkPath, args...)

err = cmd.Start()
Expand All @@ -64,7 +65,7 @@ func (c *Criu) Cleanup() {
if c.swrkCmd != nil {
c.swrkSk.Close()
c.swrkSk = nil
c.swrkCmd.Wait()
_ = c.swrkCmd.Wait()
c.swrkCmd = nil
}
}
Expand Down Expand Up @@ -187,28 +188,28 @@ func (c *Criu) doSwrkWithResp(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy N
}

// Dump dumps a process
func (c *Criu) Dump(opts rpc.CriuOpts, nfy Notify) error {
return c.doSwrk(rpc.CriuReqType_DUMP, &opts, nfy)
func (c *Criu) Dump(opts *rpc.CriuOpts, nfy Notify) error {
return c.doSwrk(rpc.CriuReqType_DUMP, opts, nfy)
}

// Restore restores a process
func (c *Criu) Restore(opts rpc.CriuOpts, nfy Notify) error {
return c.doSwrk(rpc.CriuReqType_RESTORE, &opts, nfy)
func (c *Criu) Restore(opts *rpc.CriuOpts, nfy Notify) error {
return c.doSwrk(rpc.CriuReqType_RESTORE, opts, nfy)
}

// PreDump does a pre-dump
func (c *Criu) PreDump(opts rpc.CriuOpts, nfy Notify) error {
return c.doSwrk(rpc.CriuReqType_PRE_DUMP, &opts, nfy)
func (c *Criu) PreDump(opts *rpc.CriuOpts, nfy Notify) error {
return c.doSwrk(rpc.CriuReqType_PRE_DUMP, opts, nfy)
}

// StartPageServer starts the page server
func (c *Criu) StartPageServer(opts rpc.CriuOpts) error {
return c.doSwrk(rpc.CriuReqType_PAGE_SERVER, &opts, nil)
func (c *Criu) StartPageServer(opts *rpc.CriuOpts) error {
return c.doSwrk(rpc.CriuReqType_PAGE_SERVER, opts, nil)
}

// StartPageServerChld starts the page server and returns PID and port
func (c *Criu) StartPageServerChld(opts rpc.CriuOpts) (int, int, error) {
resp, err := c.doSwrkWithResp(rpc.CriuReqType_PAGE_SERVER_CHLD, &opts, nil)
func (c *Criu) StartPageServerChld(opts *rpc.CriuOpts) (int, int, error) {
resp, err := c.doSwrkWithResp(rpc.CriuReqType_PAGE_SERVER_CHLD, opts, nil)
if err != nil {
return 0, 0, err
}
Expand Down
5 changes: 2 additions & 3 deletions notify.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package criu

//Notify interface
// Notify interface
type Notify interface {
PreDump() error
PostDump() error
Expand All @@ -14,8 +14,7 @@ type Notify interface {
}

// NoNotify struct
type NoNotify struct {
}
type NoNotify struct{}

// PreDump NoNotify
func (c NoNotify) PreDump() error {
Expand Down
2 changes: 1 addition & 1 deletion phaul/api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package phaul

import (
"github.com/checkpoint-restore/go-criu/v4"
"github.com/checkpoint-restore/go-criu/v5"
)

// Config is the configuration which is passed around
Expand Down
18 changes: 10 additions & 8 deletions phaul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package phaul
import (
"fmt"

"github.com/checkpoint-restore/go-criu/v4"
"github.com/checkpoint-restore/go-criu/v4/rpc"
"github.com/checkpoint-restore/go-criu/v4/stats"
"github.com/golang/protobuf/proto"
"github.com/checkpoint-restore/go-criu/v5"
"github.com/checkpoint-restore/go-criu/v5/rpc"
"github.com/checkpoint-restore/go-criu/v5/stats"
"google.golang.org/protobuf/proto"
)

const minPagesWritten uint64 = 64
const maxIters int = 8
const maxGrowDelta int64 = 32
const (
minPagesWritten uint64 = 64
maxIters int = 8
maxGrowDelta int64 = 32
)

// Client struct
type Client struct {
Expand Down Expand Up @@ -57,7 +59,7 @@ func (pc *Client) Migrate() error {
psi := rpc.CriuPageServerInfo{
Fd: proto.Int32(int32(pc.cfg.Memfd)),
}
opts := rpc.CriuOpts{
opts := &rpc.CriuOpts{
Pid: proto.Int32(int32(pc.cfg.Pid)),
LogLevel: proto.Int32(4),
LogFile: proto.String("pre-dump.log"),
Expand Down
Loading