summaryrefslogtreecommitdiff
path: root/tools/debug-debug-scripts
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-10-16 03:06:13 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-10-16 10:18:39 -0700
commit33bbbf30f461b030c04e4de866cafafce19d5232 (patch)
treed4b25be7d7538f108eddcdb15b06d5459dfdcace /tools/debug-debug-scripts
parenta92502ebf69c011c0ee487921b2829686be60e15 (diff)
downloadtmwa-33bbbf30f461b030c04e4de866cafafce19d5232.tar.gz
tmwa-33bbbf30f461b030c04e4de866cafafce19d5232.tar.bz2
tmwa-33bbbf30f461b030c04e4de866cafafce19d5232.tar.xz
tmwa-33bbbf30f461b030c04e4de866cafafce19d5232.zip
Split tests a lot
This probably takes longer for a from-scratch compile, but saves big on incremental recompiles.
Diffstat (limited to 'tools/debug-debug-scripts')
-rwxr-xr-xtools/debug-debug-scripts104
1 files changed, 60 insertions, 44 deletions
diff --git a/tools/debug-debug-scripts b/tools/debug-debug-scripts
index e5eeb6c..55bcb85 100755
--- a/tools/debug-debug-scripts
+++ b/tools/debug-debug-scripts
@@ -21,12 +21,15 @@ copyright = '''
// along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
+import glob
import itertools
import os
import subprocess
import sys
import tempfile
+import protocol
+
error = False
def eprint(s):
@@ -66,55 +69,68 @@ def c_quote(s):
s = s.replace('"', '\\"')
return '"' + s + '"'
-def gen_test(name, expr, expected):
- print('static')
- print('void %s()' % name)
- print('{')
- print(' auto value = %s;' % expr)
- print(' const char *expected = %s;' % c_quote(expected))
- print(' do_breakpoint(value, expected);')
- print('}')
+def gen_test(name, expr, expected, w):
+ print('static', file=w)
+ print('void %s()' % name, file=w)
+ print('{', file=w)
+ print(' auto value = %s;' % expr, file=w)
+ print(' const char *expected = %s;' % c_quote(expected), file=w)
+ print(' do_breakpoint(value, expected);', file=w)
+ print('}', file=w)
def main(args):
- print('// test.cpp - generated by', __file__)
- print(copyright)
- print('#include <cstdio>')
- print('// just mention "fwd.hpp" and "../poison.hpp" to make formatter happy')
- print('namespace tmwa')
- print('{')
- print('} // namespace tmwa')
- print()
- print('template<class T>')
- print('__attribute__((noinline))')
- print('void do_breakpoint(const T& value, const char *expected)')
- print('{')
- print(' (void)value;')
- print(' (void)expected;')
- print(' if (!expected) printf("printer test: %p = %s\\n", &value, expected);')
- print('}')
-
- names = []
+ outdir = args[0]
+ args = args[1:]
+
+ for g in glob.glob(os.path.join(outdir, '*.[ch]pp')):
+ os.rename(g, g + '.old')
+
for a in args:
+ names = []
basename, ext = os.path.splitext(a)
assert ext == '.py'
- print()
- print('// Tests from', a)
- header = basename + '.hpp'
- print('#include "%s"' % header)
-
- for (k, tests, extra) in get_classes_from_file(a):
- print()
- print('// Tests for', k)
- print(extra)
- for (i, (expr, expected)) in enumerate(tests):
- name = 'testset_%s_subtest_%d' % (k, i)
- gen_test(name, expr, expected)
- names.append(name)
- print('int main()')
- print('{')
- for n in names:
- print(' %s();' % n)
- print('}')
+ newbase = basename.split('src/')[1].replace('/', '-')
+ out = os.path.join(outdir, newbase + '.cpp')
+ with protocol.OpenWrite(out) as w:
+ print('// %s.cpp - generated by' % newbase, __file__, file=w)
+ print(copyright, file=w)
+ print('#include <cstdio>', file=w)
+ print('// just mention "fwd.hpp" and "../poison.hpp" to make formatter happy', file=w)
+ print('namespace tmwa', file=w)
+ print('{', file=w)
+ print('} // namespace tmwa', file=w)
+ print(file=w)
+ print('template<class T>', file=w)
+ print('__attribute__((noinline))', file=w)
+ print('void do_breakpoint(const T& value, const char *expected)', file=w)
+ print('{', file=w)
+ print(' (void)value;', file=w)
+ print(' (void)expected;', file=w)
+ print(' if (!expected) printf("printer test: %p = %s\\n", &value, expected);', file=w)
+ print('}', file=w)
+ print(file=w)
+ print('// Tests from', a, file=w)
+ header = basename + '.hpp'
+ print('#include "%s"' % header, file=w)
+
+ for (k, tests, extra) in get_classes_from_file(a):
+ print(file=w)
+ print('// Tests for', k, file=w)
+ print(extra, file=w)
+ for (i, (expr, expected)) in enumerate(tests):
+ name = 'testset_%s_subtest_%d' % (k, i)
+ gen_test(name, expr, expected, w)
+ names.append(name)
+ print('int main()', file=w)
+ print('{', file=w)
+ for n in names:
+ print(' %s();' % n, file=w)
+ print('}', file=w)
+
+ for g in glob.glob(os.path.join(outdir, '*.old')):
+ print('Obsolete: %s' % g)
+ os.remove(g)
+
if error and not os.getenv('TMWA_FORCE_GENERATE'):
sys.exit(1)