Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
K
kernel
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 18
    • Issues 18
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 3
    • Merge Requests 3
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • redox-os
  • kernel
  • Merge Requests
  • !98

Open
Opened Dec 06, 2018 by Julien Férard@jferard1
  • Report abuse
Report abuse

WIP: Make ACPI testable

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!

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch https://gitlab.redox-os.org/jferard/kernel.git clean_aml
git checkout -b jferard/kernel-clean_aml FETCH_HEAD

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/master
git merge --no-ff jferard/kernel-clean_aml

Step 4. Push the result of the merge to GitLab

git push origin master

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 0
  • Commits 68
  • Changes 35
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View project labels
Reference: redox-os/kernel!98