From 33bbbf30f461b030c04e4de866cafafce19d5232 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 16 Oct 2014 03:06:13 -0700 Subject: Split tests a lot This probably takes longer for a from-scratch compile, but saves big on incremental recompiles. --- tools/debug-debug-scripts | 104 ++++++++++++++++++++++++++-------------------- tools/debug-debug.gdb | 2 +- 2 files changed, 61 insertions(+), 45 deletions(-) (limited to 'tools') 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 . ''' +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 ') - print('// just mention "fwd.hpp" and "../poison.hpp" to make formatter happy') - print('namespace tmwa') - print('{') - print('} // namespace tmwa') - print() - print('template') - 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 ', 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', 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) diff --git a/tools/debug-debug.gdb b/tools/debug-debug.gdb index 314e049..79046c6 100644 --- a/tools/debug-debug.gdb +++ b/tools/debug-debug.gdb @@ -5,8 +5,8 @@ try: gdb.execute('set auto-load safe-path /') except: pass +gdb.execute('file %s' % file_to_load) end -file bin/test-debug-debug set logging file /dev/null set logging redirect on set logging off -- cgit v1.2.3-60-g2f50