diff options
-rw-r--r-- | meta/lib/oeqa/selftest/buildhistory.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/buildhistory.py b/meta/lib/oeqa/selftest/buildhistory.py new file mode 100644 index 0000000000..d8cae4664b --- /dev/null +++ b/meta/lib/oeqa/selftest/buildhistory.py | |||
@@ -0,0 +1,45 @@ | |||
1 | import unittest | ||
2 | import os | ||
3 | import re | ||
4 | import shutil | ||
5 | import datetime | ||
6 | |||
7 | import oeqa.utils.ftools as ftools | ||
8 | from oeqa.selftest.base import oeSelfTest | ||
9 | from oeqa.utils.commands import Command, runCmd, bitbake, get_bb_var, get_test_layer | ||
10 | |||
11 | |||
12 | class BuildhistoryBase(oeSelfTest): | ||
13 | |||
14 | def config_buildhistory(self, tmp_bh_location=False): | ||
15 | if (not 'buildhistory' in get_bb_var('USER_CLASSES')) and (not 'buildhistory' in get_bb_var('INHERIT')): | ||
16 | add_buildhistory_config = 'INHERIT += "buildhistory"\nBUILDHISTORY_COMMIT = "1"' | ||
17 | self.append_config(add_buildhistory_config) | ||
18 | |||
19 | if tmp_bh_location: | ||
20 | # Using a temporary buildhistory location for testing | ||
21 | tmp_bh_dir = os.path.join(self.builddir, "tmp_buildhistory_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')) | ||
22 | buildhistory_dir_config = "BUILDHISTORY_DIR = \"%s\"" % tmp_bh_dir | ||
23 | self.append_config(buildhistory_dir_config) | ||
24 | self.track_for_cleanup(tmp_bh_dir) | ||
25 | |||
26 | def run_buildhistory_operation(self, target, global_config='', target_config='', change_bh_location=False, expect_error=False, error_regex=''): | ||
27 | if change_bh_location: | ||
28 | tmp_bh_location = True | ||
29 | else: | ||
30 | tmp_bh_location = False | ||
31 | self.config_buildhistory(tmp_bh_location) | ||
32 | |||
33 | self.append_config(global_config) | ||
34 | self.append_recipeinc(target, target_config) | ||
35 | bitbake("-cclean %s" % target) | ||
36 | result = bitbake(target, ignore_status=True) | ||
37 | self.remove_config(global_config) | ||
38 | self.remove_recipeinc(target, target_config) | ||
39 | |||
40 | if expect_error: | ||
41 | self.assertEqual(result.status, 1, msg="Error expected for global config '%s' and target config '%s'" % (global_config, target_config)) | ||
42 | search_for_error = re.search(error_regex, result.output) | ||
43 | self.assertTrue(search_for_error, msg="Could not find desired error in output: %s" % error_regex) | ||
44 | else: | ||
45 | self.assertEqual(result.status, 0, msg="Command 'bitbake %s' has failed unexpectedly: %s" % (target, result.output)) | ||