diff options
-rwxr-xr-x | bin/model-config.py | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/bin/model-config.py b/bin/model-config.py index 9e86d4a..2b85a20 100755 --- a/bin/model-config.py +++ b/bin/model-config.py @@ -27,7 +27,6 @@ symbols = sorted( ), ) ) -config_vector = tuple(map(lambda sym: kconf.syms[sym].tri_value == 2, symbols)) with open("kconfigmodel.json", "r") as f: data = json.load(f) @@ -48,6 +47,7 @@ class DTreeLeaf: return f"<DTreeLeaf({self.value}, {self.stddev})>" def model(self, kconf): + # print(f"* leaf") return self.value @@ -68,8 +68,10 @@ class DTreeNode: def model(self, kconf): if kconf.syms[self.symbol].tri_value == 2 and self.true_child: + # print(f"* node {self.symbol} == y -> descent") return self.true_child.model(kconf) elif kconf.syms[self.symbol].tri_value == 0 and self.false_child: + # print(f"* node {self.symbol} == n -> descent") return self.false_child.model(kconf) return None @@ -86,30 +88,46 @@ def load_model(tree): root = load_model(model) - -def vector_diff(v1, v2): - return sum(map(lambda i: int(v1[i] != v2[i]), range(len(v1)))) - - current_model = root.model(kconf) print(f"Model result: {current_model}") for symbol in symbols: - kconf_sym = kconf.syms[symbol] + kconf2 = kconfiglib.Kconfig(kconfig_path) + kconf2.load_config(sys.argv[1]) + kconf_sym = kconf2.syms[symbol] if kconf_sym.tri_value == 0 and 2 in kconf_sym.assignable: kconf_sym.set_value(2) - new_vector = tuple(map(lambda sym: kconf.syms[sym].tri_value == 2, symbols)) - num_changes = vector_diff(config_vector, new_vector) - model_diff = root.model(kconf) - current_model - print( - f"Setting {symbol:30s} to y changes {num_changes:2d} symbols, model change: {model_diff:+5.0f}" - ) elif kconf_sym.tri_value == 2 and 0 in kconf_sym.assignable: kconf_sym.set_value(0) - new_vector = tuple(map(lambda sym: kconf.syms[sym].tri_value == 2, symbols)) - num_changes = vector_diff(config_vector, new_vector) - model_diff = root.model(kconf) - current_model + else: + continue + + # specific to multipass: + # Do not suggest changes which affect the application + skip = False + num_changes = 0 + changed_symbols = list() + for i, csymbol in enumerate(symbols): + if kconf.syms[csymbol].tri_value != kconf2.syms[csymbol].tri_value: + num_changes += 1 + changed_symbols.append(csymbol) + if ( + csymbol.startswith("app_") + and kconf.syms[csymbol].tri_value != kconf2.syms[csymbol].tri_value + ): + skip = True + break + if skip: + continue + + model_diff = root.model(kconf2) - current_model + if kconf_sym.choice: + print( + f"Setting {kconf_sym.choice.name} to {kconf_sym.name} changes {num_changes:2d} symbols, model change: {model_diff:+5.0f}" + ) + else: print( - f"Setting {symbol:30s} to n changes {num_changes:2d} symbols, model change: {model_diff:+5.0f}" + f"Setting {symbol} to {kconf_sym.str_value} changes {num_changes:2d} symbols, model change: {model_diff:+5.0f}" ) - kconf.load_config(sys.argv[1]) + for changed_symbol in changed_symbols: + print(f" {changed_symbol:30s} -> {kconf2.syms[changed_symbol].str_value}") |