Skip to content

Commit

Permalink
All macro trace tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Sep 9, 2024
1 parent b6f0794 commit 6ec2e8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
54 changes: 26 additions & 28 deletions common/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,6 @@ pub use proofman_macros::trace;
#[cfg(test)]
use crate as common;

#[test]
fn check() {
const OFFSET: usize = 1;
let num_rows = 8;

trace!(TraceRow, MyTrace<F> { a: F, b:F});

assert_eq!(TraceRow::<usize>::ROW_SIZE, 2);

let mut buffer = vec![0usize; num_rows * TraceRow::<usize>::ROW_SIZE + OFFSET];
let trace = MyTrace::map_buffer(&mut buffer, num_rows, OFFSET);
let mut trace = trace.unwrap();

// Set values
for i in 0..num_rows {
trace[i].a = i;
trace[i].b = i * 10;
}

// Check values
for i in 0..num_rows {
assert_eq!(trace[i].a, i);
assert_eq!(trace[i].b, i * 10);
}
}

#[test]
#[should_panic]
fn test_errors_are_launched_when_num_rows_is_invalid_1() {
Expand Down Expand Up @@ -64,6 +38,32 @@ fn test_errors_are_launched_when_num_rows_is_invalid_4() {
let _ = Simple::<u8>::new(3);
}

#[test]
fn check() {
const OFFSET: usize = 1;
let num_rows = 8;

trace!(TraceRow, MyTrace<F> { a: F, b:F});

assert_eq!(TraceRow::<usize>::ROW_SIZE, 2);

let mut buffer = vec![0usize; num_rows * TraceRow::<usize>::ROW_SIZE + OFFSET];
let trace = MyTrace::map_buffer(&mut buffer, num_rows, OFFSET);
let mut trace = trace.unwrap();

// Set values
for i in 0..num_rows {
trace[i].a = i;
trace[i].b = i * 10;
}

// Check values
for i in 0..num_rows {
assert_eq!(trace[i].a, i);
assert_eq!(trace[i].b, i * 10);
}
}

#[test]
fn check_array() {
let num_rows = 8;
Expand Down Expand Up @@ -152,8 +152,6 @@ fn check_multi_array_2() {
trace[i].c[1] = i + 2;
}

println!("{:?}", buffer);

// Check values
for i in 0..num_rows {
assert_eq!(buffer[i * TraceRow::<usize>::ROW_SIZE], i);
Expand Down
1 change: 1 addition & 0 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn trace_impl(input: TokenStream2) -> Result<TokenStream2> {
});

let row_struct = quote! {
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct #row_struct_name<#generics> {
#(#field_definitions)*
Expand Down

0 comments on commit 6ec2e8a

Please sign in to comment.