Skip to content

Commit

Permalink
More granular use of serial in devices/bpf.rs
Browse files Browse the repository at this point in the history
Also move extraneous `use` statement.
  • Loading branch information
128f committed Mar 6, 2022
1 parent 3e95c84 commit ec371ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
54 changes: 27 additions & 27 deletions crates/libcgroups/src/v2/devices/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ pub mod prog {

#[cfg(test)]
mod tests {
use serial_test::serial;

use super::prog;
use crate::v2::devices::mocks::{mock_libbpf_sys, mock_libc};
use errno::{set_errno, Errno};
use libc::{ENOSPC, ENOSYS};

use serial_test::serial;

#[test]
#[serial] // mock contexts are shared
#[serial(libbpf_sys)] // mock contexts are shared
fn test_bpf_load() {
// eBPF uses 64-bit instructions
let instruction_zero: &[u8] = &[0x0, 0x0, 0x0, 0x0];
Expand All @@ -172,7 +172,23 @@ mod tests {
}

#[test]
#[serial] // mock contexts are shared
#[serial(libbpf_sys)] // mock contexts are shared
fn test_bpf_attach() {
// arrange
let attach = mock_libbpf_sys::bpf_prog_attach_context();

// expect
attach.expect().once().returning(|_, _, _, _| 0);

// act
let r = prog::attach(0, 0);

// assert
assert!(r.is_ok());
}

#[test]
#[serial(libbpf_sys)] // mock contexts are shared
fn test_bpf_load_error() {
// eBPF uses 64-bit instructions
let instruction_zero: &[u8] = &[0x0, 0x0, 0x0, 0x0];
Expand All @@ -194,7 +210,7 @@ mod tests {
}

#[test]
#[serial] // mock contexts are shared
#[serial(libbpf_sys)] // mock contexts are shared
fn test_bpf_query() {
// arrange
let query = mock_libbpf_sys::bpf_prog_query_context();
Expand Down Expand Up @@ -240,7 +256,7 @@ mod tests {
}

#[test]
#[serial] // mock contexts are shared
#[serial(libbpf_sys)] // mock contexts are shared
fn test_bpf_query_recoverable_error() {
// arrange
let query = mock_libbpf_sys::bpf_prog_query_context();
Expand Down Expand Up @@ -286,7 +302,7 @@ mod tests {
}

#[test]
#[serial] // mock contexts are shared
#[serial(libbpf_sys)] // mock contexts are shared
fn test_bpf_query_other_error() {
// arrange
let query = mock_libbpf_sys::bpf_prog_query_context();
Expand Down Expand Up @@ -315,7 +331,7 @@ mod tests {
}

#[test]
#[serial] // mock contexts are shared
#[serial(libbpf_sys)] // mock contexts are shared
fn test_bpf_detach2() {
// arrange
let detach2 = mock_libbpf_sys::bpf_prog_detach2_context();
Expand All @@ -331,7 +347,7 @@ mod tests {
}

#[test]
#[serial] // mock contexts are shared
#[serial(libbpf_sys)] // mock contexts are shared
fn test_bpf_detach2_error() {
// arrange
let detach2 = mock_libbpf_sys::bpf_prog_detach2_context();
Expand All @@ -347,23 +363,7 @@ mod tests {
}

#[test]
#[serial] // mock contexts are shared
fn test_bpf_attach() {
// arrange
let attach = mock_libbpf_sys::bpf_prog_attach_context();

// expect
attach.expect().once().returning(|_, _, _, _| 0);

// act
let r = prog::attach(0, 0);

// assert
assert!(r.is_ok());
}

#[test]
#[serial] // mock contexts are shared
#[serial(libc)] // mock contexts are shared
fn test_bump_memlock_rlimit() {
// arrange
let setrlimit = mock_libc::setrlimit_context();
Expand All @@ -379,7 +379,7 @@ mod tests {
}

#[test]
#[serial] // mock contexts are shared
#[serial(libc)] // mock contexts are shared
fn test_bump_memlock_rlimit_error() {
// arrange
let setrlimit = mock_libc::setrlimit_context();
Expand Down
2 changes: 0 additions & 2 deletions crates/libcgroups/src/v2/devices/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ impl Devices {

#[cfg(test)]
mod tests {
use serial_test::serial;

use super::*;
use crate::test::setup;
use serial_test::serial;
Expand Down

0 comments on commit ec371ec

Please # to comment.