fix testbench formatting
This commit is contained in:
parent
570bd3698a
commit
36e5abab60
@ -72,7 +72,6 @@ module program1_tb ();
|
|||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
file_no = 'b1;
|
file_no = 'b1;
|
||||||
//file_no = $fopen("msg_enocder_out.txt","w");
|
|
||||||
#0ns strlen = str1.len; // length of string 1 (# characters between " ")
|
#0ns strlen = str1.len; // length of string 1 (# characters between " ")
|
||||||
if(strlen>54) strlen = 54; // clip message at 54 characters
|
if(strlen>54) strlen = 54; // clip message at 54 characters
|
||||||
// program 1 -- precompute encrypted message
|
// program 1 -- precompute encrypted message
|
||||||
@ -132,9 +131,10 @@ module program1_tb ();
|
|||||||
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h", n, msg_crypto1[n][6:0]+8'h20, msg_crypto1[n], dut.DM.core[n+64]);
|
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h", n, msg_crypto1[n][6:0]+8'h20, msg_crypto1[n], dut.DM.core[n+64]);
|
||||||
score++;
|
score++;
|
||||||
end
|
end
|
||||||
else
|
else begin
|
||||||
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h OOPS!", n, msg_crypto1[n][6:0]+8'h20, msg_crypto1[n], dut.DM.core[n+64]);
|
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h OOPS!", n, msg_crypto1[n][6:0]+8'h20, msg_crypto1[n], dut.DM.core[n+64]);
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
$fdisplay(file_no,"score = %d/64",score);
|
$fdisplay(file_no,"score = %d/64",score);
|
||||||
#20ns $fclose(file_no);
|
#20ns $fclose(file_no);
|
||||||
|
@ -4,31 +4,27 @@
|
|||||||
// runs program 2 (decrypt a message)
|
// runs program 2 (decrypt a message)
|
||||||
module program2_tb () ;
|
module program2_tb () ;
|
||||||
// DUT interface -- four one-bit wires, three to DUT, one from
|
// DUT interface -- four one-bit wires, three to DUT, one from
|
||||||
bit clk , // advances simulation step-by-step
|
bit clk; // advances simulation step-by-step
|
||||||
init = 1'b1 , // init (reset) command to DUT
|
bit init = 1'b1; // init (reset) command to DUT
|
||||||
start = 1'b1 ; // req (start program) command to DUT
|
bit start = 1'b1; // req (start program) command to DUT
|
||||||
wire done; // done flag returned by DUT
|
wire done; // done flag returned by DUT
|
||||||
|
|
||||||
// test bench parameters
|
// test bench parameters
|
||||||
bit [3:0] pre_length; // space char. bytes before first char. in message
|
bit [3:0] pre_length; // space char. bytes before first char. in message
|
||||||
bit [7:0] message1[54] , // original raw message, in binary
|
bit [7:0] message1[54]; // original raw message, in binary
|
||||||
msg_padded1[64], // original message, plus pre- and post-padding w/ ASCII spaces
|
bit [7:0] msg_padded1[64]; // original message, plus pre- and post-padding w/ ASCII spaces
|
||||||
msg_crypto1[64]; // encrypted message according to the DUT
|
bit [7:0] msg_crypto1[64]; // encrypted message according to the DUT
|
||||||
bit [6:0] lfsr_ptrn , // chosen one of 9 maximal length 7-tap shift reg. ptrns
|
bit [6:0] lfsr_ptrn; // chosen one of 9 maximal length 7-tap shift reg. ptrns
|
||||||
LFSR_ptrn[9] , // the 9 candidate maximal-length 7-bit LFSR tap ptrns
|
bit [6:0] LFSR_ptrn[9]; // the 9 candidate maximal-length 7-bit LFSR tap ptrns
|
||||||
lfsr1[64] , // states of program 1 encrypting LFSR
|
bit [6:0] lfsr1[64]; // states of program 1 encrypting LFSR
|
||||||
LFSR_init ; // one of 127 possible NONZERO starting states
|
bit [6:0] LFSR_init; // one of 127 possible NONZERO starting states
|
||||||
int score; // count of correct encyrpted characters
|
int score; // count of correct encyrpted characters
|
||||||
|
|
||||||
// our original American Standard Code for Information Interchange message follows
|
// our original American Standard Code for Information Interchange message follows
|
||||||
// note in practice your design should be able to handle ANY ASCII string that is
|
// note in practice your design should be able to handle ANY ASCII string that is
|
||||||
// restricted to characters between space (0x20) and script f (0x9f) and shorter than
|
// restricted to characters between space (0x20) and script f (0x9f) and shorter than
|
||||||
// 55 characters in length
|
// 55 characters in length
|
||||||
string str1 = "Knowledge comes, but wisdom lingers"; // sample program 1 input
|
string str1 = "Knowledge comes, but wisdom lingers"; // sample program 1 input
|
||||||
// string str1 = " . "; // alternative inputs
|
|
||||||
// string str1 = " 01234546789abcdefghijklmnopqrstuvwxyz. "; // (make up your own,
|
|
||||||
// string str1 = " f A joke is a very serious thing."; // as well)
|
|
||||||
// string str1 = " Ajok "; //
|
|
||||||
// string str1 = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
|
|
||||||
// string str1 = " Knowledge comes, but wisdom lingers. "; //
|
|
||||||
|
|
||||||
// displayed encrypted string will go here:
|
// displayed encrypted string will go here:
|
||||||
string str_enc1[64]; // program 1 desired output will go here
|
string str_enc1[64]; // program 1 desired output will go here
|
||||||
@ -45,12 +41,13 @@ module program2_tb () ;
|
|||||||
assign LFSR_ptrn[6] = 7'h5C;
|
assign LFSR_ptrn[6] = 7'h5C;
|
||||||
assign LFSR_ptrn[7] = 7'h7E;
|
assign LFSR_ptrn[7] = 7'h7E;
|
||||||
assign LFSR_ptrn[8] = 7'h7B;
|
assign LFSR_ptrn[8] = 7'h7B;
|
||||||
|
|
||||||
always_comb begin
|
always_comb begin
|
||||||
pt_no = 4;
|
pt_no = $urandom_range(0, 8);
|
||||||
//pt_no = $urandom_range(0, 8);
|
|
||||||
if(pt_no>8) pt_no[3] = 0; // restrict pt_no to 0 through 8
|
if(pt_no>8) pt_no[3] = 0; // restrict pt_no to 0 through 8
|
||||||
lfsr_ptrn = LFSR_ptrn[pt_no]; // look up and engage the selected pattern; to data_mem[62]
|
lfsr_ptrn = LFSR_ptrn[pt_no]; // look up and engage the selected pattern; to data_mem[62]
|
||||||
end
|
end
|
||||||
|
|
||||||
// now select a starting LFSR state -- any nonzero value will do
|
// now select a starting LFSR state -- any nonzero value will do
|
||||||
always_comb begin
|
always_comb begin
|
||||||
LFSR_init = $urandom;//$random>>2; // or set a value, such as 7'b1, for debug
|
LFSR_init = $urandom;//$random>>2; // or set a value, such as 7'b1, for debug
|
||||||
@ -73,14 +70,7 @@ module program2_tb () ;
|
|||||||
);
|
);
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
//***** pre-load your instruction ROM here or inside itself *****
|
|
||||||
// $readmemb("encoder.bin", dut.instr_rom.rom);
|
|
||||||
// you may also pre-load desired constants, etc. into
|
|
||||||
// your data_mem here -- the upper addresses are reserved for your use
|
|
||||||
// dut.data_mem.DM[128]=8'hfe; //whatever constants you want
|
|
||||||
// to display to console, change this line to file_no = 'b1;
|
|
||||||
file_no = 'b1;
|
file_no = 'b1;
|
||||||
// file_no = $fopen("msg_decoder_out.txt"); // create your output file
|
|
||||||
#0ns strlen = str1.len; // length of string 1 (# characters between " ")
|
#0ns strlen = str1.len; // length of string 1 (# characters between " ")
|
||||||
if(strlen>52) strlen = 52; // clip message at 52 characters
|
if(strlen>52) strlen = 52; // clip message at 52 characters
|
||||||
// program 1 -- precompute encrypted message
|
// program 1 -- precompute encrypted message
|
||||||
@ -104,8 +94,7 @@ module program2_tb () ;
|
|||||||
for (int i=0; i<64; i++) begin
|
for (int i=0; i<64; i++) begin
|
||||||
msg_crypto1[i] = (msg_padded1[i] ^ lfsr1[i]);
|
msg_crypto1[i] = (msg_padded1[i] ^ lfsr1[i]);
|
||||||
msg_crypto1[i][7] = ^msg_crypto1[i][6:0]; // prepend parity bit into MSB
|
msg_crypto1[i][7] = ^msg_crypto1[i][6:0]; // prepend parity bit into MSB
|
||||||
$fdisplay(file_no,"i=%d, msg_pad=0x%h, lfsr=%b msg_crypt w/ parity = 0x%h",
|
$fdisplay(file_no,"i=%d, msg_pad=0x%h, lfsr=%b msg_crypt w/ parity = 0x%h", i,msg_padded1[i],lfsr1[i],msg_crypto1[i]);
|
||||||
i,msg_padded1[i],lfsr1[i],msg_crypto1[i]);
|
|
||||||
// for display purposes only, add 8'h20 to avoid nonprintable characters (<8'h20)
|
// for display purposes only, add 8'h20 to avoid nonprintable characters (<8'h20)
|
||||||
str_enc1[i] = string'(msg_crypto1[i][6:0]+8'h20);
|
str_enc1[i] = string'(msg_crypto1[i][6:0]+8'h20);
|
||||||
end
|
end
|
||||||
@ -130,8 +119,10 @@ module program2_tb () ;
|
|||||||
#10ns start = 1'b0; // request/start = 1 holds your program counter
|
#10ns start = 1'b0; // request/start = 1 holds your program counter
|
||||||
#60ns; // wait for 6 clock cycles of nominal 10ns each
|
#60ns; // wait for 6 clock cycles of nominal 10ns each
|
||||||
wait(done); // wait for DUT's ack/done flag to go high
|
wait(done); // wait for DUT's ack/done flag to go high
|
||||||
|
|
||||||
#10ns $fdisplay(file_no,"");
|
#10ns $fdisplay(file_no,"");
|
||||||
$fdisplay(file_no,"program 2:");
|
$fdisplay(file_no,"program 2:");
|
||||||
|
|
||||||
// ***** reads your results and compares to test bench
|
// ***** reads your results and compares to test bench
|
||||||
// ***** use your instance name for data memory and its internal core *****
|
// ***** use your instance name for data memory and its internal core *****
|
||||||
for(int n=0; n<64; n++) begin
|
for(int n=0; n<64; n++) begin
|
||||||
@ -140,10 +131,12 @@ module program2_tb () ;
|
|||||||
n, msg_padded1[n], msg_padded1[n], dut.DM.core[n]);
|
n, msg_padded1[n], msg_padded1[n], dut.DM.core[n]);
|
||||||
score++;
|
score++;
|
||||||
end
|
end
|
||||||
else
|
else begin
|
||||||
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h OOPS!",
|
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h OOPS!",
|
||||||
n, msg_padded1[n], msg_padded1[n], dut.DM.core[n]);
|
n, msg_padded1[n], msg_padded1[n], dut.DM.core[n]);
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
$fdisplay(file_no,"score = %d/64",score);
|
$fdisplay(file_no,"score = %d/64",score);
|
||||||
#20ns $fclose(file_no);
|
#20ns $fclose(file_no);
|
||||||
#20ns $stop;
|
#20ns $stop;
|
||||||
|
Reference in New Issue
Block a user