[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 37/37] docs/devel: testing: Document writing portable test cases
From: |
Thomas Huth |
Subject: |
[PULL 37/37] docs/devel: testing: Document writing portable test cases |
Date: |
Wed, 28 Sep 2022 09:18:43 +0200 |
From: Bin Meng <bin.meng@windriver.com>
Update the best practices of how to write portable test cases that
can be built and run successfully on both Linux and Windows hosts.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220927110632.1973965-55-bmeng.cn@gmail.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
docs/devel/testing.rst | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index aea5b42356..fbb98faabe 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -81,6 +81,36 @@ QTest cases can be executed with
make check-qtest
+Writing portable test cases
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Both unit tests and qtests can run on POSIX hosts as well as Windows hosts.
+Care must be taken when writing portable test cases that can be built and run
+successfully on various hosts. The following list shows some best practices:
+
+* Use portable APIs from glib whenever necessary, e.g.: g_setenv(),
+ g_mkdtemp(), g_mkdir().
+* Avoid using hardcoded /tmp for temporary file directory.
+ Use g_get_tmp_dir() instead.
+* Bear in mind that Windows has different special string representation for
+ stdin/stdout/stderr and null devices. For example if your test case uses
+ "/dev/fd/2" and "/dev/null" on Linux, remember to use "2" and "nul" on
+ Windows instead. Also IO redirection does not work on Windows, so avoid
+ using "2>nul" whenever necessary.
+* If your test cases uses the blkdebug feature, use relative path to pass
+ the config and image file paths in the command line as Windows absolute
+ path contains the delimiter ":" which will confuse the blkdebug parser.
+* Use double quotes in your extra QEMU commmand line in your test cases
+ instead of single quotes, as Windows does not drop single quotes when
+ passing the command line to QEMU.
+* Windows opens a file in text mode by default, while a POSIX compliant
+ implementation treats text files and binary files the same. So if your
+ test cases opens a file to write some data and later wants to compare the
+ written data with the original one, be sure to pass the letter 'b' as
+ part of the mode string to fopen(), or O_BINARY flag for the open() call.
+* If a certain test case can only run on POSIX or Linux hosts, use a proper
+ #ifdef in the codes. If the whole test suite cannot run on Windows, disable
+ the build in the meson.build file.
+
QAPI schema tests
~~~~~~~~~~~~~~~~~
--
2.31.1
- [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU, (continued)
- [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU, Thomas Huth, 2022/09/28
- [PULL 09/37] tests/qtest: ide-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 12/37] tests/qtest: virtio-scsi-test: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 16/37] tests: vhost-user-bridge: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 17/37] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32, Thomas Huth, 2022/09/28
- [PULL 23/37] tests/qtest: bios-tables-test: Adapt the case for win32, Thomas Huth, 2022/09/28
- [PULL 25/37] tests/qtest: ide-test: Open file in binary mode, Thomas Huth, 2022/09/28
- [PULL 29/37] tests/qtest: migration-test: Skip running some TLS cases for win32, Thomas Huth, 2022/09/28
- [PULL 08/37] tests/qtest: virtio_blk_fuzz: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 14/37] tests/unit: test-image-locking: Avoid using hardcoded /tmp, Thomas Huth, 2022/09/28
- [PULL 37/37] docs/devel: testing: Document writing portable test cases,
Thomas Huth <=
- [PULL 18/37] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only, Thomas Huth, 2022/09/28
- [PULL 19/37] tests/qtest: qmp-test: Skip running test_qmp_oob for win32, Thomas Huth, 2022/09/28
- [PULL 26/37] tests/qtest: virtio-net-failover: Disable migration tests for win32, Thomas Huth, 2022/09/28
- [PULL 31/37] tests/x86: Move common code to function in device-plug-test, Thomas Huth, 2022/09/28
- Re: [PULL 00/37] qtests fixes, Stefan Hajnoczi, 2022/09/29