-
Notifications
You must be signed in to change notification settings - Fork 732
(test): Adding casm run and trace to e2e tests #9482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
(test): Adding casm run and trace to e2e tests #9482
Conversation
9feac89 to
0cd7778
Compare
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: 1 of 6 files reviewed, 1 unresolved discussion (waiting on @eytan-starkware and @TomerStarkware).
tests/e2e_test.rs line 521 at r1 (raw file):
.join("\n"); res.insert("memory".into(), memory_str); }
remove everything this requires as well.
printing the trace is good for debug - but for now rather not have the extra "baggage" of getting the trace as part of the function runner flow.
Code quote:
if params.include_trace {
// Format trace as a table with headers.
let trace = match result.trace {
Some(trace) => trace,
None => {
return TestRunnerResult {
outputs: res,
error: Some(
"trace: true was specified but no trace was returned. Ensure the \
function was executed correctly."
.to_string(),
),
};
}
};
let mut trace_lines = vec!["| PC | AP | FP |".to_string()];
for entry in &trace {
trace_lines.push(format!("| {} | {} | {} |", entry.pc, entry.ap, entry.fp));
}
res.insert("casm_trace".into(), trace_lines.join("\n"));
// Include memory state.
let memory_str = result
.memory
.iter()
.enumerate()
.filter_map(|(addr, value)| value.as_ref().map(|v| format!("[{}] = {}", addr, v)))
.join("\n");
res.insert("memory".into(), memory_str);
}0cd7778 to
9f17c72
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eytan-starkware made 1 comment.
Reviewable status: 1 of 6 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware).
tests/e2e_test.rs line 521 at r1 (raw file):
Previously, orizi wrote…
remove everything this requires as well.
printing the trace is good for debug - but for now rather not have the extra "baggage" of getting the trace as part of the function runner flow.
Done.
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 3 files and all commit messages, made 2 comments, and resolved 1 discussion.
Reviewable status: 4 of 6 files reviewed, 2 unresolved discussions (waiting on @eytan-starkware and @TomerStarkware).
tests/e2e_test_data/libfuncs/casm_run_sanity line 35 at r2 (raw file):
//! > casm_trace | PC | AP | FP |
remove unproduced.
tests/e2e_test.rs line 250 at r2 (raw file):
/// Parses test_data format: "function_name(input)=output" /// Allows whitespace around all components. fn parse(s: &str) -> Result<Self, String> {
f2f
9f17c72 to
bf6b4e1
Compare
bf6b4e1 to
44b56da
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eytan-starkware made 2 comments.
Reviewable status: 2 of 6 files reviewed, 2 unresolved discussions (waiting on @orizi and @TomerStarkware).
tests/e2e_test.rs line 250 at r2 (raw file):
Previously, orizi wrote…
f2f
Done.
tests/e2e_test_data/libfuncs/casm_run_sanity line 35 at r2 (raw file):
Previously, orizi wrote…
remove unproduced.
Done.

Summary
Added support for capturing and returning VM execution traces in the Cairo runner. This enables checking real run output, debugging and analysis of Cairo program execution by providing access to the program counter, allocation pointer, and frame pointer at each step, as well as the final memory state.
Type of change
Please check one:
Why is this change needed?
This PR adds the ability to capture and return VM execution traces, which is essential for debugging and analyzing Cairo program execution. The trace provides visibility into the program counter, allocation pointer, and frame pointer at each execution step, along with the final memory state. This is particularly useful for developers who need to understand the low-level execution details of their Cairo programs.
What was the behavior or documentation before?
Previously, the runner would execute Cairo programs but did not provide a way to access the execution trace or memory state after execution. This made debugging complex programs difficult as developers couldn't inspect the execution flow.
What is the behavior or documentation after?
The runner now has the ability to optionally capture and return the execution trace and memory state. This is implemented through:
tracefield toRunResultandRunResultStarknetstructsrun_function_with_starknet_context_with_tracemethod with areturn_traceparameterThe e2e test runner now supports a
trace: trueoption and can display the execution trace in a readable table format.Additional context
The implementation includes comprehensive test cases that demonstrate the trace functionality with different Cairo programs, from simple arithmetic to more complex control flow and loops. This provides examples for users on how to use and interpret the trace data.