From 6006f91e2edb21d68625d07a2858471d0aeb218a Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 28 Jun 2026 16:07:37 -0400 Subject: [PATCH] Tests: Add t_queue_array (#6921 test) --- test_regress/t/t_queue_array.py | 18 +++++++ test_regress/t/t_queue_array.v | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100755 test_regress/t/t_queue_array.py create mode 100644 test_regress/t/t_queue_array.v diff --git a/test_regress/t/t_queue_array.py b/test_regress/t/t_queue_array.py new file mode 100755 index 000000000..8a938befd --- /dev/null +++ b/test_regress/t/t_queue_array.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of either the GNU Lesser General Public License Version 3 +# or the Perl Artistic License Version 2.0. +# SPDX-FileCopyrightText: 2026 Wilson Snyder +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('simulator') + +test.compile() + +test.execute() + +test.passes() diff --git a/test_regress/t/t_queue_array.v b/test_regress/t/t_queue_array.v new file mode 100644 index 000000000..c729a4654 --- /dev/null +++ b/test_regress/t/t_queue_array.v @@ -0,0 +1,87 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain. +// SPDX-FileCopyrightText: 2026 Wilson Snyder +// SPDX-License-Identifier: CC0-1.0 + +// verilog_format: off +`define stop $stop +`define checkd(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d (%s !== %s)\n", `__FILE__,`__LINE__, (gotv), (expv), `"gotv`", `"expv`"); `stop; end while(0); +// verilog_format: on + +module t; + + int normal_queue[$]; + int array_of_queues[3][$]; + int aa_of_queues[int][$]; + + function void test_normal_queue(); + $display("[%0t] %m: Testing single queue (int normal_queue [$])", $realtime); + `checkd(normal_queue.size(), 0); + repeat (4) normal_queue.push_back($urandom); + `checkd(normal_queue.size(), 4); + repeat (4) void'(normal_queue.pop_front()); + `checkd(normal_queue.size(), 0); + endfunction + + function void test_array_of_queues(); + $display("[%0t] %m: Testing array of queues (int array_of_queues [3][$])", $realtime); + array_of_queues[0] = {}; + array_of_queues[1] = {}; + array_of_queues[2] = {}; + + for (int i = 0; i < 3; i++) begin + `checkd(array_of_queues[i].size(), 0); + end + + for (int i = 0; i < 3; i++) begin + for (int j = 0; j < 4; j++) begin : push_4_items + array_of_queues[i].push_back($urandom); + $display("[%0t] %m: array_of_queues, pushed item to queue %0d: [0]=%p [1]=%p [2]=%p", + $realtime, i, array_of_queues[0], array_of_queues[1], array_of_queues[2]); + `checkd(array_of_queues[i].size(), j + 1); + end + end + + for (int i = 0; i < 3; i++) begin : pop_4_items_from_each + repeat (4) void'(array_of_queues[i].pop_front()); + `checkd(array_of_queues[i].size(), 0); + end + endfunction + + function void test_aa_of_queues(); + $display("[%0t] %m: Testing associative-array of queues (int aa_of_queues [int][$])", + $realtime); + + aa_of_queues[0] = {}; + aa_of_queues[1] = {}; + aa_of_queues[2] = {}; + + for (int i = 0; i < 3; i++) begin + `checkd(aa_of_queues[i].size(), 0); + end + + for (int i = 0; i < 3; i++) begin + for (int j = 0; j < 4; j++) begin : push_4_items + aa_of_queues[i].push_back($urandom); + $display("[%0t] %m: aa_of_queues, pushed item to queue %0d: [0]=%p [1]=%p [2]=%p", + $realtime, i, aa_of_queues[0], aa_of_queues[1], aa_of_queues[2]); + `checkd(aa_of_queues[i].size(), j + 1); + end + end + + for (int i = 0; i < 3; i++) begin + repeat (4) void'(aa_of_queues[i].pop_front()); + `checkd(aa_of_queues[i].size(), 0); + end + endfunction + + + initial begin + test_normal_queue(); + test_aa_of_queues(); + test_array_of_queues(); + $finish; + end + +endmodule