Author: Michał Górny
Date: 2021-09-10T14:08:35+02:00
New Revision: c240d2bb06dabe8fb3a1c2da978fbdc9f642de73

URL: 
https://github.com/llvm/llvm-project/commit/c240d2bb06dabe8fb3a1c2da978fbdc9f642de73
DIFF: 
https://github.com/llvm/llvm-project/commit/c240d2bb06dabe8fb3a1c2da978fbdc9f642de73.diff

LOG: [lldb] [test] Move "platform connect" logic into a common class

Create a common GDBPlatformClientTestBase class and move the platform
select/connect logic there to reduce duplication.

Differential Revision: https://reviews.llvm.org/D109585

Added: 
    

Modified: 
    
lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
    lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
    lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py

Removed: 
    


################################################################################
diff  --git 
a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
 
b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
index c0afce00a4cf1..8109caf3d7310 100644
--- 
a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
+++ 
b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteDiskFileCompletion.py
@@ -1,6 +1,6 @@
 from gdbclientutils import *
 
-class TestGDBRemoteDiskFileCompletion(GDBRemoteTestBase):
+class TestGDBRemoteDiskFileCompletion(GDBPlatformClientTestBase):
 
     def test_autocomplete_request(self):
         """Test remote disk completion on remote-gdb-server plugin"""
@@ -14,16 +14,8 @@ def qPathComplete(self):
 
         self.server.responder = Responder()
 
-        try:
-            self.runCmd("platform select remote-gdb-server")
-            self.runCmd("platform connect connect://" +
-                        self.server.get_connect_address())
-            self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
-
-            self.complete_from_to('platform get-size ', ['test', '123'])
-            self.complete_from_to('platform get-file ', ['test', '123'])
-            self.complete_from_to('platform put-file foo ', ['test', '123'])
-            self.complete_from_to('platform file open ', ['test', '123'])
-            self.complete_from_to('platform settings -w ', ['test', '123'])
-        finally:
-            self.dbg.GetSelectedPlatform().DisconnectRemote()
+        self.complete_from_to('platform get-size ', ['test', '123'])
+        self.complete_from_to('platform get-file ', ['test', '123'])
+        self.complete_from_to('platform put-file foo ', ['test', '123'])
+        self.complete_from_to('platform file open ', ['test', '123'])
+        self.complete_from_to('platform settings -w ', ['test', '123'])

diff  --git 
a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py 
b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
index fcc2579266806..d5475986bb57d 100644
--- 
a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
+++ 
b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
@@ -1,6 +1,6 @@
 from gdbclientutils import *
 
-class TestGDBRemotePlatformFile(GDBRemoteTestBase):
+class TestGDBRemotePlatformFile(GDBPlatformClientTestBase):
 
     def test_file(self):
         """Test mock operations on a remote file"""
@@ -19,28 +19,20 @@ def vFile(self, packet):
 
         self.server.responder = Responder()
 
-        try:
-            self.runCmd("platform select remote-gdb-server")
-            self.runCmd("platform connect connect://" +
-                        self.server.get_connect_address())
-            self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
-
-            self.match("platform file open /some/file.txt -v 0755",
-                       [r"File Descriptor = 16"])
-            self.match("platform file read 16 -o 11 -c 13",
-                       [r"Return = 11\nData = \"frobnicator\""])
-            self.match("platform file write 16 -o 11 -d teststring",
-                       [r"Return = 10"])
-            self.match("platform file close 16",
-                       [r"file 16 closed."])
-            self.assertPacketLogContains([
-                "vFile:open:2f736f6d652f66696c652e747874,00000202,000001ed",
-                "vFile:pread:10,d,b",
-                "vFile:pwrite:10,b,teststring",
-                "vFile:close:10",
-                ])
-        finally:
-            self.dbg.GetSelectedPlatform().DisconnectRemote()
+        self.match("platform file open /some/file.txt -v 0755",
+                   [r"File Descriptor = 16"])
+        self.match("platform file read 16 -o 11 -c 13",
+                   [r"Return = 11\nData = \"frobnicator\""])
+        self.match("platform file write 16 -o 11 -d teststring",
+                   [r"Return = 10"])
+        self.match("platform file close 16",
+                   [r"file 16 closed."])
+        self.assertPacketLogContains([
+            "vFile:open:2f736f6d652f66696c652e747874,00000202,000001ed",
+            "vFile:pread:10,d,b",
+            "vFile:pwrite:10,b,teststring",
+            "vFile:close:10",
+            ])
 
     def test_file_fail(self):
         """Test mocked failures of remote operations"""
@@ -51,32 +43,24 @@ def vFile(self, packet):
 
         self.server.responder = Responder()
 
-        try:
-            self.runCmd("platform select remote-gdb-server")
-            self.runCmd("platform connect connect://" +
-                        self.server.get_connect_address())
-            self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
-
-            self.match("platform file open /some/file.txt -v 0755",
-                       [r"error: Invalid argument"],
-                       error=True)
-            self.match("platform file read 16 -o 11 -c 13",
-                       [r"error: Invalid argument"],
-                       error=True)
-            self.match("platform file write 16 -o 11 -d teststring",
-                       [r"error: Invalid argument"],
-                       error=True)
-            self.match("platform file close 16",
-                       [r"error: Invalid argument"],
-                       error=True)
-            self.assertPacketLogContains([
-                "vFile:open:2f736f6d652f66696c652e747874,00000202,000001ed",
-                "vFile:pread:10,d,b",
-                "vFile:pwrite:10,b,teststring",
-                "vFile:close:10",
-                ])
-        finally:
-            self.dbg.GetSelectedPlatform().DisconnectRemote()
+        self.match("platform file open /some/file.txt -v 0755",
+                   [r"error: Invalid argument"],
+                   error=True)
+        self.match("platform file read 16 -o 11 -c 13",
+                   [r"error: Invalid argument"],
+                   error=True)
+        self.match("platform file write 16 -o 11 -d teststring",
+                   [r"error: Invalid argument"],
+                   error=True)
+        self.match("platform file close 16",
+                   [r"error: Invalid argument"],
+                   error=True)
+        self.assertPacketLogContains([
+            "vFile:open:2f736f6d652f66696c652e747874,00000202,000001ed",
+            "vFile:pread:10,d,b",
+            "vFile:pwrite:10,b,teststring",
+            "vFile:close:10",
+            ])
 
     def test_file_size(self):
         """Test 'platform get-size'"""
@@ -87,19 +71,11 @@ def vFile(self, packet):
 
         self.server.responder = Responder()
 
-        try:
-            self.runCmd("platform select remote-gdb-server")
-            self.runCmd("platform connect connect://" +
-                        self.server.get_connect_address())
-            self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
-
-            self.match("platform get-size /some/file.txt",
-                       [r"File size of /some/file\.txt \(remote\): 4096"])
-            self.assertPacketLogContains([
-                "vFile:size:2f736f6d652f66696c652e747874",
-                ])
-        finally:
-            self.dbg.GetSelectedPlatform().DisconnectRemote()
+        self.match("platform get-size /some/file.txt",
+                   [r"File size of /some/file\.txt \(remote\): 4096"])
+        self.assertPacketLogContains([
+            "vFile:size:2f736f6d652f66696c652e747874",
+            ])
 
     def test_file_size_fallback(self):
         """Test 'platform get-size fallback to vFile:fstat'"""
@@ -116,19 +92,11 @@ def vFile(self, packet):
 
         self.server.responder = Responder()
 
-        try:
-            self.runCmd("platform select remote-gdb-server")
-            self.runCmd("platform connect connect://" +
-                        self.server.get_connect_address())
-            self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
-
-            self.match("platform get-size /some/file.txt",
-                       [r"File size of /some/file\.txt \(remote\): 66051"])
-            self.assertPacketLogContains([
-                "vFile:size:2f736f6d652f66696c652e747874",
-                "vFile:open:2f736f6d652f66696c652e747874,00000000,00000000",
-                "vFile:fstat:5",
-                "vFile:close:5",
-                ])
-        finally:
-            self.dbg.GetSelectedPlatform().DisconnectRemote()
+        self.match("platform get-size /some/file.txt",
+                   [r"File size of /some/file\.txt \(remote\): 66051"])
+        self.assertPacketLogContains([
+            "vFile:size:2f736f6d652f66696c652e747874",
+            "vFile:open:2f736f6d652f66696c652e747874,00000000,00000000",
+            "vFile:fstat:5",
+            "vFile:close:5",
+            ])

diff  --git a/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py 
b/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
index 0222e8453f7a0..bfbd48dd5167e 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/gdbclientutils.py
@@ -566,3 +566,23 @@ def assertPacketLogContains(self, packets):
         if i < len(packets):
             self.fail(u"Did not receive: %s\nLast 10 packets:\n\t%s" %
                     (packets[i], u'\n\t'.join(log)))
+
+
+class GDBPlatformClientTestBase(GDBRemoteTestBase):
+    """
+    Base class for platform server clients.
+
+    This class extends GDBRemoteTestBase by automatically connecting
+    via "platform connect" in the setUp() method.
+    """
+
+    def setUp(self):
+        super().setUp()
+        self.runCmd("platform select remote-gdb-server")
+        self.runCmd("platform connect connect://" +
+                    self.server.get_connect_address())
+        self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
+
+    def tearDown(self):
+        self.dbg.GetSelectedPlatform().DisconnectRemote()
+        super().tearDown()


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to