nix icon indicating copy to clipboard operation
nix copied to clipboard

cargo test with root privilege

Open sjtakada opened this issue 6 years ago • 3 comments

When I tried to run cargo test with root privilege, I am seeing following failures. I am not sure if this is known issue, or if I miss something on my environment. I am running it on Ubuntu 18.04.1 TLS and have following config in .cargo/config.

Please advise proper way to perform test with root privilege, and let me know if there is anything I can help to improve this crate, thanks!

[target.x86_64-unknown-linux-gnu]
runner = 'sudo -E'
failures:

---- test_kmod::test_finit_module_twice_and_delete_module stdout ----
thread 'test_kmod::test_finit_module_twice_and_delete_module' panicked at 'unable to copy hello.c to temporary build directory: Custom { kind: InvalidInput, error: StringError("the source path is not an existing regular file") }', libcore/result.rs:945:5

---- test_kmod::test_finit_and_delete_modul_with_params stdout ----
thread 'test_kmod::test_finit_and_delete_modul_with_params' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_kmod::test_init_and_delete_module_with_params stdout ----
thread 'test_kmod::test_init_and_delete_module_with_params' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_kmod::test_init_and_delete_module stdout ----
thread 'test_kmod::test_init_and_delete_module' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_unistd::test_execveat_empty stdout ----
thread 'test_unistd::test_execveat_empty' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_unistd::test_execveat_absolute stdout ----
thread 'test_unistd::test_execveat_absolute' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_unistd::test_execve stdout ----
thread 'test_unistd::test_execve' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_unistd::test_execveat_relative stdout ----
thread 'test_unistd::test_execveat_relative' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_unistd::test_fexecve stdout ----
thread 'test_unistd::test_fexecve' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_unistd::test_fork_and_waitpid stdout ----
thread 'test_unistd::test_fork_and_waitpid' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

---- test_unistd::test_wait stdout ----
thread 'test_unistd::test_wait' panicked at 'Mutex got poisoned by another test: "PoisonError { inner: .. }"', libcore/result.rs:945:5

sjtakada avatar Nov 04 '18 19:11 sjtakada

You should just be able to do sudo cargo test. You may need to run it like sudo cargo test -- --test-threads=1 or RUST_TEST_THREADS=1 sudo cargo test to prevent these errors.

And this definitely should be in the README...

Susurrus avatar Nov 04 '18 19:11 Susurrus

The error suggests that hello.c couldn't be found. Do you have an incomplete checkout? Or is your code mounted over NFS with the rootsquash option on?

asomers avatar Nov 04 '18 19:11 asomers

sudo cargo test doesn't work, since I installed rust with my user account and all executables are under ~/.cargo/bin, so if I just do sudo, root couldn't find the executables in the path. If I use the approach with .cargo/config, it works fine. Actually, I just tried to install rust with root account, and then apparently cargo test works fine without any trick. However, I'm getting the same failures as shown above.

I cloned the repo a few days ago, but updated to the latest. I am not using NFS, and I see hello.c under ./test/test_kmod/hello_mod/hello.c in the tree, so that's not the case.

First 4 failures are related to kmod, and rest are exec. I wonder if my environment is missing some kernel headers which might be requirement to run the tests, or kernel version matters? My kernel version is 4.15.0.

Thanks,

sjtakada avatar Nov 04 '18 21:11 sjtakada