vsk created this revision.

This patch isn't quite ready for review. It's a simple proof-of-concept which 
shows what it would take to make FileCheck available within lldb inline tests. 
I'll kick off a discussion about this on lldb-dev.


https://reviews.llvm.org/D50751

Files:
  lldb/packages/Python/lldbsuite/test/lldbtest.py


Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -48,6 +48,8 @@
 import signal
 from subprocess import *
 import sys
+import commands
+import tempfile
 import time
 import traceback
 import types
@@ -2143,6 +2145,53 @@
 
         return match_object
 
+    def filecheck(
+            self,
+            command,
+            check_file,
+            filecheck_options = '',
+            trace = False):
+        # Run the command.
+        self.runCmd(
+                command,
+                msg="FileCheck'ing result of `{0}`".format(command))
+
+        # Get the error text if there was an error, and the regular text if 
not.
+        output = self.res.GetOutput() if self.res.Succeeded() \
+                else self.res.GetError()
+
+        # Write the output to a temporary file.
+        input_file = tempfile.NamedTemporaryFile()
+        input_file.write(output)
+        input_file.flush()
+
+        self.assertTrue(len(output) > 0, "No output to FileCheck")
+
+        # Assemble the absolute path to the check file.
+        check_file_abs = os.path.join(os.path.dirname(self.test_filename),
+                check_file)
+
+        # Run FileCheck. Source the check lines from the inline test.
+        filecheck_bin = os.path.join(os.path.dirname(configuration.compiler),
+                'FileCheck')
+        filecheck_cmd = "{0} {1} -input-file {2} {3}".format(filecheck_bin,
+                check_file_abs, input_file.name, filecheck_options)
+
+        if not is_exe(filecheck_bin):
+            with recording(self, trace) as sbuf:
+                print("warning: FileCheck not found, skipping command:",
+                        filecheck_cmd, file=sbuf)
+            return
+
+        (cmd_status, cmd_output) = commands.getstatusoutput(filecheck_cmd)
+
+        with recording(self, trace) as sbuf:
+            print("filecheck:", filecheck_cmd, file=sbuf)
+
+        self.assertTrue(cmd_status == 0,
+                "FileCheck failed (code={0}):\n\n{1}".format(cmd_status,
+                    cmd_output))
+
     def expect(
             self,
             str,


Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -48,6 +48,8 @@
 import signal
 from subprocess import *
 import sys
+import commands
+import tempfile
 import time
 import traceback
 import types
@@ -2143,6 +2145,53 @@
 
         return match_object
 
+    def filecheck(
+            self,
+            command,
+            check_file,
+            filecheck_options = '',
+            trace = False):
+        # Run the command.
+        self.runCmd(
+                command,
+                msg="FileCheck'ing result of `{0}`".format(command))
+
+        # Get the error text if there was an error, and the regular text if not.
+        output = self.res.GetOutput() if self.res.Succeeded() \
+                else self.res.GetError()
+
+        # Write the output to a temporary file.
+        input_file = tempfile.NamedTemporaryFile()
+        input_file.write(output)
+        input_file.flush()
+
+        self.assertTrue(len(output) > 0, "No output to FileCheck")
+
+        # Assemble the absolute path to the check file.
+        check_file_abs = os.path.join(os.path.dirname(self.test_filename),
+                check_file)
+
+        # Run FileCheck. Source the check lines from the inline test.
+        filecheck_bin = os.path.join(os.path.dirname(configuration.compiler),
+                'FileCheck')
+        filecheck_cmd = "{0} {1} -input-file {2} {3}".format(filecheck_bin,
+                check_file_abs, input_file.name, filecheck_options)
+
+        if not is_exe(filecheck_bin):
+            with recording(self, trace) as sbuf:
+                print("warning: FileCheck not found, skipping command:",
+                        filecheck_cmd, file=sbuf)
+            return
+
+        (cmd_status, cmd_output) = commands.getstatusoutput(filecheck_cmd)
+
+        with recording(self, trace) as sbuf:
+            print("filecheck:", filecheck_cmd, file=sbuf)
+
+        self.assertTrue(cmd_status == 0,
+                "FileCheck failed (code={0}):\n\n{1}".format(cmd_status,
+                    cmd_output))
+
     def expect(
             self,
             str,
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to