summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/core
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2017-05-26 15:37:33 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-02 13:36:13 +0100
commitc118f80f17a93a425b256d64cd7c1d5fcb5fc127 (patch)
tree8b6a7b08270dec573dc60d93043e9c3a2effccea /meta/lib/oeqa/core
parentb4b9e22c40b7ce315d0286fe656581f81d965043 (diff)
downloadpoky-c118f80f17a93a425b256d64cd7c1d5fcb5fc127.tar.gz
oeqa/core/threaded: Add new module with OETestLoaderThreaded
The threded module will implement Thread support into the OEQA framework. The OETestLoaderThreaded overrides discover to return a list of suites every suite will be run by a separate Thread. Some design considerations are: - All the tests of a certain module needs to be run at one thread because unittest framework needs to keep track of setUp{Module, Class,} and tearDown{Module, Class,}. - Tests that depends on other needs to be run at the same thread because OEQA framework look at the status of dependant test to decide if skip or not, this constraint can be change in the future but a sync mechanishm is needed to implement between the Threads. [YOCTO #11450] (From OE-Core rev: b4ae730ee1d6003ff005148f741270e2878de484) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/core')
-rw-r--r--meta/lib/oeqa/core/threaded.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/threaded.py b/meta/lib/oeqa/core/threaded.py
new file mode 100644
index 0000000000..e6f214088c
--- /dev/null
+++ b/meta/lib/oeqa/core/threaded.py
@@ -0,0 +1,91 @@
1# Copyright (C) 2017 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4import multiprocessing
5
6from unittest.suite import TestSuite
7from oeqa.core.loader import OETestLoader
8
9class OETestLoaderThreaded(OETestLoader):
10 def __init__(self, tc, module_paths, modules, tests, modules_required,
11 filters, process_num=0, *args, **kwargs):
12 super(OETestLoaderThreaded, self).__init__(tc, module_paths, modules,
13 tests, modules_required, filters, *args, **kwargs)
14
15 self.process_num = process_num
16
17 def discover(self):
18 suite = super(OETestLoaderThreaded, self).discover()
19
20 if self.process_num <= 0:
21 self.process_num = min(multiprocessing.cpu_count(),
22 len(suite._tests))
23
24 suites = []
25 for _ in range(self.process_num):
26 suites.append(self.suiteClass())
27
28 def _search_for_module_idx(suites, case):
29 """
30 Cases in the same module needs to be run
31 in the same thread because PyUnit keeps track
32 of setUp{Module, Class,} and tearDown{Module, Class,}.
33 """
34
35 for idx in range(self.process_num):
36 suite = suites[idx]
37 for c in suite._tests:
38 if case.__module__ == c.__module__:
39 return idx
40
41 return -1
42
43 def _search_for_depend_idx(suites, depends):
44 """
45 Dependency cases needs to be run in the same
46 thread, because OEQA framework look at the state
47 of dependant test to figure out if skip or not.
48 """
49
50 for idx in range(self.process_num):
51 suite = suites[idx]
52
53 for case in suite._tests:
54 if case.id() in depends:
55 return idx
56 return -1
57
58 def _get_best_idx(suites):
59 sizes = [len(suite._tests) for suite in suites]
60 return sizes.index(min(sizes))
61
62 def _fill_suites(suite):
63 idx = -1
64 for case in suite:
65 if isinstance(case, TestSuite):
66 _fill_suites(case)
67 else:
68 idx = _search_for_module_idx(suites, case)
69
70 depends = {}
71 if 'depends' in self.tc._registry:
72 depends = self.tc._registry['depends']
73
74 if idx == -1 and case.id() in depends:
75 case_depends = depends[case.id()]
76 idx = _search_for_depend_idx(suites, case_depends)
77
78 if idx == -1:
79 idx = _get_best_idx(suites)
80
81 suites[idx].addTest(case)
82 _fill_suites(suite)
83
84 suites_tmp = suites
85 suites = []
86 for suite in suites_tmp:
87 if len(suite._tests) > 0:
88 suites.append(suite)
89
90 return suites
91