cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
26ba25
From 5c0a6bb69135e0fa83a1e063dfe878e5e98c1785 Mon Sep 17 00:00:00 2001
26ba25
From: Yash Mankad <ymankad@redhat.com>
26ba25
Date: Wed, 12 Dec 2018 00:14:40 +0000
26ba25
Subject: [PATCH 12/13] Bootstrap Python venv for tests
26ba25
MIME-Version: 1.0
26ba25
Content-Type: text/plain; charset=UTF-8
26ba25
Content-Transfer-Encoding: 8bit
26ba25
26ba25
RH-Author: Yash Mankad <ymankad@redhat.com>
26ba25
Message-id: <8e00545539681a5de548c444e7752894b12bc8ec.1544573601.git.ymankad@redhat.com>
26ba25
Patchwork-id: 83436
26ba25
O-Subject: [RHEL-8.0 qemu-kvm PATCH v2 6/7] Bootstrap Python venv for tests
26ba25
Bugzilla: 1655807
26ba25
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
26ba25
26ba25
From: Cleber Rosa <crosa@redhat.com>
26ba25
26ba25
A number of QEMU tests are written in Python, and may benefit
26ba25
from an untainted Python venv.
26ba25
26ba25
By using make rules, tests that depend on specific Python libs
26ba25
can set that rule as a requirement, along with rules that require
26ba25
the presence or installation of specific libraries.
26ba25
26ba25
The tests/requirements.txt is supposed to contain the Python
26ba25
requirements that should be added to the venv created by check-venv.
26ba25
26ba25
Signed-off-by: Cleber Rosa <crosa@redhat.com>
26ba25
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
26ba25
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
Acked-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
26ba25
Reviewed-by: Caio Carrara <ccarrara@redhat.com>
26ba25
Message-Id: <20181018153134.8493-2-crosa@redhat.com>
26ba25
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
26ba25
(cherry picked from commit 213137217a60eca18e9b55817f00dfdd6eaff74a)
26ba25
Signed-off-by: Yash Mankad <ymankad@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 tests/Makefile.include | 26 ++++++++++++++++++++++++++
26ba25
 tests/requirements.txt |  3 +++
26ba25
 2 files changed, 29 insertions(+)
26ba25
 create mode 100644 tests/requirements.txt
26ba25
26ba25
diff --git a/tests/Makefile.include b/tests/Makefile.include
26ba25
index 3ed8531..99a9dcd 100644
26ba25
--- a/tests/Makefile.include
26ba25
+++ b/tests/Makefile.include
26ba25
@@ -11,6 +11,7 @@ check-help:
26ba25
 	@echo " $(MAKE) check-qapi-schema    Run QAPI schema tests"
26ba25
 	@echo " $(MAKE) check-block          Run block tests"
26ba25
 	@echo " $(MAKE) check-report.html    Generates an HTML test report"
26ba25
+	@echo " $(MAKE) check-venv           Creates a Python venv for tests"
26ba25
 	@echo " $(MAKE) check-clean          Clean the tests"
26ba25
 	@echo
26ba25
 	@echo "Please note that HTML reports do not regenerate if the unit tests"
26ba25
@@ -953,6 +954,30 @@ check-decodetree:
26ba25
           ./check.sh "$(PYTHON)" "$(SRC_PATH)/scripts/decodetree.py", \
26ba25
           TEST, decodetree.py)
26ba25
 
26ba25
+# Python venv for running tests
26ba25
+
26ba25
+.PHONY: check-venv
26ba25
+
26ba25
+TESTS_VENV_DIR=$(BUILD_DIR)/tests/venv
26ba25
+TESTS_VENV_REQ=$(SRC_PATH)/tests/requirements.txt
26ba25
+
26ba25
+$(shell $(PYTHON) -c 'import sys; assert sys.version_info >= (3,0)' >/dev/null 2>&1)
26ba25
+ifeq ($(.SHELLSTATUS),0)
26ba25
+$(TESTS_VENV_DIR): $(TESTS_VENV_REQ)
26ba25
+	$(call quiet-command, \
26ba25
+            $(PYTHON) -m venv --system-site-packages $@, \
26ba25
+            VENV, $@)
26ba25
+	$(call quiet-command, \
26ba25
+            $(TESTS_VENV_DIR)/bin/python -m pip -q install -r $(TESTS_VENV_REQ), \
26ba25
+            PIP, $(TESTS_VENV_REQ))
26ba25
+	$(call quiet-command, touch $@)
26ba25
+else
26ba25
+$(TESTS_VENV_DIR):
26ba25
+	$(error "venv directory for tests requires Python 3")
26ba25
+endif
26ba25
+
26ba25
+check-venv: $(TESTS_VENV_DIR)
26ba25
+
26ba25
 # Consolidated targets
26ba25
 
26ba25
 .PHONY: check-qapi-schema check-qtest check-unit check check-clean
26ba25
@@ -967,6 +992,7 @@ check-clean:
26ba25
 	rm -rf $(check-unit-y) tests/*.o $(QEMU_IOTESTS_HELPERS-y)
26ba25
 	rm -rf $(sort $(foreach target,$(SYSEMU_TARGET_LIST), $(check-qtest-$(target)-y)) $(check-qtest-generic-y))
26ba25
 	rm -f tests/test-qapi-gen-timestamp
26ba25
+	rm -rf $(TESTS_VENV_DIR)
26ba25
 
26ba25
 clean: check-clean
26ba25
 
26ba25
diff --git a/tests/requirements.txt b/tests/requirements.txt
26ba25
new file mode 100644
26ba25
index 0000000..d39f9d1
26ba25
--- /dev/null
26ba25
+++ b/tests/requirements.txt
26ba25
@@ -0,0 +1,3 @@
26ba25
+# Add Python module requirements, one per line, to be installed
26ba25
+# in the tests/venv Python virtual environment. For more info,
26ba25
+# refer to: https://pip.pypa.io/en/stable/user_guide/#id1
26ba25
-- 
26ba25
1.8.3.1
26ba25