Skip to content

Commit ff95558

Browse files
committed
chore: cleanups
remove redundant function and assert rng metric values on direct integers at the first test step rather than after getting the variable value Signed-off-by: aerosouund <aerosound161@gmail.com>
1 parent d3a2e78 commit ff95558

4 files changed

Lines changed: 8 additions & 28 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vmm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ log-instrument = { path = "../log-instrument", optional = true }
4141
memfd = "0.6.5"
4242
micro_http = { git = "https://github.com/firecracker-microvm/micro-http" }
4343
pci = { path = "../pci" }
44+
regex = "1.12.2"
4445
semver = { version = "1.0.27", features = ["serde"] }
4546
serde = { version = "1.0.228", features = ["derive", "rc"] }
4647
serde_json = "1.0.149"

src/vmm/src/devices/virtio/rng/device.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::rc::Rc;
77
use std::sync::Arc;
88

99
use aws_lc_rs::rand;
10-
use log::info;
10+
use log::{info, warn};
1111
use vm_memory::GuestMemoryError;
1212
use vmm_sys_util::eventfd::EventFd;
1313

@@ -76,7 +76,9 @@ impl Entropy {
7676
.map(|_| EventFd::new(libc::EFD_NONBLOCK))
7777
.collect::<Result<Vec<EventFd>, io::Error>>()?;
7878
let metrics = Arc::new(EntropyDeviceMetrics::default());
79-
let _ = METRICS.set(metrics.clone()).inspect_err(|| warn!("Entropy metrics are already initialized!"));
79+
let _ = METRICS
80+
.set(metrics.clone())
81+
.inspect_err(|_| warn!("Entropy metrics are already initialized!"));
8082

8183
Ok(Self {
8284
avail_features: 1 << VIRTIO_F_VERSION_1,
@@ -453,19 +455,11 @@ mod tests {
453455
// Add a read-only descriptor (this should fail)
454456
th.add_desc_chain(RNG_QUEUE, 0, &[(0, 64, 0)]);
455457

456-
let entropy_event_fails = th.device().metrics.entropy_event_fails.count();
457-
let entropy_event_count = th.device().metrics.entropy_event_count.count();
458458
let entropy_bytes = th.device().metrics.entropy_bytes.count();
459459
let host_rng_fails = th.device().metrics.host_rng_fails.count();
460460
assert_eq!(th.emulate_for_msec(100).unwrap(), 1);
461-
assert_eq!(
462-
th.device().metrics.entropy_event_fails.count(),
463-
entropy_event_fails + 1
464-
);
465-
assert_eq!(
466-
th.device().metrics.entropy_event_count.count(),
467-
entropy_event_count + 1
468-
);
461+
assert_eq!(th.device().metrics.entropy_event_fails.count(), 1);
462+
assert_eq!(th.device().metrics.entropy_event_count.count(), 1);
469463
assert_eq!(th.device().metrics.entropy_bytes.count(), entropy_bytes);
470464
assert_eq!(th.device().metrics.host_rng_fails.count(), host_rng_fails);
471465

@@ -502,8 +496,6 @@ mod tests {
502496
],
503497
);
504498

505-
let entropy_event_fails = th.device().metrics.entropy_event_fails.count();
506-
let entropy_event_count = th.device().metrics.entropy_event_count.count();
507499
let entropy_bytes = th.device().metrics.entropy_bytes.count();
508500
let host_rng_fails = th.device().metrics.host_rng_fails.count();
509501
assert_eq!(th.emulate_for_msec(100).unwrap(), 1);

src/vmm/src/devices/virtio/rng/metrics.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,6 @@ impl EntropyDeviceMetrics {
7979
rate_limiter_event_count: SharedIncMetric::new(),
8080
}
8181
}
82-
83-
pub fn aggregate(&mut self, other: &Self) {
84-
self.activate_fails.add(other.activate_fails.fetch_diff());
85-
self.entropy_event_fails
86-
.add(other.entropy_event_fails.fetch_diff());
87-
self.entropy_event_count
88-
.add(other.entropy_event_count.fetch_diff());
89-
self.entropy_bytes.add(other.entropy_bytes.fetch_diff());
90-
self.host_rng_fails.add(other.host_rng_fails.fetch_diff());
91-
self.entropy_rate_limiter_throttled
92-
.add(other.entropy_rate_limiter_throttled.fetch_diff());
93-
self.rate_limiter_event_count
94-
.add(other.rate_limiter_event_count.fetch_diff());
95-
}
9682
}
9783

9884
#[cfg(test)]

0 commit comments

Comments
 (0)