From 3b0314e0c21363c262fcbbfa1bfcb56a86a27541 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 15 Aug 2024 08:49:48 -0400 Subject: [PATCH] fix integration tests --- miden/tests/integration/exec_iters.rs | 413 ------------------ miden/tests/integration/main.rs | 1 - .../operations/decorators/asmop.rs | 78 ++-- 3 files changed, 25 insertions(+), 467 deletions(-) delete mode 100644 miden/tests/integration/exec_iters.rs diff --git a/miden/tests/integration/exec_iters.rs b/miden/tests/integration/exec_iters.rs deleted file mode 100644 index 66e33715e7..0000000000 --- a/miden/tests/integration/exec_iters.rs +++ /dev/null @@ -1,413 +0,0 @@ -use processor::{AsmOpInfo, ContextId, RowIndex, VmState}; -use test_utils::{assert_eq, build_debug_test, Felt, ToElements, ONE}; -use vm_core::{debuginfo::Location, AssemblyOp, Operation}; - -// EXEC ITER TESTS -// ================================================================= -#[test] -fn test_exec_iter() { - let source = "proc.foo.1 loc_store.0 end begin mem_storew.1 dropw push.17 exec.foo end"; - let mut init_stack: Vec = Vec::new(); - (1..=16).for_each(|i| { - init_stack.push(i); - }); - let test = build_debug_test!(source, &init_stack); - let path = test.source.name(); - let traces = test.execute_iter(); - let fmp = Felt::new(2u64.pow(30)); - let next_fmp = fmp + ONE; - let mem = vec![(1_u64, slice_to_word(&[13, 14, 15, 16]))]; - let mem_storew1_loc = Some(Location { - path: path.clone(), - start: 33.into(), - end: (33 + 12).into(), - }); - let dropw_loc = Some(Location { - path: path.clone(), - start: 46.into(), - end: (46 + 5).into(), - }); - let push17_loc = Some(Location { - path: path.clone(), - start: 52.into(), - end: (52 + 7).into(), - }); - let locstore0_loc = Some(Location { - path: path.clone(), - start: 11.into(), - end: (11 + 11).into(), - }); - let expected_states = vec![ - VmState { - clk: RowIndex::from(0), - ctx: ContextId::root(), - op: None, - asmop: None, - stack: [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].to_elements(), - fmp, - memory: Vec::new(), - }, - VmState { - clk: RowIndex::from(1), - ctx: ContextId::root(), - op: Some(Operation::Join), - asmop: None, - stack: [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].to_elements(), - fmp, - memory: Vec::new(), - }, - VmState { - clk: RowIndex::from(2), - ctx: ContextId::root(), - op: Some(Operation::Span), - asmop: None, - stack: [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1].to_elements(), - fmp, - memory: Vec::new(), - }, - VmState { - clk: RowIndex::from(3), - ctx: ContextId::root(), - op: Some(Operation::Pad), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - mem_storew1_loc.clone(), - "#exec::#main".to_string(), - 3, - "mem_storew.1".to_string(), - false, - ), - 1, - )), - stack: [0, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].to_elements(), - fmp, - memory: Vec::new(), - }, - VmState { - clk: RowIndex::from(4), - ctx: ContextId::root(), - op: Some(Operation::Incr), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - mem_storew1_loc.clone(), - "#exec::#main".to_string(), - 3, - "mem_storew.1".to_string(), - false, - ), - 2, - )), - stack: [1, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2].to_elements(), - fmp, - memory: Vec::new(), - }, - VmState { - clk: RowIndex::from(5), - ctx: ContextId::root(), - op: Some(Operation::MStoreW), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - mem_storew1_loc, - "#exec::#main".to_string(), - 3, - "mem_storew.1".to_string(), - false, - ), - 3, - )), - stack: [16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(6), - ctx: ContextId::root(), - op: Some(Operation::Drop), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - dropw_loc.clone(), - "#exec::#main".to_string(), - 4, - "dropw".to_string(), - false, - ), - 1, - )), - stack: [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(7), - ctx: ContextId::root(), - op: Some(Operation::Drop), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - dropw_loc.clone(), - "#exec::#main".to_string(), - 4, - "dropw".to_string(), - false, - ), - 2, - )), - stack: [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(8), - ctx: ContextId::root(), - op: Some(Operation::Drop), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - dropw_loc.clone(), - "#exec::#main".to_string(), - 4, - "dropw".to_string(), - false, - ), - 3, - )), - stack: [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(9), - ctx: ContextId::root(), - op: Some(Operation::Drop), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - dropw_loc, - "#exec::#main".to_string(), - 4, - "dropw".to_string(), - false, - ), - 4, - )), - stack: [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(10), - ctx: ContextId::root(), - op: Some(Operation::Push(Felt::new(17))), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - push17_loc, - "#exec::#main".to_string(), - 1, - "push.17".to_string(), - false, - ), - 1, - )), - stack: [17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(11), - ctx: ContextId::root(), - op: Some(Operation::Noop), - asmop: None, - stack: [17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(12), - ctx: ContextId::root(), - op: Some(Operation::End), - asmop: None, - stack: [17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(13), - ctx: ContextId::root(), - op: Some(Operation::Span), - asmop: None, - stack: [17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(14), - ctx: ContextId::root(), - op: Some(Operation::Push(ONE)), - asmop: None, - stack: [1, 17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0].to_elements(), - fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(15), - ctx: ContextId::root(), - op: Some(Operation::FmpUpdate), - asmop: None, - stack: [17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0].to_elements(), - fmp: next_fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(16), - ctx: ContextId::root(), - op: Some(Operation::Pad), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - locstore0_loc.clone(), - "#exec::foo".to_string(), - 4, - "loc_store.0".to_string(), - false, - ), - 1, - )), - stack: [0, 17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0].to_elements(), - fmp: next_fmp, - memory: mem.clone(), - }, - VmState { - clk: RowIndex::from(17), - ctx: ContextId::root(), - op: Some(Operation::FmpAdd), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - locstore0_loc.clone(), - "#exec::foo".to_string(), - 4, - "loc_store.0".to_string(), - false, - ), - 2, - )), - stack: [2u64.pow(30) + 1, 17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0] - .to_elements(), - fmp: next_fmp, - memory: mem, - }, - VmState { - clk: RowIndex::from(18), - ctx: ContextId::root(), - op: Some(Operation::MStore), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - locstore0_loc.clone(), - "#exec::foo".to_string(), - 4, - "loc_store.0".to_string(), - false, - ), - 3, - )), - stack: [17, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0].to_elements(), - fmp: next_fmp, - memory: vec![ - (1_u64, slice_to_word(&[13, 14, 15, 16])), - (2u64.pow(30) + 1, slice_to_word(&[17, 0, 0, 0])), - ], - }, - VmState { - clk: RowIndex::from(19), - ctx: ContextId::root(), - op: Some(Operation::Drop), - asmop: Some(AsmOpInfo::new( - AssemblyOp::new( - locstore0_loc.clone(), - "#exec::foo".to_string(), - 4, - "loc_store.0".to_string(), - false, - ), - 4, - )), - stack: [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0].to_elements(), - fmp: next_fmp, - memory: vec![ - (1_u64, slice_to_word(&[13, 14, 15, 16])), - (2u64.pow(30) + 1, slice_to_word(&[17, 0, 0, 0])), - ], - }, - VmState { - clk: RowIndex::from(20), - ctx: ContextId::root(), - op: Some(Operation::Push(Felt::new(18446744069414584320))), - asmop: None, - stack: [18446744069414584320, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0] - .to_elements(), - fmp: next_fmp, - memory: vec![ - (1_u64, slice_to_word(&[13, 14, 15, 16])), - (2u64.pow(30) + 1, slice_to_word(&[17, 0, 0, 0])), - ], - }, - VmState { - clk: RowIndex::from(21), - ctx: ContextId::root(), - op: Some(Operation::FmpUpdate), - asmop: None, - stack: [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0].to_elements(), - fmp, - memory: vec![ - (1_u64, slice_to_word(&[13, 14, 15, 16])), - (2u64.pow(30) + 1, slice_to_word(&[17, 0, 0, 0])), - ], - }, - VmState { - clk: RowIndex::from(22), - ctx: ContextId::root(), - op: Some(Operation::Noop), - asmop: None, - stack: [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0].to_elements(), - fmp, - memory: vec![ - (1_u64, slice_to_word(&[13, 14, 15, 16])), - (2u64.pow(30) + 1, slice_to_word(&[17, 0, 0, 0])), - ], - }, - VmState { - clk: RowIndex::from(23), - ctx: ContextId::root(), - op: Some(Operation::End), - asmop: None, - stack: [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0].to_elements(), - fmp, - memory: vec![ - (1_u64, slice_to_word(&[13, 14, 15, 16])), - (2u64.pow(30) + 1, slice_to_word(&[17, 0, 0, 0])), - ], - }, - VmState { - clk: RowIndex::from(24), - ctx: ContextId::root(), - op: Some(Operation::End), - asmop: None, - stack: [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0].to_elements(), - fmp, - memory: vec![ - (1_u64, slice_to_word(&[13, 14, 15, 16])), - (2u64.pow(30) + 1, slice_to_word(&[17, 0, 0, 0])), - ], - }, - ]; - for (expected, t) in expected_states.iter().zip(traces) { - let state = t.as_ref().unwrap(); - assert_eq!(*expected, *state); - } -} - -// HELPER FUNCTIONS -// ================================================================= -fn slice_to_word(values: &[i32]) -> [Felt; 4] { - [ - Felt::new(values[0] as u64), - Felt::new(values[1] as u64), - Felt::new(values[2] as u64), - Felt::new(values[3] as u64), - ] -} diff --git a/miden/tests/integration/main.rs b/miden/tests/integration/main.rs index effe92c656..d919f49217 100644 --- a/miden/tests/integration/main.rs +++ b/miden/tests/integration/main.rs @@ -4,7 +4,6 @@ use test_utils::build_test; mod air; mod cli; -mod exec_iters; mod flow_control; mod operations; diff --git a/miden/tests/integration/operations/decorators/asmop.rs b/miden/tests/integration/operations/decorators/asmop.rs index ddce41a61e..261b585f2c 100644 --- a/miden/tests/integration/operations/decorators/asmop.rs +++ b/miden/tests/integration/operations/decorators/asmop.rs @@ -220,20 +220,10 @@ fn asmop_repeat_test() { VmStatePartial { clk: RowIndex::from(1), asmop: None, - op: Some(Operation::Join), - }, - VmStatePartial { - clk: RowIndex::from(2), - asmop: None, - op: Some(Operation::Join), - }, - VmStatePartial { - clk: RowIndex::from(3), - asmop: None, op: Some(Operation::Span), }, VmStatePartial { - clk: RowIndex::from(4), + clk: RowIndex::from(2), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push1_loc.clone(), @@ -247,7 +237,7 @@ fn asmop_repeat_test() { op: Some(Operation::Pad), }, VmStatePartial { - clk: RowIndex::from(5), + clk: RowIndex::from(3), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push1_loc.clone(), @@ -261,7 +251,7 @@ fn asmop_repeat_test() { op: Some(Operation::Incr), }, VmStatePartial { - clk: RowIndex::from(6), + clk: RowIndex::from(4), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push2_loc.clone(), @@ -275,7 +265,7 @@ fn asmop_repeat_test() { op: Some(Operation::Push(Felt::new(2))), }, VmStatePartial { - clk: RowIndex::from(7), + clk: RowIndex::from(5), asmop: Some(AsmOpInfo::new( AssemblyOp::new( add_loc.clone(), @@ -290,17 +280,7 @@ fn asmop_repeat_test() { }, // End first Span VmStatePartial { - clk: RowIndex::from(8), - asmop: None, - op: Some(Operation::End), - }, - VmStatePartial { - clk: RowIndex::from(9), - asmop: None, - op: Some(Operation::Span), - }, - VmStatePartial { - clk: RowIndex::from(10), + clk: RowIndex::from(6), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push1_loc.clone(), @@ -314,7 +294,7 @@ fn asmop_repeat_test() { op: Some(Operation::Pad), }, VmStatePartial { - clk: RowIndex::from(11), + clk: RowIndex::from(7), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push1_loc.clone(), @@ -328,7 +308,7 @@ fn asmop_repeat_test() { op: Some(Operation::Incr), }, VmStatePartial { - clk: RowIndex::from(12), + clk: RowIndex::from(8), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push2_loc.clone(), @@ -342,7 +322,7 @@ fn asmop_repeat_test() { op: Some(Operation::Push(Felt::new(2))), }, VmStatePartial { - clk: RowIndex::from(13), + clk: RowIndex::from(9), asmop: Some(AsmOpInfo::new( AssemblyOp::new( add_loc.clone(), @@ -357,23 +337,7 @@ fn asmop_repeat_test() { }, // End second Span VmStatePartial { - clk: RowIndex::from(14), - asmop: None, - op: Some(Operation::End), - }, - // End first Join - VmStatePartial { - clk: RowIndex::from(15), - asmop: None, - op: Some(Operation::End), - }, - VmStatePartial { - clk: RowIndex::from(16), - asmop: None, - op: Some(Operation::Span), - }, - VmStatePartial { - clk: RowIndex::from(17), + clk: RowIndex::from(10), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push1_loc.clone(), @@ -387,7 +351,7 @@ fn asmop_repeat_test() { op: Some(Operation::Pad), }, VmStatePartial { - clk: RowIndex::from(18), + clk: RowIndex::from(11), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push1_loc, @@ -401,7 +365,7 @@ fn asmop_repeat_test() { op: Some(Operation::Incr), }, VmStatePartial { - clk: RowIndex::from(19), + clk: RowIndex::from(12), asmop: Some(AsmOpInfo::new( AssemblyOp::new( push2_loc, @@ -415,22 +379,30 @@ fn asmop_repeat_test() { op: Some(Operation::Push(Felt::new(2))), }, VmStatePartial { - clk: RowIndex::from(20), + clk: RowIndex::from(13), asmop: Some(AsmOpInfo::new( AssemblyOp::new(add_loc, "#exec::#main".to_string(), 1, "add".to_string(), false), 1, )), op: Some(Operation::Add), }, - // End Span VmStatePartial { - clk: RowIndex::from(21), + clk: RowIndex::from(14), asmop: None, - op: Some(Operation::End), + op: Some(Operation::Noop), }, - // End second Join VmStatePartial { - clk: RowIndex::from(22), + clk: RowIndex::from(15), + asmop: None, + op: Some(Operation::Noop), + }, + VmStatePartial { + clk: RowIndex::from(16), + asmop: None, + op: Some(Operation::Noop), + }, + VmStatePartial { + clk: RowIndex::from(17), asmop: None, op: Some(Operation::End), },