diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2016-05-11 14:42:32 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-01 16:22:46 +0100 |
commit | 1d88659ef6b96408243144d41bd99dd3ff5015e2 (patch) | |
tree | fc2736ca9ce5b2bb2fd6ff27f8960a244c506c24 | |
parent | 6512d6956b23d7b596c3ae37e01c5b842da95690 (diff) | |
download | poky-1d88659ef6b96408243144d41bd99dd3ff5015e2.tar.gz |
oeqa.buildperf: implement BuildPerfTestRunner class
The new class is responsible for actually running the tests and
processing their results. This commit also adds a decorator function for
adding new tests. No automatic test discovery, at least yet.
(From OE-Core rev: bf90aecb7e150d6bfac7240286c797b79d26528b)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/buildperf/__init__.py | 3 | ||||
-rw-r--r-- | meta/lib/oeqa/buildperf/base.py | 47 | ||||
-rwxr-xr-x | scripts/oe-build-perf-test | 10 |
3 files changed, 57 insertions, 3 deletions
diff --git a/meta/lib/oeqa/buildperf/__init__.py b/meta/lib/oeqa/buildperf/__init__.py index 3bee5b9028..d6065e806d 100644 --- a/meta/lib/oeqa/buildperf/__init__.py +++ b/meta/lib/oeqa/buildperf/__init__.py | |||
@@ -10,4 +10,5 @@ | |||
10 | # more details. | 10 | # more details. |
11 | # | 11 | # |
12 | """Build performance tests""" | 12 | """Build performance tests""" |
13 | from .base import BuildPerfTest, KernelDropCaches | 13 | from .base import (build_perf_test, BuildPerfTest, BuildPerfTestRunner, |
14 | KernelDropCaches) | ||
diff --git a/meta/lib/oeqa/buildperf/base.py b/meta/lib/oeqa/buildperf/base.py index c54b70cb11..1bfcb71610 100644 --- a/meta/lib/oeqa/buildperf/base.py +++ b/meta/lib/oeqa/buildperf/base.py | |||
@@ -15,8 +15,10 @@ import logging | |||
15 | import os | 15 | import os |
16 | import re | 16 | import re |
17 | import shutil | 17 | import shutil |
18 | import socket | ||
18 | import tempfile | 19 | import tempfile |
19 | import time | 20 | import time |
21 | import traceback | ||
20 | from datetime import datetime, timedelta | 22 | from datetime import datetime, timedelta |
21 | 23 | ||
22 | from oeqa.utils.commands import runCmd, get_bb_vars | 24 | from oeqa.utils.commands import runCmd, get_bb_vars |
@@ -72,6 +74,51 @@ def time_cmd(cmd, **kwargs): | |||
72 | return ret, timedata | 74 | return ret, timedata |
73 | 75 | ||
74 | 76 | ||
77 | class BuildPerfTestRunner(object): | ||
78 | """Runner class for executing the individual tests""" | ||
79 | # List of test cases to run | ||
80 | test_run_queue = [] | ||
81 | |||
82 | def __init__(self, out_dir): | ||
83 | self.results = {} | ||
84 | self.out_dir = os.path.abspath(out_dir) | ||
85 | if not os.path.exists(self.out_dir): | ||
86 | os.makedirs(self.out_dir) | ||
87 | |||
88 | |||
89 | def run_tests(self): | ||
90 | """Method that actually runs the tests""" | ||
91 | self.results['schema_version'] = 1 | ||
92 | self.results['tester_host'] = socket.gethostname() | ||
93 | start_time = datetime.utcnow() | ||
94 | self.results['start_time'] = start_time | ||
95 | self.results['tests'] = {} | ||
96 | |||
97 | for test_class in self.test_run_queue: | ||
98 | log.info("Executing test %s: %s", test_class.name, | ||
99 | test_class.description) | ||
100 | |||
101 | test = test_class(self.out_dir) | ||
102 | try: | ||
103 | test.run() | ||
104 | except Exception: | ||
105 | # Catch all exceptions. This way e.g buggy tests won't scrap | ||
106 | # the whole test run | ||
107 | sep = '-' * 5 + ' TRACEBACK ' + '-' * 60 + '\n' | ||
108 | tb_msg = sep + traceback.format_exc() + sep | ||
109 | log.error("Test execution failed with:\n" + tb_msg) | ||
110 | self.results['tests'][test.name] = test.results | ||
111 | |||
112 | self.results['elapsed_time'] = datetime.utcnow() - start_time | ||
113 | return 0 | ||
114 | |||
115 | |||
116 | def perf_test_case(obj): | ||
117 | """Decorator for adding test classes""" | ||
118 | BuildPerfTestRunner.test_run_queue.append(obj) | ||
119 | return obj | ||
120 | |||
121 | |||
75 | class BuildPerfTest(object): | 122 | class BuildPerfTest(object): |
76 | """Base class for build performance tests""" | 123 | """Base class for build performance tests""" |
77 | SYSRES = 'sysres' | 124 | SYSRES = 'sysres' |
diff --git a/scripts/oe-build-perf-test b/scripts/oe-build-perf-test index 9589dee3ac..0a9fc9e7d4 100755 --- a/scripts/oe-build-perf-test +++ b/scripts/oe-build-perf-test | |||
@@ -18,11 +18,12 @@ import argparse | |||
18 | import logging | 18 | import logging |
19 | import os | 19 | import os |
20 | import sys | 20 | import sys |
21 | from datetime import datetime | ||
21 | 22 | ||
22 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/lib') | 23 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/lib') |
23 | import scriptpath | 24 | import scriptpath |
24 | scriptpath.add_oe_lib_path() | 25 | scriptpath.add_oe_lib_path() |
25 | from oeqa.buildperf import KernelDropCaches | 26 | from oeqa.buildperf import BuildPerfTestRunner, KernelDropCaches |
26 | from oeqa.utils.commands import runCmd | 27 | from oeqa.utils.commands import runCmd |
27 | 28 | ||
28 | 29 | ||
@@ -75,7 +76,12 @@ def main(argv=None): | |||
75 | # Check our capability to drop caches and ask pass if needed | 76 | # Check our capability to drop caches and ask pass if needed |
76 | KernelDropCaches.check() | 77 | KernelDropCaches.check() |
77 | 78 | ||
78 | return 0 | 79 | # Run actual tests |
80 | out_dir = 'results-{}'.format(datetime.now().strftime('%Y%m%d%H%M%S')) | ||
81 | runner = BuildPerfTestRunner(out_dir) | ||
82 | ret = runner.run_tests() | ||
83 | |||
84 | return ret | ||
79 | 85 | ||
80 | 86 | ||
81 | if __name__ == '__main__': | 87 | if __name__ == '__main__': |