blob: 23793aae62064ba2be7aad9f62fa7fe7698b496c [file] [log] [blame]
Anas Nashif31df3b22017-07-27 08:45:01 -04001#!/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
6import sys
7import re, os
8from email.utils import parseaddr
9import sh
10import logging
11import argparse
12
13if "ZEPHYR_BASE" not in os.environ:
14 logging.error("$ZEPHYR_BASE environment variable undefined.\n")
15 exit(1)
16
17logger = None
18
19repository_path = os.environ['ZEPHYR_BASE']
20sh_special_args = {
21 '_tty_out': False,
22 '_cwd': repository_path
23}
24
25def 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
43def 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
51def 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
71if __name__ == "__main__":
72 main()
73