diff options
-rwxr-xr-x | bin/explore-kconfig.py | 29 | ||||
-rw-r--r-- | lib/kconfig.py | 11 |
2 files changed, 32 insertions, 8 deletions
diff --git a/bin/explore-kconfig.py b/bin/explore-kconfig.py index 4c08826..d941176 100755 --- a/bin/explore-kconfig.py +++ b/bin/explore-kconfig.py @@ -19,10 +19,6 @@ import sys from dfatool import kconfig -from versuchung.experiment import Experiment -from versuchung.types import String, Bool, Integer -from versuchung.files import File, Directory - def main(): parser = argparse.ArgumentParser( @@ -45,6 +41,11 @@ def main(): help="Explore a number of random configurations (make randconfig)", ) parser.add_argument( + "--with-neighbourhood", + action="store_true", + help="Explore neighbourhood of successful random configurations", + ) + parser.add_argument( "--clean-command", type=str, help="Clean command", default="make clean" ) parser.add_argument( @@ -56,6 +57,15 @@ def main(): help="Attribute extraction command", default="make attributes", ) + parser.add_argument( + "--randconfig-command", + type=str, + help="Randconfig command for --random", + default="make randconfig", + ) + parser.add_argument( + "--kconfig-file", type=str, help="Kconfig file", default="Kconfig" + ) parser.add_argument("project_root", type=str, help="Project root directory") args = parser.parse_args() @@ -73,13 +83,22 @@ def main(): kconf.build_command = args.build_command if args.attribute_command: kconf.attribute_command = args.attribute_command + if args.randconfig_command: + kconf.randconfig_command = args.randconfig_command + if args.kconfig_file: + kconf.kconfig = args.kconfig_file if args.random: for i in range(args.random): logging.info(f"Running randconfig {i+1} of {args.random}") - kconf.run_randconfig() + status = kconf.run_randconfig() + if args.with_neighbourhood and status["success"]: + config_filename = status["config_path"] + logging.info(f"Exploring neighbourhood of {config_filename}") + kconf.run_exploration_from_file(config_filename) if args.neighbourhood: + # TODO also explore range of numeric options if os.path.isfile(args.neighbourhood): kconf.run_exploration_from_file(args.neighbourhood) elif os.path.isdir(args.neighbourhood): diff --git a/lib/kconfig.py b/lib/kconfig.py index 6ae947a..a85586f 100644 --- a/lib/kconfig.py +++ b/lib/kconfig.py @@ -2,6 +2,7 @@ import kconfiglib import logging +import os import re import shutil import subprocess @@ -80,10 +81,12 @@ class KConfig: self.clean_command = "make clean" self.build_command = "make" self.attribute_command = "make attributes" + self.randconfig_command = "make randconfig" + self.kconfig = "Kconfig" def randconfig(self): status = subprocess.run( - ["make", "randconfig"], + self.randconfig_command.split(), cwd=self.cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -131,7 +134,7 @@ class KConfig: "--randconfig_seed", self.randconfig(), "--kconfig_hash", - self.file_hash(f"{self.cwd}/Kconfig"), + self.file_hash(f"{self.cwd}/{self.kconfig}"), "--project_version", self.git_commit_id(), "--project_root", @@ -144,6 +147,8 @@ class KConfig: self.attribute_command, ] ) + success = os.path.exists(experiment.attributes.path) + return {"success": success, "config_path": experiment.config.path} def config_is_functional(self, kconf): for choice in kconf.choices: @@ -156,7 +161,7 @@ class KConfig: return True def run_exploration_from_file(self, config_file): - kconfig_file = f"{self.cwd}/Kconfig" + kconfig_file = f"{self.cwd}/{self.kconfig}" kconf = kconfiglib.Kconfig(kconfig_file) kconf.load_config(config_file) symbols = list(kconf.syms.keys()) |