From 2a784f7f385bf3193e3a166f196a8657e9bda395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 1 Oct 2024 12:57:23 -0300 Subject: [PATCH] Add cairo pie tests --- .../tests/compare_outputs_dynamic_layouts.sh | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/vm/src/tests/compare_outputs_dynamic_layouts.sh b/vm/src/tests/compare_outputs_dynamic_layouts.sh index 89583286ab..affe2ceff8 100755 --- a/vm/src/tests/compare_outputs_dynamic_layouts.sh +++ b/vm/src/tests/compare_outputs_dynamic_layouts.sh @@ -159,6 +159,22 @@ CASES=( "cairo_programs/mod_builtin_feature/proof/apply_poly.json;ratio_den" ) +# Build pie cases to execute +PIE_CASES=( + "cairo_programs/fibonacci.pie.zip;all_cairo" + "cairo_programs/fibonacci.pie.zip;double_all_cairo" + "cairo_programs/factorial.pie.zip;all_cairo" + "cairo_programs/factorial.pie.zip;double_all_cairo" + "cairo_programs/bigint.pie.zip;all_cairo" + "cairo_programs/bigint.pie.zip;double_all_cairo" + "cairo_programs/dict.pie.zip;all_cairo" + "cairo_programs/dict.pie.zip;double_all_cairo" + "cairo_programs/sha256.pie.zip;all_cairo" + "cairo_programs/sha256.pie.zip;double_all_cairo" + "cairo_programs/keccak.pie.zip;all_cairo" + "cairo_programs/keccak.pie.zip;double_all_cairo" +) + passed_tests=0 failed_tests=0 exit_code=0 @@ -227,6 +243,51 @@ for case in "${CASES[@]}"; do rm program_py.* done + +for case in "${PIE_CASES[@]}"; do + IFS=";" read -r program layout <<< "$case" + + full_program="$program" + full_layout="$TEMP_FOLDER/$layout.json" + + # Run cairo-vm + echo "Running cairo-vm with case: $case" + cargo run -p cairo-vm-cli --features mod_builtin --release -- "$full_program" \ + --layout "dynamic" --cairo_layout_params_file "$full_layout" --run_from_cairo_pie \ + --trace_file program_rs.trace --memory_file program_rs.memory + + # Run cairo-lang + echo "Running cairo-lang with case: $case" + cairo-run --run_from_cairo_pie "$full_program" \ + --layout "dynamic" --cairo_layout_params_file "$full_layout" \ + --trace_file program_py.trace --memory_file program_py.memory + + # Compare trace + echo "Running trace comparison for case: $case" + if ! diff -q program_rs.trace program_py.trace; then + echo "Trace differs for case: $case" + exit_code=1 + failed_tests=$((failed_tests + 1)) + else + passed_tests=$((passed_tests + 1)) + fi + + # Compare memory + echo "Running memory comparison for case: $case" + if ! ./vm/src/tests/memory_comparator.py program_rs.memory program_py.memory; then + echo "Memory differs for case: $case" + exit_code=1 + failed_tests=$((failed_tests + 1)) + else + passed_tests=$((passed_tests + 1)) + fi + + # Clean files generated by the script + echo "Cleaning files" + rm program_rs.* + rm program_py.* +done + if test $failed_tests != 0; then echo "Comparisons: $failed_tests failed, $passed_tests passed, $((failed_tests + passed_tests)) total" elif test $passed_tests = 0; then