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

Commit 34584e0

Browse files
committed
test: test with-serde feature in CI
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 <[email protected]>
1 parent de0c7b2 commit 34584e0

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

.buildkite/custom-tests.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
22
"tests": [
33
{
4-
"test_name": "build-fam-gnu",
5-
"command": "cargo build --release --features=fam-wrappers",
4+
"test_name": "build-all-features-gnu",
5+
"command": "cargo build --release --all-features --tests",
66
"platform": [
77
"x86_64",
88
"aarch64"
99
]
1010
},
1111
{
12-
"test_name": "build-fam-musl",
13-
"command": "cargo build --release --features=fam-wrappers --target {target_platform}-unknown-linux-musl",
12+
"test_name": "build-all-features-musl",
13+
"command": "cargo build --release --all-features --target {target_platform}-unknown-linux-musl --tests",
1414
"platform": [
1515
"x86_64",
1616
"aarch64"
1717
]
1818
},
1919
{
20-
"test_name": "check-warnings-fam",
21-
"command": "RUSTFLAGS=\"-D warnings\" cargo check --features=fam-wrappers",
20+
"test_name": "check-warnings-all-features",
21+
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-features",
2222
"platform": [
2323
"x86_64",
2424
"aarch64"

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ with-serde = ["dep:serde", "serde/derive", "dep:zerocopy"]
2323
vmm-sys-util = { version = "0.12.1", optional = true }
2424
serde = { version = "1.0.0", optional = true, features = ["derive"] }
2525
zerocopy = { version = "0.7.32", optional = true, features = ["derive"] }
26+
27+
[dev-dependencies]
28+
bincode = "1.3.3"

coverage_config_aarch64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"coverage_score": 60.9,
33
"exclude_path": "",
4-
"crate_features": "fam-wrappers"
4+
"crate_features": "fam-wrappers,with-serde"
55
}

coverage_config_x86_64.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 100,
2+
"coverage_score": 64,
33
"exclude_path": ".*bindings\\.rs",
4-
"crate_features": "fam-wrappers"
4+
"crate_features": "fam-wrappers,with-serde"
55
}

src/arm64/serialize.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ mod tests {
1818
use bindings::*;
1919
use serde::{Deserialize, Serialize};
2020

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

2330
#[test]
2431
fn static_assert_serde_implementations() {

src/x86_64/serialize.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ mod tests {
7373
use super::*;
7474
use bindings::*;
7575

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

7885
#[test]
7986
fn static_assert_serde_implementations() {

0 commit comments

Comments
 (0)