"""Test that we handle inferiors which change their process group"""
import os
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class ChangeProcessGroupTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True
def setUp(self):
TestBase.setUp(self)
self.line = line_number("main.c", "// Set breakpoint here")
@skipIfFreeBSD
@skipIfWindows
@expectedFailureAndroid("http://llvm.org/pr23762", api_levels=[16])
@expectedFailureNetBSD
@skipIftvOS
@skipIfwatchOS
def test_setpgid(self):
self.build()
exe = self.getBuildArtifact("a.out")
pid_file_path = lldbutil.append_to_process_working_directory(
self, "pid_file_%d" % (int(time.time()))
)
self.addTearDownHook(
lambda: self.run_platform_command("rm %s" % (pid_file_path))
)
popen = self.spawnSubprocess(exe, [pid_file_path])
pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
def cleanupChild():
if lldb.remote_platform:
lldb.remote_platform.Kill(int(pid))
else:
if os.path.exists("/proc/" + pid):
os.kill(int(pid), signal.SIGKILL)
self.addTearDownHook(cleanupChild)
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
listener = lldb.SBListener("my.attach.listener")
error = lldb.SBError()
process = target.AttachToProcessWithID(listener, int(pid), error)
self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
lldbutil.run_break_set_by_file_and_line(
self, "main.c", self.line, num_expected_locations=-1
)
thread = process.GetSelectedThread()
value = thread.GetSelectedFrame().EvaluateExpression("release_child_flag = 1")
self.assertTrue(value.IsValid())
self.assertEqual(value.GetValueAsUnsigned(0), 1)
process.Continue()
value = thread.GetSelectedFrame().EvaluateExpression("(int)getpgid(0)")
self.assertTrue(value.IsValid())
self.assertNotEqual(value.GetValueAsUnsigned(0), int(pid))
thread.StepOver()
self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonPlanComplete)
value = thread.GetSelectedFrame().EvaluateExpression("(int)getpgid(0)")
self.assertTrue(value.IsValid())
self.assertEqual(value.GetValueAsUnsigned(0), int(pid))
process.Continue()
self.assertState(process.GetState(), lldb.eStateExited)