[Lldb-commits] [lldb] r174777 - <rdar://problem/13176279>

Enrico Granata egranata at apple.com
Fri Feb 8 15:39:19 PST 2013


Author: enrico
Date: Fri Feb  8 17:39:18 2013
New Revision: 174777

URL: http://llvm.org/viewvc/llvm-project?rev=174777&view=rev
Log:
<rdar://problem/13176279>

The LLDB test suite now shows a progress bar instead of dots when not in verbose mode
If you crave the dots, make your Terminal window smaller than 10 columns :-)
(or ask for a flag to have the dots come back on demand)


Added:
    lldb/trunk/test/progress.py   (with props)
Modified:
    lldb/trunk/test/dotest.py
    lldb/trunk/test/unittest2/runner.py

Modified: lldb/trunk/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=174777&r1=174776&r2=174777&view=diff
==============================================================================
--- lldb/trunk/test/dotest.py (original)
+++ lldb/trunk/test/dotest.py Fri Feb  8 17:39:18 2013
@@ -29,6 +29,7 @@ import sys
 import textwrap
 import time
 import unittest2
+import progress
 
 def is_exe(fpath):
     """Returns true if fpath is an executable."""
@@ -1302,6 +1303,30 @@ for ia in range(len(archs) if iterArchs
             __singleton__ = None
             __ignore_singleton__ = False
 
+            @staticmethod
+            def getTerminalSize():
+                import os
+                env = os.environ
+                def ioctl_GWINSZ(fd):
+                    try:
+                        import fcntl, termios, struct, os
+                        cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
+                    '1234'))
+                    except:
+                        return
+                    return cr
+                cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
+                if not cr:
+                    try:
+                        fd = os.open(os.ctermid(), os.O_RDONLY)
+                        cr = ioctl_GWINSZ(fd)
+                        os.close(fd)
+                    except:
+                        pass
+                if not cr:
+                    cr = (env.get('LINES', 25), env.get('COLUMNS', 80))
+                return int(cr[1]), int(cr[0])
+
             def __init__(self, *args):
                 if not LLDBTestResult.__ignore_singleton__ and LLDBTestResult.__singleton__:
                     raise Exception("LLDBTestResult instantiated more than once")
@@ -1316,6 +1341,9 @@ for ia in range(len(archs) if iterArchs
                 self.indentation = ' ' * (counterWidth + 2)
                 # This counts from 1 .. suite.countTestCases().
                 self.counter = 0
+                (width, height) = LLDBTestResult.getTerminalSize()
+                if width > 10:
+                    self.progressbar = progress.AnimatedProgressBar(stdout=self.stream,start=0,end=suite.countTestCases(),width=width-10)
 
             def _exc_info_to_string(self, err, test):
                 """Overrides superclass TestResult's method in order to append

Added: lldb/trunk/test/progress.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/progress.py?rev=174777&view=auto
==============================================================================
--- lldb/trunk/test/progress.py (added)
+++ lldb/trunk/test/progress.py Fri Feb  8 17:39:18 2013
@@ -0,0 +1,109 @@
+#!/usr/bin/python
+
+import sys
+import time
+
+class ProgressBar(object):
+    """ProgressBar class holds the options of the progress bar.
+    The options are:
+        start   State from which start the progress. For example, if start is 
+                5 and the end is 10, the progress of this state is 50%
+        end     State in which the progress has terminated.
+        width   --
+        fill    String to use for "filled" used to represent the progress
+        blank   String to use for "filled" used to represent remaining space.
+        format  Format
+        incremental
+    """
+    light_block = unichr(0x2591).encode("utf-8")
+    solid_block = unichr(0x2588).encode("utf-8")
+    solid_right_arrow = unichr(0x25BA).encode("utf-8")
+    
+    def __init__(self, 
+                 start=0, 
+                 end=10, 
+                 width=12, 
+                 fill=unichr(0x25C9).encode("utf-8"), 
+                 blank=unichr(0x25CC).encode("utf-8"), 
+                 marker=unichr(0x25CE).encode("utf-8"), 
+                 format='[%(fill)s%(marker)s%(blank)s] %(progress)s%%', 
+                 incremental=True):
+        super(ProgressBar, self).__init__()
+
+        self.start = start
+        self.end = end
+        self.width = width
+        self.fill = fill
+        self.blank = blank
+        self.marker = marker
+        self.format = format
+        self.incremental = incremental
+        self.step = 100 / float(width) #fix
+        self.reset()
+
+    def __add__(self, increment):
+        increment = self._get_progress(increment)
+        if 100 > self.progress + increment:
+            self.progress += increment
+        else:
+            self.progress = 100
+        return self
+
+    def complete(self):
+        self.progress = 100
+        return self
+
+    def __str__(self):
+        progressed = int(self.progress / self.step) #fix
+        fill = progressed * self.fill
+        blank = (self.width - progressed) * self.blank
+        return self.format % {'fill': fill, 'blank': blank, 'marker': self.marker, 'progress': int(self.progress)}
+
+    __repr__ = __str__
+
+    def _get_progress(self, increment):
+        return float(increment * 100) / self.end
+
+    def reset(self):
+        """Resets the current progress to the start point"""
+        self.progress = self._get_progress(self.start)
+        return self
+
+
+class AnimatedProgressBar(ProgressBar):
+    """Extends ProgressBar to allow you to use it straighforward on a script.
+    Accepts an extra keyword argument named `stdout` (by default use sys.stdout)
+    and may be any file-object to which send the progress status.
+    """
+    def __init__(self, 
+                 start=0, 
+                 end=10, 
+                 width=12, 
+                 fill=unichr(0x25C9).encode("utf-8"), 
+                 blank=unichr(0x25CC).encode("utf-8"), 
+                 marker=unichr(0x25CE).encode("utf-8"), 
+                 format='[%(fill)s%(marker)s%(blank)s] %(progress)s%%', 
+                 incremental=True,
+                 stdout=sys.stdout):
+        super(AnimatedProgressBar, self).__init__(start,end,width,fill,blank,marker,format,incremental)
+        self.stdout = stdout
+
+    def show_progress(self):
+        if hasattr(self.stdout, 'isatty') and self.stdout.isatty():
+            self.stdout.write('\r')
+        else:
+            self.stdout.write('\n')
+        self.stdout.write(str(self))
+        self.stdout.flush()
+
+
+if __name__ == '__main__':
+    p = AnimatedProgressBar(end=200, width=200)
+
+    while True:
+        p + 5
+        p.show_progress()
+        time.sleep(0.3)
+        if p.progress == 100:
+            break
+    print #new line
\ No newline at end of file

Propchange: lldb/trunk/test/progress.py
------------------------------------------------------------------------------
    svn:executable = *

Modified: lldb/trunk/test/unittest2/runner.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/unittest2/runner.py?rev=174777&r1=174776&r2=174777&view=diff
==============================================================================
--- lldb/trunk/test/unittest2/runner.py (original)
+++ lldb/trunk/test/unittest2/runner.py Fri Feb  8 17:39:18 2013
@@ -3,6 +3,7 @@
 import sys
 import time
 import unittest
+import progress
 
 from unittest2 import result
 
@@ -45,6 +46,7 @@ class TextTestResult(result.TestResult):
         self.showAll = verbosity > 1
         self.dots = verbosity == 1
         self.descriptions = descriptions
+        self.progressbar = None
 
     def getDescription(self, test):
         doc_first_line = test.shortDescription()
@@ -64,6 +66,9 @@ class TextTestResult(result.TestResult):
         super(TextTestResult, self).addSuccess(test)
         if self.showAll:
             self.stream.writeln("ok")
+        elif self.progressbar:
+            self.progressbar.__add__(1)
+            self.progressbar.show_progress()
         elif self.dots:
             self.stream.write('.')
             self.stream.flush()
@@ -72,6 +77,9 @@ class TextTestResult(result.TestResult):
         super(TextTestResult, self).addError(test, err)
         if self.showAll:
             self.stream.writeln("ERROR")
+        elif self.progressbar:
+            self.progressbar.__add__(1)
+            self.progressbar.show_progress()
         elif self.dots:
             self.stream.write('E')
             self.stream.flush()
@@ -80,6 +88,9 @@ class TextTestResult(result.TestResult):
         super(TextTestResult, self).addFailure(test, err)
         if self.showAll:
             self.stream.writeln("FAIL")
+        elif self.progressbar:
+            self.progressbar.__add__(1)
+            self.progressbar.show_progress()
         elif self.dots:
             self.stream.write('F')
             self.stream.flush()
@@ -88,6 +99,9 @@ class TextTestResult(result.TestResult):
         super(TextTestResult, self).addSkip(test, reason)
         if self.showAll:
             self.stream.writeln("skipped %r" % (reason,))
+        elif self.progressbar:
+            self.progressbar.__add__(1)
+            self.progressbar.show_progress()
         elif self.dots:
             self.stream.write("s")
             self.stream.flush()
@@ -96,6 +110,9 @@ class TextTestResult(result.TestResult):
         super(TextTestResult, self).addExpectedFailure(test, err)
         if self.showAll:
             self.stream.writeln("expected failure")
+        elif self.progressbar:
+            self.progressbar.__add__(1)
+            self.progressbar.show_progress()
         elif self.dots:
             self.stream.write("x")
             self.stream.flush()
@@ -104,11 +121,17 @@ class TextTestResult(result.TestResult):
         super(TextTestResult, self).addUnexpectedSuccess(test)
         if self.showAll:
             self.stream.writeln("unexpected success")
+        elif self.progressbar:
+            self.progressbar.__add__(1)
+            self.progressbar.show_progress()
         elif self.dots:
             self.stream.write("u")
             self.stream.flush()
 
     def printErrors(self):
+        if self.progressbar:
+            self.progressbar.complete()
+            self.progressbar.show_progress()
         if self.dots or self.showAll:
             self.stream.writeln()
         self.printErrorList('ERROR', self.errors)





More information about the lldb-commits mailing list