Skip to content

Commit

Permalink
chore: Improve test coverage a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
vifino committed Feb 11, 2024
1 parent de0f230 commit 0d1d232
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ env:
jobs:
build:
runs-on: ubuntu-latest

env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -C instrument-coverage
RUSTFLAGS: -D warnings -C instrument-coverage
LLVM_PROFILE_FILE: /tmp/nvmetcfg-%p-%8m.profraw

steps:
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/helpers/hash_differences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ where
mod tests {
use super::*;

#[test]
fn test_get_btreeset_differences() {
let mut base = BTreeSet::new();
let mut new = BTreeSet::new();

base.insert("Apple");
new.insert("Apple");
base.insert("Banana");
new.insert("Carrot");

let delta = get_btreeset_differences(&base, &new);
assert!(delta.same.contains("Apple"));
assert!(delta.removed.contains("Banana"));
assert!(delta.added.contains("Carrot"));
}

#[test]
fn test_get_btreemap_differences() {
let mut base = BTreeMap::new();
Expand Down
9 changes: 6 additions & 3 deletions src/helpers/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {
// Not ASCII.
assert!(assert_valid_nqn("nqn.2023-11.💩:invalid-nqn-unicode").is_err());
// Too long.
assert!(assert_valid_nqn("nqn.2023-11.sh.tty.foodreviews:Lopado\u{AD}temacho\u{AD}selacho\u{AD}galeo\u{AD}kranio\u{AD}leipsano\u{AD}drim\u{AD}hypo\u{AD}trimmato\u{AD}silphio\u{AD}karabo\u{AD}melito\u{AD}katakechy\u{AD}meno\u{AD}kichl\u{AD}epi\u{AD}kossypho\u{AD}phatto\u{AD}perister\u{AD}alektryon\u{AD}opte\u{AD}kephallio\u{AD}kigklo\u{AD}peleio\u{AD}lagoio\u{AD}siraio\u{AD}baphe\u{AD}tragano\u{AD}pterygon").is_err());
assert!(assert_valid_nqn("nqn.2023-11.sh.tty.foodreviews:Lopado-temacho-selacho-galeo-kranio-leipsano-drim-hypo-trimmato-silphio-karabo-melito-katakechy-meno-kichl-epi-kossypho-phatto-perister-alektryon-opte-kephallio-kigklo-peleio-lagoio-siraio-baphe-tragano-pterygon").is_err());

Ok(())
}
Expand All @@ -113,9 +113,12 @@ mod tests {
// No domain/identifier.
assert!(assert_compliant_nqn("nqn.2023-11.a").is_err());
// No domain/identifier.
assert!(assert_compliant_nqn("nqn.2023-11.a:").is_err());
assert!(assert_compliant_nqn("nqn.2023-11.apple:").is_err());
// No domain/identifier.
assert!(assert_compliant_nqn("nqn.2023-11.:b").is_err());
assert!(assert_compliant_nqn("nqn.2023-11.:banana").is_err());

// No discovery.
assert!(assert_compliant_nqn("nqn.2014-08.org.nvmexpress.discovery").is_err());

// org.nvmexpress
assert!(assert_compliant_nqn("nqn.2023-11.org.nvmexpress:blah").is_err());
Expand Down
9 changes: 9 additions & 0 deletions tests/loop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
node.succeed("nvmet subsystem add ${subnqn}")
assert "${subnqn}" in node.succeed("nvmet subsystem list")
node.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}")
node.succeed("nvmet subsystem show")
node.succeed("nvmet namespace add ${subnqn} 1 /dev/loop0")
assert "1" in node.succeed("nvmet namespace list ${subnqn}")
node.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
assert "/dev/loop0" in node.succeed("cat /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1/device_path")
node.succeed("nvmet namespace show ${subnqn}")
# Create the loopback port.
node.succeed("nvmet port add 1 loop")
Expand All @@ -43,6 +45,7 @@
node.succeed("nvmet port add-subsystem 1 ${subnqn}")
assert "${subnqn}" in node.succeed("nvmet port list-subsystems 1")
node.succeed("test -h /sys/kernel/config/nvmet/ports/1/subsystems/${subnqn}")
node.succeed("nvmet port show")
assert "${subnqn}" in machine.succeed("nvme discover -t loop")
Expand All @@ -63,11 +66,17 @@
assert node.succeed("cat /root/state.yml") == node.succeed("cat /root/state-after.yml")
# Cleanup.
node.succeed("nvmet namespace remove ${subnqn} 1")
node.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
node.fail("nvmet namespace remove ${subnqn} 1")
node.succeed("nvmet subsystem remove ${subnqn}")
node.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}")
node.fail("nvmet subsystem remove ${subnqn}")
node.succeed("nvmet port remove 1")
node.fail("test -e /sys/kernel/config/nvmet/ports/1")
node.fail("nvmet port remove 1")
# Export coverage.
node.succeed("llvm-profdata merge --sparse -o /tmp/nvmetcfg.profdata /tmp/nvmetcfg-*.profraw")
Expand Down
9 changes: 9 additions & 0 deletions tests/rdma.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
target.succeed("nvmet subsystem add ${subnqn}")
assert "${subnqn}" in target.succeed("nvmet subsystem list")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}")
target.succeed("nvmet subsystem show")
target.succeed("nvmet namespace add ${subnqn} 1 /dev/loop0")
assert "1" in target.succeed("nvmet namespace list ${subnqn}")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
assert "/dev/loop0" in target.succeed("cat /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1/device_path")
target.succeed("nvmet namespace show ${subnqn}")
# Create the tcp port.
target.succeed("nvmet port add 1 rdma 0.0.0.0:4420")
Expand All @@ -65,6 +67,7 @@
target.succeed("nvmet port add-subsystem 1 ${subnqn}")
assert "${subnqn}" in target.succeed("nvmet port list-subsystems 1")
target.succeed("test -h /sys/kernel/config/nvmet/ports/1/subsystems/${subnqn}")
target.succeed("nvmet port show")
# State save/restore test.
target.succeed("nvmet state save /root/state.yml")
Expand All @@ -87,11 +90,17 @@
assert "${subnqn}" in initiator.succeed("nvme discover -t rdma -a target -s 4420")
# Cleanup.
target.succeed("nvmet namespace remove ${subnqn} 1")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
target.fail("nvmet namespace remove ${subnqn} 1")
target.succeed("nvmet subsystem remove ${subnqn}")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}")
target.fail("nvmet subsystem remove ${subnqn}")
target.succeed("nvmet port remove 1")
target.fail("test -e /sys/kernel/config/nvmet/ports/1")
target.fail("nvmet port remove 1")
# Export coverage.
target.succeed("llvm-profdata merge --sparse -o /tmp/nvmetcfg.profdata /tmp/nvmetcfg-*.profraw")
Expand Down
9 changes: 9 additions & 0 deletions tests/tcp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
target.succeed("nvmet subsystem add ${subnqn}")
assert "${subnqn}" in target.succeed("nvmet subsystem list")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}")
target.succeed("nvmet subsystem show")
target.succeed("nvmet namespace add ${subnqn} 1 /dev/loop0")
assert "1" in target.succeed("nvmet namespace list ${subnqn}")
target.succeed("test -d /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
assert "/dev/loop0" in target.succeed("cat /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1/device_path")
target.succeed("nvmet namespace show ${subnqn}")
# Create the tcp port.
target.succeed("nvmet port add 1 tcp 0.0.0.0:4420")
Expand All @@ -58,6 +60,7 @@
target.succeed("nvmet port add-subsystem 1 ${subnqn}")
assert "${subnqn}" in target.succeed("nvmet port list-subsystems 1")
target.succeed("test -h /sys/kernel/config/nvmet/ports/1/subsystems/${subnqn}")
target.succeed("nvmet port show")
# State save/restore test.
target.succeed("nvmet state save /root/state.yml")
Expand All @@ -80,11 +83,17 @@
assert "${subnqn}" in initiator.succeed("nvme discover -t tcp -a target -s 4420")
# Cleanup.
target.succeed("nvmet namespace remove ${subnqn} 1")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}/namespaces/1")
target.fail("nvmet namespace remove ${subnqn} 1")
target.succeed("nvmet subsystem remove ${subnqn}")
target.fail("test -e /sys/kernel/config/nvmet/subsystems/${subnqn}")
target.fail("nvmet subsystem remove ${subnqn}")
target.succeed("nvmet port remove 1")
target.fail("test -e /sys/kernel/config/nvmet/ports/1")
target.fail("nvmet port remove 1")
# Export coverage.
target.succeed("llvm-profdata merge --sparse -o /tmp/nvmetcfg.profdata /tmp/nvmetcfg-*.profraw")
Expand Down

0 comments on commit 0d1d232

Please sign in to comment.