forked from Imagelibrary/littlefs
Added support for lists of conditional ifs in test/bench.py
Any conditions in both the suites and cases are anded together to determine when the test/bench should run. Accepting a list here makes it easier to compose multiple conditions, since toml-level elements are a bit easier to modify than strings of C expressions.
This commit is contained in:
@@ -53,9 +53,9 @@ class BenchCase:
|
|||||||
self.path = config.pop('path')
|
self.path = config.pop('path')
|
||||||
self.suite = config.pop('suite')
|
self.suite = config.pop('suite')
|
||||||
self.lineno = config.pop('lineno', None)
|
self.lineno = config.pop('lineno', None)
|
||||||
self.if_ = config.pop('if', None)
|
self.if_ = config.pop('if', [])
|
||||||
if isinstance(self.if_, bool):
|
if not isinstance(self.if_, list):
|
||||||
self.if_ = 'true' if self.if_ else 'false'
|
self.if_ = [self.if_]
|
||||||
self.code = config.pop('code')
|
self.code = config.pop('code')
|
||||||
self.code_lineno = config.pop('code_lineno', None)
|
self.code_lineno = config.pop('code_lineno', None)
|
||||||
self.in_ = config.pop('in',
|
self.in_ = config.pop('in',
|
||||||
@@ -183,9 +183,9 @@ class BenchSuite:
|
|||||||
cases[name]['lineno'] = lineno
|
cases[name]['lineno'] = lineno
|
||||||
cases[name]['code_lineno'] = code_lineno
|
cases[name]['code_lineno'] = code_lineno
|
||||||
|
|
||||||
self.if_ = config.pop('if', None)
|
self.if_ = config.pop('if', [])
|
||||||
if isinstance(self.if_, bool):
|
if not isinstance(self.if_, list):
|
||||||
self.if_ = 'true' if self.if_ else 'false'
|
self.if_ = [self.if_]
|
||||||
|
|
||||||
self.code = config.pop('code', None)
|
self.code = config.pop('code', None)
|
||||||
self.code_lineno = min(
|
self.code_lineno = min(
|
||||||
@@ -347,13 +347,15 @@ def compile(bench_paths, **args):
|
|||||||
f.writeln()
|
f.writeln()
|
||||||
|
|
||||||
# create case filter function
|
# create case filter function
|
||||||
if suite.if_ is not None or case.if_ is not None:
|
if suite.if_ or case.if_:
|
||||||
f.writeln('bool __bench__%s__filter(void) {'
|
f.writeln('bool __bench__%s__filter(void) {'
|
||||||
% (case.name))
|
% (case.name))
|
||||||
f.writeln(4*' '+'return %s;'
|
for if_ in it.chain(suite.if_, case.if_):
|
||||||
% ' && '.join('(%s)' % if_
|
f.writeln(4*' '+'if (!(%s)) return false;' % (
|
||||||
for if_ in [suite.if_, case.if_]
|
'true' if if_ is True
|
||||||
if if_ is not None))
|
else 'false' if if_ is False
|
||||||
|
else if_))
|
||||||
|
f.writeln(4*' '+'return true;')
|
||||||
f.writeln('}')
|
f.writeln('}')
|
||||||
f.writeln()
|
f.writeln()
|
||||||
|
|
||||||
@@ -403,7 +405,7 @@ def compile(bench_paths, **args):
|
|||||||
f.writeln('extern intmax_t __bench__%s__%s__%d('
|
f.writeln('extern intmax_t __bench__%s__%s__%d('
|
||||||
'void *data, size_t i);'
|
'void *data, size_t i);'
|
||||||
% (case.name, k, i))
|
% (case.name, k, i))
|
||||||
if suite.if_ is not None or case.if_ is not None:
|
if suite.if_ or case.if_:
|
||||||
f.writeln('extern bool __bench__%s__filter('
|
f.writeln('extern bool __bench__%s__filter('
|
||||||
'void);'
|
'void);'
|
||||||
% (case.name))
|
% (case.name))
|
||||||
@@ -469,7 +471,7 @@ def compile(bench_paths, **args):
|
|||||||
f.writeln(12*' '+'},')
|
f.writeln(12*' '+'},')
|
||||||
f.writeln(12*' '+'.permutations = %d,'
|
f.writeln(12*' '+'.permutations = %d,'
|
||||||
% len(case.permutations))
|
% len(case.permutations))
|
||||||
if suite.if_ is not None or case.if_ is not None:
|
if suite.if_ or case.if_:
|
||||||
f.writeln(12*' '+'.filter = __bench__%s__filter,'
|
f.writeln(12*' '+'.filter = __bench__%s__filter,'
|
||||||
% (case.name))
|
% (case.name))
|
||||||
f.writeln(12*' '+'.run = __bench__%s__run,'
|
f.writeln(12*' '+'.run = __bench__%s__run,'
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ class TestCase:
|
|||||||
self.path = config.pop('path')
|
self.path = config.pop('path')
|
||||||
self.suite = config.pop('suite')
|
self.suite = config.pop('suite')
|
||||||
self.lineno = config.pop('lineno', None)
|
self.lineno = config.pop('lineno', None)
|
||||||
self.if_ = config.pop('if', None)
|
self.if_ = config.pop('if', [])
|
||||||
if isinstance(self.if_, bool):
|
if not isinstance(self.if_, list):
|
||||||
self.if_ = 'true' if self.if_ else 'false'
|
self.if_ = [self.if_]
|
||||||
self.code = config.pop('code')
|
self.code = config.pop('code')
|
||||||
self.code_lineno = config.pop('code_lineno', None)
|
self.code_lineno = config.pop('code_lineno', None)
|
||||||
self.in_ = config.pop('in',
|
self.in_ = config.pop('in',
|
||||||
@@ -185,9 +185,9 @@ class TestSuite:
|
|||||||
cases[name]['lineno'] = lineno
|
cases[name]['lineno'] = lineno
|
||||||
cases[name]['code_lineno'] = code_lineno
|
cases[name]['code_lineno'] = code_lineno
|
||||||
|
|
||||||
self.if_ = config.pop('if', None)
|
self.if_ = config.pop('if', [])
|
||||||
if isinstance(self.if_, bool):
|
if not isinstance(self.if_, list):
|
||||||
self.if_ = 'true' if self.if_ else 'false'
|
self.if_ = [self.if_]
|
||||||
|
|
||||||
self.code = config.pop('code', None)
|
self.code = config.pop('code', None)
|
||||||
self.code_lineno = min(
|
self.code_lineno = min(
|
||||||
@@ -352,13 +352,15 @@ def compile(test_paths, **args):
|
|||||||
f.writeln()
|
f.writeln()
|
||||||
|
|
||||||
# create case filter function
|
# create case filter function
|
||||||
if suite.if_ is not None or case.if_ is not None:
|
if suite.if_ or case.if_:
|
||||||
f.writeln('bool __test__%s__filter(void) {'
|
f.writeln('bool __test__%s__filter(void) {'
|
||||||
% (case.name))
|
% (case.name))
|
||||||
f.writeln(4*' '+'return %s;'
|
for if_ in it.chain(suite.if_, case.if_):
|
||||||
% ' && '.join('(%s)' % if_
|
f.writeln(4*' '+'if (!(%s)) return false;' % (
|
||||||
for if_ in [suite.if_, case.if_]
|
'true' if if_ is True
|
||||||
if if_ is not None))
|
else 'false' if if_ is False
|
||||||
|
else if_))
|
||||||
|
f.writeln(4*' '+'return true;')
|
||||||
f.writeln('}')
|
f.writeln('}')
|
||||||
f.writeln()
|
f.writeln()
|
||||||
|
|
||||||
@@ -408,7 +410,7 @@ def compile(test_paths, **args):
|
|||||||
f.writeln('extern intmax_t __test__%s__%s__%d('
|
f.writeln('extern intmax_t __test__%s__%s__%d('
|
||||||
'void *data, size_t i);'
|
'void *data, size_t i);'
|
||||||
% (case.name, k, i))
|
% (case.name, k, i))
|
||||||
if suite.if_ is not None or case.if_ is not None:
|
if suite.if_ or case.if_:
|
||||||
f.writeln('extern bool __test__%s__filter('
|
f.writeln('extern bool __test__%s__filter('
|
||||||
'void);'
|
'void);'
|
||||||
% (case.name))
|
% (case.name))
|
||||||
@@ -476,7 +478,7 @@ def compile(test_paths, **args):
|
|||||||
f.writeln(12*' '+'},')
|
f.writeln(12*' '+'},')
|
||||||
f.writeln(12*' '+'.permutations = %d,'
|
f.writeln(12*' '+'.permutations = %d,'
|
||||||
% len(case.permutations))
|
% len(case.permutations))
|
||||||
if suite.if_ is not None or case.if_ is not None:
|
if suite.if_ or case.if_:
|
||||||
f.writeln(12*' '+'.filter = __test__%s__filter,'
|
f.writeln(12*' '+'.filter = __test__%s__filter,'
|
||||||
% (case.name))
|
% (case.name))
|
||||||
f.writeln(12*' '+'.run = __test__%s__run,'
|
f.writeln(12*' '+'.run = __test__%s__run,'
|
||||||
|
|||||||
Reference in New Issue
Block a user