feat: add model name to log entries

This commit is contained in:
Benjamin Lipp
2025-12-08 16:55:45 +01:00
parent e14fc12f88
commit 4d4c214600
2 changed files with 46 additions and 16 deletions

View File

@@ -34,15 +34,17 @@
* ~~refactor filtering in run_proverif (see karo's comment)~~
* ~configurable target directory~
* ~lark parser: multiline comments, how???~
* ~parse errors~
* ~error when trying with: `nix run .# -- parse ../target/proverif/01_secrecy.entry.i.pv`~
* ~`in(C, Cinit_conf(Ssskm, Spsk, Sspkt, ic));`~
* ~ ^~
* ~04_dos… has a syntax error (see below)~
## Next Steps
* integrate marzipan.awk into Python, somehow
* options term special cases (c.f. manual page 133, starting with "fun" term)
* complete with CryptoVerif options
* error when trying with: `nix run .# -- parse ../target/proverif/01_secrecy.entry.i.pv`
* `in(C, Cinit_conf(Ssskm, Spsk, Sspkt, ic));`
* ^
* rewrite marzipan.awk into Python/LARK
* define a LARK grammar for marzipan.awk rules
* write python code for processing marzipan rules, e.g. alias replacement (step: i.pv->o.pv)

View File

@@ -14,6 +14,23 @@ console = pkgs.rich.console.Console()
logger = pkgs.logging.getLogger(__name__)
def set_logging_logrecordfactory(filename):
old_factory = pkgs.logging.getLogRecordFactory()
def record_factory(*args, **kwargs):
record = old_factory(*args, **kwargs)
record.filename = filename
return record
pkgs.logging.setLogRecordFactory(record_factory)
#def set_logging_format(max_length):
# pass
# #format_str = "{levelname:<8} {filename:<" + str(max_length + 2) + "} {message}"
# #pkgs.logging.basicConfig(level=pkgs.logging.DEBUG, style="{", format=format_str)
@click.group()
def main():
pkgs.logging.basicConfig(level=pkgs.logging.DEBUG)
@@ -50,7 +67,7 @@ def clean_line(prev_line, line):
return prev_line
def run_proverif(file, extra_args=[]):
def run_proverif(file, log_file, extra_args=[]):
params = ["proverif", "-test", *extra_args, file]
logger.debug(params)
@@ -63,7 +80,9 @@ def run_proverif(file, extra_args=[]):
)
try:
prev_line = None
with open(log_file, "a") as log:
for line in process.stdout:
log.write(line)
cleaned_line = clean_line(prev_line, line)
prev_line = line
if cleaned_line is not None:
@@ -83,6 +102,9 @@ def run_proverif(file, extra_args=[]):
logger.error(
f"Proverif exited with a non-zero error code {params}: {return_code}"
)
if prev_line is not None:
logger.error(f"Last line of log file {log_file}:")
logger.error(f"> {prev_line.rstrip()}")
exit(return_code)
@@ -193,7 +215,12 @@ def analyze(repo_path, output):
entries = []
analysis_dir = pkgs.os.path.join(repo_path, "analysis")
entries.extend(sorted(pkgs.glob.glob(str(analysis_dir) + "/*.entry.mpv")))
full_paths = sorted(pkgs.glob.glob(str(analysis_dir) + "/*.entry.mpv"))
entries.extend(full_paths)
#modelnames = [pkgs.os.path.basename(path).replace('.entry.mpv', '') for path in full_paths]
#max_length = max(len(modelname) for modelname in modelnames) if modelnames else 0
#set_logging_format(max_length)
with pkgs.concurrent.futures.ProcessPoolExecutor() as executor:
futures = {
@@ -231,12 +258,14 @@ def clean(repo_path, output):
def metaverif(repo_path, tmpdir, file):
print(f"Start metaverif on {file}")
# Extract the name using regex
name_match = pkgs.re.search(r"([^/]*)(?=\.mpv)", file)
name_match = pkgs.re.search(r"([^/]*)(?=\.entry\.mpv)", file)
if name_match:
name = name_match.group(0) # Get the matched name
set_logging_logrecordfactory(name)
logger.info(f"Start metaverif on {file}")
# Create the file paths
cpp_prep = pkgs.os.path.join(tmpdir, f"{name}.i.pv")
awk_prep = pkgs.os.path.join(tmpdir, f"{name}.o.pv")
@@ -253,9 +282,8 @@ def metaverif(repo_path, tmpdir, file):
ta, res, ctr, expected, descs = pretty_output_init(cpp_prep)
with open(log_file, "a") as log:
generator = run_proverif(awk_prep)
generator = run_proverif(awk_prep, log_file)
for line in generator:
log.write(line)
# parse-result-line:
match = pkgs.re.search(r"^RESULT .* \b(true|false)\b\.$", line)
if match: