Proof of concept to power up "make test" with docker
cover Proof of concept to power up "make test" with docker
Recently it was brought up that "make test" is in an orphaned state, and making it work would be a good thing because it has valuable test coverage for tcg:
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg04978.html
This RFC is an attempt to use docker to cross build the test binaries that will be run by qemu-user and meanwhile rename it from "make test" to "make check-tcg" to align with the naming convention of other test targets we have.
As the initial version only i386 is converted, not because it's easy, but because it is a test set that covers the most types of rules we will need (cross-build, run and compare result).
After these patches, "make check-tcg" will do the i386 tests with the new rules first (which fails but that's out of the scope of this series), then continue to do the old "make -C tests/tcg test" command. Once all tests are moved into the new Makefile.include file, the old Makefile can be dropped.
Fam Zheng (7):
Makefile: Rename TARGET_DIRS to TARGET_LIST
docker: Add "cc" subcommand
docker: Add fedora-i386-cross image
tests: Build fix for hello-i386
tests: Build fix for linux-test
buildsys: Add "check-tcg" target
tests: Move i386 tcg tests to check-tcg
Makefile | 21 ++++--- configure | 2 +- scripts/create_config | 2 +- tests/Makefile.include | 3 +- tests/docker/docker.py | 23 +++++++ tests/docker/dockerfiles/fedora-i386-cross.docker | 13 ++++ tests/tcg/Makefile | 60 ------------------ tests/tcg/Makefile.include | 75 +++++++++++++++++++++++ tests/tcg/hello-i386.c | 1 + tests/tcg/linux-test.c | 67 +++++++------------- 10 files changed, 149 insertions(+), 118 deletions(-) create mode 100644 tests/docker/dockerfiles/fedora-i386-cross.docker create mode 100644 tests/tcg/Makefile.include
Signature · 1 line
2.13.5
RFC PATCH 1/7 Makefile: Rename TARGET_DIRS to TARGET_LIST
To be more accurate on its purpose and make code that looks for a certain target out of this variable more readable.
--- Makefile | 20 ++++++++++---------- configure | 2 +- scripts/create_config | 2 +- tests/Makefile.include | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)
Makefile +10 -10
@@ -24,8 +24,8 @@ seems to have been used for an in-tree build. You can fix this by running \ endif endif -CONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_DIRS)),y) -CONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_DIRS)),y) +CONFIG_SOFTMMU := $(if $(filter %-softmmu,$(TARGET_LIST)),y) +CONFIG_USER_ONLY := $(if $(filter %-user,$(TARGET_LIST)),y) CONFIG_XEN := $(CONFIG_XEN_BACKEND) CONFIG_ALL=y -include config-all-devices.mak
@@ -217,8 +217,8 @@ DOCS= endif SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory) BUILD_DIR=$(BUILD_DIR) -SUBDIR_DEVICES_MAK=$(patsubst %, %/config-devices.mak, $(TARGET_DIRS)) -SUBDIR_DEVICES_MAK_DEP=$(patsubst %, %-config-devices.mak.d, $(TARGET_DIRS)) +SUBDIR_DEVICES_MAK=$(patsubst %, %/config-devices.mak, $(TARGET_LIST)) +SUBDIR_DEVICES_MAK_DEP=$(patsubst %, %-config-devices.mak.d, $(TARGET_LIST)) ifeq ($(SUBDIR_DEVICES_MAK),) config-all-devices.mak:
@@ -314,7 +314,7 @@ config-host.h-timestamp: config-host.mak qemu-options.def: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@") -SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS)) +SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_LIST)) SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES)) $(SOFTMMU_SUBDIR_RULES): $(block-obj-y)
@@ -352,7 +352,7 @@ ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) romsubdir-%: $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C pc-bios/$* V="$(V)" TARGET_DIR="$*/" CFLAGS="$(filter -O% -g%,$(CFLAGS))",) -ALL_SUBDIRS=$(TARGET_DIRS) $(patsubst %,pc-bios/%, $(ROMS)) +ALL_SUBDIRS=$(TARGET_LIST) $(patsubst %,pc-bios/%, $(ROMS)) recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES)
@@ -537,7 +537,7 @@ distclean: clean rm -f docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt rm -f docs/interop/qemu-qmp-ref.pdf docs/interop/qemu-ga-ref.pdf rm -f docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html - for d in $(TARGET_DIRS); do \ + for d in $(TARGET_LIST); do \ rm -rf $$d || exit 1 ; \ done rm -Rf .sdk
@@ -638,7 +638,7 @@ endif $(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \ done $(INSTALL_DATA) $(BUILD_DIR)/trace-events-all "$(DESTDIR)$(qemu_datadir)/trace-events-all" - for d in $(TARGET_DIRS); do \ + for d in $(TARGET_LIST); do \ $(MAKE) $(SUBDIR_MAKEFLAGS) TARGET_DIR=$$d/ -C $$d $@ || exit 1 ; \ done
@@ -832,9 +832,9 @@ help: @echo ' ctags/TAGS - Generate tags file for editors' @echo ' cscope - Generate cscope index' @echo '' - @$(if $(TARGET_DIRS), \ + @$(if $(TARGET_LIST), \ echo 'Architecture specific targets:'; \ - $(foreach t, $(TARGET_DIRS), \ + $(foreach t, $(TARGET_LIST), \ printf " %-30s - Build for %s\\n" $(patsubst %,subdir-%,$(t)) $(t);) \ echo '') @echo 'Cleaning targets:'
configure +1 -1
@@ -5587,7 +5587,7 @@ qemu_version=$(head $source_path/VERSION) echo "VERSION=$qemu_version" >>$config_host_mak echo "PKGVERSION=$pkgversion" >>$config_host_mak echo "SRC_PATH=$source_path" >> $config_host_mak -echo "TARGET_DIRS=$target_list" >> $config_host_mak +echo "TARGET_LIST=$target_list" >> $config_host_mak if [ "$docs" = "yes" ] ; then echo "BUILD_DOCS=yes" >> $config_host_mak fi
scripts/create_config +1 -1
@@ -107,7 +107,7 @@ case $line in target_name=${line#*=} echo "#define TARGET_NAME \"$target_name\"" ;; - TARGET_DIRS=*) + TARGET_LIST=*) # do nothing ;; TARGET_*=y) # configuration
tests/Makefile.include +1 -1
@@ -820,7 +820,7 @@ endif # QTest rules -TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS))) +TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_LIST))) ifeq ($(CONFIG_POSIX),y) QTEST_TARGETS = $(TARGETS) check-qtest-y=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y))
Signature · 1 line
2.13.5
RFC PATCH 2/7 docker: Add "cc" subcommand
In reply to Fam Zheng--- tests/docker/docker.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
tests/docker/docker.py +23 -0
@@ -367,6 +367,29 @@ class ImagesCommand(SubCommand): def run(self, args, argv): return Docker().command("images", argv, args.quiet) +class CcCommand(SubCommand): + """Compile sources with cc in images""" + name = "cc" + + def args(self, parser): + parser.add_argument("--image", "-i", required=True, + help="The docker image in which to run cc") + parser.add_argument("--source-path", "-s", nargs="*", dest="paths", + help="""Extra paths to (ro) mount into container for + reading sources""") + + def run(self, args, argv): + if argv and argv[0] == "--": + argv = argv[1:] + cwd = os.getcwd() + cmd = ["--rm", "-w", cwd, + "-v", "%s:%s:rw" % (cwd, cwd)] + for p in args.paths: + cmd += ["-v", "%s:%s:ro,z" % (p, p)] + cmd += [args.image, "cc"] + cmd += argv + return Docker().command("run", cmd, True) + def main(): parser = argparse.ArgumentParser(description="A Docker helper", usage="%s <subcommand> ..." % os.path.basename(sys.argv[0]))
Signature · 1 line
2.13.5
RFC PATCH 3/7 docker: Add fedora-i386-cross image
In reply to Fam ZhengIt has some basic *-devel.i686 packages to be used with "gcc -m32" as a 32 bit cross build environment.
--- tests/docker/dockerfiles/fedora-i386-cross.docker | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/docker/dockerfiles/fedora-i386-cross.docker
tests/docker/dockerfiles/fedora-i386-cross.docker new file +13 -0
@@ -0,0 +1,13 @@ +FROM fedora:latest +ENV PACKAGES \ + gcc \ + glibc-devel.i686 \ + glib2-devel.i686 \ + zlib-devel.i686 \ + glib2-devel.i686 \ + nettle-devel.i686 \ + pixman-devel.i686 \ + gnutls-devel.i686 + +RUN dnf install -y $PACKAGES +RUN rpm -q $PACKAGES | sort > /packages.txt
Signature · 1 line
2.13.5
RFC PATCH 4/7 tests: Build fix for hello-i386
In reply to Fam ZhengWe have -Werror=missing-prototype, add a dummy prototype to avoid that warning.
--- tests/tcg/hello-i386.c | 1 + 1 file changed, 1 insertion(+)
tests/tcg/hello-i386.c +1 -0
@@ -20,6 +20,7 @@ static inline int write(int fd, const char * buf, int len)return status; } +void _start (void );void _start (void ) {write (1 ,"Hello World\n" ,12 );
Signature · 1 line
2.13.5
RFC PATCH 5/7 tests: Build fix for linux-test
In reply to Fam ZhengTo keep the compiler happy, and to fit in our buildsys flags:
- Include "qemu/osdep.h" first
- Make local functions "static"
- #ifdef out unused functions
--- tests/tcg/linux-test.c | 67 +++++++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 45 deletions(-)
tests/tcg/linux-test.c +22 -45
@@ -17,6 +17,7 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #define _GNU_SOURCE +#include "qemu/osdep.h" #include <stdarg.h> #include <stdlib.h> #include <stdio.h>
@@ -31,6 +32,7 @@#include <utime.h> #include <time.h> #include <sys/time.h> +#include <sys/resource.h> #include <sys/uio.h> #include <sys/socket.h> #include <netinet/in.h>
@@ -45,7 +47,7 @@#define TESTPORT 7654#define STACK_SIZE 16384 -void error1 (const char *filename,int line,const char *fmt, ...) +static void error1 (const char *filename,int line,const char *fmt, ...) {va_list ap;va_start (ap, fmt);
@@ -56,7 +58,7 @@ void error1(const char *filename, int line, const char *fmt, ...)exit (1 ); } -int __chk_error (const char *filename,int line,int ret) +static int __chk_error (const char *filename,int line,int ret) {if (ret <0 ) { error1(filename, line, "%m (ret=%d, errno=%d)",
@@ -73,7 +75,7 @@ int __chk_error(const char *filename, int line, int ret)#define FILE_BUF_SIZE 300 -void test_file (void ) +static void test_file (void ) {int fd, i, len, ret;uint8_t buf[FILE_BUF_SIZE ];
@@ -210,7 +212,7 @@ void test_file(void)chk_error (rmdir (TESTPATH )); } -void test_fork (void ) +static void test_fork (void ) {int pid, status;
@@ -224,7 +226,7 @@ void test_fork(void)error ("waitpid status=0x%x" , status); } -void test_time (void ) +static void test_time (void ) {struct timeval tv, tv2;struct timespec ts, rem;
@@ -251,34 +253,7 @@ void test_time(void)error ("getrusage" ); } -void pstrcpy (char *buf,int buf_size,const char *str) -{ -int c; -char *q = buf; - -if (buf_size <=0 ) -return ; - -for (;;) { - c = *str++; -if (c ==0 || q >= buf + buf_size -1 ) -break ; - *q++ = c; - } - *q ='\0' ; -} - -/* strcat and truncate. */ -char *pstrcat (char *buf,int buf_size,const char *s) -{ -int len; - len =strlen (buf); -if (len < buf_size) -pstrcpy (buf + len, buf_size - len, s); -return buf; -} - -int server_socket (void ) +static int server_socket (void ) {int val, fd;struct sockaddr_in sockaddr;
@@ -298,7 +273,7 @@ int server_socket(void) } -int client_socket (void ) +static int client_socket (void ) {int fd;struct sockaddr_in sockaddr;
@@ -312,9 +287,9 @@ int client_socket(void)return fd; } -const char socket_msg[] ="hello socket\n" ; +static const char socket_msg[] ="hello socket\n" ; -void test_socket (void ) +static void test_socket (void ) {int server_fd, client_fd, fd, pid, ret, val;struct sockaddr_in sockaddr;
@@ -348,9 +323,10 @@ void test_socket(void)chk_error (close (server_fd)); } +#if 0 #define WCOUNT_MAX 512 -void test_pipe (void ) +static void test_pipe (void ) {fd_set rfds, wfds;int fds[2 ], fd_max, ret;
@@ -391,10 +367,10 @@ void test_pipe(void)chk_error (close (fds[1 ])); } -int thread1_res; -int thread2_res; +static int thread1_res; +static int thread2_res; -int thread1_func (void *arg) +static int thread1_func (void *arg) {int i;for (i=0 ;i<5 ;i++) {
@@ -404,7 +380,7 @@ int thread1_func(void *arg)return 0 ; } -int thread2_func (void *arg) +static int thread2_func (void *arg) {int i;for (i=0 ;i<6 ;i++) {
@@ -435,27 +411,28 @@ void test_clone(void) thread2_res != 6) error("clone"); } +#endif /***********************************/ volatile int alarm_count;jmp_buf jmp_env; -void sig_alarm (int sig) +static void sig_alarm (int sig) {if (sig !=SIGALRM )error ("signal" ); alarm_count++; } -void sig_segv (int sig,siginfo_t *info,void *puc) +static void sig_segv (int sig,siginfo_t *info,void *puc) {if (sig !=SIGSEGV )error ("signal" );longjmp (jmp_env,1 ); } -void test_signal (void ) +static void test_signal (void ) {struct sigaction act;struct itimerval it, oit;
@@ -510,7 +487,7 @@ void test_signal(void)#define SHM_SIZE 32768 -void test_shm (void ) +static void test_shm (void ) {void *ptr;int shmid;
Signature · 1 line
2.13.5
RFC PATCH 6/7 buildsys: Add "check-tcg" target
In reply to Fam ZhengThis is merely a thin wrapper of the old "test" target, but in a consistent form of Makefile structure.
Next patches will actually convert the rules from the old "make test".
--- Makefile | 1 + tests/Makefile.include | 1 + tests/tcg/Makefile.include | 3 +++ 3 files changed, 5 insertions(+) create mode 100644 tests/tcg/Makefile.include
Makefile +1 -0
@@ -282,6 +282,7 @@ dummy := $(call unnest-vars,, \ trace-obj-y) include $(SRC_PATH)/tests/Makefile.include +include $(SRC_PATH)/tests/tcg/Makefile.include all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules
tests/Makefile.include +1 -0
@@ -10,6 +10,7 @@ check-help: @echo " make check-speed Run qobject speed tests" @echo " make check-qapi-schema Run QAPI schema tests" @echo " make check-block Run block tests" + @echo " make check-tcg Clean TCG tests" @echo " make check-report.html Generates an HTML test report" @echo " make check-clean Clean the tests" @echo
tests/tcg/Makefile.include new file +3 -0
@@ -0,0 +1,3 @@ + +check-tcg: + $(MAKE) -C tests/tcg test
Signature · 1 line
2.13.5
RFC PATCH 7/7 tests: Move i386 tcg tests to check-tcg
In reply to Fam ZhengOnly enable the tests if i386-linux-user is a specified target in configure, and build the test programs with "docker.py cc" command.
Also change the "diff -u" to "cmp -s" because we have really huge output to compare.
--- tests/tcg/Makefile | 60 ------------------------------------- tests/tcg/Makefile.include | 74 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 61 deletions(-)
tests/tcg/Makefile +0 -60
@@ -17,15 +17,6 @@ LDFLAGS= # runcom maps page 0, so it requires root privileges # also, pi_10.com runs indefinitely -I386_TESTS=hello-i386 \ - linux-test \ - testthread \ - sha1-i386 \ - test-i386 \ - test-i386-fprem \ - test-mmap \ - # runcom - # native i386 compilers sometimes are not biarch. assume cross-compilers are ifneq ($(ARCH),i386) I386_TESTS+=run-test-x86_64
@@ -46,35 +37,11 @@ test: all run-%: % -$(QEMU) ./$* -run-hello-i386: hello-i386 -run-linux-test: linux-test -run-testthread: testthread -run-sha1-i386: sha1-i386 - -run-test-i386: test-i386 - ./test-i386 > test-i386.ref - -$(QEMU) test-i386 > test-i386.out - @if diff -u test-i386.ref test-i386.out ; then echo "Auto Test OK"; fi - -run-test-i386-fprem: test-i386-fprem - ./test-i386-fprem > test-i386-fprem.ref - -$(QEMU) test-i386-fprem > test-i386-fprem.out - @if diff -u test-i386-fprem.ref test-i386-fprem.out ; then echo "Auto Test OK"; fi - run-test-x86_64: test-x86_64 ./test-x86_64 > test-x86_64.ref -$(QEMU_X86_64) test-x86_64 > test-x86_64.out @if diff -u test-x86_64.ref test-x86_64.out ; then echo "Auto Test OK"; fi -run-test-mmap: test-mmap - -$(QEMU) ./test-mmap - -$(QEMU) -p 8192 ./test-mmap 8192 - -$(QEMU) -p 16384 ./test-mmap 16384 - -$(QEMU) -p 32768 ./test-mmap 32768 - -run-runcom: runcom - -$(QEMU) ./runcom $(SRC_PATH)/tests/pi_10.com - run-test_path: test_path ./test_path
@@ -84,37 +51,10 @@ test_path: test_path.o test_path.o: test_path.c -hello-i386: hello-i386.c - $(CC_I386) -nostdlib $(CFLAGS) -static $(LDFLAGS) -o $@ $< - strip $@ - -testthread: testthread.c - $(CC_I386) $(CFLAGS) $(LDFLAGS) -o $@ $< -lpthread - -# i386/x86_64 emulation test (test various opcodes) */ -test-i386: test-i386.c test-i386-code16.S test-i386-vm86.S \ - test-i386.h test-i386-shift.h test-i386-muldiv.h - $(CC_I386) $(QEMU_INCLUDES) $(CFLAGS) $(LDFLAGS) -o $@ \ - $(<D)/test-i386.c $(<D)/test-i386-code16.S $(<D)/test-i386-vm86.S -lm - -test-i386-fprem: test-i386-fprem.c - $(CC_I386) $(QEMU_INCLUDES) $(CFLAGS) $(LDFLAGS) -o $@ $^ - test-x86_64: test-i386.c \ test-i386.h test-i386-shift.h test-i386-muldiv.h $(CC_X86_64) $(QEMU_INCLUDES) $(CFLAGS) $(LDFLAGS) -o $@ $(<D)/test-i386.c -lm -# generic Linux and CPU test -linux-test: linux-test.c - $(CC_I386) $(CFLAGS) $(LDFLAGS) -o $@ $< -lm - -# vm86 test -runcom: runcom.c - $(CC_I386) $(CFLAGS) $(LDFLAGS) -o $@ $< - -test-mmap: test-mmap.c - $(CC_I386) -m32 $(CFLAGS) -Wall -O2 $(LDFLAGS) -o $@ $< - # speed test sha1-i386: sha1.c $(CC_I386) $(CFLAGS) $(LDFLAGS) -o $@ $<
tests/tcg/Makefile.include +73 -1
76 lines not on this page · raw message
Signature · 1 line
2.13.5
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [Qemu-devel] [PATCH RFC 0/7] Proof of concept to power up "make test" with docker
Message-id: [email protected]
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
t [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'0c7a642a86 tests: Move i386 tcg tests to check-tcg 44226ca4fd buildsys: Add "check-tcg" target e670c4e114 tests: Build fix for linux-test 09fbbd7842 tests: Build fix for hello-i386 0546399a8a docker: Add fedora-i386-cross image 5a8cd21a02 docker: Add "cc" subcommand 89d4346f6e Makefile: Rename TARGET_DIRS to TARGET_LIST
=== OUTPUT BEGIN ===
Checking PATCH 1/7: Makefile: Rename TARGET_DIRS to TARGET_LIST... Checking PATCH 2/7: docker: Add "cc" subcommand... Checking PATCH 3/7: docker: Add fedora-i386-cross image... Checking PATCH 4/7: tests: Build fix for hello-i386...
ERROR: externs should be avoided in .c files
#20: FILE: tests/tcg/hello-i386.c:23:
+void _start(void);
total: 1 errors, 0 warnings, 7 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 5/7: tests: Build fix for linux-test...
ERROR: if this code is redundant consider removing it #141: FILE: tests/tcg/linux-test.c:326:
+#if 0
total: 1 errors, 0 warnings, 179 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 6/7: buildsys: Add "check-tcg" target... Checking PATCH 7/7: tests: Move i386 tcg tests to check-tcg... === OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]