Skip to content

Commit

Permalink
Start comparison script
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Jan 17, 2024
1 parent 7eead22 commit 3df40f1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ TEST_FILES:=$(wildcard $(TEST_DIR)/*.cairo)
COMPILED_TESTS:=$(patsubst $(TEST_DIR)/%.cairo, $(TEST_DIR)/%.json, $(TEST_FILES))
CAIRO_MEM:=$(patsubst $(TEST_DIR)/%.json, $(TEST_DIR)/%.memory, $(COMPILED_TESTS))
CAIRO_TRACE:=$(patsubst $(TEST_DIR)/%.json, $(TEST_DIR)/%.trace, $(COMPILED_TESTS))
CAIRO_PIE:=$(patsubst $(TEST_DIR)/%.json, $(TEST_DIR)/%.pie.zip, $(COMPILED_TESTS))
CAIRO_RS_MEM:=$(patsubst $(TEST_DIR)/%.json, $(TEST_DIR)/%.rs.memory, $(COMPILED_TESTS))
CAIRO_RS_TRACE:=$(patsubst $(TEST_DIR)/%.json, $(TEST_DIR)/%.rs.trace, $(COMPILED_TESTS))
CAIRO_RS_PIE:=$(patsubst $(TEST_DIR)/%.json, $(TEST_DIR)/%.rs.pie.zip, $(COMPILED_TESTS))

BENCH_DIR=cairo_programs/benchmarks
BENCH_FILES:=$(wildcard $(BENCH_DIR)/*.cairo)
Expand All @@ -94,11 +96,11 @@ $(BENCH_DIR)/%.json: $(BENCH_DIR)/%.cairo
$(TEST_DIR)/%.json: $(TEST_DIR)/%.cairo
cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@

$(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory: $(TEST_DIR)/%.json $(RELBIN)
cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all_cairo $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory
$(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory $(TEST_DIR)/%.rs.pie.zip: $(TEST_DIR)/%.json $(RELBIN)
cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all_cairo $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory --cairo_pie_output $(@D)/$(*F).rs.pie.zip

$(TEST_DIR)/%.trace $(TEST_DIR)/%.memory: $(TEST_DIR)/%.json
cairo-run --layout starknet_with_keccak --program $< --trace_file $@ --memory_file $(@D)/$(*F).memory
$(TEST_DIR)/%.trace $(TEST_DIR)/%.memory $(TEST_DIR)/%.pie.zip: $(TEST_DIR)/%.json
cairo-run --layout starknet_with_keccak --program $< --trace_file $@ --memory_file $(@D)/$(*F).memory --cairo_pie_output $(@D)/$(*F).pie.zip

$(NORETROCOMPAT_DIR)/%.json: $(NORETROCOMPAT_DIR)/%.cairo
cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR):$(NORETROCOMPAT_DIR)" $< --output $@
Expand Down Expand Up @@ -306,6 +308,9 @@ compare_air_public_input: $(CAIRO_RS_AIR_PUBLIC_INPUT) $(CAIRO_AIR_PUBLIC_INPUT)
compare_air_private_input: $(CAIRO_RS_AIR_PRIVATE_INPUT) $(CAIRO_AIR_PRIVATE_INPUT)
cd vm/src/tests; ./compare_vm_state.sh memory proof_mode air_private_input

compare_pie: $(CAIRO_RS_PIE) $(CAIRO_PIE)
cd vm/src/tests; ./compare_vm_state.sh pie

# Run with nightly enable the `doc_cfg` feature wich let us provide clear explaination about which parts of the code are behind a feature flag
docs:
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --verbose --release --locked --no-deps --all-features --open
Expand All @@ -314,6 +319,7 @@ clean:
rm -f $(TEST_DIR)/*.json
rm -f $(TEST_DIR)/*.memory
rm -f $(TEST_DIR)/*.trace
rm -f $(TEST_DIR)/*.pie.zip
rm -f $(BENCH_DIR)/*.json
rm -f $(BAD_TEST_DIR)/*.json
rm -f $(PRINT_TEST_DIR)/*.json
Expand Down
20 changes: 20 additions & 0 deletions vm/src/tests/cairo_pie_comparator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

import sys
import json
from zipfile import ZipFile


filename1 = sys.argv[1]
filename2 = sys.argv[2]

with ZipFile(filename1) as cairo_lang_pie_zip, ZipFile(filename2) as cairo_vm_pie_zip:
with cairo_lang_pie_zip.open('version.json') as cl_verison_file, cairo_vm_pie_zip.open('version.json') as cv_verison_file:
cl_version = json.load(cl_verison_file)
cv_version = json.load(cv_verison_file)
if cl_version == cv_verison_file:
print(f"Comparison succesful for {filename1}/version.json vs {filename2}/version.json")
else:
print(f"Comparison unsuccesful for {filename1}/version.json vs {filename2}/version.json")
exit(1)

14 changes: 14 additions & 0 deletions vm/src/tests/compare_vm_state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ trace=false
memory=false
air_public_input=false
air_private_input=false
pie=false
passed_tests=0
failed_tests=0

Expand All @@ -30,6 +31,9 @@ for i in $@; do
"air_private_input") air_private_input=true
echo "Requested air_private_input comparison"
;;
"pie") pie=true
echo "Requested pie comparison"
;;
*)
;;
esac
Expand Down Expand Up @@ -90,6 +94,16 @@ for file in $(ls $tests_path | grep .cairo$ | sed -E 's/\.cairo$//'); do
passed_tests=$((passed_tests + 1))
fi
fi

if $pie; then
if ! ./cairo_pie_comparator.py $path_file.pie.zip $path_file.rs.pie.zip; then
echo "Cairo PIE differs for $file"
exit_code=1
failed_tests=$((failed_tests + 1))
else
passed_tests=$((passed_tests + 1))
fi
fi
done

if test $failed_tests != 0; then
Expand Down

0 comments on commit 3df40f1

Please sign in to comment.