add more memory tests
Some checks failed
/ deps (push) Successful in 19s
/ test (push) Has been cancelled
/ deps (pull_request) Successful in 14s
/ test (pull_request) Successful in 5m21s

This commit is contained in:
Jacob Lifshay 2024-12-13 15:04:48 -08:00
parent c756aeec70
commit 2af38de900
Signed by: programmerjake
SSH key fingerprint: SHA256:HnFTLGpSm4Q4Fj502oCFisjZSoakwEuTsJJMSke63RQ
3 changed files with 5960 additions and 5 deletions

View file

@ -271,7 +271,7 @@ fn test_shift_register() {
assert_eq!(
*expected,
sim.read_bool(sim.io().q),
"cycle: {cycle}\nvcd:\n{}",
"vcd:\n{}\ncycle: {cycle}",
String::from_utf8(writer.take()).unwrap(),
);
}
@ -473,7 +473,7 @@ fn test_enums() {
assert_eq!(
expected,
io,
"cycle: {cycle}\nvcd:\n{}",
"vcd:\n{}\ncycle: {cycle}",
String::from_utf8(writer.take()).unwrap(),
);
sim.write_clock(sim.io().cd.clk, false);
@ -671,7 +671,7 @@ fn test_memories() {
assert_eq!(
expected,
io,
"cycle: {cycle}\nvcd:\n{}",
"vcd:\n{}\ncycle: {cycle}",
String::from_utf8(writer.take()).unwrap(),
);
sim.advance_time(SimDuration::from_micros(1));
@ -947,7 +947,7 @@ fn test_memories2() {
assert_eq!(
expected,
io,
"cycle: {cycle}\nvcd:\n{}",
"vcd:\n{}\ncycle: {cycle}",
String::from_utf8(writer.take()).unwrap(),
);
sim.advance_time(SimDuration::from_nanos(250));
@ -967,4 +967,241 @@ fn test_memories2() {
}
}
// TODO: add more tests for memories
#[hdl_module(outline_generated)]
pub fn memories3() {
#[hdl]
let r: fayalite::memory::ReadStruct<Array<UInt<8>, 8>, ConstUsize<3>> = m.input();
#[hdl]
let w: fayalite::memory::WriteStruct<Array<UInt<8>, 8>, ConstUsize<3>> = m.input();
#[hdl]
let mut mem: MemBuilder<Array<UInt<8>, 8>> = memory();
mem.depth(8);
mem.read_latency(2);
mem.write_latency(NonZeroUsize::new(2).unwrap());
mem.read_under_write(ReadUnderWrite::Old);
connect_any(mem.new_read_port(), r);
connect_any(mem.new_write_port(), w);
}
#[hdl]
#[test]
fn test_memories3() {
let _n = SourceLocation::normalize_files_for_tests();
let mut sim = Simulation::new(memories3());
let mut writer = RcWriter::default();
sim.add_trace_writer(VcdWriterDecls::new(writer.clone()));
sim.write_clock(sim.io().r.clk, false);
sim.write_clock(sim.io().w.clk, false);
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
struct IO {
r_addr: u8,
r_en: bool,
r_data: [u8; 8],
w_addr: u8,
w_en: bool,
w_data: [u8; 8],
w_mask: [bool; 8],
}
let io_cycles = [
IO {
r_addr: 0,
r_en: false,
r_data: [0; 8],
w_addr: 0,
w_en: true,
w_data: [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0],
w_mask: [false, true, false, true, true, false, false, true],
},
IO {
r_addr: 0,
r_en: true,
r_data: [0; 8],
w_addr: 1,
w_en: false,
w_data: [0; 8],
w_mask: [false; 8],
},
IO {
r_addr: 0,
r_en: true,
r_data: [0, 0x34, 0, 0x78, 0x9A, 0, 0, 0xF0],
w_addr: 1,
w_en: false,
w_data: [0; 8],
w_mask: [false; 8],
},
IO {
r_addr: 0,
r_en: true,
r_data: [0, 0x34, 0, 0x78, 0x9A, 0, 0, 0xF0],
w_addr: 0,
w_en: true,
w_data: [0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10],
w_mask: [true; 8],
},
IO {
r_addr: 0,
r_en: true,
r_data: [0, 0x34, 0, 0x78, 0x9A, 0, 0, 0xF0],
w_addr: 0,
w_en: true,
w_data: [0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10],
w_mask: [true; 8],
},
IO {
r_addr: 0,
r_en: true,
r_data: [0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10],
w_addr: 0,
w_en: true,
w_data: [0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10],
w_mask: [true; 8],
},
IO {
r_addr: 0,
r_en: false,
r_data: [0; 8],
w_addr: 1,
w_en: true,
w_data: [0x13, 0x57, 0x9B, 0xDF, 0x02, 0x46, 0x8A, 0xCE],
w_mask: [true; 8],
},
IO {
r_addr: 0,
r_en: false,
r_data: [0; 8],
w_addr: 2,
w_en: true,
w_data: *b"testing!",
w_mask: [true; 8],
},
IO {
r_addr: 0,
r_en: false,
r_data: [0; 8],
w_addr: 3,
w_en: true,
w_data: *b"more tst",
w_mask: [true; 8],
},
IO {
r_addr: 0,
r_en: true,
r_data: [0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10],
w_addr: 0,
w_en: false,
w_data: [0; 8],
w_mask: [false; 8],
},
IO {
r_addr: 1,
r_en: true,
r_data: [0x13, 0x57, 0x9B, 0xDF, 0x02, 0x46, 0x8A, 0xCE],
w_addr: 0,
w_en: false,
w_data: [0; 8],
w_mask: [false; 8],
},
IO {
r_addr: 2,
r_en: true,
r_data: *b"testing!",
w_addr: 0,
w_en: false,
w_data: [0; 8],
w_mask: [false; 8],
},
IO {
r_addr: 3,
r_en: true,
r_data: *b"more tst",
w_addr: 0,
w_en: false,
w_data: [0; 8],
w_mask: [false; 8],
},
];
for cycle in 0..io_cycles.len() + 2 {
{
let IO {
r_addr,
r_en,
r_data: _,
w_addr,
w_en,
w_data,
w_mask,
} = io_cycles.get(cycle).copied().unwrap_or(IO {
r_addr: 0,
r_en: false,
r_data: [0; 8],
w_addr: 0,
w_en: false,
w_data: [0; 8],
w_mask: [false; 8],
});
sim.write_bool_or_int(sim.io().r.addr, r_addr.cast_to_static());
sim.write_bool(sim.io().r.en, r_en);
sim.write_bool_or_int(sim.io().w.addr, w_addr.cast_to_static());
sim.write_bool(sim.io().w.en, w_en);
for (i, v) in w_data.into_iter().enumerate() {
sim.write_bool_or_int(sim.io().w.data[i], v);
}
for (i, v) in w_mask.into_iter().enumerate() {
sim.write_bool_or_int(sim.io().w.mask[i], v);
}
}
sim.advance_time(SimDuration::from_nanos(250));
sim.write_clock(sim.io().r.clk, true);
sim.write_clock(sim.io().w.clk, true);
sim.advance_time(SimDuration::from_nanos(250));
if let Some(
expected @ IO {
r_addr,
r_en,
r_data: _,
w_addr,
w_en,
w_data,
w_mask,
},
) = cycle.checked_sub(1).and_then(|i| io_cycles.get(i).copied())
{
let io = IO {
r_addr,
r_en,
r_data: std::array::from_fn(|i| {
sim.read_bool_or_int(sim.io().r.data[i])
.to_bigint()
.try_into()
.expect("known to be in range")
}),
w_addr,
w_en,
w_data,
w_mask,
};
assert_eq!(
expected,
io,
"vcd:\n{}\ncycle: {cycle}",
String::from_utf8(writer.take()).unwrap(),
);
}
sim.advance_time(SimDuration::from_nanos(250));
sim.write_clock(sim.io().r.clk, false);
sim.write_clock(sim.io().w.clk, false);
sim.advance_time(SimDuration::from_nanos(250));
}
sim.flush_traces().unwrap();
let vcd = String::from_utf8(writer.take()).unwrap();
println!("####### VCD:\n{vcd}\n#######");
if vcd != include_str!("sim/expected/memories3.vcd") {
panic!();
}
let sim_debug = format!("{sim:#?}");
println!("#######\n{sim_debug}\n#######");
if sim_debug != include_str!("sim/expected/memories3.txt") {
panic!();
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,836 @@
$timescale 1 ps $end
$scope module memories3 $end
$scope struct r $end
$var wire 3 ! addr $end
$var wire 1 " en $end
$var wire 1 # clk $end
$scope struct data $end
$var wire 8 $ \[0] $end
$var wire 8 % \[1] $end
$var wire 8 & \[2] $end
$var wire 8 ' \[3] $end
$var wire 8 ( \[4] $end
$var wire 8 ) \[5] $end
$var wire 8 * \[6] $end
$var wire 8 + \[7] $end
$upscope $end
$upscope $end
$scope struct w $end
$var wire 3 , addr $end
$var wire 1 - en $end
$var wire 1 . clk $end
$scope struct data $end
$var wire 8 / \[0] $end
$var wire 8 0 \[1] $end
$var wire 8 1 \[2] $end
$var wire 8 2 \[3] $end
$var wire 8 3 \[4] $end
$var wire 8 4 \[5] $end
$var wire 8 5 \[6] $end
$var wire 8 6 \[7] $end
$upscope $end
$scope struct mask $end
$var wire 1 7 \[0] $end
$var wire 1 8 \[1] $end
$var wire 1 9 \[2] $end
$var wire 1 : \[3] $end
$var wire 1 ; \[4] $end
$var wire 1 < \[5] $end
$var wire 1 = \[6] $end
$var wire 1 > \[7] $end
$upscope $end
$upscope $end
$scope struct mem $end
$scope struct contents $end
$scope struct [0] $end
$scope struct mem $end
$var reg 8 ] \[0] $end
$var reg 8 e \[1] $end
$var reg 8 m \[2] $end
$var reg 8 u \[3] $end
$var reg 8 } \[4] $end
$var reg 8 '" \[5] $end
$var reg 8 /" \[6] $end
$var reg 8 7" \[7] $end
$upscope $end
$upscope $end
$scope struct [1] $end
$scope struct mem $end
$var reg 8 ^ \[0] $end
$var reg 8 f \[1] $end
$var reg 8 n \[2] $end
$var reg 8 v \[3] $end
$var reg 8 ~ \[4] $end
$var reg 8 (" \[5] $end
$var reg 8 0" \[6] $end
$var reg 8 8" \[7] $end
$upscope $end
$upscope $end
$scope struct [2] $end
$scope struct mem $end
$var reg 8 _ \[0] $end
$var reg 8 g \[1] $end
$var reg 8 o \[2] $end
$var reg 8 w \[3] $end
$var reg 8 !" \[4] $end
$var reg 8 )" \[5] $end
$var reg 8 1" \[6] $end
$var reg 8 9" \[7] $end
$upscope $end
$upscope $end
$scope struct [3] $end
$scope struct mem $end
$var reg 8 ` \[0] $end
$var reg 8 h \[1] $end
$var reg 8 p \[2] $end
$var reg 8 x \[3] $end
$var reg 8 "" \[4] $end
$var reg 8 *" \[5] $end
$var reg 8 2" \[6] $end
$var reg 8 :" \[7] $end
$upscope $end
$upscope $end
$scope struct [4] $end
$scope struct mem $end
$var reg 8 a \[0] $end
$var reg 8 i \[1] $end
$var reg 8 q \[2] $end
$var reg 8 y \[3] $end
$var reg 8 #" \[4] $end
$var reg 8 +" \[5] $end
$var reg 8 3" \[6] $end
$var reg 8 ;" \[7] $end
$upscope $end
$upscope $end
$scope struct [5] $end
$scope struct mem $end
$var reg 8 b \[0] $end
$var reg 8 j \[1] $end
$var reg 8 r \[2] $end
$var reg 8 z \[3] $end
$var reg 8 $" \[4] $end
$var reg 8 ," \[5] $end
$var reg 8 4" \[6] $end
$var reg 8 <" \[7] $end
$upscope $end
$upscope $end
$scope struct [6] $end
$scope struct mem $end
$var reg 8 c \[0] $end
$var reg 8 k \[1] $end
$var reg 8 s \[2] $end
$var reg 8 { \[3] $end
$var reg 8 %" \[4] $end
$var reg 8 -" \[5] $end
$var reg 8 5" \[6] $end
$var reg 8 =" \[7] $end
$upscope $end
$upscope $end
$scope struct [7] $end
$scope struct mem $end
$var reg 8 d \[0] $end
$var reg 8 l \[1] $end
$var reg 8 t \[2] $end
$var reg 8 | \[3] $end
$var reg 8 &" \[4] $end
$var reg 8 ." \[5] $end
$var reg 8 6" \[6] $end
$var reg 8 >" \[7] $end
$upscope $end
$upscope $end
$upscope $end
$scope struct r0 $end
$var wire 3 ? addr $end
$var wire 1 @ en $end
$var wire 1 A clk $end
$scope struct data $end
$var wire 8 B \[0] $end
$var wire 8 C \[1] $end
$var wire 8 D \[2] $end
$var wire 8 E \[3] $end
$var wire 8 F \[4] $end
$var wire 8 G \[5] $end
$var wire 8 H \[6] $end
$var wire 8 I \[7] $end
$upscope $end
$upscope $end
$scope struct w1 $end
$var wire 3 J addr $end
$var wire 1 K en $end
$var wire 1 L clk $end
$scope struct data $end
$var wire 8 M \[0] $end
$var wire 8 N \[1] $end
$var wire 8 O \[2] $end
$var wire 8 P \[3] $end
$var wire 8 Q \[4] $end
$var wire 8 R \[5] $end
$var wire 8 S \[6] $end
$var wire 8 T \[7] $end
$upscope $end
$scope struct mask $end
$var wire 1 U \[0] $end
$var wire 1 V \[1] $end
$var wire 1 W \[2] $end
$var wire 1 X \[3] $end
$var wire 1 Y \[4] $end
$var wire 1 Z \[5] $end
$var wire 1 [ \[6] $end
$var wire 1 \ \[7] $end
$upscope $end
$upscope $end
$upscope $end
$upscope $end
$enddefinitions $end
$dumpvars
b0 ]
b0 e
b0 m
b0 u
b0 }
b0 '"
b0 /"
b0 7"
b0 ^
b0 f
b0 n
b0 v
b0 ~
b0 ("
b0 0"
b0 8"
b0 _
b0 g
b0 o
b0 w
b0 !"
b0 )"
b0 1"
b0 9"
b0 `
b0 h
b0 p
b0 x
b0 ""
b0 *"
b0 2"
b0 :"
b0 a
b0 i
b0 q
b0 y
b0 #"
b0 +"
b0 3"
b0 ;"
b0 b
b0 j
b0 r
b0 z
b0 $"
b0 ,"
b0 4"
b0 <"
b0 c
b0 k
b0 s
b0 {
b0 %"
b0 -"
b0 5"
b0 ="
b0 d
b0 l
b0 t
b0 |
b0 &"
b0 ."
b0 6"
b0 >"
b0 !
0"
0#
b0 $
b0 %
b0 &
b0 '
b0 (
b0 )
b0 *
b0 +
b0 ,
1-
0.
b10010 /
b110100 0
b1010110 1
b1111000 2
b10011010 3
b10111100 4
b11011110 5
b11110000 6
07
18
09
1:
1;
0<
0=
1>
b0 ?
0@
0A
b0 B
b0 C
b0 D
b0 E
b0 F
b0 G
b0 H
b0 I
b0 J
1K
0L
b10010 M
b110100 N
b1010110 O
b1111000 P
b10011010 Q
b10111100 R
b11011110 S
b11110000 T
0U
1V
0W
1X
1Y
0Z
0[
1\
$end
#250000
1#
1.
1A
1L
#500000
#750000
0#
0.
0A
0L
#1000000
1"
b1 ,
0-
b0 /
b0 0
b0 1
b0 2
b0 3
b0 4
b0 5
b0 6
08
0:
0;
0>
1@
b1 J
0K
b0 M
b0 N
b0 O
b0 P
b0 Q
b0 R
b0 S
b0 T
0V
0X
0Y
0\
#1250000
b0 ]
b110100 e
b0 m
b1111000 u
b10011010 }
b0 '"
b0 /"
b11110000 7"
1#
1.
1A
1L
#1500000
#1750000
0#
0.
0A
0L
#2000000
#2250000
1#
1.
1A
1L
#2500000
#2750000
0#
0.
0A
0L
#3000000
b0 ,
1-
b11111110 /
b11011100 0
b10111010 1
b10011000 2
b1110110 3
b1010100 4
b110010 5
b10000 6
17
18
19
1:
1;
1<
1=
1>
b0 J
1K
b11111110 M
b11011100 N
b10111010 O
b10011000 P
b1110110 Q
b1010100 R
b110010 S
b10000 T
1U
1V
1W
1X
1Y
1Z
1[
1\
#3250000
1#
1.
1A
b110100 C
b1111000 E
b10011010 F
b11110000 I
1L
b110100 %
b1111000 '
b10011010 (
b11110000 +
#3500000
#3750000
0#
0.
0A
0L
#4000000
#4250000
b11111110 ]
b11011100 e
b10111010 m
b10011000 u
b1110110 }
b1010100 '"
b110010 /"
b10000 7"
1#
1.
1A
1L
#4500000
#4750000
0#
0.
0A
0L
#5000000
#5250000
b11111110 ]
b11011100 e
b10111010 m
b10011000 u
b1110110 }
b1010100 '"
b110010 /"
b10000 7"
1#
1.
1A
1L
#5500000
#5750000
0#
0.
0A
0L
#6000000
0"
b1 ,
b10011 /
b1010111 0
b10011011 1
b11011111 2
b10 3
b1000110 4
b10001010 5
b11001110 6
0@
b1 J
b10011 M
b1010111 N
b10011011 O
b11011111 P
b10 Q
b1000110 R
b10001010 S
b11001110 T
#6250000
b11111110 ]
b11011100 e
b10111010 m
b10011000 u
b1110110 }
b1010100 '"
b110010 /"
b10000 7"
1#
1.
1A
b11111110 B
b11011100 C
b10111010 D
b10011000 E
b1110110 F
b1010100 G
b110010 H
b10000 I
1L
b11111110 $
b11011100 %
b10111010 &
b10011000 '
b1110110 (
b1010100 )
b110010 *
b10000 +
#6500000
#6750000
0#
0.
0A
0L
#7000000
b10 ,
b1110100 /
b1100101 0
b1110011 1
b1110100 2
b1101001 3
b1101110 4
b1100111 5
b100001 6
b10 J
b1110100 M
b1100101 N
b1110011 O
b1110100 P
b1101001 Q
b1101110 R
b1100111 S
b100001 T
#7250000
b10011 ^
b1010111 f
b10011011 n
b11011111 v
b10 ~
b1000110 ("
b10001010 0"
b11001110 8"
1#
1.
1A
b0 B
b0 C
b0 D
b0 E
b0 F
b0 G
b0 H
b0 I
1L
b0 $
b0 %
b0 &
b0 '
b0 (
b0 )
b0 *
b0 +
#7500000
#7750000
0#
0.
0A
0L
#8000000
b11 ,
b1101101 /
b1101111 0
b1110010 1
b1100101 2
b100000 3
b1110100 4
b1110011 5
b1110100 6
b11 J
b1101101 M
b1101111 N
b1110010 O
b1100101 P
b100000 Q
b1110100 R
b1110011 S
b1110100 T
#8250000
b1110100 _
b1100101 g
b1110011 o
b1110100 w
b1101001 !"
b1101110 )"
b1100111 1"
b100001 9"
1#
1.
1A
1L
#8500000
#8750000
0#
0.
0A
0L
#9000000
1"
b0 ,
0-
b0 /
b0 0
b0 1
b0 2
b0 3
b0 4
b0 5
b0 6
07
08
09
0:
0;
0<
0=
0>
1@
b0 J
0K
b0 M
b0 N
b0 O
b0 P
b0 Q
b0 R
b0 S
b0 T
0U
0V
0W
0X
0Y
0Z
0[
0\
#9250000
b1101101 `
b1101111 h
b1110010 p
b1100101 x
b100000 ""
b1110100 *"
b1110011 2"
b1110100 :"
1#
1.
1A
1L
#9500000
#9750000
0#
0.
0A
0L
#10000000
b1 !
b1 ?
#10250000
1#
1.
1A
b11111110 B
b11011100 C
b10111010 D
b10011000 E
b1110110 F
b1010100 G
b110010 H
b10000 I
1L
b11111110 $
b11011100 %
b10111010 &
b10011000 '
b1110110 (
b1010100 )
b110010 *
b10000 +
#10500000
#10750000
0#
0.
0A
0L
#11000000
b10 !
b10 ?
#11250000
1#
1.
1A
b10011 B
b1010111 C
b10011011 D
b11011111 E
b10 F
b1000110 G
b10001010 H
b11001110 I
1L
b10011 $
b1010111 %
b10011011 &
b11011111 '
b10 (
b1000110 )
b10001010 *
b11001110 +
#11500000
#11750000
0#
0.
0A
0L
#12000000
b11 !
b11 ?
#12250000
1#
1.
1A
b1110100 B
b1100101 C
b1110011 D
b1110100 E
b1101001 F
b1101110 G
b1100111 H
b100001 I
1L
b1110100 $
b1100101 %
b1110011 &
b1110100 '
b1101001 (
b1101110 )
b1100111 *
b100001 +
#12500000
#12750000
0#
0.
0A
0L
#13000000
b0 !
0"
b0 ?
0@
#13250000
1#
1.
1A
b1101101 B
b1101111 C
b1110010 D
b1100101 E
b100000 F
b1110100 G
b1110011 H
b1110100 I
1L
b1101101 $
b1101111 %
b1110010 &
b1100101 '
b100000 (
b1110100 )
b1110011 *
b1110100 +
#13500000
#13750000
0#
0.
0A
0L
#14000000
#14250000
1#
1.
1A
b0 B
b0 C
b0 D
b0 E
b0 F
b0 G
b0 H
b0 I
1L
b0 $
b0 %
b0 &
b0 '
b0 (
b0 )
b0 *
b0 +
#14500000
#14750000
0#
0.
0A
0L
#15000000