Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. SHELL = /bin/bash
  2. GO ?= go
  3. CC ?= gcc
  4. COVERAGE_PATH ?= $(shell pwd)/.coverage
  5. CRIU_FEATURE_MEM_TRACK = $(shell if criu check --feature mem_dirty_track > /dev/null; then echo 1; else echo 0; fi)
  6. CRIU_FEATURE_LAZY_PAGES = $(shell if criu check --feature uffd-noncoop > /dev/null; then echo 1; else echo 0; fi)
  7. CRIU_FEATURE_PIDFD_STORE = $(shell if criu check --feature pidfd_store > /dev/null; then echo 1; else echo 0; fi)
  8. export CRIU_FEATURE_MEM_TRACK CRIU_FEATURE_LAZY_PAGES CRIU_FEATURE_PIDFD_STORE
  9. all: build test phaul-test
  10. lint:
  11. golangci-lint run ./...
  12. build:
  13. $(GO) build -v ./...
  14. TEST_PAYLOAD := test/piggie/piggie
  15. TEST_BINARIES := test/test $(TEST_PAYLOAD) test/phaul/phaul
  16. COVERAGE_BINARIES := test/test.coverage test/phaul/phaul.coverage
  17. test-bin: $(TEST_BINARIES)
  18. test/piggie/piggie: test/piggie/piggie.c
  19. $(CC) $^ -o $@
  20. test/test: test/main.go
  21. $(GO) build -v -o $@ $^
  22. test: $(TEST_BINARIES)
  23. mkdir -p image
  24. PID=$$(test/piggie/piggie) && { \
  25. test/test dump $$PID image && \
  26. test/test restore image; \
  27. pkill -9 piggie; \
  28. }
  29. rm -rf image
  30. test/phaul/phaul: test/phaul/main.go
  31. $(GO) build -v -o $@ $^
  32. phaul-test: $(TEST_BINARIES)
  33. rm -rf image
  34. PID=$$(test/piggie/piggie) && { \
  35. test/phaul/phaul $$PID; \
  36. pkill -9 piggie; \
  37. }
  38. test/test.coverage: test/*.go
  39. $(GO) test \
  40. -covermode=count \
  41. -coverpkg=./... \
  42. -mod=vendor \
  43. -tags coverage \
  44. -buildmode=pie -c -o $@ $^
  45. test/phaul/phaul.coverage: test/phaul/*.go
  46. $(GO) test \
  47. -covermode=count \
  48. -coverpkg=./... \
  49. -mod=vendor \
  50. -tags coverage \
  51. -buildmode=pie -c -o $@ $^
  52. coverage: $(COVERAGE_BINARIES) $(TEST_PAYLOAD)
  53. mkdir -p $(COVERAGE_PATH)
  54. mkdir -p image
  55. PID=$$(test/piggie/piggie) && { \
  56. test/test.coverage -test.coverprofile=coverprofile.integration.$$RANDOM -test.outputdir=${COVERAGE_PATH} COVERAGE dump $$PID image && \
  57. test/test.coverage -test.coverprofile=coverprofile.integration.$$RANDOM -test.outputdir=${COVERAGE_PATH} COVERAGE restore image; \
  58. pkill -9 piggie; \
  59. }
  60. rm -rf image
  61. PID=$$(test/piggie/piggie) && { \
  62. test/phaul/phaul.coverage -test.coverprofile=coverprofile.integration.$$RANDOM -test.outputdir=${COVERAGE_PATH} COVERAGE $$PID; \
  63. pkill -9 piggie; \
  64. }
  65. echo "mode: set" > .coverage/coverage.out && cat .coverage/coverprofile* | \
  66. grep -v mode: | sort -r | awk '{if($$1 != last) {print $$0;last=$$1}}' >> .coverage/coverage.out
  67. clean:
  68. @rm -f $(TEST_BINARIES) $(COVERAGE_BINARIES) codecov
  69. @rm -rf image $(COVERAGE_PATH)
  70. rpc/rpc.proto:
  71. curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/rpc.proto -o $@
  72. stats/stats.proto:
  73. curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/stats.proto -o $@
  74. rpc/rpc.pb.go: rpc/rpc.proto
  75. protoc --go_out=. --go_opt=M$^=rpc/ $^
  76. stats/stats.pb.go: stats/stats.proto
  77. protoc --go_out=. --go_opt=M$^=stats/ $^
  78. vendor:
  79. GO111MODULE=on $(GO) mod tidy
  80. GO111MODULE=on $(GO) mod vendor
  81. GO111MODULE=on $(GO) mod verify
  82. codecov:
  83. curl -Os https://uploader.codecov.io/latest/linux/codecov
  84. chmod +x codecov
  85. ./codecov -f '.coverage/coverage.out'
  86. .PHONY: build test phaul-test test-bin clean lint vendor coverage codecov