[Lldb-commits] [lldb] r175946 - This should get clang/gcc decorators working

Enrico Granata egranata at apple.com
Mon Feb 25 16:09:28 PST 2013


Hi Daniel,
I am very aware of the code duplication, and am not excited about it.

The issue is that Python decorators can be called in two ways:
@decorator
or
@decorator(args)

and I did not want to have to change every test case from @expectedFailure to @expectedFailure()
The “if callable” line serves the purpose of supporting both syntaxes. I am afraid that to clean that up we would need a third level of decoration (the current decorator is a function that returns what essentially was the old decorator function).
If you feel like playing with Python for a while and get it right, feel free to. Or I can just keep it on my queue as something to do at the first idle-time moment.

As for the decorator supporting a string, is there anything (other than the argument being named bugnumber) that prevents it? If not, maybe we should just call it “bugreference” or something equivalent.

Sincerely,
Enrico Granata
✉ egranata@.com
✆ 27683

On Feb 25, 2013, at 3:13 PM, "Malea, Daniel" <daniel.malea at intel.com> wrote:

> Hi Enrico,
> 
> Thanks for doing this, it will help get much better test (and buildbot) output.
> 
> However, this commit seems to duplicate some code -- any way around that? I have a patch that adds arguments to the uses of @expectedFailure[Linux|Clang|Gcc|i386] and friends in the test cases... if that would help you avoid the giant "if callable(..)" block in the decorator body, let me know and I'll post it to the list. I'd really like to avoid that logic if possible, because as-is the variable named 'bugnumber' can be a rdar tracking number integer, or a function....quite confusing!
> 
> We are planning to enable more test compilers than GCC or Clang.... if we had a function that takes the compiler name as a string, adding that feature would be a lot cleaner than duplicating all this decorator logic.
> 
> Also, I think it would be great if the decorator would be used with a full string that describes the bug (i.e. "llvm.org/pr15130") that way we can distinguish between rdar issues and llvm.org bugtracker issues.
> 
> Cheers,
> Dan
> 
> 
> 
> -----Original Message-----
> From: lldb-commits-bounces at cs.uiuc.edu [mailto:lldb-commits-bounces at cs.uiuc.edu] On Behalf Of Enrico Granata
> Sent: Friday, February 22, 2013 8:35 PM
> To: lldb-commits at cs.uiuc.edu
> Subject: [Lldb-commits] [lldb] r175946 - This should get clang/gcc decorators working
> 
> Author: enrico
> Date: Fri Feb 22 19:35:21 2013
> New Revision: 175946
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=175946&view=rev
> Log:
> This should get clang/gcc decorators working
> 
> Modified:
>    lldb/trunk/test/lldbtest.py
> 
> Modified: lldb/trunk/test/lldbtest.py
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=175946&r1=175945&r2=175946&view=diff
> ==============================================================================
> --- lldb/trunk/test/lldbtest.py (original)
> +++ lldb/trunk/test/lldbtest.py Fri Feb 22 19:35:21 2013
> @@ -368,25 +368,25 @@ def dwarf_test(func):
>     wrapper.__dwarf_test__ = True
>     return wrapper
> 
> -def expectedFailureCompiler(func,compiler,bugnumber=None):
> +def expectedFailureGcc(bugnumber=None):
>      if callable(bugnumber):
>         @wraps(bugnumber)
> -        def expectedFailureCompiler_easy_wrapper(*args, **kwargs):
> +        def expectedFailureGcc_easy_wrapper(*args, **kwargs):
>             from unittest2 import case
>             self = args[0]
>             test_compiler = self.getCompiler()
>             try:
>                 bugnumber(*args, **kwargs)
>             except Exception:
> -                if compiler in test_compiler:
> +                if "gcc" in test_compiler:
>                     raise case._ExpectedFailure(sys.exc_info(),None)
>                 else:
>                     raise
> -            if compiler in test_compiler:
> +            if "gcc" in test_compiler:
>                 raise case._UnexpectedSuccess(sys.exc_info(),None)
> -        return expectedFailureCompiler_easy_wrapper
> +        return expectedFailureGcc_easy_wrapper
>      else:
> -        def expectedFailureCompiler_impl(func):
> +        def expectedFailureGcc_impl(func):
>               @wraps(func)
>               def wrapper(*args, **kwargs):
>                 from unittest2 import case @@ -395,26 +395,51 @@ def expectedFailureCompiler(func,compile
>                 try:
>                     func(*args, **kwargs)
>                 except Exception:
> -                    if compiler in test_compiler:
> +                    if "gcc" in test_compiler:
>                         raise case._ExpectedFailure(sys.exc_info(),bugnumber)
>                     else:
>                         raise
> -                if compiler in test_compiler:
> +                if "gcc" in test_compiler:
>                     raise case._UnexpectedSuccess(sys.exc_info(),bugnumber)
>               return wrapper
> -        return expectedFailureCompiler_impl
> +        return expectedFailureGcc_impl
> 
> -def expectedFailureGcc(func):
> -    """Decorate the item as a GCC only expectedFailure."""
> -    if isinstance(func, type) and issubclass(func, unittest2.TestCase):
> -        raise Exception("@expectedFailureClang can only be used to decorate a test method")
> -    return expectedFailureCompiler(func, "gcc")
> +def expectedFailureClang(bugnumber=None):
> +     if callable(bugnumber):
> +        @wraps(bugnumber)
> +        def expectedFailureClang_easy_wrapper(*args, **kwargs):
> +            from unittest2 import case
> +            self = args[0]
> +            test_compiler = self.getCompiler()
> +            try:
> +                bugnumber(*args, **kwargs)
> +            except Exception:
> +                if "clang" in test_compiler:
> +                    raise case._ExpectedFailure(sys.exc_info(),None)
> +                else:
> +                    raise
> +            if "clang" in test_compiler:
> +                raise case._UnexpectedSuccess(sys.exc_info(),None)
> +        return expectedFailureClang_easy_wrapper
> +     else:
> +        def expectedFailureClang_impl(func):
> +              @wraps(func)
> +              def wrapper(*args, **kwargs):
> +                from unittest2 import case
> +                self = args[0]
> +                test_compiler = self.getCompiler()
> +                try:
> +                    func(*args, **kwargs)
> +                except Exception:
> +                    if "clang" in test_compiler:
> +                        raise case._ExpectedFailure(sys.exc_info(),bugnumber)
> +                    else:
> +                        raise
> +                if "clang" in test_compiler:
> +                    raise case._UnexpectedSuccess(sys.exc_info(),bugnumber)
> +              return wrapper
> +        return expectedFailureClang_impl
> 
> -def expectedFailureClang(func):
> -    """Decorate the item as a Clang only expectedFailure."""
> -    if isinstance(func, type) and issubclass(func, unittest2.TestCase):
> -        raise Exception("@expectedFailureClang can only be used to decorate a test method")
> -    return expectedFailureCompiler(func, "clang")
> 
> def expectedFailurei386(bugnumber=None):
>      if callable(bugnumber):
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20130225/e80571e0/attachment.html>


More information about the lldb-commits mailing list