105caa062SThomas Huth================================== 205caa062SThomas HuthACPI/SMBIOS testing using biosbits 305caa062SThomas Huth================================== 4d65f1ed7SAni Sinha************ 5d65f1ed7SAni SinhaIntroduction 6d65f1ed7SAni Sinha************ 7a5ebaaf9SAni SinhaBiosbits is a software written by Josh Triplett that can be downloaded 8a5ebaaf9SAni Sinhafrom https://biosbits.org/. The github codebase can be found 9d65f1ed7SAni Sinha`here <https://github.com/biosbits/bits/tree/master>`__. It is a software that 10d65f1ed7SAni Sinhaexecutes the bios components such as acpi and smbios tables directly through 11d65f1ed7SAni Sinhaacpica bios interpreter (a freely available C based library written by Intel, 12a5ebaaf9SAni Sinhadownloadable from https://acpica.org/ and is included with biosbits) without an 13d65f1ed7SAni Sinhaoperating system getting involved in between. Bios-bits has python integration 14d65f1ed7SAni Sinhawith grub so actual routines that executes bios components can be written in 15d65f1ed7SAni Sinhapython instead of bash-ish (grub's native scripting language). 16a5ebaaf9SAni SinhaThere are several advantages to directly testing the bios in a real physical 17d65f1ed7SAni Sinhamachine or in a VM as opposed to indirectly discovering bios issues through the 18d65f1ed7SAni Sinhaoperating system (the OS). Operating systems tend to bypass bios problems and 19d65f1ed7SAni Sinhahide them from the end user. We have more control of what we wanted to test and 20d65f1ed7SAni Sinhahow by being as close to the bios on a running system as possible without a 21d65f1ed7SAni Sinhacomplicated software component such as an operating system coming in between. 22d65f1ed7SAni SinhaAnother issue is that we cannot exercise bios components such as ACPI and 23d65f1ed7SAni SinhaSMBIOS without being in the highest hardware privilege level, ring 0 for 24d65f1ed7SAni Sinhaexample in case of x86. Since the OS executes from ring 0 whereas normal user 25d65f1ed7SAni Sinhaland software resides in unprivileged ring 3, operating system must be modified 26d65f1ed7SAni Sinhain order to write our test routines that exercise and test the bios. This is 27d65f1ed7SAni Sinhanot possible in all cases. Lastly, test frameworks and routines are preferably 28d65f1ed7SAni Sinhawritten using a high level scripting language such as python. OSes and 29d65f1ed7SAni SinhaOS modules are generally written using low level languages such as C and 30d65f1ed7SAni Sinhalow level assembly machine language. Writing test routines in a low level 31d65f1ed7SAni Sinhalanguage makes things more cumbersome. These and other reasons makes using 32d65f1ed7SAni Sinhabios-bits very attractive for testing bioses. More details on the inspiration 33*232c3a84SPaolo Bonzinifor developing biosbits and its real life uses were presented `at Plumbers 34*232c3a84SPaolo Bonziniin 2011 <Plumbers_>`__ and `at Linux.conf.au in 2012 <Linux.conf.au_>`__. 35d65f1ed7SAni Sinha 36*232c3a84SPaolo BonziniFor QEMU, we maintain a fork of bios bits in `gitlab`_, along with all 37*232c3a84SPaolo Bonzinithe dependent submodules. This fork contains numerous fixes, a newer 38*232c3a84SPaolo Bonziniacpica and changes specific to running these functional QEMU tests using 39*232c3a84SPaolo Bonzinibits. The author of this document is the current maintainer of the QEMU 40*232c3a84SPaolo Bonzinifork of bios bits repository. For more information, please see `the 41*232c3a84SPaolo Bonziniauthor's FOSDEM presentation <FOSDEM_>`__ on this bios-bits based test framework. 42*232c3a84SPaolo Bonzini 43*232c3a84SPaolo Bonzini.. _Plumbers: https://blog.linuxplumbersconf.org/2011/ocw/system/presentations/867/original/bits.pdf 44*232c3a84SPaolo Bonzini.. _Linux.conf.au: https://www.youtube.com/watch?v=36QIepyUuhg 45*232c3a84SPaolo Bonzini.. _gitlab: https://gitlab.com/qemu-project/biosbits-bits 46*232c3a84SPaolo Bonzini.. _FOSDEM: https://fosdem.org/2024/schedule/event/fosdem-2024-2262-exercising-qemu-generated-acpi-smbios-tables-using-biosbits-from-within-a-guest-vm-/ 47d65f1ed7SAni Sinha 48d65f1ed7SAni Sinha********************************* 49d65f1ed7SAni SinhaDescription of the test framework 50d65f1ed7SAni Sinha********************************* 51a5ebaaf9SAni Sinha 5205caa062SThomas HuthUnder the directory ``tests/functional/``, ``test_acpi_bits.py`` is a QEMU 5305caa062SThomas Huthfunctional test that drives all this. 54a5ebaaf9SAni Sinha 55a5ebaaf9SAni SinhaA brief description of the various test files follows. 56a5ebaaf9SAni Sinha 5705caa062SThomas HuthUnder ``tests/functional/`` as the root we have: 58a5ebaaf9SAni Sinha 59a5ebaaf9SAni Sinha:: 60a5ebaaf9SAni Sinha 61a5ebaaf9SAni Sinha ├── acpi-bits 62a5ebaaf9SAni Sinha │ ├── bits-config 63a5ebaaf9SAni Sinha │ │ └── bits-cfg.txt 64a5ebaaf9SAni Sinha │ ├── bits-tests 651b7a07c4SAni Sinha │ ├── smbios.py2 661b7a07c4SAni Sinha │ ├── testacpi.py2 671b7a07c4SAni Sinha │ └── testcpuid.py2 6805caa062SThomas Huth ├── test_acpi_bits.py 69a5ebaaf9SAni Sinha 7005caa062SThomas Huth* ``tests/functional``: 71a5ebaaf9SAni Sinha 7205caa062SThomas Huth ``test_acpi_bits.py``: 7305caa062SThomas Huth This is the main python functional test script that generates a 74a5ebaaf9SAni Sinha biosbits iso. It then spawns a QEMU VM with it, collects the log and reports 75a5ebaaf9SAni Sinha test failures. This is the script one would be interested in if they wanted 76a5ebaaf9SAni Sinha to add or change some component of the log parsing, add a new command line 77a5ebaaf9SAni Sinha to alter how QEMU is spawned etc. Test writers typically would not need to 78a5ebaaf9SAni Sinha modify this script unless they wanted to enhance or change the log parsing 79a5ebaaf9SAni Sinha for their tests. In order to enable debugging, you can set **V=1** 80a5ebaaf9SAni Sinha environment variable. This enables verbose mode for the test and also dumps 81a5ebaaf9SAni Sinha the entire log from bios bits and more information in case failure happens. 8265809a60SAni Sinha You can also set **BITS_DEBUG=1** to turn on debug mode. It will enable 8365809a60SAni Sinha verbose logs and also retain the temporary work directory the test used for 8465809a60SAni Sinha you to inspect and run the specific commands manually. 85a5ebaaf9SAni Sinha 86a5ebaaf9SAni Sinha In order to run this test, please perform the following steps from the QEMU 8705caa062SThomas Huth build directory (assuming that the sources are in ".."): 88a5ebaaf9SAni Sinha :: 89a5ebaaf9SAni Sinha 9005caa062SThomas Huth $ export PYTHONPATH=../python:../tests/functional 9105caa062SThomas Huth $ export QEMU_TEST_QEMU_BINARY=$PWD/qemu-system-x86_64 9205caa062SThomas Huth $ python3 ../tests/functional/test_acpi_bits.py 93a5ebaaf9SAni Sinha 9405caa062SThomas Huth The above will run all acpi-bits functional tests (producing output in 9505caa062SThomas Huth tap format). 96a5ebaaf9SAni Sinha 9705caa062SThomas Huth You can inspect the log files in tests/functional/x86_64/test_acpi_bits.*/ 9805caa062SThomas Huth for more information about the run or in order to diagnoze issues. 9905caa062SThomas Huth If you pass V=1 in the environment, more diagnostic logs will be put into 10005caa062SThomas Huth the test log. 101a5ebaaf9SAni Sinha 10205caa062SThomas Huth* ``tests/functional/acpi-bits/bits-config``: 103a5ebaaf9SAni Sinha 104a5ebaaf9SAni Sinha This location contains biosbits configuration files that determine how the 105a5ebaaf9SAni Sinha software runs the tests. 106a5ebaaf9SAni Sinha 107a5ebaaf9SAni Sinha ``bits-config.txt``: 108a5ebaaf9SAni Sinha This is the biosbits config file that determines what tests 109a5ebaaf9SAni Sinha or actions are performed by bits. The description of the config options are 110a5ebaaf9SAni Sinha provided in the file itself. 111a5ebaaf9SAni Sinha 11205caa062SThomas Huth* ``tests/functional/acpi-bits/bits-tests``: 113a5ebaaf9SAni Sinha 114a5ebaaf9SAni Sinha This directory contains biosbits python based tests that are run from within 115a5ebaaf9SAni Sinha the biosbits environment in the spawned VM. New additions of test cases can 116a5ebaaf9SAni Sinha be made in the appropriate test file. For example, new acpi tests can go 117a5ebaaf9SAni Sinha into testacpi.py2 and one would call testsuite.add_test() to register the new 118a5ebaaf9SAni Sinha test so that it gets executed as a part of the ACPI tests. 119a5ebaaf9SAni Sinha It might be occasionally necessary to disable some subtests or add a new 120a5ebaaf9SAni Sinha test that belongs to a test suite not already present in this directory. To 121a5ebaaf9SAni Sinha do this, please clone the bits source from 122a5ebaaf9SAni Sinha https://gitlab.com/qemu-project/biosbits-bits/-/tree/qemu-bits. 123a5ebaaf9SAni Sinha Note that this is the "qemu-bits" branch and not the "bits" branch of the 124a5ebaaf9SAni Sinha repository. "qemu-bits" is the branch where we have made all the QEMU 125a5ebaaf9SAni Sinha specific enhancements and we must use the source from this branch only. 126a5ebaaf9SAni Sinha Copy the test suite/script that needs modification (addition of new tests 127a5ebaaf9SAni Sinha or disabling them) from python directory into this directory. For 128a5ebaaf9SAni Sinha example, in order to change cpuid related tests, copy the following 129a5ebaaf9SAni Sinha file into this directory and rename it with .py2 extension: 130a5ebaaf9SAni Sinha https://gitlab.com/qemu-project/biosbits-bits/-/blob/qemu-bits/python/testcpuid.py 131a5ebaaf9SAni Sinha Then make your additions and changes here. Therefore, the steps are: 132a5ebaaf9SAni Sinha 133a5ebaaf9SAni Sinha (a) Copy unmodified test script to this directory from bits source. 134a5ebaaf9SAni Sinha (b) Add a SPDX license header. 135a5ebaaf9SAni Sinha (c) Perform modifications to the test. 136a5ebaaf9SAni Sinha 137d65f1ed7SAni Sinha Commits (a), (b) and (c) preferably should go under separate commits so that 138d65f1ed7SAni Sinha the original test script and the changes we have made are separated and 139d65f1ed7SAni Sinha clear. (a) and (b) can sometimes be combined into a single step. 140a5ebaaf9SAni Sinha 141a5ebaaf9SAni Sinha The test framework will then use your modified test script to run the test. 142a5ebaaf9SAni Sinha No further changes would be needed. Please check the logs to make sure that 143a5ebaaf9SAni Sinha appropriate changes have taken effect. 144a5ebaaf9SAni Sinha 145a5ebaaf9SAni Sinha The tests have an extension .py2 in order to indicate that: 146a5ebaaf9SAni Sinha 147a5ebaaf9SAni Sinha (a) They are python2.7 based scripts and not python 3 scripts. 148a5ebaaf9SAni Sinha (b) They are run from within the bios bits VM and is not subjected to QEMU 1492cb40d44SStefan Weil build/test python script maintenance and dependency resolutions. 15005caa062SThomas Huth (c) They need not be loaded by the test framework by accident when running 15105caa062SThomas Huth tests. 152a5ebaaf9SAni Sinha 153a5ebaaf9SAni Sinha 154607a079bSAni SinhaAuthor: Ani Sinha <anisinha@redhat.com> 155a5ebaaf9SAni Sinha 156