thebeanogamer / rpms / qemu-kvm

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