Skip to content

Commit f66b801

Browse files
committed
Fix AML tester
1 parent 8ccdc28 commit f66b801

File tree

4 files changed

+92
-15
lines changed

4 files changed

+92
-15
lines changed

src/registers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ where
4141
/// determine if an event has fired (and written to clear), and an `EN` enabling register to
4242
/// control whether an event should fire.
4343
pub struct Pm1EventRegisterBlock<H: Handler> {
44-
pm1_event_length: usize,
45-
pm1a: MappedGas<H>,
46-
pm1b: Option<MappedGas<H>>,
44+
pub pm1_event_length: usize,
45+
pub pm1a: MappedGas<H>,
46+
pub pm1b: Option<MappedGas<H>>,
4747
}
4848

4949
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
@@ -98,8 +98,8 @@ where
9898
}
9999

100100
pub struct Pm1ControlRegisterBlock<H: Handler> {
101-
pm1a: MappedGas<H>,
102-
pm1b: Option<MappedGas<H>>,
101+
pub pm1a: MappedGas<H>,
102+
pub pm1b: Option<MappedGas<H>>,
103103
}
104104

105105
#[derive(Clone, Copy, PartialEq, Debug)]

tests/complex_package.asl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ DefinitionBlock ("", "DSDT", 2, "uTEST", "TESTTABL", 0xF0F0F0F0)
6262
Method (MAIN) {
6363
Local0 = GPKG()
6464
Debug = Local0
65-
Local0 = 1
66-
Return (Local0)
65+
Return (0)
6766
}
6867
}

tests/fields.asl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ DefinitionBlock("fields.aml", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
5353
A = RESA
5454
B = RESB
5555
C = RESC
56+
57+
Return (0)
5658
}
5759
}

tools/aml_tester/src/main.rs

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
* - For failing tests, print out a nice summary of the errors for each file
1010
*/
1111

12-
use acpi::aml::{namespace::AmlName, AmlError, Handle, Interpreter};
12+
use acpi::{
13+
address::MappedGas,
14+
aml::{namespace::AmlName, object::Object, AmlError, Interpreter},
15+
Handle,
16+
PhysicalMapping,
17+
};
1318
use clap::{Arg, ArgAction, ArgGroup};
14-
use log::info;
19+
use log::{error, info};
1520
use pci_types::PciAddress;
1621
use std::{
1722
collections::HashSet,
@@ -20,7 +25,9 @@ use std::{
2025
io::{Read, Write},
2126
path::{Path, PathBuf},
2227
process::Command,
28+
ptr::NonNull,
2329
str::FromStr,
30+
sync::Arc,
2431
};
2532

2633
enum CompilationOutcome {
@@ -145,8 +152,7 @@ fn main() -> std::io::Result<()> {
145152
.collect::<Vec<_>>();
146153

147154
let combined_test = matches.get_flag("combined");
148-
149-
let mut interpreter = Interpreter::new(Handler, 2);
155+
let mut interpreter = new_interpreter();
150156

151157
let (passed, failed) = aml_files.into_iter().fold((0, 0), |(passed, failed), file_entry| {
152158
print!("Testing AML file: {:?}... ", file_entry);
@@ -160,7 +166,7 @@ fn main() -> std::io::Result<()> {
160166
file.read_to_end(&mut contents).unwrap();
161167

162168
if !combined_test {
163-
interpreter = Interpreter::new(Handler, 2);
169+
interpreter = new_interpreter();
164170
}
165171

166172
const AML_TABLE_HEADER_LENGTH: usize = 36;
@@ -214,9 +220,72 @@ fn main() -> std::io::Result<()> {
214220
Ok(())
215221
}
216222

223+
fn new_interpreter() -> Interpreter<Handler> {
224+
let fake_registers = Arc::new(acpi::registers::FixedRegisters {
225+
pm1_event_registers: acpi::registers::Pm1EventRegisterBlock {
226+
pm1_event_length: 8,
227+
pm1a: unsafe {
228+
MappedGas::map_gas(
229+
acpi::address::GenericAddress {
230+
address_space: acpi::address::AddressSpace::SystemIo,
231+
bit_width: 32,
232+
bit_offset: 0,
233+
access_size: 1,
234+
address: 0x400,
235+
},
236+
&Handler,
237+
)
238+
.unwrap()
239+
},
240+
pm1b: None,
241+
},
242+
pm1_control_registers: acpi::registers::Pm1ControlRegisterBlock {
243+
pm1a: unsafe {
244+
MappedGas::map_gas(
245+
acpi::address::GenericAddress {
246+
address_space: acpi::address::AddressSpace::SystemIo,
247+
bit_width: 32,
248+
bit_offset: 0,
249+
access_size: 1,
250+
address: 0x600,
251+
},
252+
&Handler,
253+
)
254+
.unwrap()
255+
},
256+
pm1b: None,
257+
},
258+
});
259+
let fake_facs = PhysicalMapping {
260+
physical_start: 0x0,
261+
virtual_start: NonNull::new(0x8000_0000_0000_0000 as *mut acpi::sdt::facs::Facs).unwrap(),
262+
region_length: 32,
263+
mapped_length: 32,
264+
handler: Handler,
265+
};
266+
Interpreter::new(Handler, 2, fake_registers, fake_facs)
267+
}
268+
217269
fn run_test(stream: &[u8], interpreter: &mut Interpreter<Handler>) -> Result<(), AmlError> {
218270
interpreter.load_table(stream)?;
219-
interpreter.evaluate_if_present(AmlName::from_str("\\MAIN").unwrap(), vec![])
271+
272+
if let Some(result) = interpreter.evaluate_if_present(AmlName::from_str("\\MAIN").unwrap(), vec![])? {
273+
match *result {
274+
Object::Integer(0) => Ok(()),
275+
Object::Integer(other) => {
276+
error!("Test _MAIN returned non-zero exit code: {}", other);
277+
// TODO: wrong error - this should probs return a more complex err type
278+
Err(AmlError::NoCurrentOp)
279+
}
280+
_ => {
281+
error!("Test _MAIN returned unexpected object type: {}", *result);
282+
// TODO: wrong error
283+
Err(AmlError::NoCurrentOp)
284+
}
285+
}
286+
} else {
287+
Ok(())
288+
}
220289
}
221290

222291
fn find_tests(matches: &clap::ArgMatches) -> std::io::Result<Vec<PathBuf>> {
@@ -312,9 +381,16 @@ impl log::Log for Logger {
312381
}
313382
}
314383

384+
#[derive(Clone)]
315385
struct Handler;
316386

317-
impl acpi::aml::Handler for Handler {
387+
impl acpi::Handler for Handler {
388+
unsafe fn map_physical_region<T>(&self, physical_address: usize, size: usize) -> PhysicalMapping<Self, T> {
389+
todo!()
390+
}
391+
392+
fn unmap_physical_region<T>(_region: &PhysicalMapping<Self, T>) {}
393+
318394
fn read_u8(&self, address: usize) -> u8 {
319395
println!("read_u8 {address:#x}");
320396
0
@@ -392,7 +468,7 @@ impl acpi::aml::Handler for Handler {
392468
}
393469

394470
fn handle_debug(&self, object: &acpi::aml::object::Object) {
395-
info!("Debug store: {:?}", object);
471+
info!("Debug store: {}", object);
396472
}
397473

398474
fn nanos_since_boot(&self) -> u64 {

0 commit comments

Comments
 (0)