mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: <linux-kernel@vger.kernel.org>
Cc: <kernel@axis.com>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	<devicetree@vger.kernel.org>, <linux-um@lists.infradead.org>,
	<shuah@kernel.org>, <brendanhiggins@google.com>,
	<linux-kselftest@vger.kernel.org>, <jic23@kernel.org>,
	<linux-iio@vger.kernel.org>, <lgirdwood@gmail.com>,
	<broonie@kernel.org>, <a.zummo@towertech.it>,
	<alexandre.belloni@bootlin.com>, <linux-rtc@vger.kernel.org>,
	<corbet@lwn.net>, <linux-doc@vger.kernel.org>
Subject: [RFC v1 05/10] roadtest: add build files
Date: Fri, 11 Mar 2022 17:24:40 +0100	[thread overview]
Message-ID: <20220311162445.346685-6-vincent.whitchurch@axis.com> (raw)
In-Reply-To: <20220311162445.346685-1-vincent.whitchurch@axis.com>

Add a Makefile and other miscellaneous build-related files for the
roadtest framework.

To make it easier to run the tests on systems which do not have the
required libraries or Python version, a Dockerfile is included and the
Makefile has built-in support for running the tests in a Docker
container.

Targets for code formatting and static checking of the Python code are
included.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 tools/testing/roadtest/.gitignore       |  2 +
 tools/testing/roadtest/Dockerfile       | 25 ++++++++
 tools/testing/roadtest/Makefile         | 84 +++++++++++++++++++++++++
 tools/testing/roadtest/pyproject.toml   | 10 +++
 tools/testing/roadtest/requirements.txt |  4 ++
 tools/testing/roadtest/src/.gitignore   |  1 +
 6 files changed, 126 insertions(+)
 create mode 100644 tools/testing/roadtest/.gitignore
 create mode 100644 tools/testing/roadtest/Dockerfile
 create mode 100644 tools/testing/roadtest/Makefile
 create mode 100644 tools/testing/roadtest/pyproject.toml
 create mode 100644 tools/testing/roadtest/requirements.txt
 create mode 100644 tools/testing/roadtest/src/.gitignore

diff --git a/tools/testing/roadtest/.gitignore b/tools/testing/roadtest/.gitignore
new file mode 100644
index 000000000000..0cbd00343694
--- /dev/null
+++ b/tools/testing/roadtest/.gitignore
@@ -0,0 +1,2 @@
+__pycache__
+.py[cod]
diff --git a/tools/testing/roadtest/Dockerfile b/tools/testing/roadtest/Dockerfile
new file mode 100644
index 000000000000..f2982179c327
--- /dev/null
+++ b/tools/testing/roadtest/Dockerfile
@@ -0,0 +1,25 @@
+FROM debian:bullseye
+
+# Kernel build
+RUN apt-get update && apt-get -y install \
+    bc \
+    build-essential \
+    flex \
+    bison \
+    rsync \
+    kmod
+
+# Running roadtests
+RUN apt-get update && apt-get -y install \
+     python3.9 \
+     libpython3.9-dev \
+     python3 \
+     device-tree-compiler
+
+# Development and debugging
+RUN apt-get update && apt-get -y install \
+     uml-utilities \
+     telnetd \
+     python3-pip
+COPY requirements.txt /tmp/
+RUN pip install --requirement /tmp/requirements.txt
diff --git a/tools/testing/roadtest/Makefile b/tools/testing/roadtest/Makefile
new file mode 100644
index 000000000000..525b26581142
--- /dev/null
+++ b/tools/testing/roadtest/Makefile
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright Axis Communications AB
+
+.PHONY: all build-kernel test clean check fmt docker-run
+
+all:
+
+KSOURCE := ${PWD}
+ROADTEST_DIR = ${CURDIR}
+ROADTEST_BUILD_DIR := ${KSOURCE}/.roadtest
+KHEADERS := ${ROADTEST_BUILD_DIR}/usr
+KMODULES := ${ROADTEST_BUILD_DIR}/modules
+
+ifeq (${KSOURCE},${ROADTEST_DIR})
+# Make make from the standard roadtest directory work without having to set
+# additional variables.
+KSOURCE=$(ROADTEST_DIR:/tools/testing/roadtest=)
+endif
+
+CFLAGS += -g -D_GNU_SOURCE=1 -Wall -Werror -std=gnu99 \
+			-I${KSOURCE}/tools/include/ \
+			-I${KHEADERS}/include/ \
+			-I${ROADTEST_DIR}/src/libvhost-user/ \
+			$(shell python3-config --embed --includes) -O2
+
+${ROADTEST_BUILD_DIR}/roadtest-backend: ${ROADTEST_BUILD_DIR}/backend.o ${ROADTEST_BUILD_DIR}/libvhost-user.o
+	$(CC) -o $@ $^ $(shell python3-config --embed --libs)
+	# For the benefit of clangd
+	echo ${CFLAGS} | tr " " "\n" > ${ROADTEST_DIR}/src/compile_flags.txt
+
+${ROADTEST_BUILD_DIR}/backend.o: src/backend.c
+	$(CC) -c -o $@ $(CFLAGS) $<
+
+${ROADTEST_BUILD_DIR}/libvhost-user.o: src/libvhost-user/libvhost-user.c
+	$(CC) -c -o $@ $(CFLAGS) $<
+
+clean:
+	rm -rf ${ROADTEST_BUILD_DIR} .docker_built
+
+ifeq ($(DOCKER),1)
+.docker_built: Dockerfile requirements.txt
+	docker build --network=host -t roadtest ${ROADTEST_DIR}
+	touch $@
+
+# --network=host allows UML's con=port:... to work seamlessly
+docker-run: .docker_built
+	mkdir -p ${ROADTEST_BUILD_DIR}/umltmp
+	docker run --network=host ${DOCKEROPTS} --user $(shell id -u ${USER}):$(shell id -g ${USER}) --interactive --tty --rm -v ${KSOURCE}:${KSOURCE} -w ${KSOURCE} --env TMPDIR=${ROADTEST_BUILD_DIR}/umltmp roadtest sh -c '${MAKE} -C ${ROADTEST_DIR} -${MAKEFLAGS} ${MAKECMDGOALS} DOCKER=0'
+
+all test build-kernel check fmt: docker-run
+	@:
+else
+all: test
+
+ifneq ($(KBUILD),0)
+# Calling make on the kernel is slow even if there is nothing to be rebuilt.
+# Allow the user to avoid it with KBUILD=0
+${ROADTEST_BUILD_DIR}/backend.o: build-kernel
+${ROADTEST_BUILD_DIR}/libvhost-user.o: build-kernel
+test: build-kernel
+endif
+
+build-kernel:
+	mkdir -p ${ROADTEST_BUILD_DIR}
+	find ${ROADTEST_DIR}/roadtest/tests/ -type f -name config | xargs cat > ${ROADTEST_BUILD_DIR}/.config
+	${MAKE} -C ${KSOURCE} ARCH=um O=${ROADTEST_BUILD_DIR} olddefconfig
+	${MAKE} -C ${KSOURCE} ARCH=um O=${ROADTEST_BUILD_DIR}
+	${MAKE} -C ${KSOURCE} ARCH=um O=${ROADTEST_BUILD_DIR} INSTALL_HDR_PATH=${KHEADERS} headers_install
+	${MAKE} -C ${KSOURCE} ARCH=um O=${ROADTEST_BUILD_DIR} INSTALL_MOD_PATH=${KMODULES} modules_install
+
+test: ${ROADTEST_BUILD_DIR}/roadtest-backend
+	python3 -m roadtest.cmd.main --ksrc-dir ${KSOURCE} --build-dir ${ROADTEST_BUILD_DIR} --work-dir ${ROADTEST_BUILD_DIR}/roadtest-work/ ${OPTS}
+
+check:
+	mypy --no-error-summary roadtest
+	pyflakes roadtest
+	black --check roadtest
+	isort --profile black --check roadtest
+
+fmt:
+	black roadtest
+	isort --profile black roadtest
+
+endif
diff --git a/tools/testing/roadtest/pyproject.toml b/tools/testing/roadtest/pyproject.toml
new file mode 100644
index 000000000000..6b8b05eb3cad
--- /dev/null
+++ b/tools/testing/roadtest/pyproject.toml
@@ -0,0 +1,10 @@
+[tool.isort]
+profile = "black"
+
+[tool.mypy]
+disallow_untyped_defs = true
+check_untyped_defs = true
+no_implicit_optional = true
+warn_return_any = true
+warn_unused_ignores = true
+show_error_codes = true
diff --git a/tools/testing/roadtest/requirements.txt b/tools/testing/roadtest/requirements.txt
new file mode 100644
index 000000000000..e1ac403d826e
--- /dev/null
+++ b/tools/testing/roadtest/requirements.txt
@@ -0,0 +1,4 @@
+black==22.1.0
+isort==5.10.1
+mypy==0.931
+pyflakes==2.4.0
diff --git a/tools/testing/roadtest/src/.gitignore b/tools/testing/roadtest/src/.gitignore
new file mode 100644
index 000000000000..895dab3fe4be
--- /dev/null
+++ b/tools/testing/roadtest/src/.gitignore
@@ -0,0 +1 @@
+compile_flags.txt
-- 
2.34.1


  parent reply	other threads:[~2022-03-11 16:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 16:24 [RFC v1 00/10] roadtest: a driver testing framework Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 01/10] roadtest: import libvhost-user from QEMU Vincent Whitchurch
2022-03-24 13:00   ` Johannes Berg
2022-04-05 13:54     ` Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 02/10] roadtest: add C backend Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 03/10] roadtest: add framework Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 04/10] roadtest: add base config Vincent Whitchurch
2022-03-11 16:24 ` Vincent Whitchurch [this message]
2022-03-11 16:24 ` [RFC v1 06/10] roadtest: add documentation Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 07/10] iio: light: opt3001: add roadtest Vincent Whitchurch
2022-03-14 23:11   ` Brendan Higgins
2022-03-18 15:49     ` Vincent Whitchurch
2022-03-18 20:09       ` Johannes Berg
2022-03-29 14:43         ` Vincent Whitchurch
2022-03-29 14:50           ` Johannes Berg
2022-03-29 14:52             ` Johannes Berg
2022-03-11 16:24 ` [RFC v1 08/10] iio: light: vcnl4000: " Vincent Whitchurch
2022-03-20 17:02   ` Jonathan Cameron
2022-04-05 13:48     ` Vincent Whitchurch
2022-04-06 13:08       ` Jonathan Cameron
2022-04-14 10:20         ` Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 09/10] regulator: tps62864: " Vincent Whitchurch
2022-03-11 18:06   ` Mark Brown
2022-03-17 15:13     ` Vincent Whitchurch
2022-03-17 17:53       ` Mark Brown
2022-04-05 14:02         ` Vincent Whitchurch
2022-03-11 16:24 ` [RFC v1 10/10] rtc: pcf8563: " Vincent Whitchurch
2022-03-14 22:24 ` [RFC v1 00/10] roadtest: a driver testing framework Brendan Higgins
2022-03-17 16:09   ` Vincent Whitchurch
2022-04-18 19:44 ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220311162445.346685-6-vincent.whitchurch@axis.com \
    --to=vincent.whitchurch@axis.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=brendanhiggins@google.com \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=kernel@axis.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®