Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import datetime |
| 2 | import unittest |
| 3 | import os |
| 4 | import re |
| 5 | import shutil |
| 6 | |
| 7 | import oeqa.utils.ftools as ftools |
| 8 | from oeqa.selftest.base import oeSelfTest |
| 9 | from oeqa.selftest.buildhistory import BuildhistoryBase |
| 10 | from oeqa.utils.commands import Command, runCmd, bitbake, get_bb_var, get_test_layer |
| 11 | from oeqa.utils.decorators import testcase |
| 12 | |
| 13 | class TestScripts(oeSelfTest): |
| 14 | |
| 15 | @testcase(300) |
| 16 | def test_cleanup_workdir(self): |
| 17 | path = os.path.dirname(get_bb_var('WORKDIR', 'gzip')) |
| 18 | old_version_recipe = os.path.join(get_bb_var('COREBASE'), 'meta/recipes-extended/gzip/gzip_1.3.12.bb') |
| 19 | old_version = '1.3.12' |
| 20 | bitbake("-ccleansstate gzip") |
| 21 | bitbake("-ccleansstate -b %s" % old_version_recipe) |
| 22 | if os.path.exists(get_bb_var('WORKDIR', "-b %s" % old_version_recipe)): |
| 23 | shutil.rmtree(get_bb_var('WORKDIR', "-b %s" % old_version_recipe)) |
| 24 | if os.path.exists(get_bb_var('WORKDIR', 'gzip')): |
| 25 | shutil.rmtree(get_bb_var('WORKDIR', 'gzip')) |
| 26 | |
| 27 | if os.path.exists(path): |
| 28 | initial_contents = os.listdir(path) |
| 29 | else: |
| 30 | initial_contents = [] |
| 31 | |
| 32 | bitbake('gzip') |
| 33 | intermediary_contents = os.listdir(path) |
| 34 | bitbake("-b %s" % old_version_recipe) |
| 35 | runCmd('cleanup-workdir') |
| 36 | remaining_contents = os.listdir(path) |
| 37 | |
| 38 | expected_contents = [x for x in intermediary_contents if x not in initial_contents] |
| 39 | remaining_not_expected = [x for x in remaining_contents if x not in expected_contents] |
| 40 | self.assertFalse(remaining_not_expected, msg="Not all necessary content has been deleted from %s: %s" % (path, ', '.join(map(str, remaining_not_expected)))) |
| 41 | expected_not_remaining = [x for x in expected_contents if x not in remaining_contents] |
| 42 | self.assertFalse(expected_not_remaining, msg="The script removed extra contents from %s: %s" % (path, ', '.join(map(str, expected_not_remaining)))) |
| 43 | |
| 44 | class BuildhistoryDiffTests(BuildhistoryBase): |
| 45 | |
| 46 | @testcase(295) |
| 47 | def test_buildhistory_diff(self): |
| 48 | self.add_command_to_tearDown('cleanup-workdir') |
| 49 | target = 'xcursor-transparent-theme' |
| 50 | self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True) |
| 51 | self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True) |
| 52 | result = runCmd("buildhistory-diff -p %s" % get_bb_var('BUILDHISTORY_DIR')) |
| 53 | expected_output = 'PR changed from "r1" to "r0"' |
| 54 | self.assertTrue(expected_output in result.output, msg="Did not find expected output: %s" % result.output) |