From 3087771c21aced2aa7731b10e0a7facad68102a0 Mon Sep 17 00:00:00 2001 From: Changyuan Lyu Date: Wed, 8 Jul 2026 03:47:29 -0700 Subject: [PATCH 1/2] style: follow Golang's arch naming convention in file names Since we are following Golong's source file naming convention, let us also use Golang's arch names. Signed-off-by: Changyuan Lyu --- alioth/src/board/board.rs | 4 ++-- .../board_x86_64.rs => board_amd64/board_amd64.rs} | 2 +- .../board_x86_64_test.rs => board_amd64/board_amd64_test.rs} | 0 .../dsdt.x86_64.dsl => board_amd64/dsdt_amd64.dsl} | 0 alioth/src/board/{board_x86_64 => board_amd64}/sev.rs | 0 alioth/src/board/{board_x86_64 => board_amd64}/tdx.rs | 0 alioth/src/board/{board_aarch64.rs => board_arm64.rs} | 2 +- .../src/board/{board_aarch64_test.rs => board_arm64_test.rs} | 0 alioth/src/cpu/cpu.rs | 4 ++-- .../cpu/{cpu_x86_64/cpu_x86_64.rs => cpu_amd64/cpu_amd64.rs} | 0 alioth/src/cpu/{cpu_x86_64 => cpu_amd64}/sev.rs | 0 alioth/src/cpu/{cpu_x86_64 => cpu_amd64}/tdx.rs | 0 alioth/src/cpu/{cpu_aarch64.rs => cpu_arm64.rs} | 0 alioth/src/firmware/ovmf/ovmf.rs | 2 +- .../{ovmf_x86_64/ovmf_x86_64.rs => ovmf_amd64/ovmf_amd64.rs} | 0 alioth/src/firmware/ovmf/{ovmf_x86_64 => ovmf_amd64}/sev.rs | 0 alioth/src/firmware/ovmf/{ovmf_x86_64 => ovmf_amd64}/tdx.rs | 0 .../src/firmware/ovmf/{ovmf_x86_64 => ovmf_amd64}/tdx_test.rs | 0 alioth/src/hv/kvm/kvm.rs | 2 +- .../kvm/{kvm_x86_64/kvm_x86_64.rs => kvm_amd64/kvm_amd64.rs} | 2 +- .../kvm_x86_64_test.rs => kvm_amd64/kvm_amd64_test.rs} | 0 alioth/src/hv/kvm/{kvm_x86_64 => kvm_amd64}/sev.rs | 0 alioth/src/hv/kvm/{kvm_x86_64 => kvm_amd64}/tdx.rs | 0 alioth/src/hv/kvm/vcpu/vcpu.rs | 4 ++-- alioth/src/hv/kvm/vcpu/{vcpu_x86_64 => vcpu_amd64}/tdx.rs | 0 .../{vcpu_x86_64/vcpu_x86_64.rs => vcpu_amd64/vcpu_amd64.rs} | 2 +- .../vcpu_x86_64_test.rs => vcpu_amd64/vcpu_amd64_test.rs} | 0 alioth/src/hv/kvm/vcpu/{vcpu_aarch64.rs => vcpu_arm64.rs} | 0 alioth/src/hv/kvm/vm/vm.rs | 4 ++-- alioth/src/hv/kvm/vm/{vm_x86_64 => vm_amd64}/sev.rs | 0 alioth/src/hv/kvm/vm/{vm_x86_64 => vm_amd64}/tdx.rs | 0 .../kvm/vm/{vm_x86_64/vm_x86_64.rs => vm_amd64/vm_amd64.rs} | 2 +- .../vm_x86_64_test.rs => vm_amd64/vm_amd64_test.rs} | 0 alioth/src/hv/kvm/vm/{vm_aarch64.rs => vm_arm64.rs} | 0 alioth/src/loader/firmware/firmware.rs | 4 ++-- .../loader/firmware/{firmware_x86_64.rs => firmware_amd64.rs} | 0 .../firmware/{firmware_aarch64.rs => firmware_arm64.rs} | 0 alioth/src/loader/linux/linux.rs | 4 ++-- alioth/src/loader/linux/{linux_x86_64.rs => linux_amd64.rs} | 0 alioth/src/loader/linux/{linux_aarch64.rs => linux_arm64.rs} | 0 40 files changed, 19 insertions(+), 19 deletions(-) rename alioth/src/board/{board_x86_64/board_x86_64.rs => board_amd64/board_amd64.rs} (99%) rename alioth/src/board/{board_x86_64/board_x86_64_test.rs => board_amd64/board_amd64_test.rs} (100%) rename alioth/src/board/{board_x86_64/dsdt.x86_64.dsl => board_amd64/dsdt_amd64.dsl} (100%) rename alioth/src/board/{board_x86_64 => board_amd64}/sev.rs (100%) rename alioth/src/board/{board_x86_64 => board_amd64}/tdx.rs (100%) rename alioth/src/board/{board_aarch64.rs => board_arm64.rs} (99%) rename alioth/src/board/{board_aarch64_test.rs => board_arm64_test.rs} (100%) rename alioth/src/cpu/{cpu_x86_64/cpu_x86_64.rs => cpu_amd64/cpu_amd64.rs} (100%) rename alioth/src/cpu/{cpu_x86_64 => cpu_amd64}/sev.rs (100%) rename alioth/src/cpu/{cpu_x86_64 => cpu_amd64}/tdx.rs (100%) rename alioth/src/cpu/{cpu_aarch64.rs => cpu_arm64.rs} (100%) rename alioth/src/firmware/ovmf/{ovmf_x86_64/ovmf_x86_64.rs => ovmf_amd64/ovmf_amd64.rs} (100%) rename alioth/src/firmware/ovmf/{ovmf_x86_64 => ovmf_amd64}/sev.rs (100%) rename alioth/src/firmware/ovmf/{ovmf_x86_64 => ovmf_amd64}/tdx.rs (100%) rename alioth/src/firmware/ovmf/{ovmf_x86_64 => ovmf_amd64}/tdx_test.rs (100%) rename alioth/src/hv/kvm/{kvm_x86_64/kvm_x86_64.rs => kvm_amd64/kvm_amd64.rs} (99%) rename alioth/src/hv/kvm/{kvm_x86_64/kvm_x86_64_test.rs => kvm_amd64/kvm_amd64_test.rs} (100%) rename alioth/src/hv/kvm/{kvm_x86_64 => kvm_amd64}/sev.rs (100%) rename alioth/src/hv/kvm/{kvm_x86_64 => kvm_amd64}/tdx.rs (100%) rename alioth/src/hv/kvm/vcpu/{vcpu_x86_64 => vcpu_amd64}/tdx.rs (100%) rename alioth/src/hv/kvm/vcpu/{vcpu_x86_64/vcpu_x86_64.rs => vcpu_amd64/vcpu_amd64.rs} (99%) rename alioth/src/hv/kvm/vcpu/{vcpu_x86_64/vcpu_x86_64_test.rs => vcpu_amd64/vcpu_amd64_test.rs} (100%) rename alioth/src/hv/kvm/vcpu/{vcpu_aarch64.rs => vcpu_arm64.rs} (100%) rename alioth/src/hv/kvm/vm/{vm_x86_64 => vm_amd64}/sev.rs (100%) rename alioth/src/hv/kvm/vm/{vm_x86_64 => vm_amd64}/tdx.rs (100%) rename alioth/src/hv/kvm/vm/{vm_x86_64/vm_x86_64.rs => vm_amd64/vm_amd64.rs} (99%) rename alioth/src/hv/kvm/vm/{vm_x86_64/vm_x86_64_test.rs => vm_amd64/vm_amd64_test.rs} (100%) rename alioth/src/hv/kvm/vm/{vm_aarch64.rs => vm_arm64.rs} (100%) rename alioth/src/loader/firmware/{firmware_x86_64.rs => firmware_amd64.rs} (100%) rename alioth/src/loader/firmware/{firmware_aarch64.rs => firmware_arm64.rs} (100%) rename alioth/src/loader/linux/{linux_x86_64.rs => linux_amd64.rs} (100%) rename alioth/src/loader/linux/{linux_aarch64.rs => linux_arm64.rs} (100%) diff --git a/alioth/src/board/board.rs b/alioth/src/board/board.rs index ffaf4a93..46a8cb92 100644 --- a/alioth/src/board/board.rs +++ b/alioth/src/board/board.rs @@ -13,10 +13,10 @@ // limitations under the License. #[cfg(target_arch = "aarch64")] -#[path = "board_aarch64.rs"] +#[path = "board_arm64.rs"] mod aarch64; #[cfg(target_arch = "x86_64")] -#[path = "board_x86_64/board_x86_64.rs"] +#[path = "board_amd64/board_amd64.rs"] mod x86_64; use std::ffi::CStr; diff --git a/alioth/src/board/board_x86_64/board_x86_64.rs b/alioth/src/board/board_amd64/board_amd64.rs similarity index 99% rename from alioth/src/board/board_x86_64/board_x86_64.rs rename to alioth/src/board/board_amd64/board_amd64.rs index 22cd63b1..a197f927 100644 --- a/alioth/src/board/board_x86_64/board_x86_64.rs +++ b/alioth/src/board/board_amd64/board_amd64.rs @@ -385,5 +385,5 @@ const DSDT_TEMPLATE: [u8; 352] = [ const DSDT_OFFSET_PCI_QWORD_MEM: usize = 0x12b; #[cfg(test)] -#[path = "board_x86_64_test.rs"] +#[path = "board_amd64_test.rs"] mod tests; diff --git a/alioth/src/board/board_x86_64/board_x86_64_test.rs b/alioth/src/board/board_amd64/board_amd64_test.rs similarity index 100% rename from alioth/src/board/board_x86_64/board_x86_64_test.rs rename to alioth/src/board/board_amd64/board_amd64_test.rs diff --git a/alioth/src/board/board_x86_64/dsdt.x86_64.dsl b/alioth/src/board/board_amd64/dsdt_amd64.dsl similarity index 100% rename from alioth/src/board/board_x86_64/dsdt.x86_64.dsl rename to alioth/src/board/board_amd64/dsdt_amd64.dsl diff --git a/alioth/src/board/board_x86_64/sev.rs b/alioth/src/board/board_amd64/sev.rs similarity index 100% rename from alioth/src/board/board_x86_64/sev.rs rename to alioth/src/board/board_amd64/sev.rs diff --git a/alioth/src/board/board_x86_64/tdx.rs b/alioth/src/board/board_amd64/tdx.rs similarity index 100% rename from alioth/src/board/board_x86_64/tdx.rs rename to alioth/src/board/board_amd64/tdx.rs diff --git a/alioth/src/board/board_aarch64.rs b/alioth/src/board/board_arm64.rs similarity index 99% rename from alioth/src/board/board_aarch64.rs rename to alioth/src/board/board_arm64.rs index ea0a41fe..3de662f8 100644 --- a/alioth/src/board/board_aarch64.rs +++ b/alioth/src/board/board_arm64.rs @@ -533,5 +533,5 @@ const PHANDLE_MSI: u32 = 3; const PHANDLE_CPU: u32 = 1 << 31; #[cfg(test)] -#[path = "board_aarch64_test.rs"] +#[path = "board_arm64_test.rs"] mod tests; diff --git a/alioth/src/board/board_aarch64_test.rs b/alioth/src/board/board_arm64_test.rs similarity index 100% rename from alioth/src/board/board_aarch64_test.rs rename to alioth/src/board/board_arm64_test.rs diff --git a/alioth/src/cpu/cpu.rs b/alioth/src/cpu/cpu.rs index 202befc2..67e070da 100644 --- a/alioth/src/cpu/cpu.rs +++ b/alioth/src/cpu/cpu.rs @@ -13,10 +13,10 @@ // limitations under the License. #[cfg(target_arch = "aarch64")] -#[path = "cpu_aarch64.rs"] +#[path = "cpu_arm64.rs"] mod aarch64; #[cfg(target_arch = "x86_64")] -#[path = "cpu_x86_64/cpu_x86_64.rs"] +#[path = "cpu_amd64/cpu_amd64.rs"] mod x86_64; use std::sync::Arc; diff --git a/alioth/src/cpu/cpu_x86_64/cpu_x86_64.rs b/alioth/src/cpu/cpu_amd64/cpu_amd64.rs similarity index 100% rename from alioth/src/cpu/cpu_x86_64/cpu_x86_64.rs rename to alioth/src/cpu/cpu_amd64/cpu_amd64.rs diff --git a/alioth/src/cpu/cpu_x86_64/sev.rs b/alioth/src/cpu/cpu_amd64/sev.rs similarity index 100% rename from alioth/src/cpu/cpu_x86_64/sev.rs rename to alioth/src/cpu/cpu_amd64/sev.rs diff --git a/alioth/src/cpu/cpu_x86_64/tdx.rs b/alioth/src/cpu/cpu_amd64/tdx.rs similarity index 100% rename from alioth/src/cpu/cpu_x86_64/tdx.rs rename to alioth/src/cpu/cpu_amd64/tdx.rs diff --git a/alioth/src/cpu/cpu_aarch64.rs b/alioth/src/cpu/cpu_arm64.rs similarity index 100% rename from alioth/src/cpu/cpu_aarch64.rs rename to alioth/src/cpu/cpu_arm64.rs diff --git a/alioth/src/firmware/ovmf/ovmf.rs b/alioth/src/firmware/ovmf/ovmf.rs index 66ccd218..3a94dbb3 100644 --- a/alioth/src/firmware/ovmf/ovmf.rs +++ b/alioth/src/firmware/ovmf/ovmf.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[path = "ovmf_x86_64/ovmf_x86_64.rs"] +#[path = "ovmf_amd64/ovmf_amd64.rs"] pub mod x86_64; #[cfg(target_arch = "x86_64")] diff --git a/alioth/src/firmware/ovmf/ovmf_x86_64/ovmf_x86_64.rs b/alioth/src/firmware/ovmf/ovmf_amd64/ovmf_amd64.rs similarity index 100% rename from alioth/src/firmware/ovmf/ovmf_x86_64/ovmf_x86_64.rs rename to alioth/src/firmware/ovmf/ovmf_amd64/ovmf_amd64.rs diff --git a/alioth/src/firmware/ovmf/ovmf_x86_64/sev.rs b/alioth/src/firmware/ovmf/ovmf_amd64/sev.rs similarity index 100% rename from alioth/src/firmware/ovmf/ovmf_x86_64/sev.rs rename to alioth/src/firmware/ovmf/ovmf_amd64/sev.rs diff --git a/alioth/src/firmware/ovmf/ovmf_x86_64/tdx.rs b/alioth/src/firmware/ovmf/ovmf_amd64/tdx.rs similarity index 100% rename from alioth/src/firmware/ovmf/ovmf_x86_64/tdx.rs rename to alioth/src/firmware/ovmf/ovmf_amd64/tdx.rs diff --git a/alioth/src/firmware/ovmf/ovmf_x86_64/tdx_test.rs b/alioth/src/firmware/ovmf/ovmf_amd64/tdx_test.rs similarity index 100% rename from alioth/src/firmware/ovmf/ovmf_x86_64/tdx_test.rs rename to alioth/src/firmware/ovmf/ovmf_amd64/tdx_test.rs diff --git a/alioth/src/hv/kvm/kvm.rs b/alioth/src/hv/kvm/kvm.rs index b20f2f52..37913fe7 100644 --- a/alioth/src/hv/kvm/kvm.rs +++ b/alioth/src/hv/kvm/kvm.rs @@ -13,7 +13,7 @@ // limitations under the License. #[cfg(target_arch = "x86_64")] -#[path = "kvm_x86_64/kvm_x86_64.rs"] +#[path = "kvm_amd64/kvm_amd64.rs"] mod x86_64; #[cfg(target_arch = "aarch64")] diff --git a/alioth/src/hv/kvm/kvm_x86_64/kvm_x86_64.rs b/alioth/src/hv/kvm/kvm_amd64/kvm_amd64.rs similarity index 99% rename from alioth/src/hv/kvm/kvm_x86_64/kvm_x86_64.rs rename to alioth/src/hv/kvm/kvm_amd64/kvm_amd64.rs index f3117bcf..cef776f1 100644 --- a/alioth/src/hv/kvm/kvm_x86_64/kvm_x86_64.rs +++ b/alioth/src/hv/kvm/kvm_amd64/kvm_amd64.rs @@ -91,5 +91,5 @@ impl Kvm { } #[cfg(test)] -#[path = "kvm_x86_64_test.rs"] +#[path = "kvm_amd64_test.rs"] mod tests; diff --git a/alioth/src/hv/kvm/kvm_x86_64/kvm_x86_64_test.rs b/alioth/src/hv/kvm/kvm_amd64/kvm_amd64_test.rs similarity index 100% rename from alioth/src/hv/kvm/kvm_x86_64/kvm_x86_64_test.rs rename to alioth/src/hv/kvm/kvm_amd64/kvm_amd64_test.rs diff --git a/alioth/src/hv/kvm/kvm_x86_64/sev.rs b/alioth/src/hv/kvm/kvm_amd64/sev.rs similarity index 100% rename from alioth/src/hv/kvm/kvm_x86_64/sev.rs rename to alioth/src/hv/kvm/kvm_amd64/sev.rs diff --git a/alioth/src/hv/kvm/kvm_x86_64/tdx.rs b/alioth/src/hv/kvm/kvm_amd64/tdx.rs similarity index 100% rename from alioth/src/hv/kvm/kvm_x86_64/tdx.rs rename to alioth/src/hv/kvm/kvm_amd64/tdx.rs diff --git a/alioth/src/hv/kvm/vcpu/vcpu.rs b/alioth/src/hv/kvm/vcpu/vcpu.rs index 4c80509e..825f0c8a 100644 --- a/alioth/src/hv/kvm/vcpu/vcpu.rs +++ b/alioth/src/hv/kvm/vcpu/vcpu.rs @@ -13,10 +13,10 @@ // limitations under the License. #[cfg(target_arch = "aarch64")] -#[path = "vcpu_aarch64.rs"] +#[path = "vcpu_arm64.rs"] mod aarch64; #[cfg(target_arch = "x86_64")] -#[path = "vcpu_x86_64/vcpu_x86_64.rs"] +#[path = "vcpu_amd64/vcpu_amd64.rs"] mod x86_64; mod vmentry; diff --git a/alioth/src/hv/kvm/vcpu/vcpu_x86_64/tdx.rs b/alioth/src/hv/kvm/vcpu/vcpu_amd64/tdx.rs similarity index 100% rename from alioth/src/hv/kvm/vcpu/vcpu_x86_64/tdx.rs rename to alioth/src/hv/kvm/vcpu/vcpu_amd64/tdx.rs diff --git a/alioth/src/hv/kvm/vcpu/vcpu_x86_64/vcpu_x86_64.rs b/alioth/src/hv/kvm/vcpu/vcpu_amd64/vcpu_amd64.rs similarity index 99% rename from alioth/src/hv/kvm/vcpu/vcpu_x86_64/vcpu_x86_64.rs rename to alioth/src/hv/kvm/vcpu/vcpu_amd64/vcpu_amd64.rs index 59c7a60d..77081eca 100644 --- a/alioth/src/hv/kvm/vcpu/vcpu_x86_64/vcpu_x86_64.rs +++ b/alioth/src/hv/kvm/vcpu/vcpu_amd64/vcpu_amd64.rs @@ -315,5 +315,5 @@ impl KvmVcpu { } #[cfg(test)] -#[path = "vcpu_x86_64_test.rs"] +#[path = "vcpu_amd64_test.rs"] mod tests; diff --git a/alioth/src/hv/kvm/vcpu/vcpu_x86_64/vcpu_x86_64_test.rs b/alioth/src/hv/kvm/vcpu/vcpu_amd64/vcpu_amd64_test.rs similarity index 100% rename from alioth/src/hv/kvm/vcpu/vcpu_x86_64/vcpu_x86_64_test.rs rename to alioth/src/hv/kvm/vcpu/vcpu_amd64/vcpu_amd64_test.rs diff --git a/alioth/src/hv/kvm/vcpu/vcpu_aarch64.rs b/alioth/src/hv/kvm/vcpu/vcpu_arm64.rs similarity index 100% rename from alioth/src/hv/kvm/vcpu/vcpu_aarch64.rs rename to alioth/src/hv/kvm/vcpu/vcpu_arm64.rs diff --git a/alioth/src/hv/kvm/vm/vm.rs b/alioth/src/hv/kvm/vm/vm.rs index 05a4efa3..1886edd2 100644 --- a/alioth/src/hv/kvm/vm/vm.rs +++ b/alioth/src/hv/kvm/vm/vm.rs @@ -13,10 +13,10 @@ // limitations under the License. #[cfg(target_arch = "aarch64")] -#[path = "vm_aarch64.rs"] +#[path = "vm_arm64.rs"] mod aarch64; #[cfg(target_arch = "x86_64")] -#[path = "vm_x86_64/vm_x86_64.rs"] +#[path = "vm_amd64/vm_amd64.rs"] mod x86_64; #[cfg(target_arch = "x86_64")] diff --git a/alioth/src/hv/kvm/vm/vm_x86_64/sev.rs b/alioth/src/hv/kvm/vm/vm_amd64/sev.rs similarity index 100% rename from alioth/src/hv/kvm/vm/vm_x86_64/sev.rs rename to alioth/src/hv/kvm/vm/vm_amd64/sev.rs diff --git a/alioth/src/hv/kvm/vm/vm_x86_64/tdx.rs b/alioth/src/hv/kvm/vm/vm_amd64/tdx.rs similarity index 100% rename from alioth/src/hv/kvm/vm/vm_x86_64/tdx.rs rename to alioth/src/hv/kvm/vm/vm_amd64/tdx.rs diff --git a/alioth/src/hv/kvm/vm/vm_x86_64/vm_x86_64.rs b/alioth/src/hv/kvm/vm/vm_amd64/vm_amd64.rs similarity index 99% rename from alioth/src/hv/kvm/vm/vm_x86_64/vm_x86_64.rs rename to alioth/src/hv/kvm/vm/vm_amd64/vm_amd64.rs index 295cd249..be6da959 100644 --- a/alioth/src/hv/kvm/vm/vm_x86_64/vm_x86_64.rs +++ b/alioth/src/hv/kvm/vm/vm_amd64/vm_amd64.rs @@ -116,5 +116,5 @@ impl KvmVm { } #[cfg(test)] -#[path = "vm_x86_64_test.rs"] +#[path = "vm_amd64_test.rs"] mod test; diff --git a/alioth/src/hv/kvm/vm/vm_x86_64/vm_x86_64_test.rs b/alioth/src/hv/kvm/vm/vm_amd64/vm_amd64_test.rs similarity index 100% rename from alioth/src/hv/kvm/vm/vm_x86_64/vm_x86_64_test.rs rename to alioth/src/hv/kvm/vm/vm_amd64/vm_amd64_test.rs diff --git a/alioth/src/hv/kvm/vm/vm_aarch64.rs b/alioth/src/hv/kvm/vm/vm_arm64.rs similarity index 100% rename from alioth/src/hv/kvm/vm/vm_aarch64.rs rename to alioth/src/hv/kvm/vm/vm_arm64.rs diff --git a/alioth/src/loader/firmware/firmware.rs b/alioth/src/loader/firmware/firmware.rs index d94bd596..40358146 100644 --- a/alioth/src/loader/firmware/firmware.rs +++ b/alioth/src/loader/firmware/firmware.rs @@ -13,10 +13,10 @@ // limitations under the License. #[cfg(target_arch = "aarch64")] -#[path = "firmware_aarch64.rs"] +#[path = "firmware_arm64.rs"] mod aarch64; #[cfg(target_arch = "x86_64")] -#[path = "firmware_x86_64.rs"] +#[path = "firmware_amd64.rs"] mod x86_64; #[cfg(target_arch = "aarch64")] diff --git a/alioth/src/loader/firmware/firmware_x86_64.rs b/alioth/src/loader/firmware/firmware_amd64.rs similarity index 100% rename from alioth/src/loader/firmware/firmware_x86_64.rs rename to alioth/src/loader/firmware/firmware_amd64.rs diff --git a/alioth/src/loader/firmware/firmware_aarch64.rs b/alioth/src/loader/firmware/firmware_arm64.rs similarity index 100% rename from alioth/src/loader/firmware/firmware_aarch64.rs rename to alioth/src/loader/firmware/firmware_arm64.rs diff --git a/alioth/src/loader/linux/linux.rs b/alioth/src/loader/linux/linux.rs index 97f4ea10..a40da9e0 100644 --- a/alioth/src/loader/linux/linux.rs +++ b/alioth/src/loader/linux/linux.rs @@ -13,12 +13,12 @@ // limitations under the License. #[cfg(target_arch = "aarch64")] -#[path = "linux_aarch64.rs"] +#[path = "linux_arm64.rs"] mod aarch64; #[cfg(target_arch = "x86_64")] pub mod bootparams; #[cfg(target_arch = "x86_64")] -#[path = "linux_x86_64.rs"] +#[path = "linux_amd64.rs"] mod x86_64; #[cfg(target_arch = "aarch64")] diff --git a/alioth/src/loader/linux/linux_x86_64.rs b/alioth/src/loader/linux/linux_amd64.rs similarity index 100% rename from alioth/src/loader/linux/linux_x86_64.rs rename to alioth/src/loader/linux/linux_amd64.rs diff --git a/alioth/src/loader/linux/linux_aarch64.rs b/alioth/src/loader/linux/linux_arm64.rs similarity index 100% rename from alioth/src/loader/linux/linux_aarch64.rs rename to alioth/src/loader/linux/linux_arm64.rs From 567dfa2b3037ea87eeadba9060d6de3520180a79 Mon Sep 17 00:00:00 2001 From: Changyuan Lyu Date: Wed, 8 Jul 2026 03:56:19 -0700 Subject: [PATCH 2/2] style(aco): move tests to a standalone file Signed-off-by: Changyuan Lyu --- serde-aco/src/de.rs | 520 +------------------------------------- serde-aco/src/de_test.rs | 529 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 531 insertions(+), 518 deletions(-) create mode 100644 serde-aco/src/de_test.rs diff --git a/serde-aco/src/de.rs b/serde-aco/src/de.rs index 33d4d428..1f1b9ca7 100644 --- a/serde-aco/src/de.rs +++ b/serde-aco/src/de.rs @@ -536,521 +536,5 @@ impl<'s> VariantAccess<'s> for Enum<'_, 's, '_> { } #[cfg(test)] -mod test { - use std::collections::HashMap; - use std::marker::PhantomData; - - use assert_matches::assert_matches; - use serde::Deserialize; - use serde_bytes::{ByteArray, ByteBuf}; - - use crate::{Error, from_arg, from_args}; - - #[test] - fn test_option() { - assert_matches!(from_arg::>(""), Err(Error::ExpectedInteger)); - assert_eq!(from_arg::>("12").unwrap(), Some(12)); - - assert_eq!(from_arg::>("").unwrap(), Some("")); - assert_eq!( - from_args::>("id_1", &HashMap::from([("id_1", "")])).unwrap(), - None - ); - assert_eq!(from_arg::>("12").unwrap(), Some("12")); - assert_matches!( - from_arg::>("id_1"), - Err(Error::IdNotFound(id)) if id == "id_1" - ); - assert_eq!( - from_args::>("id_1", &HashMap::from([("id_1", "id_2")])).unwrap(), - Some("id_2") - ); - - let map_none = HashMap::from([("id_none", "")]); - assert_eq!(from_arg::>>("").unwrap(), vec![]); - assert_eq!( - from_args::>>("id_none,", &map_none).unwrap(), - vec![None] - ); - assert_eq!(from_arg::>>("1,").unwrap(), vec![Some(1)]); - assert_eq!( - from_arg::>>("1,2,").unwrap(), - vec![Some(1), Some(2)] - ); - assert_eq!( - from_args::>>("1,2,id_none,", &map_none).unwrap(), - vec![Some(1), Some(2), None] - ); - assert_eq!( - from_args::>>("id_none,2", &map_none).unwrap(), - vec![None, Some(2)] - ); - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct SimpleStruct { - val: u32, - other: u32, - } - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct TestOptionStruct { - opt: Option, - } - assert_eq!( - from_args::("opt=id_s", &[("id_s", "val=12,other=34")].into()) - .unwrap(), - TestOptionStruct { - opt: Some(SimpleStruct { val: 12, other: 34 }) - } - ); - } - - #[test] - fn test_unit() { - assert!(from_arg::<()>("").is_ok()); - assert_matches!(from_arg::<()>("unit"), Err(Error::ExpectedUnit)); - - assert!(from_arg::>("").is_ok()); - assert_matches!(from_arg::>("12"), Err(Error::ExpectedUnit)); - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct Param { - p: PhantomData, - } - assert_eq!(from_arg::("p=").unwrap(), Param { p: PhantomData }); - assert_matches!(from_arg::("p=1,"), Err(Error::ExpectedUnit)); - } - - #[test] - fn test_numbers() { - assert_eq!(from_arg::("0").unwrap(), 0); - assert_eq!(from_arg::("1").unwrap(), 1); - assert_eq!(from_arg::("127").unwrap(), 127); - assert_matches!(from_arg::("128"), Err(Error::Overflow)); - assert_eq!(from_arg::("-1").unwrap(), -1); - assert_eq!(from_arg::("-128").unwrap(), -128); - assert_matches!(from_arg::("-129"), Err(Error::Overflow)); - - assert_eq!(from_arg::("1k").unwrap(), 1 << 10); - - assert_eq!(from_arg::("1g").unwrap(), 1 << 30); - assert_matches!(from_arg::("2g"), Err(Error::Overflow)); - assert_matches!(from_arg::("0xffffffff"), Err(Error::Overflow)); - - assert_eq!(from_arg::("0xffffffff").unwrap(), 0xffffffff); - - assert_matches!(from_arg::("gg"), Err(Error::ExpectedInteger)); - - assert_matches!(from_arg::("0.125").unwrap(), 0.125); - - assert_matches!(from_arg::("-0.5").unwrap(), -0.5); - } - - #[test] - fn test_char() { - assert_eq!(from_arg::("=").unwrap(), '='); - assert_eq!(from_arg::("a").unwrap(), 'a'); - assert_matches!(from_arg::("an"), Err(Error::Message(_))); - - assert_eq!( - from_args::>( - "id_1=a,b=id_2,id_2=id_1", - &HashMap::from([("id_1", ","), ("id_2", "="),]) - ) - .unwrap(), - HashMap::from([(',', 'a'), ('b', '='), ('=', ',')]) - ); - } - - #[test] - fn test_bytes() { - assert!(from_arg::>("0xea,0xd7,0xa8,0xe8,0xc6,0x2f").is_ok()); - assert_matches!( - from_arg::>("0xea,0xd7,0xa8,0xe8,0xc6,0x2f"), - Err(Error::Trailing(t)) if t == "0x2f" - ); - assert_eq!( - from_arg::("0xea,0xd7,0xa8,0xe8,0xc6,0x2f").unwrap(), - vec![0xea, 0xd7, 0xa8, 0xe8, 0xc6, 0x2f] - ); - - #[derive(Debug, Deserialize, Eq, PartialEq)] - struct MacAddr { - addr: ByteArray<6>, - } - assert_eq!( - from_args::( - "addr=id_addr", - &HashMap::from([("id_addr", "0xea,0xd7,0xa8,0xe8,0xc6,0x2f")]) - ) - .unwrap(), - MacAddr { - addr: ByteArray::new([0xea, 0xd7, 0xa8, 0xe8, 0xc6, 0x2f]) - } - ) - } - - #[test] - fn test_string() { - assert_eq!( - from_arg::("test,s=1,c").unwrap(), - "test,s=1,c".to_owned() - ); - assert_eq!( - from_args::>( - "cmd=id_1", - &HashMap::from([("id_1", "console=ttyS0")]) - ) - .unwrap(), - HashMap::from([("cmd".to_owned(), "console=ttyS0".to_owned())]) - ) - } - - #[test] - fn test_seq() { - assert_eq!(from_arg::>("").unwrap(), vec![]); - - assert_eq!(from_arg::>("1").unwrap(), vec![1]); - - assert_eq!(from_arg::>("1,2,3,4").unwrap(), vec![1, 2, 3, 4]); - - assert_eq!(from_arg::<(u16, bool)>("12,true").unwrap(), (12, true)); - assert_matches!( - from_arg::<(u16, bool)>("12,true,false"), - Err(Error::Trailing(t)) if t == "false" - ); - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct TestStruct { - a: (u16, bool), - } - assert_eq!( - from_args::("a=id_a", &HashMap::from([("id_a", "12,true")])).unwrap(), - TestStruct { a: (12, true) } - ); - assert_matches!( - from_args::("a=id_a", &HashMap::from([("id_a", "12,true,true")])), - Err(Error::Trailing(t)) if t == "true" - ); - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct Node { - #[serde(default)] - name: String, - #[serde(default)] - start: u64, - size: u64, - } - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct Numa { - nodes: Vec, - } - - assert_eq!( - from_args::( - "nodes=id_nodes", - &HashMap::from([ - ("id_nodes", "id_node1,id_node2"), - ("id_node1", "name=a,start=0,size=2g"), - ("id_node2", "name=b,start=4g,size=2g"), - ]) - ) - .unwrap(), - Numa { - nodes: vec![ - Node { - name: "a".to_owned(), - start: 0, - size: 2 << 30 - }, - Node { - name: "b".to_owned(), - start: 4 << 30, - size: 2 << 30 - } - ] - } - ); - - assert_eq!( - from_arg::("nodes=size=2g,").unwrap(), - Numa { - nodes: vec![Node { - name: "".to_owned(), - start: 0, - size: 2 << 30 - }] - } - ); - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct Info(bool, u32); - - assert_eq!(from_arg::("true,32").unwrap(), Info(true, 32)); - } - - #[test] - fn test_map() { - #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] - struct MapKey { - name: String, - id: u32, - } - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct MapVal { - addr: String, - info: HashMap, - } - - assert_matches!( - from_arg::("name=a,id=1,addr=b"), - Err(Error::Ignored(k)) if k == "addr" - ); - assert_matches!( - from_arg::("name=a,addr=b,id=1"), - Err(Error::Ignored(k)) if k == "addr" - ); - assert_matches!(from_arg::("name=a,ids=b"), Err(Error::Ignored(k)) if k == "ids"); - assert_matches!(from_arg::("name=a,ids=b,id=1"), Err(Error::Ignored(k)) if k == "ids"); - - assert_eq!( - from_args::>( - "id_key1=id_val1,id_key2=id_val2", - &HashMap::from([ - ("id_key1", "name=gic,id=1"), - ("id_key2", "name=pci,id=2"), - ("id_val1", "addr=0xff,info=id_info1"), - ("id_info1", "compatible=id_gic,msi-controller=,#msi-cells=1"), - ("id_gic", "arm,gic-v3-its"), - ("id_val2", "addr=0xcc,info=compatible=pci-host-ecam-generic"), - ]) - ) - .unwrap(), - HashMap::from([ - ( - MapKey { - name: "gic".to_owned(), - id: 1 - }, - MapVal { - addr: "0xff".to_owned(), - info: HashMap::from([ - ("compatible".to_owned(), "arm,gic-v3-its".to_owned()), - ("msi-controller".to_owned(), "".to_owned()), - ("#msi-cells".to_owned(), "1".to_owned()) - ]) - } - ), - ( - MapKey { - name: "pci".to_owned(), - id: 2 - }, - MapVal { - addr: "0xcc".to_owned(), - info: HashMap::from([( - "compatible".to_owned(), - "pci-host-ecam-generic".to_owned() - )]) - } - ) - ]) - ); - } - - #[test] - fn test_nested_struct() { - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct Param { - byte: u8, - word: u16, - dw: u32, - long: u64, - enable_1: bool, - enable_2: bool, - enable_3: Option, - sub: SubParam, - addr: Addr, - } - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct SubParam { - b: u8, - w: u16, - enable: Option, - s: String, - } - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct Addr(u32); - - assert_eq!( - from_args::( - "byte=0b10,word=0o7k,dw=0x8m,long=10t,enable_1=on,enable_2=off,sub=id_1,addr=1g", - &[("id_1", "b=1,w=2,s=s1,enable=on")].into() - ) - .unwrap(), - Param { - byte: 0b10, - word: 0o7 << 10, - dw: 0x8 << 20, - long: 10 << 40, - enable_1: true, - enable_2: false, - enable_3: None, - sub: SubParam { - b: 1, - w: 2, - enable: Some(true), - s: "s1".to_owned(), - }, - addr: Addr(1 << 30) - } - ); - assert_matches!( - from_arg::("b=1,w=2,enable,s=s1"), - Err(Error::ExpectedMapEq) - ); - assert_matches!( - from_arg::("b=1,w=2,s=s1,enable"), - Err(Error::ExpectedMapEq) - ); - } - - #[test] - fn test_bool() { - assert_matches!(from_arg::("on"), Ok(true)); - assert_matches!(from_arg::("off"), Ok(false)); - assert_matches!(from_arg::("true"), Ok(true)); - assert_matches!(from_arg::("false"), Ok(false)); - assert_matches!(from_arg::("on,off"), Err(Error::Trailing(t)) if t == "off"); - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct BoolStruct { - val: bool, - } - assert_eq!( - from_arg::("val=on").unwrap(), - BoolStruct { val: true } - ); - assert_eq!( - from_arg::("val=off").unwrap(), - BoolStruct { val: false } - ); - assert_eq!( - from_arg::("val=true").unwrap(), - BoolStruct { val: true } - ); - assert_eq!( - from_arg::("val=false").unwrap(), - BoolStruct { val: false } - ); - assert_matches!(from_arg::("val=a"), Err(Error::ExpectedBool)); - - assert_matches!( - from_arg::("val=on,key=off"), - Err(Error::Ignored(k)) if k == "key" - ); - } - - #[test] - fn test_enum() { - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct SubStruct { - a: u32, - b: bool, - } - - #[derive(Debug, Deserialize, PartialEq, Eq)] - enum TestEnum { - A { - #[serde(default)] - val: u32, - }, - B(u64), - C(u8, u8), - D, - #[serde(alias = "e")] - E, - F(SubStruct), - G(u16, String, bool), - } - - #[derive(Debug, Deserialize, PartialEq, Eq)] - struct TestStruct { - num: u32, - e: TestEnum, - } - - assert_eq!( - from_args::("num=3,e=id_a", &[("id_a", "A,val=1")].into()).unwrap(), - TestStruct { - num: 3, - e: TestEnum::A { val: 1 } - } - ); - assert_eq!( - from_arg::("num=4,e=A").unwrap(), - TestStruct { - num: 4, - e: TestEnum::A { val: 0 }, - } - ); - assert_eq!( - from_args::("num=4,e=id_a", &[("id_a", "A")].into()).unwrap(), - TestStruct { - num: 4, - e: TestEnum::A { val: 0 }, - } - ); - assert_eq!( - from_arg::("num=4,e=D").unwrap(), - TestStruct { - num: 4, - e: TestEnum::D, - } - ); - assert_eq!( - from_args::("num=4,e=id_d", &[("id_d", "D")].into()).unwrap(), - TestStruct { - num: 4, - e: TestEnum::D, - } - ); - assert_eq!( - from_arg::("num=3,e=e").unwrap(), - TestStruct { - num: 3, - e: TestEnum::E - } - ); - assert_matches!( - from_arg::("num=4,e=id_d"), - Err(Error::IdNotFound(id)) if id == "id_d" - ); - assert_matches!( - from_args::("num=4,e=id_d", &[].into()), - Err(Error::IdNotFound(id)) if id == "id_d" - ); - assert_eq!(from_arg::("B,1").unwrap(), TestEnum::B(1)); - assert_eq!(from_arg::("D").unwrap(), TestEnum::D); - assert_eq!( - from_arg::("F,a=1,b=on").unwrap(), - TestEnum::F(SubStruct { a: 1, b: true }) - ); - assert_eq!( - from_arg::("G,1,a,true").unwrap(), - TestEnum::G(1, "a".to_owned(), true) - ); - assert_matches!( - from_arg::("G,1,a,true,false"), - Err(Error::Trailing(t)) if t == "false" - ); - assert_matches!( - from_args::( - "num=4,e=id_e", - &HashMap::from([("id_e", "G,1,a,true,false")]) - ), - Err(Error::Trailing(t)) if t == "false" - ); - } -} +#[path = "de_test.rs"] +mod tests; diff --git a/serde-aco/src/de_test.rs b/serde-aco/src/de_test.rs new file mode 100644 index 00000000..378e295c --- /dev/null +++ b/serde-aco/src/de_test.rs @@ -0,0 +1,529 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::collections::HashMap; +use std::marker::PhantomData; + +use assert_matches::assert_matches; +use serde::Deserialize; +use serde_bytes::{ByteArray, ByteBuf}; + +use crate::{Error, from_arg, from_args}; + +#[test] +fn test_option() { + assert_matches!(from_arg::>(""), Err(Error::ExpectedInteger)); + assert_eq!(from_arg::>("12").unwrap(), Some(12)); + + assert_eq!(from_arg::>("").unwrap(), Some("")); + assert_eq!( + from_args::>("id_1", &HashMap::from([("id_1", "")])).unwrap(), + None + ); + assert_eq!(from_arg::>("12").unwrap(), Some("12")); + assert_matches!( + from_arg::>("id_1"), + Err(Error::IdNotFound(id)) if id == "id_1" + ); + assert_eq!( + from_args::>("id_1", &HashMap::from([("id_1", "id_2")])).unwrap(), + Some("id_2") + ); + + let map_none = HashMap::from([("id_none", "")]); + assert_eq!(from_arg::>>("").unwrap(), vec![]); + assert_eq!( + from_args::>>("id_none,", &map_none).unwrap(), + vec![None] + ); + assert_eq!(from_arg::>>("1,").unwrap(), vec![Some(1)]); + assert_eq!( + from_arg::>>("1,2,").unwrap(), + vec![Some(1), Some(2)] + ); + assert_eq!( + from_args::>>("1,2,id_none,", &map_none).unwrap(), + vec![Some(1), Some(2), None] + ); + assert_eq!( + from_args::>>("id_none,2", &map_none).unwrap(), + vec![None, Some(2)] + ); + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct SimpleStruct { + val: u32, + other: u32, + } + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct TestOptionStruct { + opt: Option, + } + assert_eq!( + from_args::("opt=id_s", &[("id_s", "val=12,other=34")].into()).unwrap(), + TestOptionStruct { + opt: Some(SimpleStruct { val: 12, other: 34 }) + } + ); +} + +#[test] +fn test_unit() { + assert!(from_arg::<()>("").is_ok()); + assert_matches!(from_arg::<()>("unit"), Err(Error::ExpectedUnit)); + + assert!(from_arg::>("").is_ok()); + assert_matches!(from_arg::>("12"), Err(Error::ExpectedUnit)); + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct Param { + p: PhantomData, + } + assert_eq!(from_arg::("p=").unwrap(), Param { p: PhantomData }); + assert_matches!(from_arg::("p=1,"), Err(Error::ExpectedUnit)); +} + +#[test] +fn test_numbers() { + assert_eq!(from_arg::("0").unwrap(), 0); + assert_eq!(from_arg::("1").unwrap(), 1); + assert_eq!(from_arg::("127").unwrap(), 127); + assert_matches!(from_arg::("128"), Err(Error::Overflow)); + assert_eq!(from_arg::("-1").unwrap(), -1); + assert_eq!(from_arg::("-128").unwrap(), -128); + assert_matches!(from_arg::("-129"), Err(Error::Overflow)); + + assert_eq!(from_arg::("1k").unwrap(), 1 << 10); + + assert_eq!(from_arg::("1g").unwrap(), 1 << 30); + assert_matches!(from_arg::("2g"), Err(Error::Overflow)); + assert_matches!(from_arg::("0xffffffff"), Err(Error::Overflow)); + + assert_eq!(from_arg::("0xffffffff").unwrap(), 0xffffffff); + + assert_matches!(from_arg::("gg"), Err(Error::ExpectedInteger)); + + assert_matches!(from_arg::("0.125").unwrap(), 0.125); + + assert_matches!(from_arg::("-0.5").unwrap(), -0.5); +} + +#[test] +fn test_char() { + assert_eq!(from_arg::("=").unwrap(), '='); + assert_eq!(from_arg::("a").unwrap(), 'a'); + assert_matches!(from_arg::("an"), Err(Error::Message(_))); + + assert_eq!( + from_args::>( + "id_1=a,b=id_2,id_2=id_1", + &HashMap::from([("id_1", ","), ("id_2", "="),]) + ) + .unwrap(), + HashMap::from([(',', 'a'), ('b', '='), ('=', ',')]) + ); +} + +#[test] +fn test_bytes() { + assert!(from_arg::>("0xea,0xd7,0xa8,0xe8,0xc6,0x2f").is_ok()); + assert_matches!( + from_arg::>("0xea,0xd7,0xa8,0xe8,0xc6,0x2f"), + Err(Error::Trailing(t)) if t == "0x2f" + ); + assert_eq!( + from_arg::("0xea,0xd7,0xa8,0xe8,0xc6,0x2f").unwrap(), + vec![0xea, 0xd7, 0xa8, 0xe8, 0xc6, 0x2f] + ); + + #[derive(Debug, Deserialize, Eq, PartialEq)] + struct MacAddr { + addr: ByteArray<6>, + } + assert_eq!( + from_args::( + "addr=id_addr", + &HashMap::from([("id_addr", "0xea,0xd7,0xa8,0xe8,0xc6,0x2f")]) + ) + .unwrap(), + MacAddr { + addr: ByteArray::new([0xea, 0xd7, 0xa8, 0xe8, 0xc6, 0x2f]) + } + ) +} + +#[test] +fn test_string() { + assert_eq!( + from_arg::("test,s=1,c").unwrap(), + "test,s=1,c".to_owned() + ); + assert_eq!( + from_args::>( + "cmd=id_1", + &HashMap::from([("id_1", "console=ttyS0")]) + ) + .unwrap(), + HashMap::from([("cmd".to_owned(), "console=ttyS0".to_owned())]) + ) +} + +#[test] +fn test_seq() { + assert_eq!(from_arg::>("").unwrap(), vec![]); + + assert_eq!(from_arg::>("1").unwrap(), vec![1]); + + assert_eq!(from_arg::>("1,2,3,4").unwrap(), vec![1, 2, 3, 4]); + + assert_eq!(from_arg::<(u16, bool)>("12,true").unwrap(), (12, true)); + assert_matches!( + from_arg::<(u16, bool)>("12,true,false"), + Err(Error::Trailing(t)) if t == "false" + ); + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct TestStruct { + a: (u16, bool), + } + assert_eq!( + from_args::("a=id_a", &HashMap::from([("id_a", "12,true")])).unwrap(), + TestStruct { a: (12, true) } + ); + assert_matches!( + from_args::("a=id_a", &HashMap::from([("id_a", "12,true,true")])), + Err(Error::Trailing(t)) if t == "true" + ); + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct Node { + #[serde(default)] + name: String, + #[serde(default)] + start: u64, + size: u64, + } + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct Numa { + nodes: Vec, + } + + assert_eq!( + from_args::( + "nodes=id_nodes", + &HashMap::from([ + ("id_nodes", "id_node1,id_node2"), + ("id_node1", "name=a,start=0,size=2g"), + ("id_node2", "name=b,start=4g,size=2g"), + ]) + ) + .unwrap(), + Numa { + nodes: vec![ + Node { + name: "a".to_owned(), + start: 0, + size: 2 << 30 + }, + Node { + name: "b".to_owned(), + start: 4 << 30, + size: 2 << 30 + } + ] + } + ); + + assert_eq!( + from_arg::("nodes=size=2g,").unwrap(), + Numa { + nodes: vec![Node { + name: "".to_owned(), + start: 0, + size: 2 << 30 + }] + } + ); + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct Info(bool, u32); + + assert_eq!(from_arg::("true,32").unwrap(), Info(true, 32)); +} + +#[test] +fn test_map() { + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] + struct MapKey { + name: String, + id: u32, + } + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct MapVal { + addr: String, + info: HashMap, + } + + assert_matches!( + from_arg::("name=a,id=1,addr=b"), + Err(Error::Ignored(k)) if k == "addr" + ); + assert_matches!( + from_arg::("name=a,addr=b,id=1"), + Err(Error::Ignored(k)) if k == "addr" + ); + assert_matches!(from_arg::("name=a,ids=b"), Err(Error::Ignored(k)) if k == "ids"); + assert_matches!(from_arg::("name=a,ids=b,id=1"), Err(Error::Ignored(k)) if k == "ids"); + + assert_eq!( + from_args::>( + "id_key1=id_val1,id_key2=id_val2", + &HashMap::from([ + ("id_key1", "name=gic,id=1"), + ("id_key2", "name=pci,id=2"), + ("id_val1", "addr=0xff,info=id_info1"), + ("id_info1", "compatible=id_gic,msi-controller=,#msi-cells=1"), + ("id_gic", "arm,gic-v3-its"), + ("id_val2", "addr=0xcc,info=compatible=pci-host-ecam-generic"), + ]) + ) + .unwrap(), + HashMap::from([ + ( + MapKey { + name: "gic".to_owned(), + id: 1 + }, + MapVal { + addr: "0xff".to_owned(), + info: HashMap::from([ + ("compatible".to_owned(), "arm,gic-v3-its".to_owned()), + ("msi-controller".to_owned(), "".to_owned()), + ("#msi-cells".to_owned(), "1".to_owned()) + ]) + } + ), + ( + MapKey { + name: "pci".to_owned(), + id: 2 + }, + MapVal { + addr: "0xcc".to_owned(), + info: HashMap::from([( + "compatible".to_owned(), + "pci-host-ecam-generic".to_owned() + )]) + } + ) + ]) + ); +} + +#[test] +fn test_nested_struct() { + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct Param { + byte: u8, + word: u16, + dw: u32, + long: u64, + enable_1: bool, + enable_2: bool, + enable_3: Option, + sub: SubParam, + addr: Addr, + } + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct SubParam { + b: u8, + w: u16, + enable: Option, + s: String, + } + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct Addr(u32); + + assert_eq!( + from_args::( + "byte=0b10,word=0o7k,dw=0x8m,long=10t,enable_1=on,enable_2=off,sub=id_1,addr=1g", + &[("id_1", "b=1,w=2,s=s1,enable=on")].into() + ) + .unwrap(), + Param { + byte: 0b10, + word: 0o7 << 10, + dw: 0x8 << 20, + long: 10 << 40, + enable_1: true, + enable_2: false, + enable_3: None, + sub: SubParam { + b: 1, + w: 2, + enable: Some(true), + s: "s1".to_owned(), + }, + addr: Addr(1 << 30) + } + ); + assert_matches!( + from_arg::("b=1,w=2,enable,s=s1"), + Err(Error::ExpectedMapEq) + ); + assert_matches!( + from_arg::("b=1,w=2,s=s1,enable"), + Err(Error::ExpectedMapEq) + ); +} + +#[test] +fn test_bool() { + assert_matches!(from_arg::("on"), Ok(true)); + assert_matches!(from_arg::("off"), Ok(false)); + assert_matches!(from_arg::("true"), Ok(true)); + assert_matches!(from_arg::("false"), Ok(false)); + assert_matches!(from_arg::("on,off"), Err(Error::Trailing(t)) if t == "off"); + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct BoolStruct { + val: bool, + } + assert_eq!( + from_arg::("val=on").unwrap(), + BoolStruct { val: true } + ); + assert_eq!( + from_arg::("val=off").unwrap(), + BoolStruct { val: false } + ); + assert_eq!( + from_arg::("val=true").unwrap(), + BoolStruct { val: true } + ); + assert_eq!( + from_arg::("val=false").unwrap(), + BoolStruct { val: false } + ); + assert_matches!(from_arg::("val=a"), Err(Error::ExpectedBool)); + + assert_matches!( + from_arg::("val=on,key=off"), + Err(Error::Ignored(k)) if k == "key" + ); +} + +#[test] +fn test_enum() { + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct SubStruct { + a: u32, + b: bool, + } + + #[derive(Debug, Deserialize, PartialEq, Eq)] + enum TestEnum { + A { + #[serde(default)] + val: u32, + }, + B(u64), + C(u8, u8), + D, + #[serde(alias = "e")] + E, + F(SubStruct), + G(u16, String, bool), + } + + #[derive(Debug, Deserialize, PartialEq, Eq)] + struct TestStruct { + num: u32, + e: TestEnum, + } + + assert_eq!( + from_args::("num=3,e=id_a", &[("id_a", "A,val=1")].into()).unwrap(), + TestStruct { + num: 3, + e: TestEnum::A { val: 1 } + } + ); + assert_eq!( + from_arg::("num=4,e=A").unwrap(), + TestStruct { + num: 4, + e: TestEnum::A { val: 0 }, + } + ); + assert_eq!( + from_args::("num=4,e=id_a", &[("id_a", "A")].into()).unwrap(), + TestStruct { + num: 4, + e: TestEnum::A { val: 0 }, + } + ); + assert_eq!( + from_arg::("num=4,e=D").unwrap(), + TestStruct { + num: 4, + e: TestEnum::D, + } + ); + assert_eq!( + from_args::("num=4,e=id_d", &[("id_d", "D")].into()).unwrap(), + TestStruct { + num: 4, + e: TestEnum::D, + } + ); + assert_eq!( + from_arg::("num=3,e=e").unwrap(), + TestStruct { + num: 3, + e: TestEnum::E + } + ); + assert_matches!( + from_arg::("num=4,e=id_d"), + Err(Error::IdNotFound(id)) if id == "id_d" + ); + assert_matches!( + from_args::("num=4,e=id_d", &[].into()), + Err(Error::IdNotFound(id)) if id == "id_d" + ); + assert_eq!(from_arg::("B,1").unwrap(), TestEnum::B(1)); + assert_eq!(from_arg::("D").unwrap(), TestEnum::D); + assert_eq!( + from_arg::("F,a=1,b=on").unwrap(), + TestEnum::F(SubStruct { a: 1, b: true }) + ); + assert_eq!( + from_arg::("G,1,a,true").unwrap(), + TestEnum::G(1, "a".to_owned(), true) + ); + assert_matches!( + from_arg::("G,1,a,true,false"), + Err(Error::Trailing(t)) if t == "false" + ); + assert_matches!( + from_args::( + "num=4,e=id_e", + &HashMap::from([("id_e", "G,1,a,true,false")]) + ), + Err(Error::Trailing(t)) if t == "false" + ); +}