Skip to content

Commit 7ab6731

Browse files
committed
Print function name and missing capability when skipping tests
1 parent dab7332 commit 7ab6731

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

test/common/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ use cfg_if::cfg_if;
1414
cfg_if! {
1515
if #[cfg(any(target_os = "android", target_os = "linux"))] {
1616
#[macro_export] macro_rules! require_capability {
17-
($capname:ident) => {
17+
($name:expr, $capname:ident) => {
1818
use ::caps::{Capability, CapSet, has_cap};
1919

2020
if !has_cap(None, CapSet::Effective, Capability::$capname)
2121
.unwrap()
2222
{
23-
skip!("Insufficient capabilities. Skipping test.");
23+
skip!("{} requires capability {}. Skipping test.", $name, Capability::$capname);
2424
}
2525
}
2626
}
2727
} else if #[cfg(not(target_os = "redox"))] {
2828
#[macro_export] macro_rules! require_capability {
29-
($capname:ident) => {}
29+
($name:expr, $capname:ident) => {}
3030
}
3131
}
3232
}

test/sys/test_ptrace.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::*;
1313
fn test_ptrace() {
1414
// Just make sure ptrace can be called at all, for now.
1515
// FIXME: qemu-user doesn't implement ptrace on all arches, so permit ENOSYS
16-
require_capability!(CAP_SYS_PTRACE);
16+
require_capability!("test_ptrace", CAP_SYS_PTRACE);
1717
let err = ptrace::attach(getpid()).unwrap_err();
1818
assert!(err == Errno::EPERM || err == Errno::EINVAL ||
1919
err == Errno::ENOSYS);
@@ -23,7 +23,7 @@ fn test_ptrace() {
2323
#[test]
2424
#[cfg(any(target_os = "android", target_os = "linux"))]
2525
fn test_ptrace_setoptions() {
26-
require_capability!(CAP_SYS_PTRACE);
26+
require_capability!("test_ptrace_setoptions", CAP_SYS_PTRACE);
2727
let err = ptrace::setoptions(getpid(), Options::PTRACE_O_TRACESYSGOOD).unwrap_err();
2828
assert!(err != Errno::EOPNOTSUPP);
2929
}
@@ -32,7 +32,7 @@ fn test_ptrace_setoptions() {
3232
#[test]
3333
#[cfg(any(target_os = "android", target_os = "linux"))]
3434
fn test_ptrace_getevent() {
35-
require_capability!(CAP_SYS_PTRACE);
35+
require_capability!("test_ptrace_getevent", CAP_SYS_PTRACE);
3636
let err = ptrace::getevent(getpid()).unwrap_err();
3737
assert!(err != Errno::EOPNOTSUPP);
3838
}
@@ -41,7 +41,7 @@ fn test_ptrace_getevent() {
4141
#[test]
4242
#[cfg(any(target_os = "android", target_os = "linux"))]
4343
fn test_ptrace_getsiginfo() {
44-
require_capability!(CAP_SYS_PTRACE);
44+
require_capability!("test_ptrace_getsiginfo", CAP_SYS_PTRACE);
4545
if let Err(Errno::EOPNOTSUPP) = ptrace::getsiginfo(getpid()) {
4646
panic!("ptrace_getsiginfo returns Errno::EOPNOTSUPP!");
4747
}
@@ -51,7 +51,7 @@ fn test_ptrace_getsiginfo() {
5151
#[test]
5252
#[cfg(any(target_os = "android", target_os = "linux"))]
5353
fn test_ptrace_setsiginfo() {
54-
require_capability!(CAP_SYS_PTRACE);
54+
require_capability!("test_ptrace_setsiginfo", CAP_SYS_PTRACE);
5555
let siginfo = unsafe { mem::zeroed() };
5656
if let Err(Errno::EOPNOTSUPP) = ptrace::setsiginfo(getpid(), &siginfo) {
5757
panic!("ptrace_setsiginfo returns Errno::EOPNOTSUPP!");
@@ -67,7 +67,7 @@ fn test_ptrace_cont() {
6767
use nix::unistd::fork;
6868
use nix::unistd::ForkResult::*;
6969

70-
require_capability!(CAP_SYS_PTRACE);
70+
require_capability!("test_ptrace_cont", CAP_SYS_PTRACE);
7171

7272
let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
7373

@@ -125,7 +125,7 @@ fn test_ptrace_interrupt() {
125125
use std::thread::sleep;
126126
use std::time::Duration;
127127

128-
require_capability!(CAP_SYS_PTRACE);
128+
require_capability!("test_ptrace_interrupt", CAP_SYS_PTRACE);
129129

130130
let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
131131

@@ -171,7 +171,7 @@ fn test_ptrace_syscall() {
171171
use nix::unistd::getpid;
172172
use nix::unistd::ForkResult::*;
173173

174-
require_capability!(CAP_SYS_PTRACE);
174+
require_capability!("test_ptrace_syscall", CAP_SYS_PTRACE);
175175

176176
let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
177177

test/sys/test_sockopt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn test_local_peercred_stream() {
4949
fn is_so_mark_functional() {
5050
use nix::sys::socket::sockopt;
5151

52-
require_capability!(CAP_NET_ADMIN);
52+
require_capability!("is_so_mark_functional", CAP_NET_ADMIN);
5353

5454
let s = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), None).unwrap();
5555
setsockopt(s, sockopt::Mark, &1337).unwrap();

test/sys/test_uio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn test_process_vm_readv() {
213213
use nix::sys::wait::*;
214214
use crate::*;
215215

216-
require_capability!(CAP_SYS_PTRACE);
216+
require_capability!("test_process_vm_readv", CAP_SYS_PTRACE);
217217
let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
218218

219219
// Pre-allocate memory in the child, since allocation isn't safe

test/sys/test_wait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ mod ptrace {
9696

9797
#[test]
9898
fn test_wait_ptrace() {
99-
require_capability!(CAP_SYS_PTRACE);
99+
require_capability!("test_wait_ptrace", CAP_SYS_PTRACE);
100100
let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test");
101101

102102
match unsafe{fork()}.expect("Error: Fork Failed") {

test/test_kmod/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::io::Read;
4141

4242
#[test]
4343
fn test_finit_and_delete_module() {
44-
require_capability!(CAP_SYS_MODULE);
44+
require_capability!("test_finit_and_delete_module", CAP_SYS_MODULE);
4545
let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
4646
let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
4747

@@ -58,8 +58,8 @@ fn test_finit_and_delete_module() {
5858
}
5959

6060
#[test]
61-
fn test_finit_and_delete_modul_with_params() {
62-
require_capability!(CAP_SYS_MODULE);
61+
fn test_finit_and_delete_module_with_params() {
62+
require_capability!("test_finit_and_delete_module_with_params", CAP_SYS_MODULE);
6363
let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
6464
let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
6565

@@ -80,7 +80,7 @@ fn test_finit_and_delete_modul_with_params() {
8080

8181
#[test]
8282
fn test_init_and_delete_module() {
83-
require_capability!(CAP_SYS_MODULE);
83+
require_capability!("test_init_and_delete_module", CAP_SYS_MODULE);
8484
let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
8585
let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
8686

@@ -100,7 +100,7 @@ fn test_init_and_delete_module() {
100100

101101
#[test]
102102
fn test_init_and_delete_module_with_params() {
103-
require_capability!(CAP_SYS_MODULE);
103+
require_capability!("test_init_and_delete_module_with_params", CAP_SYS_MODULE);
104104
let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
105105
let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
106106

@@ -121,7 +121,7 @@ fn test_init_and_delete_module_with_params() {
121121

122122
#[test]
123123
fn test_finit_module_invalid() {
124-
require_capability!(CAP_SYS_MODULE);
124+
require_capability!("test_finit_module_invalid", CAP_SYS_MODULE);
125125
let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
126126
let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
127127

@@ -135,7 +135,7 @@ fn test_finit_module_invalid() {
135135

136136
#[test]
137137
fn test_finit_module_twice_and_delete_module() {
138-
require_capability!(CAP_SYS_MODULE);
138+
require_capability!("test_finit_module_twice_and_delete_module", CAP_SYS_MODULE);
139139
let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
140140
let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
141141

@@ -157,7 +157,7 @@ fn test_finit_module_twice_and_delete_module() {
157157

158158
#[test]
159159
fn test_delete_module_not_loaded() {
160-
require_capability!(CAP_SYS_MODULE);
160+
require_capability!("test_delete_module_not_loaded", CAP_SYS_MODULE);
161161
let _m0 = crate::KMOD_MTX.lock().expect("Mutex got poisoned by another test");
162162
let _m1 = crate::CWD_LOCK.read().expect("Mutex got poisoned by another test");
163163

test/test_unistd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ cfg_if!{
549549
if #[cfg(any(target_os = "android", target_os = "linux"))] {
550550
macro_rules! require_acct{
551551
() => {
552-
require_capability!(CAP_SYS_PACCT);
552+
require_capability!("test_acct", CAP_SYS_PACCT);
553553
}
554554
}
555555
} else if #[cfg(target_os = "freebsd")] {
@@ -1040,7 +1040,7 @@ fn test_user_into_passwd() {
10401040
fn test_setfsuid() {
10411041
use std::os::unix::fs::PermissionsExt;
10421042
use std::{fs, io, thread};
1043-
require_capability!(CAP_SETUID);
1043+
require_capability!("test_setfsuid", CAP_SETUID);
10441044

10451045
// get the UID of the "nobody" user
10461046
let nobody = User::from_name("nobody").unwrap().unwrap();

0 commit comments

Comments
 (0)