blob: ba60868b98ba23ca6d407d5d00f3a83e7f184c0c [file] [log] [blame]
Anas Nashif31df3b22017-07-27 08:45:01 -04001#!/usr/bin/env python3
Anas Nashif3ae52622019-04-06 09:08:09 -04002# SPDX-License-Identifier: Apache-2.0
Anas Nashif31df3b22017-07-27 08:45:01 -04003
4# A script to generate a list of tests that have changed or added and create an
Anas Nashiff2cb20c2019-06-18 14:45:40 -04005# arguments file for sanitycheck to allow running those tests with --all
Anas Nashif31df3b22017-07-27 08:45:01 -04006
Ulf Magnussond5b0bd12019-03-19 19:37:07 +01007import os
Anas Nashif31df3b22017-07-27 08:45:01 -04008import sh
9import logging
10import argparse
11
12if "ZEPHYR_BASE" not in os.environ:
13 logging.error("$ZEPHYR_BASE environment variable undefined.\n")
14 exit(1)
15
16logger = None
17
18repository_path = os.environ['ZEPHYR_BASE']
19sh_special_args = {
20 '_tty_out': False,
21 '_cwd': repository_path
22}
23
24def 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
42def 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
50def main():
51 args = parse_args()
52 if not args.commits:
53 exit(1)
54
Ulf Magnussonc1911562019-09-03 13:06:05 +020055 # 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 Nashif31df3b22017-07-27 08:45:01 -040058 files = commit.split("\n")
59 tests = set()
60 for f in files:
Anas Nashif062d0562019-02-09 15:01:19 -050061 if f.endswith(".rst"):
62 continue
Anas Nashif31df3b22017-07-27 08:45:01 -040063 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
74if __name__ == "__main__":
75 main()