[PATCH v2 3/9] auto-t: only call set_value for changed values in default()

James Prestwood
2023-12-06T15:07:17Z

The default() method was added for convenience but was extending the
test times significantly when the hostapd config was lengthy. This
was because it called set_value for every value regardless if it
had changed. Instead store the current configuration and in default()
only reset values that differ.
---
autotests/util/hostapd.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
index 1b1bc399..cee08092 100644
--- a/autotests/util/hostapd.py
+++ b/autotests/util/hostapd.py
@@ -75,6 +75,8 @@ class HostapdCLI(object):
if self._default_config.get('vendor_elements', None) == None:
self._default_config['vendor_elements'] = ''

+ self._current_config = self._default_config.copy()
+
if not self.interface:
raise Exception('config %s not found' % config)

@@ -170,6 +172,8 @@ class HostapdCLI(object):
if self._default_config.get(key, None) == None:
raise Exception("Untracked setting '%s'! Please set default in hostapd config" % key)

+ self._current_config[key] = value
+
cmd = self.cmdline + ['set', key, value]
ctx.start_process(cmd).wait()

@@ -200,7 +204,10 @@ class HostapdCLI(object):

def default(self):
for k, v in self._default_config.items():
- self.set_value(k, v)
+ # Only bother setting the value if it differs
+ if self._current_config[k] != v:
+ self.set_value(k, v)
+ self._current_config[k] = v

self.reload()

--
2.34.1