aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/qemu_test
AgeCommit message (Collapse)Author
2024-11-25tests/functional: avoid accessing log_filename on earlier failuresDaniel P. Berrangé
If a failure occurs early in the QemuBaseTest constructor, the 'log_filename' object atttribute may not exist yet. This happens most notably if the QEMU_TEST_QEMU_BINARY is not set. We can't initialize 'log_filename' earlier as we use the binary to identify the architecture which is then used to build the path in which the logs are stored. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-19-berrange@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-19-alex.bennee@linaro.org>
2024-11-25tests/functional: add a QMP backdoor for debugging stalled testsDaniel P. Berrangé
Support the QEMU_TEST_QMP_BACKDOOR=backdoor.sock env variable as a way to get a QMP backdoor for debugging a stalled QEMU test. Most typically this would be used if running the tests directly: $ QEMU_TEST_QMP_BACKDOOR=backdoor.sock \ QEMU_TEST_QEMU_BINARY=./build/qemu-system-arm \ PYTHONPATH=./python \ ./tests/functional/test_arm_tuxrun.py And then, when the test stalls, in a second shell run: $ ./scripts/qmp/qmp-shell backdoor.sock Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-18-berrange@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-18-alex.bennee@linaro.org>
2024-11-25tests/functional: remove time.sleep usage from tuxrun testsDaniel P. Berrangé
The tuxrun tests send a series of strings to the guest to login and then run commands. Since we have been unable to match on console output that isn't followed by a newline, the test used many time.sleep() statements to pretend to synchronize with the guest. This has proved to be unreliable for the aarch64be instance of the tuxrun tests, with the test often hanging. The hang is a very subtle timing problem, and it is suspected that some (otherwise apparently harmless) I/O error messages could be resulting in full FIFO buffers, stalling interaction with the guest. With the newly rewritten console interaction able to match strings that don't have a following newline, the tux run tests can now match directly on the login prompt, and/or shell PS1 prompt. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2689 Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-17-berrange@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-17-alex.bennee@linaro.org>
2024-11-25tests/functional: rewrite console handling to be bytewiseDaniel P. Berrangé
The console interaction that waits for predicted strings uses readline(), and thus is only capable of waiting for strings that are followed by a newline. This is inconvenient when needing to match on some things, particularly login prompts, or shell prompts, causing tests to use time.sleep(...) instead, which is unreliable. Switch to reading the console 1 byte at a time, comparing against the success/failure messages until we see a match, regardless of whether a newline is encountered. The success/failure comparisons are done with the python bytes type, rather than strings, to avoid the problem of needing to decode partially received multibyte utf8 characters. Heavily inspired by a patch proposed by Cédric, but written again to work in bytes, rather than strings. Co-developed-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-16-berrange@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-16-alex.bennee@linaro.org>
2024-11-25tests/functional: require non-NULL success_message for console waitDaniel P. Berrangé
When waiting for expected output, the 'success_message' is a mandatory parameter, with 'failure_message' defaulting to None. The code has logic which indicates it was trying to cope with 'success_message' being None and 'failure_message' being non-None but it does not appear able to actually do anything useful. The check for 'success_message is None' will break out of the loop before any check for 'failure_message' has been performed. IOW, for practcal purposes 'success_message' must be non-None unless 'send_string' is set. Assert this expectation and simplify the loop logic. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-15-berrange@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-15-alex.bennee@linaro.org>
2024-11-25tests/functional: logs details of console interaction operationsDaniel P. Berrangé
When functional tests go wrong, it will often be related to the console interaction wait state. By logging the messages that we're looking for, and data we're about to be sending, it'll be easier to diagnose where tests are getting stuck. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-13-berrange@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-13-alex.bennee@linaro.org>
2024-11-25tests/functional: enable debug logging for QEMUMachineDaniel P. Berrangé
Set the 'qemu.machine' logger to 'DEBUG' level, to ensure we see log messages related to the QEMUMachine class. Most importantly this ensures we capture the full QEMU command line args for instances we spawn. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-12-berrange@redhat.com> Tested-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-Id: <20241121165806.476008-12-alex.bennee@linaro.org>
2024-11-25tests/functional: honour requested test VM name in QEMUMachineDaniel P. Berrangé
The functional test case class is going to the trouble of passing around a machine name, but then fails to give this QEMUMachine. As a result, QEMUMachine will create a completely random name. Since log file names match the machine name, this results in log files accumulating over time. Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-11-berrange@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-11-alex.bennee@linaro.org>
2024-11-25tests/functional: put QEMUMachine logs in testcase log directoryDaniel P. Berrangé
We are not passing the 'log_dir' parameter to QEMUMachine, so the QEMU stdout/err logs are being placed in a temp directory and thus deleted after execution. This makes them inaccessible as gitlab CI artifacts. Pass the testcase log directory path into QEMUMachine to make the logs persistent. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-10-berrange@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-10-alex.bennee@linaro.org>
2024-11-25tests/functional: remove obsolete reference to avocado bugDaniel P. Berrangé
Historical bugs in avocado related to zstd support are not relevant to the code now that it uses QEMU's native test harness. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-7-berrange@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-7-alex.bennee@linaro.org>
2024-11-25tests/functional: automatically clean up scratch files after testsDaniel P. Berrangé
The build/tests/functional subdirectories are consuming huge amounts of disk space. Split the location for scratch files into a 'scratch' sub-directory, separate from log files, and delete it upon completion of each test. The new env variable QEMU_TEST_KEEP_SCRATCH can be set to preserve this scratch dir for debugging access if required. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20241121154218.1423005-3-berrange@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-3-alex.bennee@linaro.org>
2024-11-08tests/functional: Provide the user with hints where to find more log filesThomas Huth
Since the base.log and console.log files are not referenced from the meson test logs yet, they might be hard to find for the casual users. Thus let's print some hints in case a test case failed. For this we have to run unittest.main() with exit=False to get the results of the testing. Then we can iterate through the failed test cases to print out the information accordingly. Message-ID: <20241105123849.359391-1-thuth@redhat.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Tested-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-11-04tests/functional: Convert BananaPi tests to the functional frameworkThomas Huth
Move the BananaPi tests from tests/avocado/boot_linux_console.py into a new file dedicated for Banana Pi tests in the functional framework. Update the hash sums of the assets to sha256 along the way and fix the broken link for the buildroot image from storage.kernelci.org. (Note: The test_arm_bpim2u_openwrt_22_03_3 test is currently broken due to a regression in commit 4c2c047469 ("target/arm: Fix usage of MMU indexes when EL3 is AArch32") - it works if that commit gets reverted) Signed-off-by: Thomas Huth <thuth@redhat.com> Message-ID: <20241029092440.25021-2-thuth@redhat.com>
2024-11-04tests/functional: make cached asset files read-onlyDaniel P. Berrangé
This ensures that if a functional test runs QEMU with a writable disk pointing to a cached asset, an error will be reported, rather than silently modifying the cache file. As an example, tweaking test_sbsaref.py to set snapshot=off, results in a clear error: Command: ./build/qemu-system-aarch64 ...snip... -drive file=/var/home/berrange/.cache/qemu/download/44cdbae275ef1bb6dab1d5fbb59473d4f741e1c8ea8a80fd9e906b531d6ad461,format=raw,snapshot=off -cpu max,pauth=off Output: qemu-system-aarch64: Could not open '/var/home/berrange/.cache/qemu/download/44cdbae275ef1bb6dab1d5fbb59473d4f741e1c8ea8a80fd9e906b531d6ad461': Permission denied Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Tested-by: Thomas Huth <thuth@redhat.com> Message-ID: <20241025092659.2312118-3-berrange@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-11-04tests/functional: make tuxrun disk images writableDaniel P. Berrangé
The zstd command will preserve the input archive permissions on the output file. So when we decompress the readonly cached image, the resulting per-test run private disk image will also be readonly. We need it to be writable, so make it so. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-ID: <20241025092659.2312118-2-berrange@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-10-21tests/functional: Add a base class for the TuxRun testsThomas Huth
Add a base class for the TuxRun tests, based on the code from tests/avocado/tuxrun_baselines.py (the test have to be put into separate file in the following commits, depending on the target architecture that gets tested). Signed-off-by: Thomas Huth <thuth@redhat.com> Message-ID: <20241011131937.377223-2-thuth@redhat.com>
2024-10-04tests/functional: Fix hash validationThomas Huth
The _check() function is supposed to check whether the hash of the downloaded file matches the expected one. Unfortunately, during the last rework of this function, the check was accidentally turned into returning the hash value itself instead of a True/False value, effectively accepting each hash as valid. Let's do a proper check again now. Fixes:05e303210d ("tests/functional/qemu_test: Use Python hashlib ...") Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2024-09-24tests/functional/qemu_test: Add a function for launching kernels more easilyThomas Huth
The task for launching a kernel is quite repetitive: Set the serial console, set the -kernel and maybe -initrd and -dtb parameters, launch the VM and then wait for the expected console output. So it's easier in some tests to provide these steps via a separate function. Message-ID: <20240919185749.71222-2-thuth@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-11tests/functional/qemu_test: Use Python hashlib instead of external programsThomas Huth
Some systems (like OpenBSD) do not have the sha256sum or sha512sum programs installed by default, or use different names for those. Use the Python hashlib instead so we don't have to rely on the external programs. Reported-by: Peter Maydell <peter.maydell@linaro.org> Message-ID: <20240910201742.239559-1-thuth@redhat.com> Reviewed-by: Brian Cain <bcain@quicinc.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-11tests/functional: Fix bad usage of has_cmdThomas Huth
has_cmd returns a tuple, not a boolean value. This fixes a crash when e.g. "tesseract" is not available in the test_m68k_nextcube test. Reported-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20240910075820.51346-1-thuth@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-11tests/functional: Add the LinuxKernelTest for testing the Linux boot processThomas Huth
Copy the LinuxKernelTest from tests/acceptance/boot_linux_console.py to be able to convert the related tests to the functional test framework in the following patches. Message-ID: <20240906180549.792832-2-thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Convert ARM bFLT linux-user avocado testPhilippe Mathieu-Daudé
Straight forward conversion. Update the SHA1 hashes to SHA256 hashes since SHA1 should not be used anymore nowadays. Expose cpio_extract() in qemu_test.utils for possible reuse. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240822104238.75045-3-philmd@linaro.org> [thuth: Add test to meson.build] Message-ID: <20240830133841.142644-39-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Add QemuUserTest classPhilippe Mathieu-Daudé
Per commit 5334df4822 ("tests/avocado: Introduce QemuUserTest base class"): Similarly to the 'System' Test base class with methods for testing system emulation, the QemuUserTest class contains methods useful to test user-mode emulation. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240822104238.75045-2-philmd@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-ID: <20240830133841.142644-38-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Convert Aarch64 Virt machine avocado testsPhilippe Mathieu-Daudé
Straight forward conversion. Update the SHA1 hash to SHA256 since SHA1 should not be used anymore nowadays. Provide get_qemu_img() helper in qemu_test. $ make check-functional-aarch64 V=1 ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv2 OK ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv3 OK ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_alpine_virt_tcg_gic_max OK 1/4 qemu:func-thorough+func-aarch64-thorough+thorough / func-aarch64-aarch64_virt OK 30.44s 3 subtests passed ... Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240826103634.52384-1-philmd@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-ID: <20240830133841.142644-36-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Convert the rx_gdbsim avocado test into a standalone testThomas Huth
Provide a "gzip_uncompress" function based on the standard "gzip" module to avoid the usage of avocado.utils here. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240830133841.142644-31-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Convert the m68k nextcube test with tesseractThomas Huth
The code that handles running of tesseract needs to be tweaked a little bit to be able to run without the functions from avocado.utils, and while we're at it, drop some legacy stuff that was still there due to Tesseract 3 support that we already dropped a while ago. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240830133841.142644-29-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Convert the s390x avocado tests into standalone testsThomas Huth
These tests use archive.lzma_uncompress() from the Avocado utils, so provide a small helper function for this, based on the standard lzma module from Python instead. And while we're at it, replace the MD5 hashes in the topology test with proper SHA256 hashes, since MD5 should not be used anymore nowadays. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240830133841.142644-21-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Add a function for extracting files from an archiveThomas Huth
Some Avocado-based tests use the "archive" module from avocado.utils to extract files from an archive. To be able to use these tests without Avocado, we have to provide our own function for extracting files. Fortunately, there is already the tarfile module that will provide us with this functionality, so let's just add a nice wrapper function around that. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20240830133841.142644-19-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Allow asset downloading with concurrent threadsThomas Huth
When running "make -j$(nproc) check-functional", tests that use the same asset might be running in parallel. Improve the downloading to detect this situation and wait for the other thread to finish the download. Message-ID: <20240830133841.142644-17-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: enable pre-emptive caching of assetsDaniel P. Berrangé
Many tests need to access assets stored on remote sites. We don't want to download these during test execution when run by meson, since this risks hitting test timeouts when data transfers are slow. Add support for pre-emptive caching of assets by setting the env var QEMU_TEST_PRECACHE to point to a timestamp file. When this is set, instead of running the test, the assets will be downloaded and saved to the cache, then the timestamp file created. A meson custom target is created as a dependency of each test suite to trigger the pre-emptive caching logic before the test runs. When run in caching mode, it will locate assets by looking for class level variables with a name prefix "ASSET_", and type "Asset". At the ninja level ninja test --suite functional will speculatively download any assets that are not already cached, so it is advisable to set a timeout multiplier. QEMU_TEST_NO_DOWNLOAD=1 ninja test --suite functional will fail the test if a required asset is not already cached ninja precache-functional will download and cache all assets required by the functional tests At the make level, precaching is always done by make check-functional Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Tested-by: Richard Henderson <richard.henderson@linaro.org> [thuth: Remove the duplicated "path = os.path.basename(...)" line] Message-ID: <20240830133841.142644-16-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: add a module for handling asset download & cachingDaniel P. Berrangé
The 'Asset' class is a simple module that declares a downloadable asset that can be cached locally. Downloads are stored in the user's home dir at ~/.cache/qemu/download, using a sha256 sum of the URL. [thuth: Drop sha1 support, use hash on file content for naming instead of URL, add the possibility to specify the cache dir via environment variable] Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20240830133841.142644-15-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Set up loggingThomas Huth
Create log files for each test separately, one file that contains the basic logging and one that contains the console output. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20240830133841.142644-10-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-09-04tests/functional: Add base classes for the upcoming pytest-based testsThomas Huth
The files are mostly a copy of the tests/avocado/avocado_qemu/__init__.py file with some adjustments to get rid of the Avocado dependencies (i.e. we also have to drop the LinuxSSHMixIn and LinuxTest for now). The emulator binary and build directory are now passed via environment variables that will be set via meson.build later. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20240830133841.142644-9-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>