2015-05-28 08:59:21 +00:00
|
|
|
"""Test that we handle inferiors which change their process group"""
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
|
2015-05-28 08:59:21 +00:00
|
|
|
import os
|
|
|
|
|
import lldb
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test import lldbutil
|
2015-05-28 08:59:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeProcessGroupTestCase(TestBase):
|
2018-02-21 15:33:53 +00:00
|
|
|
NO_DEBUG_INFO_TESTCASE = True
|
2015-05-28 08:59:21 +00:00
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
# Call super's setUp().
|
|
|
|
|
TestBase.setUp(self)
|
|
|
|
|
# Find the line number to break for main.c.
|
|
|
|
|
self.line = line_number("main.c", "// Set breakpoint here")
|
|
|
|
|
|
2015-06-02 14:11:25 +00:00
|
|
|
@skipIfFreeBSD # Times out on FreeBSD llvm.org/pr23731
|
2015-05-28 08:59:21 +00:00
|
|
|
@skipIfWindows # setpgid call does not exist on Windows
|
2015-06-05 00:22:49 +00:00
|
|
|
@expectedFailureAndroid("http://llvm.org/pr23762", api_levels=[16])
|
2019-03-04 16:54:06 +00:00
|
|
|
@expectedFailureNetBSD
|
2020-11-05 15:09:38 +01:00
|
|
|
@skipIftvOS # fork not available on tvOS.
|
|
|
|
|
@skipIfwatchOS # fork not available on watchOS.
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_setpgid(self):
|
|
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2015-05-28 08:59:21 +00:00
|
|
|
|
|
|
|
|
# Use a file as a synchronization point between test and inferior.
|
2018-02-21 15:33:53 +00:00
|
|
|
pid_file_path = lldbutil.append_to_process_working_directory(
|
2015-06-06 00:25:50 +00:00
|
|
|
self, "pid_file_%d" % (int(time.time()))
|
2023-05-25 08:48:57 -07:00
|
|
|
)
|
2015-05-28 08:59:21 +00:00
|
|
|
self.addTearDownHook(
|
|
|
|
|
lambda: self.run_platform_command("rm %s" % (pid_file_path))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
popen = self.spawnSubprocess(exe, [pid_file_path])
|
|
|
|
|
|
2016-04-05 14:08:18 +00:00
|
|
|
pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
|
2015-05-28 08:59:21 +00:00
|
|
|
|
2015-05-28 13:12:48 +00:00
|
|
|
# make sure we cleanup the forked child also
|
|
|
|
|
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)
|
2023-05-25 08:48:57 -07:00
|
|
|
|
2015-05-28 13:12:48 +00:00
|
|
|
self.addTearDownHook(cleanupChild)
|
2015-05-28 08:59:21 +00:00
|
|
|
|
|
|
|
|
# Create a target by the debugger.
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
# set a breakpoint just before the setpgid() call
|
2015-05-28 12:46:13 +00:00
|
|
|
lldbutil.run_break_set_by_file_and_line(
|
|
|
|
|
self, "main.c", self.line, num_expected_locations=-1
|
|
|
|
|
)
|
2015-05-28 08:59:21 +00:00
|
|
|
|
|
|
|
|
thread = process.GetSelectedThread()
|
|
|
|
|
|
|
|
|
|
# release the child from its loop
|
2015-10-29 13:44:09 +00:00
|
|
|
value = thread.GetSelectedFrame().EvaluateExpression("release_child_flag = 1")
|
[lldb] Replace assertTrue(a == b, "msg") with assertEquals(a, b, "msg") in the test suite
Summary:
The error message from the construct `assertTrue(a == b, "msg") ` are nearly always completely useless for actually debugging the issue.
This patch is just replacing this construct (and similar ones like `assertTrue(a != b, ...)` with the proper call to assertEqual or assertNotEquals.
This patch was mostly written by a shell script with some manual verification afterwards:
```
lang=python
import sys
def sanitize_line(line):
if line.strip().startswith("self.assertTrue(") and " == " in line:
line = line.replace("self.assertTrue(", "self.assertEquals(")
line = line.replace(" == ", ", ", 1)
if line.strip().startswith("self.assertTrue(") and " != " in line:
line = line.replace("self.assertTrue(", "self.assertNotEqual(")
line = line.replace(" != ", ", ", 1)
return line
for a in sys.argv[1:]:
with open(a, "r") as f:
lines = f.readlines()
with open(a, "w") as f:
for line in lines:
f.write(sanitize_line(line))
```
Reviewers: labath, JDevlieghere
Reviewed By: labath
Subscribers: abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D74475
2020-02-13 13:40:22 +01:00
|
|
|
self.assertTrue(value.IsValid())
|
|
|
|
|
self.assertEquals(value.GetValueAsUnsigned(0), 1)
|
2015-05-28 08:59:21 +00:00
|
|
|
process.Continue()
|
|
|
|
|
|
|
|
|
|
# make sure the child's process group id is different from its pid
|
2015-10-29 13:44:09 +00:00
|
|
|
value = thread.GetSelectedFrame().EvaluateExpression("(int)getpgid(0)")
|
|
|
|
|
self.assertTrue(value.IsValid())
|
|
|
|
|
self.assertNotEqual(value.GetValueAsUnsigned(0), int(pid))
|
2015-05-28 08:59:21 +00:00
|
|
|
|
|
|
|
|
# step over the setpgid() call
|
|
|
|
|
thread.StepOver()
|
2022-08-03 11:42:12 -07:00
|
|
|
self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonPlanComplete)
|
2015-05-28 08:59:21 +00:00
|
|
|
|
|
|
|
|
# verify that the process group has been set correctly
|
|
|
|
|
# this also checks that we are still in full control of the child
|
2015-10-29 13:44:09 +00:00
|
|
|
value = thread.GetSelectedFrame().EvaluateExpression("(int)getpgid(0)")
|
|
|
|
|
self.assertTrue(value.IsValid())
|
|
|
|
|
self.assertEqual(value.GetValueAsUnsigned(0), int(pid))
|
2015-05-28 08:59:21 +00:00
|
|
|
|
|
|
|
|
# run to completion
|
|
|
|
|
process.Continue()
|
2022-06-29 17:01:36 -07:00
|
|
|
self.assertState(process.GetState(), lldb.eStateExited)
|