1*ff41da50SThomas Huth================================== 2*ff41da50SThomas HuthACPI/SMBIOS testing using biosbits 3*ff41da50SThomas Huth================================== 4*ff41da50SThomas Huth************ 5*ff41da50SThomas HuthIntroduction 6*ff41da50SThomas Huth************ 7*ff41da50SThomas HuthBiosbits is a software written by Josh Triplett that can be downloaded 8*ff41da50SThomas Huthfrom https://biosbits.org/. The github codebase can be found 9*ff41da50SThomas Huth`here <https://github.com/biosbits/bits/tree/master>`__. It is a software that 10*ff41da50SThomas Huthexecutes the bios components such as acpi and smbios tables directly through 11*ff41da50SThomas Huthacpica bios interpreter (a freely available C based library written by Intel, 12*ff41da50SThomas Huthdownloadable from https://acpica.org/ and is included with biosbits) without an 13*ff41da50SThomas Huthoperating system getting involved in between. Bios-bits has python integration 14*ff41da50SThomas Huthwith grub so actual routines that executes bios components can be written in 15*ff41da50SThomas Huthpython instead of bash-ish (grub's native scripting language). 16*ff41da50SThomas HuthThere are several advantages to directly testing the bios in a real physical 17*ff41da50SThomas Huthmachine or in a VM as opposed to indirectly discovering bios issues through the 18*ff41da50SThomas Huthoperating system (the OS). Operating systems tend to bypass bios problems and 19*ff41da50SThomas Huthhide them from the end user. We have more control of what we wanted to test and 20*ff41da50SThomas Huthhow by being as close to the bios on a running system as possible without a 21*ff41da50SThomas Huthcomplicated software component such as an operating system coming in between. 22*ff41da50SThomas HuthAnother issue is that we cannot exercise bios components such as ACPI and 23*ff41da50SThomas HuthSMBIOS without being in the highest hardware privilege level, ring 0 for 24*ff41da50SThomas Huthexample in case of x86. Since the OS executes from ring 0 whereas normal user 25*ff41da50SThomas Huthland software resides in unprivileged ring 3, operating system must be modified 26*ff41da50SThomas Huthin order to write our test routines that exercise and test the bios. This is 27*ff41da50SThomas Huthnot possible in all cases. Lastly, test frameworks and routines are preferably 28*ff41da50SThomas Huthwritten using a high level scripting language such as python. OSes and 29*ff41da50SThomas HuthOS modules are generally written using low level languages such as C and 30*ff41da50SThomas Huthlow level assembly machine language. Writing test routines in a low level 31*ff41da50SThomas Huthlanguage makes things more cumbersome. These and other reasons makes using 32*ff41da50SThomas Huthbios-bits very attractive for testing bioses. More details on the inspiration 33*ff41da50SThomas Huthfor developing biosbits and its real life uses can be found in [#a]_ and [#b]_. 34*ff41da50SThomas Huth 35*ff41da50SThomas HuthFor QEMU, we maintain a fork of bios bits in gitlab along with all the 36*ff41da50SThomas Huthdependent submodules `here <https://gitlab.com/qemu-project/biosbits-bits>`__. 37*ff41da50SThomas HuthThis fork contains numerous fixes, a newer acpica and changes specific to 38*ff41da50SThomas Huthrunning these functional QEMU tests using bits. The author of this document 39*ff41da50SThomas Huthis the sole maintainer of the QEMU fork of bios bits repository. For more 40*ff41da50SThomas Huthinformation, please see author's `FOSDEM talk on this bios-bits based test 41*ff41da50SThomas Huthframework <https://fosdem.org/2024/schedule/event/fosdem-2024-2262-exercising-qemu-generated-acpi-smbios-tables-using-biosbits-from-within-a-guest-vm-/>`__. 42*ff41da50SThomas Huth 43*ff41da50SThomas Huth********************************* 44*ff41da50SThomas HuthDescription of the test framework 45*ff41da50SThomas Huth********************************* 46*ff41da50SThomas Huth 47*ff41da50SThomas HuthUnder the directory ``tests/functional/``, ``test_acpi_bits.py`` is a QEMU 48*ff41da50SThomas Huthfunctional test that drives all this. 49*ff41da50SThomas Huth 50*ff41da50SThomas HuthA brief description of the various test files follows. 51*ff41da50SThomas Huth 52*ff41da50SThomas HuthUnder ``tests/functional/`` as the root we have: 53*ff41da50SThomas Huth 54*ff41da50SThomas Huth:: 55*ff41da50SThomas Huth 56*ff41da50SThomas Huth ├── acpi-bits 57*ff41da50SThomas Huth │ ├── bits-config 58*ff41da50SThomas Huth │ │ └── bits-cfg.txt 59*ff41da50SThomas Huth │ ├── bits-tests 60*ff41da50SThomas Huth │ ├── smbios.py2 61*ff41da50SThomas Huth │ ├── testacpi.py2 62*ff41da50SThomas Huth │ └── testcpuid.py2 63*ff41da50SThomas Huth ├── test_acpi_bits.py 64*ff41da50SThomas Huth 65*ff41da50SThomas Huth* ``tests/functional``: 66*ff41da50SThomas Huth 67*ff41da50SThomas Huth ``test_acpi_bits.py``: 68*ff41da50SThomas Huth This is the main python functional test script that generates a 69*ff41da50SThomas Huth biosbits iso. It then spawns a QEMU VM with it, collects the log and reports 70*ff41da50SThomas Huth test failures. This is the script one would be interested in if they wanted 71*ff41da50SThomas Huth to add or change some component of the log parsing, add a new command line 72*ff41da50SThomas Huth to alter how QEMU is spawned etc. Test writers typically would not need to 73*ff41da50SThomas Huth modify this script unless they wanted to enhance or change the log parsing 74*ff41da50SThomas Huth for their tests. In order to enable debugging, you can set **V=1** 75*ff41da50SThomas Huth environment variable. This enables verbose mode for the test and also dumps 76*ff41da50SThomas Huth the entire log from bios bits and more information in case failure happens. 77*ff41da50SThomas Huth You can also set **BITS_DEBUG=1** to turn on debug mode. It will enable 78*ff41da50SThomas Huth verbose logs and also retain the temporary work directory the test used for 79*ff41da50SThomas Huth you to inspect and run the specific commands manually. 80*ff41da50SThomas Huth 81*ff41da50SThomas Huth In order to run this test, please perform the following steps from the QEMU 82*ff41da50SThomas Huth build directory (assuming that the sources are in ".."): 83*ff41da50SThomas Huth :: 84*ff41da50SThomas Huth 85*ff41da50SThomas Huth $ export PYTHONPATH=../python:../tests/functional 86*ff41da50SThomas Huth $ export QEMU_TEST_QEMU_BINARY=$PWD/qemu-system-x86_64 87*ff41da50SThomas Huth $ python3 ../tests/functional/test_acpi_bits.py 88*ff41da50SThomas Huth 89*ff41da50SThomas Huth The above will run all acpi-bits functional tests (producing output in 90*ff41da50SThomas Huth tap format). 91*ff41da50SThomas Huth 92*ff41da50SThomas Huth You can inspect the log files in tests/functional/x86_64/test_acpi_bits.*/ 93*ff41da50SThomas Huth for more information about the run or in order to diagnoze issues. 94*ff41da50SThomas Huth If you pass V=1 in the environment, more diagnostic logs will be put into 95*ff41da50SThomas Huth the test log. 96*ff41da50SThomas Huth 97*ff41da50SThomas Huth* ``tests/functional/acpi-bits/bits-config``: 98*ff41da50SThomas Huth 99*ff41da50SThomas Huth This location contains biosbits configuration files that determine how the 100*ff41da50SThomas Huth software runs the tests. 101*ff41da50SThomas Huth 102*ff41da50SThomas Huth ``bits-config.txt``: 103*ff41da50SThomas Huth This is the biosbits config file that determines what tests 104*ff41da50SThomas Huth or actions are performed by bits. The description of the config options are 105*ff41da50SThomas Huth provided in the file itself. 106*ff41da50SThomas Huth 107*ff41da50SThomas Huth* ``tests/functional/acpi-bits/bits-tests``: 108*ff41da50SThomas Huth 109*ff41da50SThomas Huth This directory contains biosbits python based tests that are run from within 110*ff41da50SThomas Huth the biosbits environment in the spawned VM. New additions of test cases can 111*ff41da50SThomas Huth be made in the appropriate test file. For example, new acpi tests can go 112*ff41da50SThomas Huth into testacpi.py2 and one would call testsuite.add_test() to register the new 113*ff41da50SThomas Huth test so that it gets executed as a part of the ACPI tests. 114*ff41da50SThomas Huth It might be occasionally necessary to disable some subtests or add a new 115*ff41da50SThomas Huth test that belongs to a test suite not already present in this directory. To 116*ff41da50SThomas Huth do this, please clone the bits source from 117*ff41da50SThomas Huth https://gitlab.com/qemu-project/biosbits-bits/-/tree/qemu-bits. 118*ff41da50SThomas Huth Note that this is the "qemu-bits" branch and not the "bits" branch of the 119*ff41da50SThomas Huth repository. "qemu-bits" is the branch where we have made all the QEMU 120*ff41da50SThomas Huth specific enhancements and we must use the source from this branch only. 121*ff41da50SThomas Huth Copy the test suite/script that needs modification (addition of new tests 122*ff41da50SThomas Huth or disabling them) from python directory into this directory. For 123*ff41da50SThomas Huth example, in order to change cpuid related tests, copy the following 124*ff41da50SThomas Huth file into this directory and rename it with .py2 extension: 125*ff41da50SThomas Huth https://gitlab.com/qemu-project/biosbits-bits/-/blob/qemu-bits/python/testcpuid.py 126*ff41da50SThomas Huth Then make your additions and changes here. Therefore, the steps are: 127*ff41da50SThomas Huth 128*ff41da50SThomas Huth (a) Copy unmodified test script to this directory from bits source. 129*ff41da50SThomas Huth (b) Add a SPDX license header. 130*ff41da50SThomas Huth (c) Perform modifications to the test. 131*ff41da50SThomas Huth 132*ff41da50SThomas Huth Commits (a), (b) and (c) preferably should go under separate commits so that 133*ff41da50SThomas Huth the original test script and the changes we have made are separated and 134*ff41da50SThomas Huth clear. (a) and (b) can sometimes be combined into a single step. 135*ff41da50SThomas Huth 136*ff41da50SThomas Huth The test framework will then use your modified test script to run the test. 137*ff41da50SThomas Huth No further changes would be needed. Please check the logs to make sure that 138*ff41da50SThomas Huth appropriate changes have taken effect. 139*ff41da50SThomas Huth 140*ff41da50SThomas Huth The tests have an extension .py2 in order to indicate that: 141*ff41da50SThomas Huth 142*ff41da50SThomas Huth (a) They are python2.7 based scripts and not python 3 scripts. 143*ff41da50SThomas Huth (b) They are run from within the bios bits VM and is not subjected to QEMU 144*ff41da50SThomas Huth build/test python script maintenance and dependency resolutions. 145*ff41da50SThomas Huth (c) They need not be loaded by the test framework by accident when running 146*ff41da50SThomas Huth tests. 147*ff41da50SThomas Huth 148*ff41da50SThomas Huth 149*ff41da50SThomas HuthAuthor: Ani Sinha <anisinha@redhat.com> 150*ff41da50SThomas Huth 151*ff41da50SThomas HuthReferences: 152*ff41da50SThomas Huth----------- 153*ff41da50SThomas Huth.. [#a] https://blog.linuxplumbersconf.org/2011/ocw/system/presentations/867/original/bits.pdf 154*ff41da50SThomas Huth.. [#b] https://www.youtube.com/watch?v=36QIepyUuhg 155*ff41da50SThomas Huth.. [#c] https://fosdem.org/2024/schedule/event/fosdem-2024-2262-exercising-qemu-generated-acpi-smbios-tables-using-biosbits-from-within-a-guest-vm-/ 156