From mboxrd@z Thu Jan 1 00:00:00 1970 From: Romain Naour Date: Mon, 13 Apr 2020 23:38:08 +0200 Subject: [Buildroot] [PATCH v5 4/5] support/scripts/boot-qemu-image.py: boot Qemu images with Qemu-system. In-Reply-To: <20200413071532.GV29898@scaer> References: <20200217205030.8157-1-romain.naour@smile.fr> <20200217205030.8157-5-romain.naour@smile.fr> <20200413071532.GV29898@scaer> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: buildroot@busybox.net Hi Yann, All, Le 13/04/2020 ? 09:15, Yann E. MORIN a ?crit?: > Romain, Jugurtha, All, > > On 2020-02-17 21:50 +0100, Romain Naour spake thusly: >> From: Jugurtha BELKALEM >> This script is intended to be used by gitlab CI to test >> at runtime Qemu images generated by Buildroot's Qemu defconfigs. > [--SNIP--] >> diff --git a/support/scripts/boot-qemu-image.py b/support/scripts/boot-qemu-image.py >> new file mode 100755 >> index 0000000000..abaf88d446 >> --- /dev/null >> +++ b/support/scripts/boot-qemu-image.py >> @@ -0,0 +1,105 @@ >> +#!/usr/bin/env python3 >> + >> +# This script expect to run from the Buildroot top directory. >> + >> +import pexpect >> +import sys >> +import os >> +import re >> +import shlex >> +import shutil >> +import subprocess >> + >> +argc = len(sys.argv) >> +if not (argc == 2): >> + print("Error: incorrect number of arguments") >> + print("""Usage: boot-qemu-image.py """) >> + sys.exit(1) >> + >> +defconfig_filename = sys.argv[1] >> + >> +# Ignore non Qemu defconfig >> +if defconfig_filename.startswith('qemu_') is False: >> + sys.exit(0) >> + >> +qemu_start_script_filepath = os.path.join(os.getcwd(), 'output/images/start-qemu.sh') >> + >> +# Ignore if start-qemu.sh is missing, we can't test. >> +if not os.path.exists(qemu_start_script_filepath): >> + print("Error: " + qemu_start_script_filepath) + " file is missing." >> + sys.exit(1) >> + >> +qemu_cmd = "" >> + >> +with open(qemu_start_script_filepath, 'r') as script_file: >> + for line in script_file: >> + if re.search("qemu-system", line): >> + qemu_cmd = line >> + break >> + >> +if not qemu_cmd: >> + print("Error: No QEMU command line found in " + qemu_start_script_filepath) >> + sys.exit(1) > > Why do you extract the command line, and can't directly run the script? > >> +# Replace bashism >> +qemu_cmd = line.replace("${IMAGE_DIR}", "output/images") > > This would avoid this dance... > >> +# pexpect needs a list, convert a sting to a list and escape quoted substring. >> +qemu_cmd = shlex.split(qemu_cmd) > > ... as well as this one. > >> +# Use host Qemu if provided by Buildroot. >> +os.environ["PATH"] = os.getcwd() + "/output/host/bin" + os.pathsep + os.environ["PATH"] > > And this one can be avoided too if the script is called with PATH > properly set to include ${HOST_DIR}/bin. This should be easy, as this > script is only expected to run from the gitlab-ci pipelines. > >> +# Ignore when no Qemu emulation is available >> +if not shutil.which(qemu_cmd[0]): >> + print("No " + qemu_cmd[0] + " binary available, THIS DEFCONFIG CAN NOT BE TESTED!") >> + sys.exit(0) Extracting the qemu command line in the boot-qemu-image.py allowed to test if at least one qemu-systemd- binary is present. Starting start-qemu.sh directly crash the python script. https://gitlab.com/kubu93/buildroot/-/jobs/509053135/artifacts/file/runtime-test.log csky and or1k defconfig doesn't select any host-qemu and there is none installed in the Buildroot Docker image used by gitlab CI. It seems we need to catch the exception while calling pexpect.spawn(qemu_start...) https://git.buildroot.net/buildroot/tree/support/scripts/boot-qemu-image.py#n22 Or just add this test in start-qemu.sh Best regards, Romain