From c3826aacc9e0f656a3149a4b75a51be72ab5492e Mon Sep 17 00:00:00 2001 From: Zhou Kang Date: Mon, 14 Aug 2023 13:04:06 +0000 Subject: [PATCH] add test_symbolic_link --- .vscode/settings.json | 9 ++++++++- Makefile | 12 ++++++++---- tests/test_sysboostd.rs | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e3259c6..2e5eb79 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,10 @@ { - "editor.tabSize": 8 + "editor.tabSize": 8, + // rust不显示类型 + "rust-analyzer.inlayHints.typeHints.enable": false, + "rust-analyzer.inlayHints.parameterHints.enable": false, + "rust-analyzer.hover.actions.debug.enable": false, + // rust不显示透镜按钮 Run Test等 + "rust-analyzer.lens.debug.enable": false, + "rust-analyzer.lens.enable": false, } \ No newline at end of file diff --git a/Makefile b/Makefile index b548989..a44990f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ .PHONY: all clean test -SYSBOOSTD=./target/debug/sysboostd -SYSBOOST=../build/sysboost/sysboost +ROOT_DIR=. +SYSBOOSTD=$(ROOT_DIR)/target/debug/sysboostd +BUILD_DIR=$(ROOT_DIR)/build +SYSBOOST=$(BUILD_DIR)/src/sysboost SYSBOOSTD_INSTALL_PATH=/usr/bin/sysboostd SYSBOOST_INSTALL_PATH=/usr/bin/sysboost @@ -36,10 +38,12 @@ format: meson --internal clangformat ./ ./build cargo fmt -test: sysboostd - clear +install: cp -f $(SYSBOOSTD) $(SYSBOOSTD_INSTALL_PATH) cp -f $(SYSBOOST) $(SYSBOOST_INSTALL_PATH) + +test: sysboostd install + clear cargo test test-debug: diff --git a/tests/test_sysboostd.rs b/tests/test_sysboostd.rs index ae19823..888a4d4 100644 --- a/tests/test_sysboostd.rs +++ b/tests/test_sysboostd.rs @@ -250,5 +250,29 @@ mod tests { let bak_path = "/usr/lib64/libtinfo.so.bak"; assert!(fs::metadata(bak_path).unwrap().is_file()); } + + // cargo test --test test_sysboostd -- tests::test_symbolic_link --exact --nocapture + // 测试命令是否正确设置链接flag + // sysboost -s /usr/bin/bash + // 设置后, 执行 bash & + // 观察点: /proc/pid/maps 里面包含 bash.rto 文件路径 + #[test] + fn test_symbolic_link() { + Command::new("sysboost").arg("-s").arg("/usr/bin/bash").output().expect("Failed to execute command"); + let child = Command::new("bash").arg("&").spawn().expect("Failed to execute command"); + let c_pid = child.id(); + let maps_path = format!("/proc/{}/maps", c_pid); + let output = Command::new("cat").arg(maps_path).output().expect("Failed to execute command"); + if output.status.success() { + let stdout = String::from_utf8_lossy(&output.stdout); + let maps_str = stdout.trim(); + let is_con = maps_str.contains("bash.rto"); + assert!(is_con, "contains bash.rto, \n{}", maps_str); + } else { + assert!(false, "output is fail"); + } + + Command::new("kill").arg("-9").arg(c_pid.to_string()).output().expect("Failed to execute command"); + } } -- Gitee