logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

c.py (2042B)


  1. import fnmatch
  2. import re
  3. from subprocess import DEVNULL
  4. from milc import cli
  5. from qmk.commands import find_make, get_make_parallel_args, build_environment
  6. @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs; 0 means unlimited.")
  7. @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.")
  8. @cli.argument('-c', '--clean', arg_only=True, action='store_true', help="Remove object files before compiling.")
  9. @cli.argument('-l', '--list', arg_only=True, action='store_true', help='List available tests.')
  10. @cli.argument('-t', '--test', arg_only=True, action='append', default=[], help="Test to run from the available list. Supports wildcard globs. May be passed multiple times.")
  11. @cli.subcommand("QMK C Unit Tests.", hidden=False if cli.config.user.developer else True)
  12. def test_c(cli):
  13. """Run native unit tests.
  14. """
  15. list_tests = cli.run([find_make(), 'list-tests', 'SILENT=true'])
  16. available_tests = sorted(list_tests.stdout.strip().split())
  17. if cli.args.list:
  18. return print("\n".join(available_tests))
  19. # expand any wildcards
  20. filtered_tests = set()
  21. for test in cli.args.test:
  22. regex = re.compile(fnmatch.translate(test))
  23. filtered_tests |= set(filter(regex.match, available_tests))
  24. for invalid in filtered_tests - set(available_tests):
  25. cli.log.warning(f'Invalid test provided: {invalid}')
  26. # convert test names to build targets
  27. targets = list(map(lambda x: f'test:{x}', filtered_tests or ['all']))
  28. if cli.args.clean:
  29. targets.insert(0, 'clean')
  30. # Add in the environment vars
  31. for key, value in build_environment(cli.args.env).items():
  32. targets.append(f'{key}={value}')
  33. command = [find_make(), *get_make_parallel_args(cli.config.test_c.parallel), *targets]
  34. cli.log.info('Compiling tests with {fg_cyan}%s', ' '.join(command))
  35. return cli.run(command, capture_output=False, stdin=DEVNULL).returncode