aboutsummaryrefslogtreecommitdiff
path: root/libs/acpi/acpi/data/madt.test.cpp
blob: 5d3b3660441ef4c1574ca48d18b8dcb480a921c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <acpi/data/madt.hpp>

#include <kstd/units>

#include <catch2/catch_test_macros.hpp>

#include <iterator>

#include <test_data/tables.hpp>

SCENARIO("MADT parsing", "[madt]")
{
  GIVEN("The basic compiled MADT containing a single LAPIC entry and the default x86 LAPIC address")
  {
    auto data = acpi::test_data::tables::basic_madt();

    WHEN("parsing the table")
    {
      auto madt = reinterpret_cast<acpi::madt const *>(data.data());

      THEN("the signature is correct")
      {
        REQUIRE(madt->signature() == "APIC");
      }

      THEN("validate returns true")
      {
        REQUIRE(madt->validate());
      }

      THEN("there is a single entry in the table")
      {
        REQUIRE(std::distance(madt->begin(), madt->end()) == 1);
      }

      THEN("the LAPIC address is 0xfee00000")
      {
        REQUIRE(madt->local_interrupt_controller_address() == 0xfee0'0000);
      }

      THEN("the length is sizeof(madt) + sizeof(processor_local_apic)")
      {
        REQUIRE(madt->length().value == sizeof(acpi::madt) + sizeof(acpi::processor_local_apic_entry));
      }

      THEN("the first entry has type processor_local_apic")
      {
        REQUIRE(madt->cbegin()->type() == acpi::madt_entry::type::processor_local_apic);
      }

      THEN("`only` can be used to get a view of all processor_local_apic entries")
      {
        REQUIRE(std::ranges::distance(madt->only<acpi::processor_local_apic_entry>()) == 1);
      }
    }
  }
}