From e4d84cf30445e61c28841d2e24cb65fd67f7ae21 Mon Sep 17 00:00:00 2001
From: Dave Tucker
Date: Wed, 12 Apr 2017 13:36:25 +0100
Subject: [PATCH] tests: add makefile for tests
this removes all test targets from the top level makefile with the
exception of `make test` that now calls `$(MAKE) -C test`.
all tests now use `moby run` by instead of the older `./scripts`.
this removes the need for dedicated qemu/hyperkit test targets.
Signed-off-by: Dave Tucker
---
Makefile | 66 +++++++------------------------------------------
test/Makefile | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 57 deletions(-)
create mode 100644 test/Makefile
diff --git a/Makefile b/Makefile
index daac32daf..354c05519 100644
--- a/Makefile
+++ b/Makefile
@@ -31,62 +31,15 @@ bin/linuxkit: $(LINUXKIT_DEPS) | bin
rm tmp_linuxkit_bin.tar
touch $@
-test-initrd.img: $(MOBY) test/test.yml
- $(MOBY) build --pull test/test.yml
-
-test-bzImage: test-initrd.img
-
-.PHONY: test-qemu-efi
-test-qemu-efi: $(LINUXKIT) test-efi.iso
- $(LINUXKIT) run qemu test | tee test-efi.log
- $(call check_test_log, test-efi.log)
-
bin:
mkdir -p $@
install:
cp -R ./bin/* $(PREFIX)/bin
-define check_test_log
- @cat $1 |grep -q 'test suite PASSED'
-endef
-
-.PHONY: test-hyperkit
-test-hyperkit: $(LINUXKIT) test-initrd.img test-bzImage test-cmdline
- rm -f disk.img
- $(LINUXKIT) run hyperkit test | tee test.log
- $(call check_test_log, test.log)
-
-.PHONY: test-gcp
-test-gcp: export CLOUDSDK_IMAGE_NAME?=test
-test-gcp: $(LINUXKIT) test.img.tar.gz
- $(LINUXKIT) push gcp test.img.tar.gz
- $(LINUXKIT) run gcp $(CLOUDSDK_IMAGE_NAME) | tee test-gcp.log
- $(call check_test_log, test-gcp.log)
-
.PHONY: test
-test: $(LINUXKIT) test-initrd.img test-bzImage test-cmdline
- $(LINUXKIT) run test | tee test.log
- $(call check_test_log, test.log)
-
-test-ltp.img.tar.gz: $(MOBY) test/ltp/test-ltp.yml
- $(MOBY) build --pull test/ltp/test-ltp.yml
-
-.PHONY: test-ltp
-test-ltp: export CLOUDSDK_IMAGE_NAME?=test-ltp
-test-ltp: $(LINUXKIT) artifacts/test-ltp.img.tar.gz
- $(LINUXKIT) push gcp artifacts/test-ltp.img.tar.gz
- $(LINUXKIT) run gcp -skip-cleanup -machine n1-highcpu-4 $(CLOUDSDK_IMAGE_NAME) | tee test-ltp.log
- $(call check_test_log, test-ltp.log)
-
-artifacts:
- mkdir -p $@
-
-artifacts/test.img.tar.gz: test.img.tar.gz | artifacts
- cp test.img.tar.gz artifacts/
-
-artifacts/test-ltp.img.tar.gz: test-ltp.img.tar.gz | artifacts
- cp test-ltp.img.tar.gz artifacts/
+test:
+ $(MAKE) -C test
.PHONY: collect-artifacts
collect-artifacts: artifacts/test.img.tar.gz artifacts/test-ltp.img.tar.gz
@@ -95,23 +48,22 @@ collect-artifacts: artifacts/test.img.tar.gz artifacts/test-ltp.img.tar.gz
ci:
$(MAKE) clean
$(MAKE)
- $(MAKE) test
- $(MAKE) collect-artifacts
- $(MAKE) test-ltp
+ $(MAKE) install
+ $(MAKE) -C test all
ci-tag:
$(MAKE) clean
$(MAKE)
- $(MAKE) test
- $(MAKE) collect-artifacts
- $(MAKE) test-ltp
+ $(MAKE) install
+ $(MAKE) -C test all
ci-pr:
$(MAKE) clean
$(MAKE)
- $(MAKE) test
- $(MAKE) artifacts/test.img.tar.gz
+ $(MAKE) install
+ $(MAKE) -C test pr
.PHONY: clean
clean:
rm -rf bin *.log *-kernel *-cmdline *.img *.iso *.tar.gz *.qcow2 *.vhd *.vmx *.vmdk
+ $(MAKE) -C test clean
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 000000000..d5520efce
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,68 @@
+.PHONY: default pr all
+
+default: check-deps kernel-config
+pr: check-deps kernel-config ../artifacts/test.img.tar.gz
+all: check-deps kernel-config ltp ../artifacts/test.img.tar.gz ../artifacts/test-ltp.img.tar.gz
+
+MOBY:=$(shell command -v moby 2> /dev/null)
+LINUXKIT:=$(shell command -v linuxkit 2> /dev/null)
+
+.PHONY: check-deps
+check-deps:
+ifndef MOBY
+ $(error "moby is not available. please install it.")
+endif
+ifndef LINUXKIT
+ $(error "linuxkit binary not found. please install it.")
+endif
+
+define check_test_log
+ @cat $1 |grep -q 'test suite PASSED'
+endef
+
+../artifacts:
+ mkdir -p $@
+
+test-kernel-config-initrd.img: $(MOBY) cases/test-kernel-config.yml
+ $(MOBY) build --pull cases/test-kernel-config.yml
+
+# uses qemu
+.PHONY: kernel-config
+kernel-config: $(LINUXKIT) test-kernel-config-initrd.img test-kernel-config-kernel test-kernel-config-cmdline
+ $(LINUXKIT) run qemu test-kernel-config 2>&1 | tee test.log
+ $(call check_test_log, test.log)
+
+# qemu only at this time
+.PHONY: qemu-efi
+efi: $(LINUXKIT) test-kernel-config-efi.iso
+ $(LINUXKIT) run qemu -uefi test-kernel-config | tee test-efi.log
+ $(call check_test_log, test-efi.log)
+
+# For GCP tests
+../artifacts/test.img.tar.gz: test-kernel-config.img.tar.gz | ../artifacts
+ mv test-kernel-config.img.tar.gz ../artifacts/test.img.tar.gz
+
+.PHONY: gcp
+gcp: export CLOUDSDK_IMAGE_NAME?=test-kernel-config
+gcp: $(LINUXKIT) ../test.img.tar.gz
+ $(LINUXKIT) push gcp ../artifacts/test.img.tar.gz
+ $(LINUXKIT) run gcp $(CLOUDSDK_IMAGE_NAME) | tee test-gcp.log
+ $(call check_test_log, test-gcp.log)
+
+# For LTP tests
+test-ltp.img.tar.gz: $(MOBY) cases/test-ltp.yml
+ $(MOBY) build --pull cases/test-ltp.yml
+
+../artifacts/test-ltp.img.tar.gz: test-ltp.img.tar.gz | ../artifacts
+ mv test-ltp.img.tar.gz ../artifacts
+
+.PHONY: ltp
+ltp: export CLOUDSDK_IMAGE_NAME?=test-ltp
+ltp: $(LINUXKIT) test-ltp.img.tar.gz
+ $(LINUXKIT) push gcp ../artifacts/test-ltp.img.tar.gz
+ $(LINUXKIT) run gcp -skip-cleanup -machine n1-highcpu-4 $(CLOUDSDK_IMAGE_NAME) | tee test-ltp.log
+ $(call check_test_log, test-ltp.log)
+
+.PHONY: clean
+clean:
+ rm -rf bin *.log *-kernel *-cmdline *.img *.iso *.tar.gz *.qcow2 *.vhd *.vmx *.vmdk