From 372911d50d0b19058c2ffd74ab45be6926890a6d Mon Sep 17 00:00:00 2001 From: Nicholas Mosier Date: Thu, 4 Dec 2025 11:17:37 -0800 Subject: [PATCH] raise ConfigExceptions rather than ignoring them It appears almost all ConfigExceptions were instantiated but never raised, allowing execution to improperly continue. This patch raises these ConfigExceptions. --- src/config.py | 14 +++++++------- src/coverage.py | 3 +-- src/executor.py | 2 +- src/generator.py | 3 +-- src/input_generator.py | 3 +-- src/model.py | 9 +++------ 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/config.py b/src/config.py index 9fe6c96..729edc8 100644 --- a/src/config.py +++ b/src/config.py @@ -316,20 +316,20 @@ def set(self, name, value): } if name[0] == "_": - ConfigException(f"Attempting to set an internal configuration variable {name}.") + raise ConfigException(f"Attempting to set an internal configuration variable {name}.") if getattr(self, name, None) is None: - ConfigException(f"Unknown configuration variable {name}.\n" - f"It's likely a typo in the configuration file.") + raise ConfigException(f"Unknown configuration variable {name}.\n" + f"It's likely a typo in the configuration file.") if type(self.__getattribute__(name)) != type(value): - ConfigException(f"Wrong type of the configuration variable {name}.\n" - f"It's likely a typo in the configuration file.") + raise ConfigException(f"Wrong type of the configuration variable {name}.\n" + f"It's likely a typo in the configuration file.") # value checks if options.get(name, '') != '' and value not in options[name]: - ConfigException(f"Unknown value '{value}' of configuration variable '{name}'") + raise ConfigException(f"Unknown value '{value}' of configuration variable '{name}'") if (self.input_main_region_size % 4096 != 0) or \ (self.input_assist_region_size % 4096 != 0): - ConfigException("Inputs must be page-aligned") + raise ConfigException("Inputs must be page-aligned") # special handling if name == "extended_instruction_blocklist": diff --git a/src/coverage.py b/src/coverage.py index 7bb342c..a930ec7 100644 --- a/src/coverage.py +++ b/src/coverage.py @@ -285,5 +285,4 @@ def get_coverage(instruction_set: InstructionSet, executor: Executor, model: Mod elif CONF.coverage_type == 'none': return NoCoverage(instruction_set, executor, model, analyser) else: - ConfigException("unknown value of `coverage_type` configuration option") - exit(1) + raise ConfigException("unknown value of `coverage_type` configuration option") diff --git a/src/executor.py b/src/executor.py index 9581e58..1aa3297 100644 --- a/src/executor.py +++ b/src/executor.py @@ -1178,6 +1178,6 @@ def get_executor() -> Executor: 'x86-gem5': X86Gem5 } if CONF.executor not in options: - ConfigException("unknown executor in config.py") + raise ConfigException("unknown executor in config.py") return options[CONF.executor]() diff --git a/src/generator.py b/src/generator.py index 70a0aaf..9e3b504 100644 --- a/src/generator.py +++ b/src/generator.py @@ -1273,5 +1273,4 @@ def get_generator(instruction_set: InstructionSet) -> Generator: if CONF.generator == 'random': return X86RandomGenerator(instruction_set) - ConfigException("unknown value of `instruction_set` configuration option") - exit(1) + raise ConfigException("unknown value of `instruction_set` configuration option") diff --git a/src/input_generator.py b/src/input_generator.py index 5aec1df..4043611 100644 --- a/src/input_generator.py +++ b/src/input_generator.py @@ -98,6 +98,5 @@ def get_input_generator() -> InputGenerator: 'random': RandomInputGenerator, } if CONF.input_generator not in options: - ConfigException("unknown input_generator in config.py") - exit(1) + raise ConfigException("unknown input_generator in config.py") return options[CONF.input_generator]() diff --git a/src/model.py b/src/model.py index 7cc286e..6ac4ad7 100644 --- a/src/model.py +++ b/src/model.py @@ -1044,8 +1044,7 @@ def get_model(bases: Tuple[int, int]) -> Model: elif "seq" in CONF.contract_execution_clause: model = X86UnicornSeq(bases[0], bases[1]) else: - ConfigException("unknown value of `contract_execution_clause` configuration option") - exit(1) + raise ConfigException("unknown value of `contract_execution_clause` configuration option") # observational part of the contract if CONF.contract_observation_clause == "l1d": @@ -1063,10 +1062,8 @@ def get_model(bases: Tuple[int, int]) -> Model: elif CONF.contract_observation_clause == 'arch': model.tracer = ArchTracer() else: - ConfigException("unknown value of `contract_observation_clause` configuration option") - exit(1) + raise ConfigException("unknown value of `contract_observation_clause` configuration option") return model else: - ConfigException("unknown value of `model` configuration option") - exit(1) + raise ConfigException("unknown value of `model` configuration option")