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