diff options
| author | Daniel Istrate <daniel.alexandrux.istrate@intel.com> | 2016-01-05 16:53:34 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-07 13:40:17 +0000 |
| commit | c2bda6c000794b881274de953818e0de6635cc4a (patch) | |
| tree | 409cabdb95cdd93acce5a995587e75eb165f56b4 /meta/lib | |
| parent | 8e1435eb717b22f15e898bee15f9c75128deae03 (diff) | |
| download | poky-c2bda6c000794b881274de953818e0de6635cc4a.tar.gz | |
scripts/oe-selftest: Allow to run tests on random/all MACHINEs
Add an option for random MACHINE into oe-selftest:
--machine [random/all]
1. random: will set a random MACHINE for each test
2. all: will run tests for all machines
Custom machine sets only weak default values (??=) for MACHINE in machine.inc.
This let test cases that require a specific MACHINE to be able to
override it, using (?= or =).
e.g.:
oe-selftest --run-tests signing --machine random -->
will run all tests switching MACHINE randomly for each test
oe-selftest --run-tests signing --machine all -->
for each machine will run all tests
oe-selftest --run-all-tests --machine random
Also update oeqa/selftest/base.py to accomodate this feature.
Fix for [YOCTO #5880].
(From OE-Core rev: 4a9c3653eecd9a3c1b45bab5e16c8d679c55f8bd)
Signed-off-by: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
| -rw-r--r-- | meta/lib/oeqa/selftest/base.py | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/meta/lib/oeqa/selftest/base.py b/meta/lib/oeqa/selftest/base.py index 9bddc23f87..dc937310dc 100644 --- a/meta/lib/oeqa/selftest/base.py +++ b/meta/lib/oeqa/selftest/base.py | |||
| @@ -16,6 +16,8 @@ import errno | |||
| 16 | import oeqa.utils.ftools as ftools | 16 | import oeqa.utils.ftools as ftools |
| 17 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer | 17 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer |
| 18 | from oeqa.utils.decorators import LogResults | 18 | from oeqa.utils.decorators import LogResults |
| 19 | from random import choice | ||
| 20 | import glob | ||
| 19 | 21 | ||
| 20 | @LogResults | 22 | @LogResults |
| 21 | class oeSelfTest(unittest.TestCase): | 23 | class oeSelfTest(unittest.TestCase): |
| @@ -29,9 +31,10 @@ class oeSelfTest(unittest.TestCase): | |||
| 29 | self.testinc_path = os.path.join(self.builddir, "conf/selftest.inc") | 31 | self.testinc_path = os.path.join(self.builddir, "conf/selftest.inc") |
| 30 | self.local_bblayers_path = os.path.join(self.builddir, "conf/bblayers.conf") | 32 | self.local_bblayers_path = os.path.join(self.builddir, "conf/bblayers.conf") |
| 31 | self.testinc_bblayers_path = os.path.join(self.builddir, "conf/bblayers.inc") | 33 | self.testinc_bblayers_path = os.path.join(self.builddir, "conf/bblayers.inc") |
| 34 | self.machineinc_path = os.path.join(self.builddir, "conf/machine.inc") | ||
| 32 | self.testlayer_path = oeSelfTest.testlayer_path | 35 | self.testlayer_path = oeSelfTest.testlayer_path |
| 33 | self._extra_tear_down_commands = [] | 36 | self._extra_tear_down_commands = [] |
| 34 | self._track_for_cleanup = [self.testinc_path] | 37 | self._track_for_cleanup = [self.testinc_path, self.testinc_bblayers_path, self.machineinc_path] |
| 35 | super(oeSelfTest, self).__init__(methodName) | 38 | super(oeSelfTest, self).__init__(methodName) |
| 36 | 39 | ||
| 37 | def setUp(self): | 40 | def setUp(self): |
| @@ -47,11 +50,25 @@ class oeSelfTest(unittest.TestCase): | |||
| 47 | for f in files: | 50 | for f in files: |
| 48 | if f == 'test_recipe.inc': | 51 | if f == 'test_recipe.inc': |
| 49 | os.remove(os.path.join(root, f)) | 52 | os.remove(os.path.join(root, f)) |
| 50 | try: | 53 | |
| 51 | os.remove(self.testinc_bblayers_path) | 54 | for incl_file in [self.testinc_bblayers_path, self.machineinc_path]: |
| 52 | except OSError as e: | 55 | try: |
| 53 | if e.errno != errno.ENOENT: | 56 | os.remove(incl_file) |
| 54 | raise | 57 | except OSError as e: |
| 58 | if e.errno != errno.ENOENT: | ||
| 59 | raise | ||
| 60 | |||
| 61 | # Get CUSTOMMACHINE from env (set by --machine argument to oe-selftest) | ||
| 62 | custommachine = os.getenv('CUSTOMMACHINE') | ||
| 63 | if custommachine: | ||
| 64 | if custommachine == 'random': | ||
| 65 | machine = get_random_machine() | ||
| 66 | else: | ||
| 67 | machine = custommachine | ||
| 68 | machine_conf = 'MACHINE ??= "%s"\n' % machine | ||
| 69 | self.set_machine_config(machine_conf) | ||
| 70 | print 'MACHINE: %s' % machine | ||
| 71 | |||
| 55 | # tests might need their own setup | 72 | # tests might need their own setup |
| 56 | # but if they overwrite this one they have to call | 73 | # but if they overwrite this one they have to call |
| 57 | # super each time, so let's give them an alternative | 74 | # super each time, so let's give them an alternative |
| @@ -99,11 +116,21 @@ class oeSelfTest(unittest.TestCase): | |||
| 99 | self.log.debug("Writing to: %s\n%s\n" % (self.testinc_path, data)) | 116 | self.log.debug("Writing to: %s\n%s\n" % (self.testinc_path, data)) |
| 100 | ftools.write_file(self.testinc_path, data) | 117 | ftools.write_file(self.testinc_path, data) |
| 101 | 118 | ||
| 119 | custommachine = os.getenv('CUSTOMMACHINE') | ||
| 120 | if custommachine and 'MACHINE' in data: | ||
| 121 | machine = get_bb_var('MACHINE') | ||
| 122 | self.log.warning('MACHINE overridden: %s' % machine) | ||
| 123 | |||
| 102 | # append to <builddir>/conf/selftest.inc | 124 | # append to <builddir>/conf/selftest.inc |
| 103 | def append_config(self, data): | 125 | def append_config(self, data): |
| 104 | self.log.debug("Appending to: %s\n%s\n" % (self.testinc_path, data)) | 126 | self.log.debug("Appending to: %s\n%s\n" % (self.testinc_path, data)) |
| 105 | ftools.append_file(self.testinc_path, data) | 127 | ftools.append_file(self.testinc_path, data) |
| 106 | 128 | ||
| 129 | custommachine = os.getenv('CUSTOMMACHINE') | ||
| 130 | if custommachine and 'MACHINE' in data: | ||
| 131 | machine = get_bb_var('MACHINE') | ||
| 132 | self.log.warning('MACHINE overridden: %s' % machine) | ||
| 133 | |||
| 107 | # remove data from <builddir>/conf/selftest.inc | 134 | # remove data from <builddir>/conf/selftest.inc |
| 108 | def remove_config(self, data): | 135 | def remove_config(self, data): |
| 109 | self.log.debug("Removing from: %s\n\%s\n" % (self.testinc_path, data)) | 136 | self.log.debug("Removing from: %s\n\%s\n" % (self.testinc_path, data)) |
| @@ -151,3 +178,28 @@ class oeSelfTest(unittest.TestCase): | |||
| 151 | def remove_bblayers_config(self, data): | 178 | def remove_bblayers_config(self, data): |
| 152 | self.log.debug("Removing from: %s\n\%s\n" % (self.testinc_bblayers_path, data)) | 179 | self.log.debug("Removing from: %s\n\%s\n" % (self.testinc_bblayers_path, data)) |
| 153 | ftools.remove_from_file(self.testinc_bblayers_path, data) | 180 | ftools.remove_from_file(self.testinc_bblayers_path, data) |
| 181 | |||
| 182 | # write to <builddir>/conf/machine.inc | ||
| 183 | def set_machine_config(self, data): | ||
| 184 | self.log.debug("Writing to: %s\n%s\n" % (self.machineinc_path, data)) | ||
| 185 | ftools.write_file(self.machineinc_path, data) | ||
| 186 | |||
| 187 | |||
| 188 | def get_available_machines(): | ||
| 189 | # Get a list of all available machines | ||
| 190 | bbpath = get_bb_var('BBPATH').split(':') | ||
| 191 | machines = [] | ||
| 192 | |||
| 193 | for path in bbpath: | ||
| 194 | found_machines = glob.glob(os.path.join(path, 'conf', 'machine', '*.conf')) | ||
| 195 | if found_machines: | ||
| 196 | for i in found_machines: | ||
| 197 | # eg: '/home/<user>/poky/meta-intel/conf/machine/intel-core2-32.conf' | ||
| 198 | machines.append(os.path.splitext(os.path.basename(i))[0]) | ||
| 199 | |||
| 200 | return machines | ||
| 201 | |||
| 202 | |||
| 203 | def get_random_machine(): | ||
| 204 | # Get a random machine | ||
| 205 | return choice(get_available_machines()) | ||
