Skip to content

Commit 5743dcb

Browse files
committed
Add a few tests as a demo
1 parent a4099c6 commit 5743dcb

2 files changed

Lines changed: 107 additions & 65 deletions

File tree

tests/basic.rs

Lines changed: 0 additions & 65 deletions
This file was deleted.

tests/normal_fields.rs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Test operations on "normal" fields - those that are not Index or Bank fields.
2+
3+
use aml_test_tools::handlers::{
4+
check_cmd_handler::AcpiCommands as CheckCommands,
5+
listed_response_handler::AcpiCommands as Results,
6+
std_test_handler::{Command, construct_std_handler},
7+
};
8+
9+
mod test_infra;
10+
11+
#[test]
12+
fn test_basic_store_and_load() {
13+
const AML: &str = r#"DefinitionBlock("%FN%", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
14+
OperationRegion(MEM, SystemMemory, 0x40000, 0x1000)
15+
Field(MEM, WordAcc, NoLock, Preserve) {
16+
A, 16,
17+
B, 16
18+
}
19+
20+
Method(MAIN, 0, NotSerialized) {
21+
A = 0xA5A5
22+
B = A
23+
Return (0)
24+
}
25+
}
26+
"#;
27+
28+
const EXPECTED_COMMANDS: &[Command] = &[
29+
(CheckCommands::CreateMutex, Results::Skip()),
30+
31+
// A = 0xA5A5
32+
(CheckCommands::WriteU16(0x40000, 0xA5A5), Results::Skip()),
33+
34+
// B = A
35+
(CheckCommands::ReadU16(0x40000), Results::ReadU16(0xA5A5)),
36+
(CheckCommands::WriteU16(0x40002, 0xA5A5), Results::Skip()),
37+
];
38+
39+
let handler = construct_std_handler(EXPECTED_COMMANDS.to_vec());
40+
test_infra::run_aml_test(AML, handler);
41+
}
42+
43+
#[test]
44+
fn test_narrow_access_store_and_load() {
45+
const AML: &str = r#"DefinitionBlock("%FN%", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
46+
OperationRegion(MEM, SystemIO, 0x40, 0x10)
47+
Field(MEM, ByteAcc, NoLock, Preserve) {
48+
A, 16,
49+
B, 16
50+
}
51+
52+
Method(MAIN, 0, NotSerialized) {
53+
A = 0xA55A
54+
B = A
55+
Return (0)
56+
}
57+
}
58+
"#;
59+
60+
const EXPECTED_COMMANDS: &[Command] = &[
61+
(CheckCommands::CreateMutex, Results::Skip()),
62+
63+
// A = 0xA55A
64+
(CheckCommands::WriteIoU8(0x40, 0x5A), Results::Skip()),
65+
(CheckCommands::WriteIoU8(0x41, 0xA5), Results::Skip()),
66+
67+
// B = A
68+
(CheckCommands::ReadIoU8(0x40), Results::ReadIoU8(0x5A)),
69+
(CheckCommands::ReadIoU8(0x41), Results::ReadIoU8(0xA5)),
70+
(CheckCommands::WriteIoU8(0x42, 0x5A), Results::Skip()),
71+
(CheckCommands::WriteIoU8(0x43, 0xA5), Results::Skip()),
72+
];
73+
74+
let handler = construct_std_handler(EXPECTED_COMMANDS.to_vec());
75+
test_infra::run_aml_test(AML, handler);
76+
}
77+
78+
#[test]
79+
fn test_unaligned_field_store() {
80+
const AML: &str = r#"DefinitionBlock("%FN%", "DSDT", 1, "RSACPI", "BUFFLD", 1) {
81+
OperationRegion(MEM, SystemIO, 0x40, 0x10)
82+
Field(MEM, WordAcc, NoLock, Preserve) {
83+
A, 7,
84+
B, 8
85+
}
86+
87+
Method(MAIN, 0, NotSerialized) {
88+
A = 4
89+
B = A
90+
91+
Return (0)
92+
}
93+
}
94+
"#;
95+
96+
const EXPECTED_COMMANDS: &[Command] = &[
97+
(CheckCommands::CreateMutex, Results::Skip()),
98+
(CheckCommands::ReadIoU16(0x40), Results::ReadIoU16(0)),
99+
(CheckCommands::WriteIoU16(0x40, 0x04), Results::Skip()),
100+
(CheckCommands::ReadIoU16(0x40), Results::ReadIoU16(4)),
101+
(CheckCommands::ReadIoU16(0x40), Results::ReadIoU16(4)),
102+
(CheckCommands::WriteIoU16(0x40, 0x204), Results::Skip()),
103+
];
104+
105+
let handler = construct_std_handler(EXPECTED_COMMANDS.to_vec());
106+
test_infra::run_aml_test(AML, handler);
107+
}

0 commit comments

Comments
 (0)