diff --git a/tests/test_os_ops_common.py b/tests/test_os_ops_common.py index 50a9ef2..7f983c9 100644 --- a/tests/test_os_ops_common.py +++ b/tests/test_os_ops_common.py @@ -2860,6 +2860,8 @@ def test_get_process_children__with_child( logging.info(f"Parent PID from stdout: {parent_pid}") logging.info(f"Expected Child PID from stdout: {expected_child_pid}") + assert parent_pid == p1.pid + # A short pause to ensure registration in the OS # time.sleep(0.5) @@ -2911,9 +2913,9 @@ def test_get_process_children__with_three_children( script = ( "import time, os, subprocess; " "s = str(os.getpid()); " - "p1 = subprocess.Popen('exec sleep 60', shell=True, stdout=subprocess.PIPE); " - "p2 = subprocess.Popen('exec sleep 60', shell=True, stdout=subprocess.PIPE); " - "p3 = subprocess.Popen('exec sleep 60', shell=True, stdout=subprocess.PIPE); " + "p1 = subprocess.Popen(['sleep', '60'], shell=False, stdout=subprocess.PIPE); " + "p2 = subprocess.Popen(['sleep', '60'], shell=False, stdout=subprocess.PIPE); " + "p3 = subprocess.Popen(['sleep', '60'], shell=False, stdout=subprocess.PIPE); " "s += ':' + str(p1.pid) + ':' + str(p2.pid) + ':' + str(p3.pid); " "print(s, flush=True); " "time.sleep(60)" @@ -2943,6 +2945,8 @@ def test_get_process_children__with_three_children( # A short pause to ensure registration in the OS # time.sleep(0.5) + assert parent_pid == p.pid + childs = os_ops.get_process_children(parent_pid) assert childs is not None @@ -2954,6 +2958,29 @@ def test_get_process_children__with_three_children( assert actual_child_pids == expected_child_pids + for i in range(len(childs)): + child_cmdline = childs[i].cmdline() + + logging.info("child cmdline: {}".format( + child_cmdline, + )) + assert type(child_cmdline) is list + + if child_cmdline == ["sleep", "60"]: + pass + elif child_cmdline == ['/usr/bin/coreutils', '--coreutils-prog-shebang=sleep', '/usr/bin/sleep', '60']: + # Rocky Linux + pass + elif child_cmdline == ['/bin/sh', '-c', 'exec sleep 60']: + # Rocky Linux 10 (GitHub CI) + pass + else: + logging.error("Unknown child[{}] cmdline {}".format( + i, + child_cmdline, + )) + continue + p.terminate() p.wait() return