mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Found by user iamscottmoyers, this was an interesting bug with the test system. If the new test.c file is generated fast enough, it may not have a new timestamp and not get recompiled. To fix, we can remove the specific files that need to be rebuilt (lfs and test.o).
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env python
 | |
| 
 | |
| import re
 | |
| import sys
 | |
| import subprocess
 | |
| import os
 | |
| 
 | |
| def generate(test):
 | |
|     with open("tests/template.fmt") as file:
 | |
|         template = file.read()
 | |
| 
 | |
|     lines = []
 | |
|     for line in re.split('(?<=[;{}])\n', test.read()):
 | |
|         match = re.match('(?: *\n)*( *)(.*)=>(.*);', line, re.DOTALL | re.MULTILINE)
 | |
|         if match:
 | |
|             tab, test, expect = match.groups()
 | |
|             lines.append(tab+'res = {test};'.format(test=test.strip()))
 | |
|             lines.append(tab+'test_assert("{name}", res, {expect});'.format(
 | |
|                     name = re.match('\w*', test.strip()).group(),
 | |
|                     expect = expect.strip()))
 | |
|         else:
 | |
|             lines.append(line)
 | |
| 
 | |
|     # Create test file
 | |
|     with open('test.c', 'w') as file:
 | |
|         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():
 | |
|     os.environ['CFLAGS'] = os.environ.get('CFLAGS', '') + ' -Werror'
 | |
|     subprocess.check_call(['make', '--no-print-directory', '-s'], env=os.environ)
 | |
| 
 | |
| def execute():
 | |
|     subprocess.check_call(["./lfs"])
 | |
| 
 | |
| def main(test=None):
 | |
|     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()
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     main(*sys.argv[1:])
 |