WIP: metaverif part 2

Co-Authored-By: Benjamin Lipp <blipp@rosenpass.eu>
This commit is contained in:
Anja Rabich
2025-07-01 17:07:47 +02:00
parent 73d180c4cf
commit c259be76c8
2 changed files with 58 additions and 11 deletions

View File

@@ -48,10 +48,36 @@ def run_proverif(file, extra_args=[]):
p = line p = line
else: else:
p = null p = null
# append to log file if p != null:
# parse result line yield p
# pretty output #print(p)
# save to file except Exception as e:
print(f"An error occurred: {e}")
finally:
process.stdout.close()
process.wait()
def _run_proverif(file, extra_args=[]):
if extra_args is None:
extra_args = []
params = ["proverif", "-test", *extra_args, file]
print(params)
eprint(params)
process = exc_piped(params, stderr=pkgs.subprocess.PIPE, stdout=pkgs.subprocess.PIPE, text=True, bufsize=1)
try:
null, p = clean_warnings_init()
for line in process.stdout:
print(f"received a line: {line.strip()}")
# clean warnings
line = line.rstrip()
if not pkgs.re.match(r"^Warning: identifier \w+ rebound.$", line):
if p != null:
yield p
#print(p)
p = line
else:
p = null
if p != null: if p != null:
yield p yield p
#print(p) #print(p)
@@ -75,6 +101,17 @@ def cpp(file, cpp_prep):
return exc(params, stderr=pkgs.sys.stderr) return exc(params, stderr=pkgs.sys.stderr)
def _cpp(file, cpp_prep):
print(f"_cpp: {file}, {cpp_prep}")
file_path = pkgs.pathlib.Path(file)
dirname = file_path.parent
cwd = pkgs.pathlib.Path.cwd()
params = ["cpp", "-P", f"-I{cwd}/{dirname}", file, "-o", cpp_prep]
return exc(params, stderr=pkgs.sys.stderr)
@click.command() @click.command()
def parse_result_line(): def parse_result_line():
for outp in pkgs.sys.stdin: for outp in pkgs.sys.stdin:
@@ -96,6 +133,13 @@ def awk(cpp_prep, awk_prep):
exc(params, stderr=pkgs.sys.stderr, stdout=file) exc(params, stderr=pkgs.sys.stderr, stdout=file)
file.write("\nprocess main") file.write("\nprocess main")
def _awk(cpp_prep, awk_prep):
params = ["awk", "-f", "marzipan/marzipan.awk", cpp_prep]
with open(awk_prep, 'w') as file:
exc(params, stderr=pkgs.sys.stderr, stdout=file)
file.write("\nprocess main")
def pretty_output_line(prefix, mark, color, text): def pretty_output_line(prefix, mark, color, text):
prefix = f"[grey42]{prefix}[/grey42]" prefix = f"[grey42]{prefix}[/grey42]"
@@ -238,14 +282,14 @@ def metaverif(tmpdir, file):
print(f"CPP Prep Path: {cpp_prep}") print(f"CPP Prep Path: {cpp_prep}")
print(f"AWK Prep Path: {awk_prep}") print(f"AWK Prep Path: {awk_prep}")
cpp(name, cpp_prep) _cpp(file, cpp_prep)
awk(cpp_prep, awk_prep) _awk(cpp_prep, awk_prep)
log_file = pkgs.os.path.join(tmpdir, f"{name}.log") log_file = pkgs.os.path.join(tmpdir, f"{name}.log")
ta, res, ctr, expected, descs = pretty_output_init(cpp_prep) ta, res, ctr, expected, descs = pretty_output_init(cpp_prep)
with open(log_file, 'a') as log: with open(log_file, 'a') as log:
generator = run_proverif(awk_prep) generator = _run_proverif(awk_prep)
for line in generator: for line in generator:
log.write(line) log.write(line)
# parse-result-line: # parse-result-line:

View File

@@ -65,12 +65,15 @@ analyze() {
local procs; procs=() local procs; procs=()
for entry in "${entries[@]}"; do for entry in "${entries[@]}"; do
echo "call metaverif" echo "call metaverif"
exc rosenpass-marzipan metaverif "${tmpdir}" "${entry}" >&2 & procs+=("$!") # TODO: commented out for testing
#exc rosenpass-marzipan metaverif "${tmpdir}" "${entry}" >&2 & procs+=("$!")
exc rosenpass-marzipan metaverif "${tmpdir}" "${entry}" >&2
done done
for entry in "${procs[@]}"; do # TODO: commented out for testing
exc wait -f "${entry}" # for entry in "${procs[@]}"; do
done # exc wait -f "${entry}"
# done
} }
err_usage() { err_usage() {