Skip to content

Commit

Permalink
feat: support ppc64le and riscv64
Browse files Browse the repository at this point in the history
Add `BASE_MAGIC_ID` in ppc64le and riscv64 archs.

Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high committed Dec 12, 2023
1 parent 098fca6 commit fd2fe98
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const BASE_MAGIC_ID: u64 = 0x0710_1984_8664_0000u64;
#[cfg(target_arch = "aarch64")]
const BASE_MAGIC_ID: u64 = 0x0710_1984_AAAA_0000u64;

#[cfg(target_arch = "powerpc64")]
const BASE_MAGIC_ID: u64 = 0x0710_1984_CC64_0000u64;

#[cfg(target_arch = "riscv64")]
const BASE_MAGIC_ID: u64 = 0x0710_1984_C564_0000u64;

/// Error definitions for the Snapshot API.
#[derive(Debug, thiserror::Error, displaydoc::Display, PartialEq)]
pub enum Error {
Expand Down Expand Up @@ -326,6 +332,10 @@ mod tests {
let good_magic_id = 0x0710_1984_8664_0001u64;
#[cfg(target_arch = "aarch64")]
let good_magic_id = 0x0710_1984_AAAA_0001u64;
#[cfg(target_arch = "powerpc64")]
let good_magic_id = 0x0710_1984_CC64_0001u64;
#[cfg(target_arch = "riscv64")]
let good_magic_id = 0x0710_1984_C564_0001u64;

assert_eq!(get_format_version(good_magic_id).unwrap(), 1u16);

Expand Down Expand Up @@ -550,6 +560,10 @@ mod tests {
let expected_err = Error::Crc64(0x1960_4E6A_A13F_6615);
#[cfg(target_arch = "x86_64")]
let expected_err = Error::Crc64(0x103F_8F52_8F51_20B1);
#[cfg(target_arch = "powerpc64")]
let expected_err = Error::Crc64(0x33D0_CCE5_DA3C_CCEA);
#[cfg(target_arch = "riscv64")]
let expected_err = Error::Crc64(0xFAC5_E225_5586_9011);

let load_result: Result<(Test1, _), Error> =
Snapshot::load(&mut snapshot_mem.as_slice(), 38, vm);
Expand Down
51 changes: 50 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ fn test_hardcoded_snapshot_deserialization() {
0xAA,
#[cfg(target_arch = "aarch64")]
0xAA,
#[cfg(target_arch = "powerpc64")]
0x64,
#[cfg(target_arch = "powerpc64")]
0xCC,
#[cfg(target_arch = "riscv64")]
0x64,
#[cfg(target_arch = "riscv64")]
0xC5,
#[cfg(target_arch = "x86_64")]
0x64,
#[cfg(target_arch = "x86_64")]
Expand All @@ -75,10 +83,19 @@ fn test_hardcoded_snapshot_deserialization() {
0xAA,
#[cfg(target_arch = "aarch64")]
0xAA,
#[cfg(target_arch = "powerpc64")]
0x64,
#[cfg(target_arch = "powerpc64")]
0xCC,
#[cfg(target_arch = "riscv64")]
0x64,
#[cfg(target_arch = "riscv64")]
0xC5,
#[cfg(target_arch = "x86_64")]
0x64,
#[cfg(target_arch = "x86_64")]
0x86, 0x84, 0x19, 0x10, 0x07,
0x86,
0x84, 0x19, 0x10, 0x07,
// Version 2 +
0x02, 0x00,
// `a` field +
Expand Down Expand Up @@ -129,6 +146,14 @@ fn test_invalid_format_version() {
0xAA,
#[cfg(target_arch = "aarch64")]
0xAA,
#[cfg(target_arch = "powerpc64")]
0x64,
#[cfg(target_arch = "powerpc64")]
0xCC,
#[cfg(target_arch = "riscv64")]
0x64,
#[cfg(target_arch = "riscv64")]
0xC5,
#[cfg(target_arch = "x86_64")]
0x64,
#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -156,6 +181,14 @@ fn test_invalid_format_version() {
0xAA,
#[cfg(target_arch = "aarch64")]
0xAA,
#[cfg(target_arch = "powerpc64")]
0x64,
#[cfg(target_arch = "powerpc64")]
0xCC,
#[cfg(target_arch = "riscv64")]
0x64,
#[cfg(target_arch = "riscv64")]
0xC5,
#[cfg(target_arch = "x86_64")]
0x64,
#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -185,6 +218,14 @@ fn test_invalid_data_version() {
0xAA,
#[cfg(target_arch = "aarch64")]
0xAA,
#[cfg(target_arch = "powerpc64")]
0x64,
#[cfg(target_arch = "powerpc64")]
0xCC,
#[cfg(target_arch = "riscv64")]
0x64,
#[cfg(target_arch = "riscv64")]
0xC5,
#[cfg(target_arch = "x86_64")]
0x64,
#[cfg(target_arch = "x86_64")]
Expand All @@ -211,6 +252,14 @@ fn test_invalid_data_version() {
0xAA,
#[cfg(target_arch = "aarch64")]
0xAA,
#[cfg(target_arch = "powerpc64")]
0x64,
#[cfg(target_arch = "powerpc64")]
0xCC,
#[cfg(target_arch = "riscv64")]
0x64,
#[cfg(target_arch = "riscv64")]
0xC5,
#[cfg(target_arch = "x86_64")]
0x64,
#[cfg(target_arch = "x86_64")]
Expand Down

0 comments on commit fd2fe98

Please sign in to comment.