1"""
2Test denied process attach.
3"""
4
5
6
7import time
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13exe_name = 'AttachDenied'  # Must match Makefile
14
15
16class AttachDeniedTestCase(TestBase):
17    NO_DEBUG_INFO_TESTCASE = True
18
19    @skipIfWindows
20    @skipIfiOSSimulator
21    @skipIfDarwinEmbedded  # ptrace(ATTACH_REQUEST...) won't work on ios/tvos/etc
22    def test_attach_to_process_by_id_denied(self):
23        """Test attach by process id denied"""
24        self.build()
25        exe = self.getBuildArtifact(exe_name)
26
27        # Use a file as a synchronization point between test and inferior.
28        pid_file_path = lldbutil.append_to_process_working_directory(self,
29            "pid_file_%d" % (int(time.time())))
30        self.addTearDownHook(
31            lambda: self.run_platform_command(
32                "rm %s" %
33                (pid_file_path)))
34
35        # Spawn a new process
36        popen = self.spawnSubprocess(exe, [pid_file_path])
37
38        pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
39
40        self.expect('process attach -p ' + pid,
41                    startstr='error: attach failed:',
42                    error=True)
43