kunit: tool: reconfigure when the used kunitconfig changes
Problem: currently, if you remove something from your kunitconfig, kunit.py will not regenerate the .config file. The same thing happens if you did --kunitconfig_add=CONFIG_KASAN=y [1] and then ran again without it. Your new run will still have KASAN. The reason is that kunit.py won't regenerate the .config file if it's a superset of the kunitconfig. This speeds it up a bit for iterating. This patch adds an additional check that forces kunit.py to regenerate the .config file if the current kunitconfig doesn't match the previous one. What this means: * deleting entries from .kunitconfig works as one would expect * dropping a --kunitconfig_add also triggers a rebuild * you can still edit .config directly to turn on new options We implement this by creating a `last_used_kunitconfig` file in the build directory (so .kunit, by default) after we generate the .config. When comparing the kconfigs, we compare python sets, so duplicates and permutations don't trip us up. The majority of this patch is adding unit tests for the existing logic and for the new case where `last_used_kunitconfig` differs. [1] https://lore.kernel.org/linux-kselftest/20211106013058.2621799-2-dlatypov@google.com/ Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
committed by
Shuah Khan
parent
c44895b6cd
commit
4c2911f1e1
@@ -413,6 +413,51 @@ class LinuxSourceTreeTest(unittest.TestCase):
|
||||
with open(kunit_kernel.get_outfile_path(build_dir), 'rt') as outfile:
|
||||
self.assertEqual(outfile.read(), 'hi\nbye\n', msg='Missing some output')
|
||||
|
||||
def test_build_reconfig_no_config(self):
|
||||
with tempfile.TemporaryDirectory('') as build_dir:
|
||||
with open(kunit_kernel.get_kunitconfig_path(build_dir), 'w') as f:
|
||||
f.write('CONFIG_KUNIT=y')
|
||||
|
||||
tree = kunit_kernel.LinuxSourceTree(build_dir)
|
||||
mock_build_config = mock.patch.object(tree, 'build_config').start()
|
||||
|
||||
# Should generate the .config
|
||||
self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
|
||||
mock_build_config.assert_called_once_with(build_dir, [])
|
||||
|
||||
def test_build_reconfig_existing_config(self):
|
||||
with tempfile.TemporaryDirectory('') as build_dir:
|
||||
# Existing .config is a superset, should not touch it
|
||||
with open(kunit_kernel.get_kunitconfig_path(build_dir), 'w') as f:
|
||||
f.write('CONFIG_KUNIT=y')
|
||||
with open(kunit_kernel.get_old_kunitconfig_path(build_dir), 'w') as f:
|
||||
f.write('CONFIG_KUNIT=y')
|
||||
with open(kunit_kernel.get_kconfig_path(build_dir), 'w') as f:
|
||||
f.write('CONFIG_KUNIT=y\nCONFIG_KUNIT_TEST=y')
|
||||
|
||||
tree = kunit_kernel.LinuxSourceTree(build_dir)
|
||||
mock_build_config = mock.patch.object(tree, 'build_config').start()
|
||||
|
||||
self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
|
||||
self.assertEqual(mock_build_config.call_count, 0)
|
||||
|
||||
def test_build_reconfig_remove_option(self):
|
||||
with tempfile.TemporaryDirectory('') as build_dir:
|
||||
# We removed CONFIG_KUNIT_TEST=y from our .kunitconfig...
|
||||
with open(kunit_kernel.get_kunitconfig_path(build_dir), 'w') as f:
|
||||
f.write('CONFIG_KUNIT=y')
|
||||
with open(kunit_kernel.get_old_kunitconfig_path(build_dir), 'w') as f:
|
||||
f.write('CONFIG_KUNIT=y\nCONFIG_KUNIT_TEST=y')
|
||||
with open(kunit_kernel.get_kconfig_path(build_dir), 'w') as f:
|
||||
f.write('CONFIG_KUNIT=y\nCONFIG_KUNIT_TEST=y')
|
||||
|
||||
tree = kunit_kernel.LinuxSourceTree(build_dir)
|
||||
mock_build_config = mock.patch.object(tree, 'build_config').start()
|
||||
|
||||
# ... so we should trigger a call to build_config()
|
||||
self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
|
||||
mock_build_config.assert_called_once_with(build_dir, [])
|
||||
|
||||
# TODO: add more test cases.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user