From 29872606d220420d53fde7cc5e3bea15f8da62e7 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Sun, 1 Sep 2019 09:12:37 +0000 Subject: [lldb] Restructure test folders to match LLDB command hierarchy Summary: As discussed on lldb-dev, this patch moves some LLDB tests into a hierarchy that more closely resembles the commands we use in the LLDB interpreter. This patch should only move tests that use the command interpreter and shouldn't touch any tests that primarily test the SB API. Reviewers: #lldb, jfb, JDevlieghere Reviewed By: #lldb, JDevlieghere Subscribers: dexonsmith, arphaman, JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67033 llvm-svn: 370605 --- .../test/functionalities/process_attach/Makefile | 7 -- .../process_attach/TestProcessAttach.py | 91 ----------------- .../process_attach/attach_denied/Makefile | 14 --- .../attach_denied/TestAttachDenied.py | 46 --------- .../attach_denied/entitlements.plist | 8 -- .../process_attach/attach_denied/main.cpp | 108 --------------------- .../test/functionalities/process_attach/main.cpp | 20 ---- 7 files changed, 294 deletions(-) delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/process_attach/Makefile delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/process_attach/TestProcessAttach.py delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/Makefile delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/entitlements.plist delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/main.cpp delete mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/process_attach/main.cpp (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/process_attach') diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/Makefile deleted file mode 100644 index a964853f534..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -LEVEL = ../../make - -CXX_SOURCES := main.cpp - -EXE := ProcessAttach - -include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/TestProcessAttach.py b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/TestProcessAttach.py deleted file mode 100644 index 6210ba0eefc..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/TestProcessAttach.py +++ /dev/null @@ -1,91 +0,0 @@ -""" -Test process attach. -""" - -from __future__ import print_function - - -import os -import lldb -import shutil -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -exe_name = "ProcessAttach" # Must match Makefile - - -class ProcessAttachTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - - NO_DEBUG_INFO_TESTCASE = True - - @skipIfiOSSimulator - @expectedFailureNetBSD - def test_attach_to_process_by_id(self): - """Test attach by process id""" - self.build() - exe = self.getBuildArtifact(exe_name) - - # Spawn a new process - popen = self.spawnSubprocess(exe) - self.addTearDownHook(self.cleanupSubprocesses) - - self.runCmd("process attach -p " + str(popen.pid)) - - target = self.dbg.GetSelectedTarget() - - process = target.GetProcess() - self.assertTrue(process, PROCESS_IS_VALID) - - @expectedFailureNetBSD - def test_attach_to_process_from_different_dir_by_id(self): - """Test attach by process id""" - newdir = self.getBuildArtifact("newdir") - try: - os.mkdir(newdir) - except OSError as e: - if e.errno != os.errno.EEXIST: - raise - testdir = self.getBuildDir() - exe = os.path.join(newdir, 'proc_attach') - self.buildProgram('main.cpp', exe) - self.addTearDownHook(lambda: shutil.rmtree(newdir)) - - # Spawn a new process - popen = self.spawnSubprocess(exe) - self.addTearDownHook(self.cleanupSubprocesses) - - os.chdir(newdir) - self.addTearDownHook(lambda: os.chdir(testdir)) - self.runCmd("process attach -p " + str(popen.pid)) - - target = self.dbg.GetSelectedTarget() - - process = target.GetProcess() - self.assertTrue(process, PROCESS_IS_VALID) - - @expectedFailureNetBSD - def test_attach_to_process_by_name(self): - """Test attach by process name""" - self.build() - exe = self.getBuildArtifact(exe_name) - - # Spawn a new process - popen = self.spawnSubprocess(exe) - self.addTearDownHook(self.cleanupSubprocesses) - - self.runCmd("process attach -n " + exe_name) - - target = self.dbg.GetSelectedTarget() - - process = target.GetProcess() - self.assertTrue(process, PROCESS_IS_VALID) - - def tearDown(self): - # Destroy process before TestBase.tearDown() - self.dbg.GetSelectedTarget().GetProcess().Destroy() - - # Call super's tearDown(). - TestBase.tearDown(self) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/Makefile deleted file mode 100644 index 3c1f73515eb..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -LEVEL = ../../../make - -CXX_SOURCES := main.cpp - -EXE := AttachDenied - -all: AttachDenied sign - -include $(LEVEL)/Makefile.rules - -sign: entitlements.plist AttachDenied -ifeq ($(OS),Darwin) - codesign -s - -f --entitlements $^ -endif diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py deleted file mode 100644 index 49499554c2e..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/TestAttachDenied.py +++ /dev/null @@ -1,46 +0,0 @@ -""" -Test denied process attach. -""" - -from __future__ import print_function - - -import time -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - -exe_name = 'AttachDenied' # Must match Makefile - - -class AttachDeniedTestCase(TestBase): - - mydir = TestBase.compute_mydir(__file__) - NO_DEBUG_INFO_TESTCASE = True - - @skipIfWindows - @skipIfiOSSimulator - @skipIfDarwinEmbedded # ptrace(ATTACH_REQUEST...) won't work on ios/tvos/etc - def test_attach_to_process_by_id_denied(self): - """Test attach by process id denied""" - self.build() - exe = self.getBuildArtifact(exe_name) - - # Use a file as a synchronization point between test and inferior. - 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))) - - # Spawn a new process - popen = self.spawnSubprocess(exe, [pid_file_path]) - self.addTearDownHook(self.cleanupSubprocesses) - - pid = lldbutil.wait_for_file_on_target(self, pid_file_path) - - self.expect('process attach -p ' + pid, - startstr='error: attach failed:', - error=True) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/entitlements.plist b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/entitlements.plist deleted file mode 100644 index 3d60e8bd0b9..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/entitlements.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - com.apple.security.cs.debugger - - - diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/main.cpp deleted file mode 100644 index ff1fccae4b1..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/attach_denied/main.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#if defined(PTRACE_ATTACH) -#define ATTACH_REQUEST PTRACE_ATTACH -#define DETACH_REQUEST PTRACE_DETACH -#elif defined(PT_ATTACH) -#define ATTACH_REQUEST PT_ATTACH -#define DETACH_REQUEST PT_DETACH -#else -#error "Unsupported platform" -#endif - -bool writePid (const char* file_name, const pid_t pid) -{ - char *tmp_file_name = (char *)malloc(strlen(file_name) + 16); - strcpy(tmp_file_name, file_name); - strcat(tmp_file_name, "_tmp"); - int fd = open (tmp_file_name, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); - if (fd == -1) - { - fprintf (stderr, "open(%s) failed: %s\n", tmp_file_name, strerror (errno)); - free(tmp_file_name); - return false; - } - char buffer[64]; - snprintf (buffer, sizeof(buffer), "%ld", (long)pid); - - bool res = true; - if (write (fd, buffer, strlen (buffer)) == -1) - { - fprintf (stderr, "write(%s) failed: %s\n", buffer, strerror (errno)); - res = false; - } - close (fd); - - if (rename (tmp_file_name, file_name) == -1) - { - fprintf (stderr, "rename(%s, %s) failed: %s\n", tmp_file_name, file_name, strerror (errno)); - res = false; - } - free(tmp_file_name); - - return res; -} - -void signal_handler (int) -{ -} - -int main (int argc, char const *argv[]) -{ - if (argc < 2) - { - fprintf (stderr, "invalid number of command line arguments\n"); - return 1; - } - - const pid_t pid = fork (); - if (pid == -1) - { - fprintf (stderr, "fork failed: %s\n", strerror (errno)); - return 1; - } - - if (pid > 0) - { - // Make pause call to return when a signal is received. Normally this happens when the - // test runner tries to terminate us. - signal (SIGHUP, signal_handler); - signal (SIGTERM, signal_handler); - if (ptrace (ATTACH_REQUEST, pid, NULL, 0) == -1) - { - fprintf (stderr, "ptrace(ATTACH) failed: %s\n", strerror (errno)); - } - else - { - if (writePid (argv[1], pid)) - pause (); // Waiting for the debugger trying attach to the child. - - if (ptrace (DETACH_REQUEST, pid, NULL, 0) != 0) - fprintf (stderr, "ptrace(DETACH) failed: %s\n", strerror (errno)); - } - - kill (pid, SIGTERM); - int status = 0; - if (waitpid (pid, &status, 0) == -1) - fprintf (stderr, "waitpid failed: %s\n", strerror (errno)); - } - else - { - // child inferior. - pause (); - } - - printf ("Exiting now\n"); - return 0; -} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/main.cpp deleted file mode 100644 index 46ffacc0a84..00000000000 --- a/lldb/packages/Python/lldbsuite/test/functionalities/process_attach/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#include -#include - -int main(int argc, char const *argv[]) { - int temp; - lldb_enable_attach(); - - // Waiting to be attached by the debugger. - temp = 0; - - while (temp < 30) // Waiting to be attached... - { - std::this_thread::sleep_for(std::chrono::seconds(2)); - temp++; - } - - printf("Exiting now\n"); -} -- cgit v1.2.3