Skip to content

Commit 4d66363

Browse files
committed
Add ToInteger test case from uACPI
1 parent 6e81489 commit 4d66363

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

src/aml/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,12 @@ where
15481548
Object::Integer(u64::from_le_bytes(to_interpret))
15491549
}
15501550
Object::String(ref value) => {
1551+
/*
1552+
* This is about the same level of effort as ACPICA puts in. The uACPI test suite
1553+
* has tests that this fails - namely because of support for octal, signs, strings
1554+
* that won't fit in a `u64` etc. We probably need to write a more robust parser
1555+
* 'real' parser to handle those cases.
1556+
*/
15511557
if let Some(value) = value.strip_prefix("0x") {
15521558
let parsed = u64::from_str_radix(value, 16).map_err(|_| {
15531559
AmlError::InvalidOperationOnObject { op: Operation::ToInteger, typ: ObjectType::String }

tests/to_integer.asl

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
DefinitionBlock ("", "SSDT", 2, "uTEST", "TESTTABL", 0xF0F0F0F0)
2+
{
3+
Name(FCNT, 0)
4+
5+
Method (CHEK, 3)
6+
{
7+
If (Arg0 != Arg1) {
8+
FCNT++
9+
Printf("On line %o: invalid number %o, expected %o", ToDecimalString(Arg2), ToHexString(Arg0), ToHexString(Arg1))
10+
}
11+
}
12+
13+
Method (MAIN, 0, NotSerialized)
14+
{
15+
Local0 = ToInteger(123)
16+
Local1 = 123
17+
CHEK(Local0, Local1, __LINE__)
18+
19+
Local0 = ToInteger("123")
20+
Local1 = 123
21+
CHEK(Local0, Local1, __LINE__)
22+
23+
Local0 = ToInteger(" \t\t\t\v 123")
24+
Local1 = 123
25+
CHEK(Local0, Local1, __LINE__)
26+
27+
Local0 = ToInteger("123abcd")
28+
Local1 = 123
29+
CHEK(Local0, Local1, __LINE__)
30+
31+
Local0 = ToInteger("0x123abcd")
32+
Local1 = 0x123abcd
33+
CHEK(Local0, Local1, __LINE__)
34+
35+
Local0 = ToInteger("")
36+
Local1 = 0
37+
CHEK(Local0, Local1, __LINE__)
38+
39+
Local0 = ToInteger("0X")
40+
Local1 = 0
41+
CHEK(Local0, Local1, __LINE__)
42+
43+
Local0 = ToInteger("0x")
44+
Local1 = 0
45+
CHEK(Local0, Local1, __LINE__)
46+
47+
Local0 = ToInteger("0")
48+
Local1 = 0
49+
CHEK(Local0, Local1, __LINE__)
50+
51+
Local0 = ToInteger("0xDeAdBeeF")
52+
Local1 = 0xDEADBEEF
53+
CHEK(Local0, Local1, __LINE__)
54+
55+
Local0 = ToInteger("0XDeAdBeeFCafeBabeHelloWorld")
56+
Local1 = 0xDEADBEEFCAFEBABE
57+
CHEK(Local0, Local1, __LINE__)
58+
59+
Local0 = ToInteger(Buffer { 0xDE, 0xAD, 0xBE, 0xEF })
60+
Local1 = 0xEFBEADDE
61+
CHEK(Local0, Local1, __LINE__)
62+
63+
Local0 = ToInteger(Buffer { 1 })
64+
Local1 = 1
65+
CHEK(Local0, Local1, __LINE__)
66+
67+
Local0 = ToInteger(Buffer { 0 })
68+
Local1 = 0
69+
CHEK(Local0, Local1, __LINE__)
70+
71+
Local0 = ToInteger(Buffer { 0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE })
72+
Local1 = 0xBEBAFECAEFBEADDE
73+
CHEK(Local0, Local1, __LINE__)
74+
75+
// These are incompatible with ACPICA, skip if it's detected
76+
// TODO: these currently fail on our interpreter too. Can fix later.
77+
/*If (ToHexString(0xF) == "0xF") {
78+
Local0 = ToInteger("99999999999999999999999999999999999999999999999")
79+
Local1 = 0xFFFFFFFFFFFFFFFF
80+
CHEK(Local0, Local1, __LINE__)
81+
82+
Local0 = ToInteger("0xDEADBEEFCAFEBABE1")
83+
Local1 = 0xFFFFFFFFFFFFFFFF
84+
CHEK(Local0, Local1, __LINE__)
85+
86+
Local0 = ToInteger("+123")
87+
Local1 = 123
88+
CHEK(Local0, Local1, __LINE__)
89+
90+
Local0 = ToInteger("-123")
91+
Local1 = 0xFFFFFFFFFFFFFF85
92+
CHEK(Local0, Local1, __LINE__)
93+
94+
Local0 = ToInteger("-0xDEADBEF HELLOWORLD")
95+
Local1 = 0xFFFFFFFFF2152411
96+
CHEK(Local0, Local1, __LINE__)
97+
98+
Local0 = ToInteger("+0XC0D\t123")
99+
Local1 = 0xC0D
100+
CHEK(Local0, Local1, __LINE__)
101+
102+
Local0 = ToInteger("0123")
103+
Local1 = 83
104+
CHEK(Local0, Local1, __LINE__)
105+
}*/
106+
107+
Return (FCNT)
108+
}
109+
}

0 commit comments

Comments
 (0)