summaryrefslogtreecommitdiff
path: root/tools/buildman/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/buildman/test.py')
-rw-r--r--tools/buildman/test.py153
1 files changed, 138 insertions, 15 deletions
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index b9c65c0d326..714bb3e4f91 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -12,6 +12,7 @@ import unittest
from buildman import board
from buildman import bsettings
from buildman import builder
+from buildman import cfgutil
from buildman import control
from buildman import toolchain
from patman import commit
@@ -147,7 +148,7 @@ class TestBuild(unittest.TestCase):
self.toolchains.Add('gcc', test=False)
# Avoid sending any output
- terminal.SetPrintTestMode()
+ terminal.set_print_test_mode()
self._col = terminal.Color()
self.base_dir = tempfile.mkdtemp()
@@ -181,10 +182,10 @@ class TestBuild(unittest.TestCase):
col.YELLOW if outcome == OUTCOME_WARN else col.RED)
expect = '%10s: ' % arch
# TODO(sjg@chromium.org): If plus is '', we shouldn't need this
- expect += ' ' + col.Color(expected_colour, plus)
+ expect += ' ' + col.build(expected_colour, plus)
expect += ' '
for board in boards:
- expect += col.Color(expected_colour, ' %s' % board)
+ expect += col.build(expected_colour, ' %s' % board)
self.assertEqual(text, expect)
def _SetupTest(self, echo_lines=False, threads=1, **kwdisplay_args):
@@ -208,7 +209,7 @@ class TestBuild(unittest.TestCase):
# associated with each. This calls our Make() to inject the fake output.
build.BuildBoards(self.commits, board_selected, keep_outputs=False,
verbose=False)
- lines = terminal.GetPrintTestLines()
+ lines = terminal.get_print_test_lines()
count = 0
for line in lines:
if line.text.strip():
@@ -220,8 +221,8 @@ class TestBuild(unittest.TestCase):
build.SetDisplayOptions(**kwdisplay_args);
build.ShowSummary(self.commits, board_selected)
if echo_lines:
- terminal.EchoPrintTestLines()
- return iter(terminal.GetPrintTestLines())
+ terminal.echo_print_test_lines()
+ return iter(terminal.get_print_test_lines())
def _CheckOutput(self, lines, list_error_boards=False,
filter_dtb_warnings=False,
@@ -253,12 +254,12 @@ class TestBuild(unittest.TestCase):
new_lines = []
for line in lines:
if boards:
- expect = self._col.Color(colour, prefix + '(')
- expect += self._col.Color(self._col.MAGENTA, boards,
+ expect = self._col.build(colour, prefix + '(')
+ expect += self._col.build(self._col.MAGENTA, boards,
bright=False)
- expect += self._col.Color(colour, ') %s' % line)
+ expect += self._col.build(colour, ') %s' % line)
else:
- expect = self._col.Color(colour, prefix + line)
+ expect = self._col.build(colour, prefix + line)
new_lines.append(expect)
return '\n'.join(new_lines)
@@ -316,12 +317,12 @@ class TestBuild(unittest.TestCase):
self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
if filter_migration_warnings:
expect = '%10s: ' % 'powerpc'
- expect += ' ' + col.Color(col.GREEN, '')
+ expect += ' ' + col.build(col.GREEN, '')
expect += ' '
- expect += col.Color(col.GREEN, ' %s' % 'board2')
- expect += ' ' + col.Color(col.YELLOW, 'w+')
+ expect += col.build(col.GREEN, ' %s' % 'board2')
+ expect += ' ' + col.build(col.YELLOW, 'w+')
expect += ' '
- expect += col.Color(col.YELLOW, ' %s' % 'board3')
+ expect += col.build(col.YELLOW, ' %s' % 'board3')
self.assertEqual(next(lines).text, expect)
else:
self.assertSummary(next(lines).text, 'powerpc', 'w+',
@@ -606,7 +607,7 @@ class TestBuild(unittest.TestCase):
def testPrepareOutputSpace(self):
def _Touch(fname):
- tools.WriteFile(os.path.join(base_dir, fname), b'')
+ tools.write_file(os.path.join(base_dir, fname), b'')
base_dir = tempfile.mkdtemp()
@@ -624,5 +625,127 @@ class TestBuild(unittest.TestCase):
expected = set([os.path.join(base_dir, f) for f in to_remove])
self.assertEqual(expected, result)
+ def test_adjust_cfg_nop(self):
+ """check various adjustments of config that are nops"""
+ # enable an enabled CONFIG
+ self.assertEqual(
+ 'CONFIG_FRED=y',
+ cfgutil.adjust_cfg_line('CONFIG_FRED=y', {'FRED':'FRED'})[0])
+
+ # disable a disabled CONFIG
+ self.assertEqual(
+ '# CONFIG_FRED is not set',
+ cfgutil.adjust_cfg_line(
+ '# CONFIG_FRED is not set', {'FRED':'~FRED'})[0])
+
+ # use the adjust_cfg_lines() function
+ self.assertEqual(
+ ['CONFIG_FRED=y'],
+ cfgutil.adjust_cfg_lines(['CONFIG_FRED=y'], {'FRED':'FRED'}))
+ self.assertEqual(
+ ['# CONFIG_FRED is not set'],
+ cfgutil.adjust_cfg_lines(['CONFIG_FRED=y'], {'FRED':'~FRED'}))
+
+ # handling an empty line
+ self.assertEqual('#', cfgutil.adjust_cfg_line('#', {'FRED':'~FRED'})[0])
+
+ def test_adjust_cfg(self):
+ """check various adjustments of config"""
+ # disable a CONFIG
+ self.assertEqual(
+ '# CONFIG_FRED is not set',
+ cfgutil.adjust_cfg_line('CONFIG_FRED=1' , {'FRED':'~FRED'})[0])
+
+ # enable a disabled CONFIG
+ self.assertEqual(
+ 'CONFIG_FRED=y',
+ cfgutil.adjust_cfg_line(
+ '# CONFIG_FRED is not set', {'FRED':'FRED'})[0])
+
+ # enable a CONFIG that doesn't exist
+ self.assertEqual(
+ ['CONFIG_FRED=y'],
+ cfgutil.adjust_cfg_lines([], {'FRED':'FRED'}))
+
+ # disable a CONFIG that doesn't exist
+ self.assertEqual(
+ ['# CONFIG_FRED is not set'],
+ cfgutil.adjust_cfg_lines([], {'FRED':'~FRED'}))
+
+ # disable a value CONFIG
+ self.assertEqual(
+ '# CONFIG_FRED is not set',
+ cfgutil.adjust_cfg_line('CONFIG_FRED="fred"' , {'FRED':'~FRED'})[0])
+
+ # setting a value CONFIG
+ self.assertEqual(
+ 'CONFIG_FRED="fred"',
+ cfgutil.adjust_cfg_line('# CONFIG_FRED is not set' ,
+ {'FRED':'FRED="fred"'})[0])
+
+ # changing a value CONFIG
+ self.assertEqual(
+ 'CONFIG_FRED="fred"',
+ cfgutil.adjust_cfg_line('CONFIG_FRED="ernie"' ,
+ {'FRED':'FRED="fred"'})[0])
+
+ # setting a value for a CONFIG that doesn't exist
+ self.assertEqual(
+ ['CONFIG_FRED="fred"'],
+ cfgutil.adjust_cfg_lines([], {'FRED':'FRED="fred"'}))
+
+ def test_convert_adjust_cfg_list(self):
+ """Check conversion of the list of changes into a dict"""
+ self.assertEqual({}, cfgutil.convert_list_to_dict(None))
+
+ expect = {
+ 'FRED':'FRED',
+ 'MARY':'~MARY',
+ 'JOHN':'JOHN=0x123',
+ 'ALICE':'ALICE="alice"',
+ 'AMY':'AMY',
+ 'ABE':'~ABE',
+ 'MARK':'MARK=0x456',
+ 'ANNA':'ANNA="anna"',
+ }
+ actual = cfgutil.convert_list_to_dict(
+ ['FRED', '~MARY', 'JOHN=0x123', 'ALICE="alice"',
+ 'CONFIG_AMY', '~CONFIG_ABE', 'CONFIG_MARK=0x456',
+ 'CONFIG_ANNA="anna"'])
+ self.assertEqual(expect, actual)
+
+ def test_check_cfg_file(self):
+ """Test check_cfg_file detects conflicts as expected"""
+ # Check failure to disable CONFIG
+ result = cfgutil.check_cfg_lines(['CONFIG_FRED=1'], {'FRED':'~FRED'})
+ self.assertEqual([['~FRED', 'CONFIG_FRED=1']], result)
+
+ result = cfgutil.check_cfg_lines(
+ ['CONFIG_FRED=1', 'CONFIG_MARY="mary"'], {'FRED':'~FRED'})
+ self.assertEqual([['~FRED', 'CONFIG_FRED=1']], result)
+
+ result = cfgutil.check_cfg_lines(
+ ['CONFIG_FRED=1', 'CONFIG_MARY="mary"'], {'MARY':'~MARY'})
+ self.assertEqual([['~MARY', 'CONFIG_MARY="mary"']], result)
+
+ # Check failure to enable CONFIG
+ result = cfgutil.check_cfg_lines(
+ ['# CONFIG_FRED is not set'], {'FRED':'FRED'})
+ self.assertEqual([['FRED', '# CONFIG_FRED is not set']], result)
+
+ # Check failure to set CONFIG value
+ result = cfgutil.check_cfg_lines(
+ ['# CONFIG_FRED is not set', 'CONFIG_MARY="not"'],
+ {'MARY':'MARY="mary"', 'FRED':'FRED'})
+ self.assertEqual([
+ ['FRED', '# CONFIG_FRED is not set'],
+ ['MARY="mary"', 'CONFIG_MARY="not"']], result)
+
+ # Check failure to add CONFIG value
+ result = cfgutil.check_cfg_lines([], {'MARY':'MARY="mary"'})
+ self.assertEqual([
+ ['MARY="mary"', 'Missing expected line: CONFIG_MARY="mary"']], result)
+
+
if __name__ == "__main__":
unittest.main()