From: Thomas Jarosch Date: Tue, 30 Dec 2025 10:58:20 +0000 (+0100) Subject: Make TestPidOf1 unit test more robust X-Git-Tag: v2.13~5 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=7948e0e2d267015796ba3de1cf8bfb2f4c348478;p=libi2ncommon Make TestPidOf1 unit test more robust The test expects to find PID 1 by searching for "init" or "systemd". While some LXC container is running: - PID 1 runs systemd (not traditional init) - Another process (e.g., PID 41150) may have "init" in its cmdline This causes pid_of("init") to return PID 41150 instead of PID 1, and the test would fail because PID 1 is not in the result. The fix checks if PID 1 is found after the "init" search, and if not, falls back to searching for "systemd" to find PID 1. --- diff --git a/test/test_filefunc.cpp b/test/test_filefunc.cpp index f3fa0c5..583de35 100644 --- a/test/test_filefunc.cpp +++ b/test/test_filefunc.cpp @@ -313,17 +313,17 @@ BOOST_AUTO_TEST_CASE(TestPidOf1) bool res= pid_of("init", pid_list); BOOST_CHECK_EQUAL( true, res); - if (pid_list.empty()) + // Check if PID 1 was found. If not, try systemd. + std::vector< pid_t >::const_iterator pos1 = + std::find( pid_list.begin(), pid_list.end(), 1); + + if (pos1 == pid_list.end()) { res= pid_of("systemd", pid_list); BOOST_CHECK_EQUAL( true, res); + pos1 = std::find( pid_list.begin(), pid_list.end(), 1); } - BOOST_CHECK_EQUAL( false, pid_list.empty() ); - - std::vector< pid_t >::const_iterator pos1 = - std::find( pid_list.begin(), pid_list.end(), 1); - BOOST_CHECK( pos1 != pid_list.end() ); } // eo TestPidOf1()