Skip to content

Commit 842c6a7

Browse files
committed
Fix sporadic test_print test failures
We have seen a few sporadic CI failures of the test_print tests. The reason is that these tests set process-global state that is also touched by ObjectBuilder::debug(). This is fallout of commit 1a8fe38 ("Reorganize test code"). To fix the issue, make sure to run the test_print tests, which actively check correctness of set_print(), in separate processes. Signed-off-by: Daniel Müller <[email protected]>
1 parent ad9ba1a commit 842c6a7

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

Cargo.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libbpf-rs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ probe = "0.3"
5959
scopeguard = "1.1"
6060
serial_test = { version = "3.0", default-features = false }
6161
tempfile = "3.3"
62+
test-fork = "0.1"
6263
test-tag = "0.1"
6364

6465
# A set of unused dependencies that we require to force correct minimum versions

libbpf-rs/tests/test_print.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//! This test is in its own file because the underlying `libbpf_set_print` function used by
2-
//! `set_print()` and `ObjectBuilder::debug()` sets global state. The default is to run multiple
3-
//! tests in different threads, so this test will always race with the others unless its isolated to
4-
//! a different process.
5-
//!
6-
//! For the same reason, all tests here must run serially.
1+
// Note that the `libbpf_set_print` function underlying `set_print()`
2+
// and `ObjectBuilder::debug()` sets global state. To prevent issues
3+
// with tests loading objects and similar we run print tests in separate
4+
// processes.
75

86
use std::sync::atomic::AtomicBool;
97
use std::sync::atomic::Ordering;
@@ -13,10 +11,12 @@ use libbpf_rs::set_print;
1311
use libbpf_rs::ObjectBuilder;
1412
use libbpf_rs::PrintCallback;
1513
use libbpf_rs::PrintLevel;
16-
use serial_test::serial;
1714

15+
use test_fork::fork;
16+
17+
18+
#[fork]
1819
#[test]
19-
#[serial]
2020
fn test_set_print() {
2121
static CORRECT_LEVEL: AtomicBool = AtomicBool::new(false);
2222
static CORRECT_MESSAGE: AtomicBool = AtomicBool::new(false);
@@ -42,8 +42,8 @@ fn test_set_print() {
4242
assert!(correct_message, "Did not capture the correct message");
4343
}
4444

45+
#[fork]
4546
#[test]
46-
#[serial]
4747
fn test_set_restore_print() {
4848
fn callback1(_: PrintLevel, _: String) {
4949
println!("one");
@@ -61,8 +61,8 @@ fn test_set_restore_print() {
6161
assert_eq!(prev, Some((PrintLevel::Debug, callback2 as PrintCallback)));
6262
}
6363

64+
#[fork]
6465
#[test]
65-
#[serial]
6666
fn test_set_and_save_print() {
6767
fn callback1(_: PrintLevel, _: String) {
6868
println!("one");

0 commit comments

Comments
 (0)