Skip to content

Commit

Permalink
Fixed TB output syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Strömbergson <joachim@assured.se>
  • Loading branch information
secworks committed Oct 31, 2023
1 parent 8bbd1b1 commit ff9855d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
35 changes: 18 additions & 17 deletions src/tb/tb_prince.v
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module tb_prince();
//----------------------------------------------------------------
task reset_dut;
begin
$display("*** Toggle reset.");
$display("--- Toggle reset.");
tb_reset_n = 0;
#(2 * CLK_PERIOD);
tb_reset_n = 1;
Expand All @@ -189,11 +189,11 @@ module tb_prince();
begin
if (error_ctr == 0)
begin
$display("*** All %02d test cases completed successfully", tc_ctr);
$display("--- All %02d test cases completed successfully", tc_ctr);
end
else
begin
$display("*** %02d tests completed - %02d test cases did not complete successfully.",
$display("--- %02d tests completed - %02d test cases did not complete successfully.",
tc_ctr, error_ctr);
end
end
Expand Down Expand Up @@ -233,7 +233,7 @@ module tb_prince();
begin
if (DEBUG)
begin
$display("*** Writing 0x%08x to 0x%02x.", word, address);
$display("--- Writing 0x%08x to 0x%02x.", word, address);
$display("");
end

Expand Down Expand Up @@ -266,7 +266,7 @@ module tb_prince();

if (DEBUG)
begin
$display("*** Reading 0x%08x from 0x%02x.", read_data, address);
$display("--- Reading 0x%08x from 0x%02x.", read_data, address);
$display("");
end
end
Expand Down Expand Up @@ -299,7 +299,7 @@ module tb_prince();
tc_ctr = tc_ctr + 1;

$display("");
$display("*** TC%02d started.", testcase);
$display("--- TC%02d started.", testcase);

// Encryption.
write_word(ADDR_KEY0, key[031 : 00]);
Expand All @@ -310,9 +310,9 @@ module tb_prince();
write_word(ADDR_BLOCK0, plaintext[31 : 00]);
write_word(ADDR_BLOCK1, plaintext[63 : 32]);
write_word(ADDR_CTRL, 32'h1);
$display("*** TC%02d - encryption started.", testcase);
$display("--- TC%02d - encryption started.", testcase);
wait_ready();
$display("*** TC%02d - encryption completed.", testcase);
$display("--- TC%02d - encryption completed.", testcase);

read_word(ADDR_RESULT0);
enc_res[31 : 0] = read_data;
Expand All @@ -321,11 +321,11 @@ module tb_prince();

if (enc_res == ciphertext)
begin
$display("*** Correct ciphertext received.");
$display("--- Correct ciphertext received.");
end
else
begin
$display("*** Incorrect ciphertext received. Expected 0x%016x, got 0x%016x", ciphertext, enc_res);
$display("--- Incorrect ciphertext received. Expected 0x%016x, got 0x%016x", ciphertext, enc_res);
error_ctr = error_ctr + 1;
end
$display("");
Expand All @@ -335,9 +335,9 @@ module tb_prince();
write_word(ADDR_BLOCK1, ciphertext[63 : 32]);
write_word(ADDR_CONFIG, 32'h0);
write_word(ADDR_CTRL, 32'h1);
$display("*** TC%02d - decryption started.", testcase);
$display("--- TC%02d - decryption started.", testcase);
wait_ready();
$display("*** TC%02d - decryption started.", testcase);
$display("--- TC%02d - decryption started.", testcase);

read_word(ADDR_RESULT0);
dec_res[31 : 0] = read_data;
Expand All @@ -346,15 +346,15 @@ module tb_prince();

if (dec_res == plaintext)
begin
$display("*** Correct plaintext received.");
$display("--- Correct plaintext received.");
end
else
begin
$display("*** Incorrect plaintext received. Expected 0x%016x, got 0x%016x", plaintext, dec_res);
$display("--- Incorrect plaintext received. Expected 0x%016x, got 0x%016x", plaintext, dec_res);
error_ctr = error_ctr + 1;
end

$display("*** TC%02d completed.", testcase);
$display("--- TC%02d completed.", testcase);
$display("");
end
endtask // test
Expand All @@ -366,7 +366,7 @@ module tb_prince();
initial
begin : prince_test
$display(" -= Testbench for prince started =-");
$display(" ============================");
$display(" ==============================");
$display("");

init_sim();
Expand Down Expand Up @@ -401,7 +401,8 @@ module tb_prince();

display_test_result();
$display("");
$display("*** prince simulation done. ***");
$display(" -= Testbench for prince completed =-");
$display(" ================================");
$finish;
end // prince_test
endmodule // tb_prince
Expand Down
45 changes: 24 additions & 21 deletions src/tb/tb_prince_core.v
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ module tb_prince_core();
//----------------------------------------------------------------
task reset_dut;
begin
$display("*** DUT before reset:");
$display("--- DUT before reset:");
dump_dut_state();
$display("*** Toggling reset.");
$display("--- Toggling reset.");
tb_reset_n = 0;
#(2 * CLK_PERIOD);
tb_reset_n = 1;
$display("*** DUT after reset:");
$display("--- DUT after reset:");
dump_dut_state();
end
endtask // reset_dut
Expand All @@ -189,11 +189,11 @@ module tb_prince_core();
begin
if (error_ctr == 0)
begin
$display("*** All %02d test cases completed successfully", tc_ctr);
$display("--- All %02d test cases completed successfully", tc_ctr);
end
else
begin
$display("*** %02d tests completed - %02d test cases did not complete successfully.",
$display("--- %02d tests completed - %02d test cases did not complete successfully.",
tc_ctr, error_ctr);
end
end
Expand Down Expand Up @@ -260,55 +260,55 @@ module tb_prince_core();
tc_ctr = tc_ctr + 1;
tb_monitor = 0;

$display("*** TC%01d started.", tc);
$display("--- TC%01d started.", tc);
dump_dut_state();

$display("*** TC%01d - encryption started.", tc);
$display("--- TC%01d - encryption started.", tc);
tb_key = key;
tb_encdec = 1'h1;
tb_block = plaintext;
tb_next = 1'h1;
#(CLK_PERIOD);
tb_next = 1'h0;
wait_ready();
$display("*** TC%01d - encryption completed.", tc);
$display("--- TC%01d - encryption completed.", tc);
dump_dut_state();

if (tb_result == ciphertext)
$display("*** TC%01d correct ciphertext generated: 0x%016x",
$display("--- TC%01d correct ciphertext generated: 0x%016x",
tc, tb_result);
else
begin
error_ctr = error_ctr + 1;
$display("*** TC%01d incorrect ciphertext generated", tc);
$display("*** TC%01d expected: 0x%016x", tc, ciphertext);
$display("*** TC%01d got: 0x%016x", tc, tb_result);
$display("--- TC%01d incorrect ciphertext generated", tc);
$display("--- TC%01d expected: 0x%016x", tc, ciphertext);
$display("--- TC%01d got: 0x%016x", tc, tb_result);
end

$display("*** TC%01d - decryption started.", tc);
$display("--- TC%01d - decryption started.", tc);
tb_key = key;
tb_block = ciphertext;
tb_encdec = 1'h0;
tb_next = 1'h1;
#(CLK_PERIOD);
tb_next = 1'h0;
wait_ready();
$display("*** TC%01d - decryption completed.", tc);
$display("--- TC%01d - decryption completed.", tc);

if (tb_result == plaintext)
$display("*** TC%01d correct plaintext generated: 0x%016x",
$display("--- TC%01d correct plaintext generated: 0x%016x",
tc, tb_result);
else
begin
error_ctr = error_ctr + 1;
$display("*** TC%01d incorrect plaintext generated", tc);
$display("*** TC%01d expected: 0x%016x", tc, plaintext);
$display("*** TC%01d got: 0x%016x", tc, tb_result);
$display("--- TC%01d incorrect plaintext generated", tc);
$display("--- TC%01d expected: 0x%016x", tc, plaintext);
$display("--- TC%01d got: 0x%016x", tc, tb_result);
end

tb_monitor = 0;

$display("*** TC%01d completed.", tc);
$display("--- TC%01d completed.", tc);
$display("");
end
endtask // test
Expand All @@ -321,7 +321,8 @@ module tb_prince_core();
//----------------------------------------------------------------
initial
begin : prince_core_test
$display("*** Simulation of PRINCE core started.");
$display(" -= Testbench for prince core started =-");
$display(" ===================================");
$display("");

init_sim();
Expand Down Expand Up @@ -356,7 +357,9 @@ module tb_prince_core();

display_test_result();
$display("");
$display("*** Simulation of PRINCE core completed.");
$display(" -= Testbench for prince core completed =-");
$display(" =====================================");
$display("");
$finish;
end // prince_core_test
endmodule // tb_prince_core
Expand Down

0 comments on commit ff9855d

Please sign in to comment.