mirror of
https://xff.cz/git/u-boot/
synced 2025-09-26 21:11:18 +02:00
buildman: Add helper functions for updating .config files
At present the only straightforward way to write tests that need a slightly different configuration is to create a new board with its own configuration. This is cumbersome. It would be useful if buildman could adjust the configuration of a build on the fly. In preparation for this, add a utility library which can modify a .config file according to various parameters passed to it. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user