Skip to content

WIP: Make ACPI testable

Julien Férard requested to merge jferard/kernel:clean_aml into master

Note: I didn't find the "provided form" (14. in https://gitlab.redox-os.org/redox-os/redox/blob/master/CONTRIBUTING.md#creating-a-pr). I'll try to give as much information as I can

This is a work in progress. The main goal is to reduce coupling between ACPI and the rest of the kernel and to unit test ACPI.

But there are a lot of things in this MR on ACPI:

  • I added comments everywhere it was possible;
  • I used constants instead of magic numbers;
  • I moved, when possible, the switch out of parse functions: since we know the opcode in the main parse functions, we can decide which object we have to parse;
  • I put all connections between ACPI and the rest of the kernel in a trait KernelServiceForAcpi. The kernel implements this trait in arch.

I made a little script here to unit test ACPI. This script copies the acpi directory in a temp directory and creates a temp fake cargo project to run the tests.

jferard@jferard-Z170XP-SLI:~/prog/rust/perso-redox/work-in-progress$ python3 acpi-tester.py ~/prog/rust/redox/kernel/
.:
.:
Cargo.toml  src

...

Finished dev [unoptimized + debuginfo] target(s) in 4.16s
 Running target/debug/deps/acpi-0be920ff12be4550

running 16 tests
test acpi::aml::dataobj::tests::test_byte ... ok
test acpi::aml::pkglength::tests::test_pkg_length_bad_reserved ... ok
test acpi::aml::pkglength::tests::test_pkg_length_max_size ... ok
test acpi::aml::pkglength::tests::test_pkg_length_one_byte ... ok
test acpi::aml::termlist::tests::test_term_arg ... ok
test acpi::aml::tests::test_apic ... ok
test acpi::aml::pkglength::tests::test_pkg_length_two_bytes ... ok
test acpi::aml::type1opcode::tests::test_break ... ok
test acpi::aml::type1opcode::tests::test_continue ... ok
test acpi::aml::type1opcode::tests::test_fatal ... ok
test acpi::aml::type2opcode::tests::test_leftmost ... ok
test acpi::aml::type2opcode::tests::test_u64_from_bcd ... ok
test acpi::aml::type2opcode::tests::test_u64_to_bcd ... ok
test acpi::aml::namestring::tests::test_name_string ... ok
test acpi::aml::type2opcode::tests::test_rightmost ... ok
test acpi::aml::type1opcode::tests::test_if_else ... ok

test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Doc-tests acpi
error: no global memory allocator found but one is required; link to std or add #[global_allocator] to a static item that implements the GlobalAlloc trait.


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

But I think the AML parser is bugged because I couldn't parse the AML in the table /sys/firmware/acpi/tables/SSDT1 on my Linux/Ubuntu.

TODO:

  • add more unit tests for simple parse functions;
  • use a stream (= data + offset) instead of things like &data[2 + if_length + else_length_len..2 + if_length + else_length]
  • draw a distinction between parse and execute (runX = parseX + executeX), but keep the immediate execution of parsed instructions.
  • MAYBE: add debugging (this implies a 7th function in the interface). Goals: a verbose mode, a view of the AST, maybe a detection of endless loops. And finally make it parse whole tables!

Merge request reports