From a77399393b04634cc289b676a63711c5816e46e9 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Wed, 27 Nov 2024 11:50:48 +0100 Subject: [PATCH] test(aya): iter: Disable the init system assertion in containers It's hard to predict what's the PID of the first process in a container. Use this assertion only on non-containerized systems. --- test/integration-test/src/tests/iter.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/integration-test/src/tests/iter.rs b/test/integration-test/src/tests/iter.rs index 3325ad2e..388656a1 100644 --- a/test/integration-test/src/tests/iter.rs +++ b/test/integration-test/src/tests/iter.rs @@ -1,4 +1,4 @@ -use std::io::BufRead; +use std::{env, io::BufRead, path::Path}; use aya::{programs::Iter, Btf, Ebpf}; use test_log::test; @@ -20,11 +20,15 @@ fn iter_task() { let line_init = lines.next().unwrap().unwrap(); assert_eq!(line_title, "tgid pid name"); - let expected_values = ["1 1 init", "1 1 systemd"]; - assert!( - expected_values.contains(&line_init.as_str()), - "Unexpected line_init value: '{}', expected one of: {:?}", - line_init, - expected_values - ); + // It's hard to predict what's the PID of the first process in a container. + // Use this assertion only on non-containerized systems. + if !Path::new("/.dockerenv").exists() && env::var_os("container").is_none() { + let expected_values = ["1 1 init", "1 1 systemd"]; + assert!( + expected_values.contains(&line_init.as_str()), + "Unexpected line_init value: '{}', expected one of: {:?}", + line_init, + expected_values + ); + } }