76 lines
2.7 KiB
Diff
76 lines
2.7 KiB
Diff
From c600ca109d74c38f130b84353b6f21ff2439a36d Mon Sep 17 00:00:00 2001
|
|
From: chenjiayi <chenjiayi22@huawei.com>
|
|
Date: Wed, 15 Nov 2023 15:35:26 +0800
|
|
Subject: [PATCH 062/103] test(device): add UT for device monitor
|
|
|
|
---
|
|
libs/device/src/device_monitor.rs | 19 +++++++++++++------
|
|
1 file changed, 13 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/libs/device/src/device_monitor.rs b/libs/device/src/device_monitor.rs
|
|
index 3f1d1ba6..c6ad3ec6 100644
|
|
--- a/libs/device/src/device_monitor.rs
|
|
+++ b/libs/device/src/device_monitor.rs
|
|
@@ -216,7 +216,7 @@ impl Drop for DeviceMonitor {
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
- use crate::device::*;
|
|
+ use crate::{device::*, DeviceAction};
|
|
use event::*;
|
|
use std::{os::unix::prelude::RawFd, rc::Rc, thread::spawn};
|
|
|
|
@@ -264,9 +264,13 @@ mod tests {
|
|
}
|
|
|
|
/// test whether device monitor can receive uevent from kernel normally
|
|
- #[ignore]
|
|
#[test]
|
|
fn test_monitor_kernel() {
|
|
+ let device = Device::from_subsystem_sysname("net", "lo").unwrap();
|
|
+ if device.trigger(DeviceAction::Change).is_err() {
|
|
+ return;
|
|
+ }
|
|
+
|
|
let e = Events::new().unwrap();
|
|
let s: Rc<dyn Source> = Rc::new(Monitor {
|
|
device_monitor: DeviceMonitor::new(MonitorNetlinkGroup::Kernel, None),
|
|
@@ -275,7 +279,7 @@ mod tests {
|
|
e.set_enabled(s.clone(), EventState::On).unwrap();
|
|
|
|
spawn(|| {
|
|
- let device = Device::from_devname("/dev/sda").unwrap();
|
|
+ let device = Device::from_subsystem_sysname("net", "lo").unwrap();
|
|
device.set_sysattr_value("uevent", Some("change")).unwrap();
|
|
})
|
|
.join()
|
|
@@ -287,9 +291,13 @@ mod tests {
|
|
}
|
|
|
|
/// test whether device monitor can receive device message from userspace normally
|
|
- #[ignore]
|
|
#[test]
|
|
fn test_monitor_userspace() {
|
|
+ let device = Device::from_subsystem_sysname("net", "lo").unwrap();
|
|
+ if device.trigger(DeviceAction::Change).is_err() {
|
|
+ return;
|
|
+ }
|
|
+
|
|
let e = Events::new().unwrap();
|
|
let s: Rc<dyn Source> = Rc::new(Monitor {
|
|
device_monitor: DeviceMonitor::new(MonitorNetlinkGroup::Userspace, None),
|
|
@@ -298,9 +306,8 @@ mod tests {
|
|
e.set_enabled(s.clone(), EventState::On).unwrap();
|
|
|
|
spawn(|| {
|
|
- let device = Device::from_devname("/dev/sda").unwrap();
|
|
+ let device = Device::from_subsystem_sysname("net", "lo").unwrap();
|
|
device.set_action_from_string("change").unwrap();
|
|
- device.set_subsystem("block");
|
|
device.set_seqnum(1000);
|
|
|
|
let broadcaster = DeviceMonitor::new(MonitorNetlinkGroup::None, None);
|
|
--
|
|
2.33.0
|
|
|