blob: 674da6205a238cc71dd5ff31a1032d8f6a522a64 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import os
2import re
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003import datetime
4
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005from oeqa.selftest.base import oeSelfTest
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006from oeqa.utils.commands import bitbake, get_bb_var
7from oeqa.utils.decorators import testcase
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008
9
10class BuildhistoryBase(oeSelfTest):
11
12 def config_buildhistory(self, tmp_bh_location=False):
13 if (not 'buildhistory' in get_bb_var('USER_CLASSES')) and (not 'buildhistory' in get_bb_var('INHERIT')):
14 add_buildhistory_config = 'INHERIT += "buildhistory"\nBUILDHISTORY_COMMIT = "1"'
15 self.append_config(add_buildhistory_config)
16
17 if tmp_bh_location:
18 # Using a temporary buildhistory location for testing
19 tmp_bh_dir = os.path.join(self.builddir, "tmp_buildhistory_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
20 buildhistory_dir_config = "BUILDHISTORY_DIR = \"%s\"" % tmp_bh_dir
21 self.append_config(buildhistory_dir_config)
22 self.track_for_cleanup(tmp_bh_dir)
23
24 def run_buildhistory_operation(self, target, global_config='', target_config='', change_bh_location=False, expect_error=False, error_regex=''):
25 if change_bh_location:
26 tmp_bh_location = True
27 else:
28 tmp_bh_location = False
29 self.config_buildhistory(tmp_bh_location)
30
31 self.append_config(global_config)
32 self.append_recipeinc(target, target_config)
33 bitbake("-cclean %s" % target)
34 result = bitbake(target, ignore_status=True)
35 self.remove_config(global_config)
36 self.remove_recipeinc(target, target_config)
37
38 if expect_error:
39 self.assertEqual(result.status, 1, msg="Error expected for global config '%s' and target config '%s'" % (global_config, target_config))
40 search_for_error = re.search(error_regex, result.output)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041 self.assertTrue(search_for_error, msg="Could not find desired error in output: %s (%s)" % (error_regex, result.output))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042 else:
43 self.assertEqual(result.status, 0, msg="Command 'bitbake %s' has failed unexpectedly: %s" % (target, result.output))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050044
45 # No tests should be added to the base class.
46 # Please create a new class that inherit this one, or use one of those already available for adding tests.