VHDL 的 TAP(测试任何协议)模块

发布于 2024-10-06 02:21:11 字数 478 浏览 0 评论 0原文

是否有 VHDL 的 TAP(测试任何协议)实现?那就太好了,因为这样我就可以使用证明来自动检查我的结果。还有一些很好的格式化 swuites,例如 smolder 可以处理它输出。您可能会问为什么不使用断言。部分 TAP 为我提供了一些很好的报告,例如文件数量和测试数量。我正在寻找一个最小的实现,在开始和结束时进行大量测试以及确定、诊断和失败功能。 is() 确实很好,但不是必需的。我可以写这个,但为什么要重新发明轮子呢?

这是这个问题 但对于 VHDL 而不是 Verilog。

Is there a TAP (Test Anything Protocol) implementation for VHDL? It would be nice because then I could use prove to check my results automatically. There are also nice formatting swuites such as smolder that can process it output. You might ask why not use assertions. Partly TAP gives me some good reporting such as number of files and number of tests. I'm looking for a minimal implentation with number of tests at the beginning and end and the ok, diag and fail functions. is() would really nice, but not necessary. I could write this, but why reinvent the wheel.

This is the question as in this question but for VHDL instead of Verilog.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浪漫之都 2024-10-13 02:21:11

我写了一篇我经常使用的文章,但我从未分发过它。就是这样(未包含的 base_pkg 大部分都有 to_string() 实现)。

-- Copyright © 2010 Wesley J. Landaker <[email protected]>
-- 
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.

-- 
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
-- 
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

-- Output is standard TAP (Test Anything Protocol) version 13

package test_pkg is

  procedure test_redirect(filename : string);
  procedure test_plan(tests : natural; directive : string := "");
  procedure test_abort(reason : string);
  procedure test_finished(directive : string := "");
  procedure test_comment (message : string);
  procedure test_pass (description : string := ""; directive : string := "");
  procedure test_fail (description : string := ""; directive : string := "");
  procedure test_ok   (result : boolean; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : integer; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : real; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : time; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : string; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : bit_vector; description : string := ""; directive : string := "");
  procedure test_approx_absolute(actual, expected, absolute_error : real; description : string := ""; directive : string := "");
  procedure test_approx_relative(actual, expected, relative_error : real; description : string := ""; directive : string := "");

end package;

use std.textio.all;
use work.base_pkg.all;

package body test_pkg is

  file test_output : text;
  shared variable initialized : boolean := false;
  shared variable have_plan : boolean := false;
  shared variable last_test_number : natural := 0;

  function remove_eol(s : string) return string is
    variable s_no_eol : string(s'range);
  begin
    for i in s'range loop
      case s(i) is
        when LF | CR => s_no_eol(i) := '_';
        when others  => s_no_eol(i) := s(i);
      end case;
    end loop;
    return s_no_eol;
  end function;

  function make_safe (s : string) return string is
    variable s_no_hash : string(s'range);
  begin
    for i in s'range loop
      case s(i) is
        when '#'    => s_no_hash(i) := '_';
        when others => s_no_hash(i) := s(i);
      end case;
    end loop;
    return remove_eol(s_no_hash);
  end function;

  procedure init is
    variable l : line;
  begin
    if initialized then
      return;
    end if;
    initialized := true;
    file_open(test_output, "STD_OUTPUT", write_mode);
    write(l, string'("TAP version 13"));
    writeline(test_output, l);
  end procedure;

  procedure test_redirect(filename : string) is
  begin
    init;
    file_close(test_output);
    file_open(test_output, filename, write_mode);
  end procedure;

  procedure test_plan(tests : natural; directive : string := "") is
    variable l : line;
  begin
    init;
    have_plan := true;
    write(l, string'("1.."));
    write(l, tests);
    if directive'length > 0 then
      write(l, " # " & remove_eol(directive));
    end if;
    writeline(test_output, l);
  end procedure;

  procedure test_abort(reason : string) is
    variable l : line;
  begin
    init;
    write(l, "Bail out! " & remove_eol(reason));
    writeline(test_output, l);
    assert false
      report "abort called"
      severity failure;
  end procedure;

  procedure test_finished (directive : string := "") is
  begin
    if not have_plan then
      test_plan(last_test_number, directive);
    elsif directive'length > 0 then
      test_comment("1.." & integer'image(last_test_number) & " # " & directive);
    else
      test_comment("1.." & integer'image(last_test_number));
    end if;
  end procedure;

  procedure test_comment (message : string) is
    variable l : line;
  begin
    init;
    write(l, '#');
    if message'length > 0 then
      write(l, " " & remove_eol(message));
    end if;
    writeline(test_output, l);
  end procedure;

  procedure result (status : string; description : string; directive : string) is
    variable l : line;
  begin
    init;
    last_test_number := last_test_number + 1;
    write(l, status & " ");
    write(l, last_test_number);
    if description'length > 0 then
      write(l, " " & make_safe(description));
    end if;
    if directive'length > 0 then
      write(l, " # " & remove_eol(directive));
    end if;
    writeline(test_output, l);
  end procedure;

  procedure test_pass (description : string := ""; directive : string := "") is
  begin
    result("ok", description, directive);
  end procedure;

  procedure test_fail (description : string := ""; directive : string := "") is
  begin
    result("not ok", description, directive);
  end procedure;

  procedure test_ok (result : boolean; description : string := ""; directive : string := "") is
  begin
    if result then
      test_pass(description, directive);
    else
      test_fail(description, directive);
    end if;
  end procedure;

  procedure test_equal(actual, expected : integer; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & integer'image(actual) & ", expected = " & integer'image(expected));
    end if;
  end procedure;

  procedure test_equal(actual, expected : real; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & real'image(actual) & ", expected = " & real'image(expected));
    end if;
  end procedure;

  procedure test_equal(actual, expected : time; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & time'image(actual) & ", expected = " & time'image(expected));
    end if;
  end procedure;

  procedure test_equal(actual, expected : string; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & actual & ", expected = " & expected);
    end if;
  end procedure;

  procedure test_equal(actual, expected : bit_vector; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & to_string(actual) & ", expected = " & to_string(expected));
    end if;
  end procedure;

  procedure test_approx_absolute(actual, expected, absolute_error : real; description : string := ""; directive : string := "") is
    variable err : real := abs(actual - expected);
    variable ok : boolean := err <= absolute_error;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & to_string(actual) & ", expected = " & to_string(expected) & ", absolute error = " & to_string(err));
    end if;
  end procedure;

  procedure test_approx_relative(actual, expected, relative_error : real; description : string := ""; directive : string := "") is
    variable err : real := abs(actual - expected)/abs(expected);
    variable ok : boolean := err <= relative_error;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & to_string(actual) & ", expected = " & to_string(expected) & ", relative error = " & to_string(err));
    end if;
  end procedure;

end package body;

I wrote one that I've used a lot, but I've never distributed it. Here it is (the not-included base_pkg mostly has to_string() implementations for everything).

-- Copyright © 2010 Wesley J. Landaker <[email protected]>
-- 
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.

-- 
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
-- 
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

-- Output is standard TAP (Test Anything Protocol) version 13

package test_pkg is

  procedure test_redirect(filename : string);
  procedure test_plan(tests : natural; directive : string := "");
  procedure test_abort(reason : string);
  procedure test_finished(directive : string := "");
  procedure test_comment (message : string);
  procedure test_pass (description : string := ""; directive : string := "");
  procedure test_fail (description : string := ""; directive : string := "");
  procedure test_ok   (result : boolean; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : integer; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : real; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : time; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : string; description : string := ""; directive : string := "");
  procedure test_equal(actual, expected : bit_vector; description : string := ""; directive : string := "");
  procedure test_approx_absolute(actual, expected, absolute_error : real; description : string := ""; directive : string := "");
  procedure test_approx_relative(actual, expected, relative_error : real; description : string := ""; directive : string := "");

end package;

use std.textio.all;
use work.base_pkg.all;

package body test_pkg is

  file test_output : text;
  shared variable initialized : boolean := false;
  shared variable have_plan : boolean := false;
  shared variable last_test_number : natural := 0;

  function remove_eol(s : string) return string is
    variable s_no_eol : string(s'range);
  begin
    for i in s'range loop
      case s(i) is
        when LF | CR => s_no_eol(i) := '_';
        when others  => s_no_eol(i) := s(i);
      end case;
    end loop;
    return s_no_eol;
  end function;

  function make_safe (s : string) return string is
    variable s_no_hash : string(s'range);
  begin
    for i in s'range loop
      case s(i) is
        when '#'    => s_no_hash(i) := '_';
        when others => s_no_hash(i) := s(i);
      end case;
    end loop;
    return remove_eol(s_no_hash);
  end function;

  procedure init is
    variable l : line;
  begin
    if initialized then
      return;
    end if;
    initialized := true;
    file_open(test_output, "STD_OUTPUT", write_mode);
    write(l, string'("TAP version 13"));
    writeline(test_output, l);
  end procedure;

  procedure test_redirect(filename : string) is
  begin
    init;
    file_close(test_output);
    file_open(test_output, filename, write_mode);
  end procedure;

  procedure test_plan(tests : natural; directive : string := "") is
    variable l : line;
  begin
    init;
    have_plan := true;
    write(l, string'("1.."));
    write(l, tests);
    if directive'length > 0 then
      write(l, " # " & remove_eol(directive));
    end if;
    writeline(test_output, l);
  end procedure;

  procedure test_abort(reason : string) is
    variable l : line;
  begin
    init;
    write(l, "Bail out! " & remove_eol(reason));
    writeline(test_output, l);
    assert false
      report "abort called"
      severity failure;
  end procedure;

  procedure test_finished (directive : string := "") is
  begin
    if not have_plan then
      test_plan(last_test_number, directive);
    elsif directive'length > 0 then
      test_comment("1.." & integer'image(last_test_number) & " # " & directive);
    else
      test_comment("1.." & integer'image(last_test_number));
    end if;
  end procedure;

  procedure test_comment (message : string) is
    variable l : line;
  begin
    init;
    write(l, '#');
    if message'length > 0 then
      write(l, " " & remove_eol(message));
    end if;
    writeline(test_output, l);
  end procedure;

  procedure result (status : string; description : string; directive : string) is
    variable l : line;
  begin
    init;
    last_test_number := last_test_number + 1;
    write(l, status & " ");
    write(l, last_test_number);
    if description'length > 0 then
      write(l, " " & make_safe(description));
    end if;
    if directive'length > 0 then
      write(l, " # " & remove_eol(directive));
    end if;
    writeline(test_output, l);
  end procedure;

  procedure test_pass (description : string := ""; directive : string := "") is
  begin
    result("ok", description, directive);
  end procedure;

  procedure test_fail (description : string := ""; directive : string := "") is
  begin
    result("not ok", description, directive);
  end procedure;

  procedure test_ok (result : boolean; description : string := ""; directive : string := "") is
  begin
    if result then
      test_pass(description, directive);
    else
      test_fail(description, directive);
    end if;
  end procedure;

  procedure test_equal(actual, expected : integer; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & integer'image(actual) & ", expected = " & integer'image(expected));
    end if;
  end procedure;

  procedure test_equal(actual, expected : real; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & real'image(actual) & ", expected = " & real'image(expected));
    end if;
  end procedure;

  procedure test_equal(actual, expected : time; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & time'image(actual) & ", expected = " & time'image(expected));
    end if;
  end procedure;

  procedure test_equal(actual, expected : string; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & actual & ", expected = " & expected);
    end if;
  end procedure;

  procedure test_equal(actual, expected : bit_vector; description : string := ""; directive : string := "") is
    variable ok : boolean := actual = expected;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & to_string(actual) & ", expected = " & to_string(expected));
    end if;
  end procedure;

  procedure test_approx_absolute(actual, expected, absolute_error : real; description : string := ""; directive : string := "") is
    variable err : real := abs(actual - expected);
    variable ok : boolean := err <= absolute_error;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & to_string(actual) & ", expected = " & to_string(expected) & ", absolute error = " & to_string(err));
    end if;
  end procedure;

  procedure test_approx_relative(actual, expected, relative_error : real; description : string := ""; directive : string := "") is
    variable err : real := abs(actual - expected)/abs(expected);
    variable ok : boolean := err <= relative_error;
  begin
    test_ok(ok, description, directive);
    if not ok then
      test_comment("actual = " & to_string(actual) & ", expected = " & to_string(expected) & ", relative error = " & to_string(err));
    end if;
  end procedure;

end package body;
七分※倦醒 2024-10-13 02:21:11

从我有限的对 TAP 的快速阅读来看——不太可能......因为大多数 HDL 设计者与软件测试领域的联系并不那么紧密(尽管他们早在单元测试被称为单元测试之前就已经开始进行了:)我喜欢感觉自己是一名 HDL 设计师, 与软件测试领域有着相当密切的联系,但我以前从未接触过 TAP。我一直坚持使用 Python 自己的单元测试功能(并涉足 pytest)。以及我自己使用 VHDL 及其断言的混合物。

不过,它看起来像是一个相当简单的...如果您决定自己编写一个包,请告诉我们!

From my limited quick reading up on TAP - unlikely... because most HDL designers are not that well-connected with the world of software testing (even though they've been doing unit-testing since well before it was called that :) I like to feel I am an HDL designer who is reasonably well-connected to the world of software testing, and I've never come across TAP before. I've stuck to Python's own unittest functionality (and dabbled with pytest). And my own concoction for working with VHDL and its asserts.

It looks like a fairly simple package to write though... do let us know if you decide to write one yourself!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文