[Piglit] [PATCH 1/2] framework: Write exceptions and traceback to /dev/stderr and json results.

Dylan Baker baker.dylan.c at gmail.com
Mon Dec 7 10:06:31 PST 2015


On Mon, Dec 07, 2015 at 02:25:59PM +0000, Jose Fonseca wrote:
> Both were being completely hidden.
> 
> Junit is probably still busted.  But the right fix is beyond any doubt
> to not catch generic Python exceptions, or override stderr, at all.
> ---
>  framework/results.py       | 3 ++-
>  framework/test/base.py     | 9 ++++++---
>  templates/test_result.mako | 8 ++++++++
>  3 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/framework/results.py b/framework/results.py
> index eeffcb7..ef19fd4 100644
> --- a/framework/results.py
> +++ b/framework/results.py
> @@ -196,6 +196,7 @@ class TestResult(object):
>              'subtests': self.subtests,
>              'time': self.time,
>              'exception': self.exception,
> +            'traceback': self.traceback,
>              'dmesg': self.dmesg,
>          }
>          return obj
> @@ -215,7 +216,7 @@ class TestResult(object):
>          # pylint: disable=assigning-non-slot
>          inst = cls()
>  
> -        for each in ['returncode', 'command', 'exception', 'environment',
> +        for each in ['returncode', 'command', 'exception', 'traceback', 'environment',
>                       'time', 'result', 'dmesg']:
>              if each in dict_:
>                  setattr(inst, each, dict_[each])
> diff --git a/framework/test/base.py b/framework/test/base.py
> index bf998d8..6cff2d3 100644
> --- a/framework/test/base.py
> +++ b/framework/test/base.py
> @@ -184,11 +184,14 @@ class Test(object):
>              # This is a rare case where a bare exception is okay, since we're
>              # using it to log exceptions
>              except:
> -                exception = sys.exc_info()
> +                exc_type, exc_value, exc_traceback = sys.exc_info()
> +                if sys.platform == 'linux2':
> +                    stderr = open("/dev/stderr", "wt")
> +                    traceback.print_exc(file=stderr)

does "traceback.print_exc(file=sys.stderr)" not work?

>                  self.result.result = 'fail'
> -                self.result.exception = "{}{}".format(*exception[:2])
> +                self.result.exception = "{}{}".format(exc_type, exc_value)
>                  self.result.traceback = "".join(
> -                    traceback.format_tb(exception[2]))
> +                    traceback.format_tb(exc_traceback))
>  
>              log.log(self.result.result)
>          else:
> diff --git a/templates/test_result.mako b/templates/test_result.mako
> index 229a5a7..ff08797 100644
> --- a/templates/test_result.mako
> +++ b/templates/test_result.mako
> @@ -75,6 +75,14 @@
>            </pre>${value.command}</pre>
>          </td>
>        </tr>
> +    % if value.exception:
> +      <tr>
> +        <td>Exception</td>
> +        <td>
> +          <pre>${value.exception | h}</pre>
> +        </td>
> +      </tr>
> +    % endif
>      % if value.traceback:
>        <tr>
>          <td>Traceback</td>
> -- 
> 2.5.0
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20151207/2205138d/attachment.sig>


More information about the Piglit mailing list