Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
test: test with-serde feature in CI
Browse files Browse the repository at this point in the history
Do a build-test of the `with-serde` feature. Also do some simple
round-trip testing to ensure consistent serialization (particularly, for
the items that have manual (De)Serialize implementations).

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
  • Loading branch information
roypat committed Mar 7, 2024
1 parent b2bc5fd commit 9d8be09
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .buildkite/custom-tests.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"tests": [
{
"test_name": "build-fam-gnu",
"command": "cargo build --release --features=fam-wrappers",
"test_name": "build-all-features-gnu",
"command": "cargo build --release --all-features --tests",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "build-fam-musl",
"command": "cargo build --release --features=fam-wrappers --target {target_platform}-unknown-linux-musl",
"test_name": "build-all-features-musl",
"command": "cargo build --release --all-features --target {target_platform}-unknown-linux-musl --tests",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "check-warnings-fam",
"command": "RUSTFLAGS=\"-D warnings\" cargo check --features=fam-wrappers",
"test_name": "check-warnings-all-features",
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-features",
"platform": [
"x86_64",
"aarch64"
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ with-serde = ["dep:serde", "serde/derive"]
[dependencies]
vmm-sys-util = { version = "0.12.1", optional = true }
serde = { version = "1.0.0", optional = true, features = ["derive"] }

[dev-dependencies]
bincode = "1.3.3"
2 changes: 1 addition & 1 deletion coverage_config_aarch64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 60.9,
"exclude_path": "",
"crate_features": "fam-wrappers"
"crate_features": "fam-wrappers,with-serde"
}
2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 100,
"exclude_path": ".*bindings\\.rs",
"crate_features": "fam-wrappers"
"crate_features": "fam-wrappers,with-serde"
}
9 changes: 8 additions & 1 deletion src/arm64/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ mod tests {
use bindings::*;
use serde::{Deserialize, Serialize};

fn is_serde<T: Serialize + for<'de> Deserialize<'de>>() {}
fn is_serde<T: Serialize + for<'de> Deserialize<'de> + Default>() {
let serialized = bincode::serialize(&T::default()).unwrap();
let deserialized = bincode::deserialize::<T>(serialized.as_ref()).unwrap();
let serialized_again = bincode::serialize(&deserialized).unwrap();
// Compare the serialized state after a roundtrip, to work around issues with
// bindings not implementing `PartialEq`.
assert_eq!(serialized, serialized_again);
}

#[test]
fn static_assert_serde_implementations() {
Expand Down
9 changes: 8 additions & 1 deletion src/x86_64/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ mod tests {
use super::*;
use bindings::*;

fn is_serde<T: Serialize + for<'de> Deserialize<'de>>() {}
fn is_serde<T: Serialize + for<'de> Deserialize<'de> + Default>() {
let serialized = bincode::serialize(&T::default()).unwrap();
let deserialized = bincode::deserialize::<T>(serialized.as_ref()).unwrap();
let serialized_again = bincode::serialize(&deserialized).unwrap();
// Compare the serialized state after a roundtrip, to work around issues with
// bindings not implementing `PartialEq`.
assert_eq!(serialized, serialized_again);
}

#[test]
fn static_assert_serde_implementations() {
Expand Down

0 comments on commit 9d8be09

Please sign in to comment.