zturner created this revision. zturner added reviewers: tfiala, labath, tberghammer. zturner added a subscriber: lldb-commits. Herald added subscribers: srhines, danalbert, tberghammer.
The original motivation for this came when I tried to combine two decorators: ``` @expectedFailureDarwin @expectedFailureLinux ``` into a single decorator: ``` @expectedFailureAll(oslist=...) ``` This results in a really ugly syntax, because `@expectedFailureDarwin` calls `getDarwinOsTriples()` which is itself a list. So you would have to do something like this: ``` @expectedFailureAll(oslist=getDarwinOsTriples()+["linux"]) ``` Not the end of the world, but not ideal either. Then I remembered that we've all had this ugliness surrounding the translation of python api calls such as `sys.name`, `os.platform`, and target names and host names into something consistent, so it occurred to me that many things would become cleaner and more elegant if we had actual enums for everything, and a centralized place where we can convert between enums and strings or whatever else we need. So this patch introduces two enums. `target` and `host`, updates the common decorator to support these values from these enums, and changes two decorators to using these new values as a proof of concept. One nice thing about these enums is that we can make standardized enum values for "combinations" of targets or hosts where it makes sense (such as is the case of with darwin, which is why the `getDarwinOsTriples()` function existed in the first place. So in that sense it works similarly to a flags enum in C / C++. Eventually it would be nice if we could start using these enums all over the codebase instead of using strings everywhere, but this patch does not attempt to solve that problem. http://reviews.llvm.org/D17088 Files: packages/Python/lldbsuite/test/decorators.py packages/Python/lldbsuite/test/functionalities/asan/TestMemoryHistory.py packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py packages/Python/lldbsuite/test/lldbplatformutil.py
Index: packages/Python/lldbsuite/test/lldbplatformutil.py =================================================================== --- packages/Python/lldbsuite/test/lldbplatformutil.py +++ packages/Python/lldbsuite/test/lldbplatformutil.py @@ -4,11 +4,13 @@ from __future__ import absolute_import # System modules +import itertools import re import subprocess import sys # Third-party modules +import six from six.moves.urllib import parse as urlparse # LLDB modules @@ -16,6 +18,53 @@ import use_lldb_suite import lldb +def _translate_platform_list(platforms, names): + if isinstance(platforms, six.integer_types): + # This is a value from lldbplatformutil.target, translate it. + return names[platforms] + elif isinstance(platforms, six.string_types): + # This is a raw string, return it. + return [platforms] + elif hasattr(platforms, "__iter__"): + # This is an iterable, convert each item. + result = [_translate_platform_list(x, names) for x in platforms] + result = list(itertools.chain(*result)) + return result + return platforms + +class target: + windows, linux, macosx, darwin, ios, darwin_all, freebsd, netbsd, bsd_all, android = range(10) + + @staticmethod + def translate(values): + platform_names = { + target.windows : ["windows"], + target.linux : ["linux"], + target.macosx : ["macosx"], + target.darwin : ["darwin"], + target.ios : ["ios"], + target.darwin_all : ["macosx", "darwin", "ios"], + target.freebsd : ["freebsd"], + target.netbsd : ["netbsd"], + target.bsd_all : ["freebsd", "netbsd"], + target.android : ["android"] + } + return _translate_platform_list(values, platform_names) + +class host: + windows, linux, darwin, freebsd, netbsd = range(5) + + @staticmethod + def translate(values): + platform_names = { + target.windows : ["windows"], + target.linux : ["linux"], + target.darwin : ["darwin"], + target.freebsd : ["freebsd"], + target.netbsd : ["netbsd"] + } + return _translate_platform_list(values, platform_names) + def check_first_register_readable(test_case): arch = test_case.getArchitecture() Index: packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py =================================================================== --- packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py +++ packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py @@ -11,6 +11,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil +from lldbsuite.test.lldbplatformutil import target class CommandLineCompletionTestCase(TestBase): @@ -256,7 +257,7 @@ self.complete_from_to('target va', 'target variable ') @expectedFailureAll(hostoslist=["windows"], bugnumber="llvm.org/pr24679") - @expectedFailureDarwin("llvm.org/pr25485") + @expectedFailureAll(oslist=target.darwin_all, bugnumber="llvm.org/pr25485") def test_symbol_name(self): self.build() self.complete_from_to('''file a.out Index: packages/Python/lldbsuite/test/functionalities/asan/TestMemoryHistory.py =================================================================== --- packages/Python/lldbsuite/test/functionalities/asan/TestMemoryHistory.py +++ packages/Python/lldbsuite/test/functionalities/asan/TestMemoryHistory.py @@ -11,6 +11,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil +from lldbsuite.test.lldbplatformutil import target class AsanTestCase(TestBase): @@ -20,7 +21,7 @@ @skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default @skipIfRemote @skipUnlessCompilerRt - @expectedFailureDarwin + @expectedFailureAll(oslist=target.darwin_all) def test (self): self.build () self.asan_tests () Index: packages/Python/lldbsuite/test/decorators.py =================================================================== --- packages/Python/lldbsuite/test/decorators.py +++ packages/Python/lldbsuite/test/decorators.py @@ -4,6 +4,7 @@ # System modules from distutils.version import LooseVersion, StrictVersion from functools import wraps +import itertools import os import re import sys @@ -138,8 +139,8 @@ swig_version=None, py_version=None, remote=None): def fn(self): - skip_for_os = _match_decorator_property(oslist, self.getPlatform()) - skip_for_hostos = _match_decorator_property(hostoslist, lldbplatformutil.getHostPlatform()) + skip_for_os = _match_decorator_property(lldbplatformutil.target.translate(oslist), self.getPlatform()) + skip_for_hostos = _match_decorator_property(lldbplatformutil.host.translate(hostoslist), lldbplatformutil.getHostPlatform()) skip_for_compiler = _match_decorator_property(compiler, self.getCompiler()) and self.expectedCompilerVersion(compiler_version) skip_for_arch = _match_decorator_property(archs, self.getArchitecture()) skip_for_debug_info = _match_decorator_property(debug_info, self.debug_info) @@ -296,10 +297,10 @@ def expectedFailureDarwin(bugnumber=None, compilers=None, debug_info=None): # For legacy reasons, we support both "darwin" and "macosx" as OS X triples. - return expectedFailureOS(lldbplatformutil.getDarwinOSTriples(), bugnumber, compilers, debug_info=debug_info) + return expectedFailureOS(lldbplatformutil.target.darwin_all, bugnumber, compilers, debug_info=debug_info) def expectedFailureFreeBSD(bugnumber=None, compilers=None, debug_info=None): - return expectedFailureOS(['freebsd'], bugnumber, compilers, debug_info=debug_info) + return expectedFailureOS(lldbplatformutil.target.freebsd, bugnumber, compilers, debug_info=debug_info) def expectedFailureAndroid(bugnumber=None, api_levels=None, archs=None): """ Mark a test as xfail for Android. @@ -426,7 +427,7 @@ def skipIfDarwin(func): """Decorate the item to skip tests that should be skipped on Darwin.""" - return skipIfPlatform(lldbplatformutil.getDarwinOSTriples())(func) + return skipIfPlatform(lldbplatformutil.target.translate(lldbplatformutil.target.darwin_all))(func) def skipIfLinux(func): """Decorate the item to skip tests that should be skipped on Linux."""
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits