Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import os |
| 2 | import re |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3 | import datetime |
| 4 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | from oeqa.selftest.base import oeSelfTest |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 6 | from oeqa.utils.commands import bitbake, get_bb_var |
| 7 | from oeqa.utils.decorators import testcase |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | |
| 9 | |
| 10 | class 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 41 | self.assertTrue(search_for_error, msg="Could not find desired error in output: %s (%s)" % (error_regex, result.output)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | else: |
| 43 | self.assertEqual(result.status, 0, msg="Command 'bitbake %s' has failed unexpectedly: %s" % (target, result.output)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 44 | |
| 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. |