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.py123
1 files changed, 123 insertions, 0 deletions
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index b9c65c0d32..2751377e87 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
@@ -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()