Anas Nashif | 31df3b2 | 2017-07-27 08:45:01 -0400 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # A script to generate a list of tests that have changed or added and create an |
| 4 | # arguemnts file for sanitycheck to allow running those tests with --all |
| 5 | |
| 6 | import sys |
| 7 | import re, os |
| 8 | from email.utils import parseaddr |
| 9 | import sh |
| 10 | import logging |
| 11 | import argparse |
| 12 | |
| 13 | if "ZEPHYR_BASE" not in os.environ: |
| 14 | logging.error("$ZEPHYR_BASE environment variable undefined.\n") |
| 15 | exit(1) |
| 16 | |
| 17 | logger = None |
| 18 | |
| 19 | repository_path = os.environ['ZEPHYR_BASE'] |
| 20 | sh_special_args = { |
| 21 | '_tty_out': False, |
| 22 | '_cwd': repository_path |
| 23 | } |
| 24 | |
| 25 | def init_logs(): |
| 26 | global logger |
| 27 | log_lev = os.environ.get('LOG_LEVEL', None) |
| 28 | level = logging.INFO |
| 29 | if log_lev == "DEBUG": |
| 30 | level = logging.DEBUG |
| 31 | elif log_lev == "ERROR": |
| 32 | level = logging.ERROR |
| 33 | |
| 34 | console = logging.StreamHandler() |
| 35 | format = logging.Formatter('%(levelname)-8s: %(message)s') |
| 36 | console.setFormatter(format) |
| 37 | logger = logging.getLogger('') |
| 38 | logger.addHandler(console) |
| 39 | logger.setLevel(level) |
| 40 | |
| 41 | logging.debug("Log init completed") |
| 42 | |
| 43 | def parse_args(): |
| 44 | parser = argparse.ArgumentParser( |
| 45 | description="Generate a sanitycheck argument for for tests " |
| 46 | " that have changed") |
| 47 | parser.add_argument('-c', '--commits', default=None, |
| 48 | help="Commit range in the form: a..b") |
| 49 | return parser.parse_args() |
| 50 | |
| 51 | def main(): |
| 52 | args = parse_args() |
| 53 | if not args.commits: |
| 54 | exit(1) |
| 55 | |
| 56 | commit = sh.git("diff","--name-only", args.commits, **sh_special_args) |
| 57 | files = commit.split("\n") |
| 58 | tests = set() |
| 59 | for f in files: |
| 60 | d = os.path.dirname(f) |
| 61 | while d: |
| 62 | if os.path.exists(os.path.join(d, "testcase.yaml")) or os.path.exists(os.path.join(d, "sample.yaml")): |
| 63 | tests.add(d) |
| 64 | break |
| 65 | else: |
| 66 | d = os.path.dirname(d) |
| 67 | |
| 68 | if tests: |
| 69 | print("-T\n%s\n--all" %("\n-T\n".join(tests))) |
| 70 | |
| 71 | if __name__ == "__main__": |
| 72 | main() |
| 73 | |