Skip to content

Commit

Permalink
Add cairo pie tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed Oct 1, 2024
1 parent a8d73c0 commit 2a784f7
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions vm/src/tests/compare_outputs_dynamic_layouts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2a784f7

Please sign in to comment.