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