summaryrefslogtreecommitdiff
path: root/test/test_kmod
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2019-05-26 19:44:47 -0600
committerAlan Somers <asomers@gmail.com>2019-06-06 08:54:51 -0600
commitd26749e33a06cf46ca5c2e2e716faf2a71ca747f (patch)
tree0311c19024981f63d7ec3cd5c0e3c2d8e2b5d2d2 /test/test_kmod
parent129485cfa3455b7eda3217e36ee89d4ca75d38b2 (diff)
downloadnix-d26749e33a06cf46ca5c2e2e716faf2a71ca747f.zip
Fix some bugs with multithreaded tests:
* kmod tests must run exclusively, because they load and unload a module with a constant name. * A few tests were doing some variant of chdir, but weren't taking the CWD_MTX. * The kmod tests read files by path relative to CWD, so they need the CWD_MTX. But they don't need it exclusively, so convert the CWD_MTX into an RwLock. * Tests that do change the cwd need to change it back when they're done.
Diffstat (limited to 'test/test_kmod')
-rw-r--r--test/test_kmod/mod.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/test_kmod/mod.rs b/test/test_kmod/mod.rs
index 86558d1b..ad406357 100644
--- a/test/test_kmod/mod.rs
+++ b/test/test_kmod/mod.rs
@@ -41,6 +41,8 @@ use std::io::Read;
#[test]
fn test_finit_and_delete_module() {
require_capability!(CAP_SYS_MODULE);
+ let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test");
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -57,6 +59,8 @@ fn test_finit_and_delete_module() {
#[test]
fn test_finit_and_delete_modul_with_params() {
require_capability!(CAP_SYS_MODULE);
+ let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test");
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -76,6 +80,8 @@ fn test_finit_and_delete_modul_with_params() {
#[test]
fn test_init_and_delete_module() {
require_capability!(CAP_SYS_MODULE);
+ let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test");
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -94,6 +100,8 @@ fn test_init_and_delete_module() {
#[test]
fn test_init_and_delete_module_with_params() {
require_capability!(CAP_SYS_MODULE);
+ let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test");
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -113,6 +121,8 @@ fn test_init_and_delete_module_with_params() {
#[test]
fn test_finit_module_invalid() {
require_capability!(CAP_SYS_MODULE);
+ let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test");
let kmod_path = "/dev/zero";
@@ -125,6 +135,8 @@ fn test_finit_module_invalid() {
#[test]
fn test_finit_module_twice_and_delete_module() {
require_capability!(CAP_SYS_MODULE);
+ let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test");
let (kmod_path, kmod_name, _kmod_dir) = compile_kernel_module();
@@ -145,6 +157,8 @@ fn test_finit_module_twice_and_delete_module() {
#[test]
fn test_delete_module_not_loaded() {
require_capability!(CAP_SYS_MODULE);
+ let _m0 = ::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m1 = ::CWD_LOCK.read().expect("Mutex got poisoned by another test");
let result = delete_module(&CString::new("hello").unwrap(), DeleteModuleFlags::empty());