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