Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/aml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,17 +1972,19 @@ where
* that won't fit in a `u64` etc. We probably need to write a more robust parser
* 'real' parser to handle those cases.
*/
if let Some(value) = value.strip_prefix("0x") {
let parsed = u64::from_str_radix(value, 16).map_err(|_| {
let value = value.trim();
let value = value.to_ascii_lowercase();
let (value, radix): (&str, u32) = match value.strip_prefix("0x") {
Some(value) => {
(value.split(|c: char| !c.is_ascii_hexdigit()).next().unwrap_or(""), 16)
}
None => (value.split(|c: char| !c.is_ascii_digit()).next().unwrap_or(""), 10),
};
match value.len() {
0 => Object::Integer(0),
_ => Object::Integer(u64::from_str_radix(value, radix).map_err(|_| {
AmlError::InvalidOperationOnObject { op: Operation::ToInteger, typ: ObjectType::String }
})?;
Object::Integer(parsed)
} else {
let parsed = str::parse::<u64>(value).map_err(|_| AmlError::InvalidOperationOnObject {
op: Operation::ToInteger,
typ: ObjectType::String,
})?;
Object::Integer(parsed)
})?),
}
}
_ => Err(AmlError::InvalidOperationOnObject { op: Operation::ToBuffer, typ: operand.typ() })?,
Expand Down Expand Up @@ -2031,7 +2033,7 @@ where
Object::String(ref value) => Object::String(value.clone()),
Object::Integer(value) => match op.op {
Opcode::ToDecimalString => Object::String(value.to_string()),
Opcode::ToHexString => Object::String(alloc::format!("{value:#x}")),
Opcode::ToHexString => Object::String(alloc::format!("{value:#X}")),
_ => panic!(),
},
Object::Buffer(ref bytes) => {
Expand Down Expand Up @@ -3333,4 +3335,12 @@ pub enum AmlError {
/// This is emitted to signal that the library does not support the requested behaviour. This
/// should eventually never be emitted.
LibUnimplemented,

/// The library has given a response the host does not understand, or the host is otherwise
/// unable to continue operating the library correctly. The specific reason is given in the
/// contained String.
///
/// This variant is set by the host, not by the library, and can be used when it is convenient
/// not to construct a more complex error type around [`AmlError`].
HostError(String),
}
6 changes: 3 additions & 3 deletions tests/normal_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_infra;

#[test]
fn test_basic_store_and_load() {
const AML: &str = r#"DefinitionBlock("%FN%", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
const AML: &str = r#"DefinitionBlock("", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
OperationRegion(MEM, SystemMemory, 0x40000, 0x1000)
Field(MEM, WordAcc, NoLock, Preserve) {
A, 16,
Expand Down Expand Up @@ -46,7 +46,7 @@ fn test_basic_store_and_load() {

#[test]
fn test_narrow_access_store_and_load() {
const AML: &str = r#"DefinitionBlock("%FN%", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
const AML: &str = r#"DefinitionBlock("", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
OperationRegion(MEM, SystemIO, 0x40, 0x10)
Field(MEM, ByteAcc, NoLock, Preserve) {
A, 16,
Expand Down Expand Up @@ -79,7 +79,7 @@ fn test_narrow_access_store_and_load() {

#[test]
fn test_unaligned_field_store() {
const AML: &str = r#"DefinitionBlock("%FN%", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
const AML: &str = r#"DefinitionBlock("", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
OperationRegion(MEM, SystemIO, 0x40, 0x10)
Field(MEM, WordAcc, NoLock, Preserve) {
A, 7,
Expand Down
14 changes: 9 additions & 5 deletions tests/test_infra/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use acpi::Handler;
use aml_test_tools::{new_interpreter, run_test_for_string, TestResult};
use aml_test_tools::handlers::logging_handler::LoggingHandler;
use aml_test_tools::{
RunTestResult,
handlers::logging_handler::LoggingHandler,
new_interpreter,
run_test_for_string,
};

pub fn run_aml_test(asl: &'static str, handler: impl Handler) {
// Tests calling `run_aml_test` don't do much else, and we usually want logging, so initialize it here.
let _ = pretty_env_logger::try_init();

let logged_handler = LoggingHandler::new(handler);
let mut interpreter = new_interpreter(logged_handler);
let interpreter = new_interpreter(logged_handler);

assert_eq!(run_test_for_string(asl, &mut interpreter), TestResult::Pass);
assert!(matches!(run_test_for_string(asl, interpreter), RunTestResult::Pass(_)));
}
Loading
Loading