mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 00:38:29 +01:00
- Now test errors have correct line reporting! #line directives
are passed to the compiler that reference the relevant line in
the test case shell script.
--- Multi-block directory ---
./tests/test_dirs.sh:109: assert failed with 0, expected 1
lfs_unmount(&lfs) => 1
- Cleaned up the number of implicit global variables provided to
tests. A lot of these were infrequently used and made it difficult
to remember what was provided. This isn't an MCU, so there's very
little cost to stack allocations when needed.
- Minimized the results.py script (previously stats.py) output to
match minimization of test output.
82 lines
2.2 KiB
Python
Executable File
82 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python2
|
|
|
|
import re
|
|
import sys
|
|
import subprocess
|
|
import os
|
|
|
|
|
|
def generate(test):
|
|
with open("scripts/template.fmt") as file:
|
|
template = file.read()
|
|
|
|
haslines = 'TEST_LINE' in os.environ and 'TEST_FILE' in os.environ
|
|
|
|
lines = []
|
|
for offset, line in enumerate(
|
|
re.split('(?<=(?:.;| [{}]))\n', test.read())):
|
|
match = re.match('((?: *\n)*)( *)(.*)=>(.*);',
|
|
line, re.DOTALL | re.MULTILINE)
|
|
if match:
|
|
preface, tab, test, expect = match.groups()
|
|
lines.extend(['']*preface.count('\n'))
|
|
lines.append(tab+'test_assert({test}, {expect});'.format(
|
|
test=test.strip(), expect=expect.strip()))
|
|
else:
|
|
lines.append(line)
|
|
|
|
# Create test file
|
|
with open('test.c', 'w') as file:
|
|
if 'TEST_LINE' in os.environ and 'TEST_FILE' in os.environ:
|
|
lines.insert(0, '#line %d "%s"' % (
|
|
int(os.environ['TEST_LINE']) + 1,
|
|
os.environ['TEST_FILE']))
|
|
lines.append('#line %d "test.c"' % (
|
|
template[:template.find('{tests}')].count('\n')
|
|
+ len(lines) + 2))
|
|
|
|
file.write(template.format(tests='\n'.join(lines)))
|
|
|
|
# Remove build artifacts to force rebuild
|
|
try:
|
|
os.remove('test.o')
|
|
os.remove('lfs')
|
|
except OSError:
|
|
pass
|
|
|
|
def compile():
|
|
subprocess.check_call([
|
|
os.environ.get('MAKE', 'make'),
|
|
'--no-print-directory', '-s'])
|
|
|
|
def execute():
|
|
if 'EXEC' in os.environ:
|
|
subprocess.check_call([os.environ['EXEC'], "./lfs"])
|
|
else:
|
|
subprocess.check_call(["./lfs"])
|
|
|
|
def main(test=None):
|
|
try:
|
|
if test and not test.startswith('-'):
|
|
with open(test) as file:
|
|
generate(file)
|
|
else:
|
|
generate(sys.stdin)
|
|
|
|
compile()
|
|
|
|
if test == '-s':
|
|
sys.exit(1)
|
|
|
|
execute()
|
|
|
|
except subprocess.CalledProcessError:
|
|
# Python stack trace is counterproductive, just exit
|
|
sys.exit(2)
|
|
except KeyboardInterrupt:
|
|
# Python stack trace is counterproductive, just exit
|
|
sys.exit(3)
|
|
|
|
if __name__ == "__main__":
|
|
main(*sys.argv[1:])
|