From e5a991988f6983768121a63328a5e9058337379f Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 12 Apr 2012 20:13:35 -0400 Subject: [PATCH] Tests added --- test_regress/t/t_dpi_shortcircuit.pl | 23 +++ test_regress/t/t_dpi_shortcircuit.v | 214 ++++++++++++++++++++++++ test_regress/t/t_dpi_shortcircuit_c.cpp | 59 +++++++ 3 files changed, 296 insertions(+) create mode 100755 test_regress/t/t_dpi_shortcircuit.pl create mode 100644 test_regress/t/t_dpi_shortcircuit.v create mode 100644 test_regress/t/t_dpi_shortcircuit_c.cpp diff --git a/test_regress/t/t_dpi_shortcircuit.pl b/test_regress/t/t_dpi_shortcircuit.pl new file mode 100755 index 000000000..3b0bfdcb5 --- /dev/null +++ b/test_regress/t/t_dpi_shortcircuit.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. 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. + +$Self->{vlt} and $Self->unsupported("Verilator unsupported, bug413 short circuit"); + +compile ( + # Amazingly VCS, NC and Verilator all just accept the C file here! + v_flags2 => ["t/t_dpi_shortcircuit_c.cpp"], + verilator_flags2 => ["-Wno-DECLFILENAME"], + ); + +execute ( + check_finished=>1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_dpi_shortcircuit.v b/test_regress/t/t_dpi_shortcircuit.v new file mode 100644 index 000000000..4bd1dc22a --- /dev/null +++ b/test_regress/t/t_dpi_shortcircuit.v @@ -0,0 +1,214 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// Copyright 2009 by Wilson Snyder. 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. + +`ifdef VCS + `define NO_SHORTREAL +`endif +`ifdef NC + `define NO_SHORTREAL +`endif +`ifdef VERILATOR // Unsupported + `define NO_SHORTREAL +`endif + +module t (/*AUTOARG*/); + + // Note these are NOT pure. + import "DPI-C" function int dpii_clear (); + import "DPI-C" function int dpii_count (input int i); + import "DPI-C" function bit dpii_inc0 (input int i); + import "DPI-C" function bit dpii_inc1 (input int i); + import "DPI-C" function bit dpii_incx (input int i, input bit value); + + // verilator lint_off UNUSED + integer i; + bit b; + // verilator lint_on UNUSED + integer errors; + + task check1(integer line, bit got, bit ex); + if (got != ex) begin + $display("%%Error: Line %0d: Bad result, got=%0d expect=%0d",line,got,ex); + errors++; + end + endtask + task check(integer line, int got, int ex); + if (got != ex) begin + $display("%%Error: Line %0d: Bad result, got=%0d expect=%0d",line,got,ex); + errors++; + end + endtask + + // Test loop + initial begin + // Spec says && || -> and ?: short circuit, no others do. + // Check both constant & non constants. + dpii_clear(); + check1(`__LINE__, (1'b0 && dpii_inc0(0)), 1'b0); + check1(`__LINE__, (1'b1 && dpii_inc0(1)), 1'b0); + check1(`__LINE__, (dpii_inc0(2) && dpii_inc0(3)), 1'b0); + check1(`__LINE__, (dpii_inc1(4) && dpii_inc0(5)), 1'b0); + check1(`__LINE__, (dpii_inc0(6) && dpii_inc1(7)), 1'b0); + check1(`__LINE__, (!(dpii_inc1(8) && dpii_inc1(9))), 1'b0); + check (`__LINE__, dpii_count(0), 0); + check (`__LINE__, dpii_count(1), 1); + check (`__LINE__, dpii_count(2), 1); + check (`__LINE__, dpii_count(3), 0); + check (`__LINE__, dpii_count(4), 1); + check (`__LINE__, dpii_count(5), 1); + check (`__LINE__, dpii_count(6), 1); + check (`__LINE__, dpii_count(7), 0); + check (`__LINE__, dpii_count(8), 1); + check (`__LINE__, dpii_count(9), 1); + // + dpii_clear(); + check1(`__LINE__, (1'b0 & dpii_inc0(0)), 1'b0); + check1(`__LINE__, (1'b1 & dpii_inc0(1)), 1'b0); + check1(`__LINE__, (dpii_inc0(2) & dpii_inc0(3)), 1'b0); + check1(`__LINE__, (dpii_inc1(4) & dpii_inc0(5)), 1'b0); + check1(`__LINE__, (dpii_inc0(6) & dpii_inc1(7)), 1'b0); + check1(`__LINE__, (!(dpii_inc1(8) & dpii_inc1(9))), 1'b0); + check (`__LINE__, dpii_count(0), 1); + check (`__LINE__, dpii_count(1), 1); + check (`__LINE__, dpii_count(2), 1); + check (`__LINE__, dpii_count(3), 1); + check (`__LINE__, dpii_count(4), 1); + check (`__LINE__, dpii_count(5), 1); + check (`__LINE__, dpii_count(6), 1); + check (`__LINE__, dpii_count(7), 1); + check (`__LINE__, dpii_count(8), 1); + check (`__LINE__, dpii_count(9), 1); + // + dpii_clear(); + check1(`__LINE__, (1'b0 || dpii_inc0(0)), 1'b0); + check1(`__LINE__, (1'b1 || dpii_inc0(1)), 1'b1); + check1(`__LINE__, (dpii_inc0(2) || dpii_inc0(3)), 1'b0); + check1(`__LINE__, (dpii_inc1(4) || dpii_inc0(5)), 1'b1); + check1(`__LINE__, (dpii_inc0(6) || dpii_inc1(7)), 1'b1); + check1(`__LINE__, (!(dpii_inc1(8) || dpii_inc1(9))), 1'b0); + check (`__LINE__, dpii_count(0), 1); + check (`__LINE__, dpii_count(1), 0); + check (`__LINE__, dpii_count(2), 1); + check (`__LINE__, dpii_count(3), 1); + check (`__LINE__, dpii_count(4), 1); + check (`__LINE__, dpii_count(5), 0); + check (`__LINE__, dpii_count(6), 1); + check (`__LINE__, dpii_count(7), 1); + check (`__LINE__, dpii_count(8), 1); + check (`__LINE__, dpii_count(9), 0); + // + dpii_clear(); + check1(`__LINE__, (1'b0 | dpii_inc0(0)), 1'b0); + check1(`__LINE__, (1'b1 | dpii_inc0(1)), 1'b1); + check1(`__LINE__, (dpii_inc0(2) | dpii_inc0(3)), 1'b0); + check1(`__LINE__, (dpii_inc1(4) | dpii_inc0(5)), 1'b1); + check1(`__LINE__, (dpii_inc0(6) | dpii_inc1(7)), 1'b1); + check1(`__LINE__, (!(dpii_inc1(8) | dpii_inc1(9))), 1'b0); + check (`__LINE__, dpii_count(0), 1); + check (`__LINE__, dpii_count(1), 1); + check (`__LINE__, dpii_count(2), 1); + check (`__LINE__, dpii_count(3), 1); + check (`__LINE__, dpii_count(4), 1); + check (`__LINE__, dpii_count(5), 1); + check (`__LINE__, dpii_count(6), 1); + check (`__LINE__, dpii_count(7), 1); + check (`__LINE__, dpii_count(8), 1); + check (`__LINE__, dpii_count(9), 1); + // + dpii_clear(); + check1(`__LINE__, (1'b0 -> dpii_inc0(0)), 1'b1); + check1(`__LINE__, (1'b1 -> dpii_inc0(1)), 1'b0); + check1(`__LINE__, (dpii_inc0(2) -> dpii_inc0(3)), 1'b1); + check1(`__LINE__, (dpii_inc1(4) -> dpii_inc0(5)), 1'b0); + check1(`__LINE__, (dpii_inc0(6) -> dpii_inc1(7)), 1'b1); + check1(`__LINE__, (!(dpii_inc1(8) -> dpii_inc1(9))), 1'b0); + check (`__LINE__, dpii_count(0), 0); + check (`__LINE__, dpii_count(1), 1); + check (`__LINE__, dpii_count(2), 1); + check (`__LINE__, dpii_count(3), 0); + check (`__LINE__, dpii_count(4), 1); + check (`__LINE__, dpii_count(5), 1); + check (`__LINE__, dpii_count(6), 1); + check (`__LINE__, dpii_count(7), 0); + check (`__LINE__, dpii_count(8), 1); + check (`__LINE__, dpii_count(9), 1); + // + dpii_clear(); + check1(`__LINE__, (1'b0 ? dpii_inc0(0) : dpii_inc0(1)), 1'b0); + check1(`__LINE__, (1'b1 ? dpii_inc0(2) : dpii_inc0(3)), 1'b0); + check1(`__LINE__, (dpii_inc0(4) ? dpii_inc0(5) : dpii_inc0(6)), 1'b0); + check1(`__LINE__, (dpii_inc1(7) ? dpii_inc0(8) : dpii_inc0(9)), 1'b0); + check (`__LINE__, dpii_count(0), 0); + check (`__LINE__, dpii_count(1), 1); + check (`__LINE__, dpii_count(2), 1); + check (`__LINE__, dpii_count(3), 0); + check (`__LINE__, dpii_count(4), 1); + check (`__LINE__, dpii_count(5), 0); + check (`__LINE__, dpii_count(6), 1); + check (`__LINE__, dpii_count(7), 1); + check (`__LINE__, dpii_count(8), 1); + check (`__LINE__, dpii_count(9), 0); + // + dpii_clear(); + check1(`__LINE__, (1'b0 * dpii_inc0(0)), 1'b0); + check1(`__LINE__, (1'b1 * dpii_inc0(1)), 1'b0); + check1(`__LINE__, (dpii_inc0(2) * dpii_inc0(3)), 1'b0); + check1(`__LINE__, (dpii_inc1(4) * dpii_inc0(5)), 1'b0); + check1(`__LINE__, (dpii_inc0(6) * dpii_inc1(7)), 1'b0); + check1(`__LINE__, (!(dpii_inc1(8) * dpii_inc1(9))), 1'b0); + check (`__LINE__, dpii_count(0), 1); + check (`__LINE__, dpii_count(1), 1); + check (`__LINE__, dpii_count(2), 1); + check (`__LINE__, dpii_count(3), 1); + check (`__LINE__, dpii_count(4), 1); + check (`__LINE__, dpii_count(5), 1); + check (`__LINE__, dpii_count(6), 1); + check (`__LINE__, dpii_count(7), 1); + check (`__LINE__, dpii_count(8), 1); + check (`__LINE__, dpii_count(9), 1); + // + dpii_clear(); + check1(`__LINE__, (1'b0 + dpii_inc0(0)), 1'b0); + check1(`__LINE__, (1'b1 + dpii_inc0(1)), 1'b1); + check1(`__LINE__, (dpii_inc0(2) + dpii_inc0(3)), 1'b0); + check1(`__LINE__, (dpii_inc1(4) + dpii_inc0(5)), 1'b1); + check1(`__LINE__, (dpii_inc0(6) + dpii_inc1(7)), 1'b1); + check1(`__LINE__, (dpii_inc1(8) + dpii_inc1(9)), 1'b0); + check (`__LINE__, dpii_count(0), 1); + check (`__LINE__, dpii_count(1), 1); + check (`__LINE__, dpii_count(2), 1); + check (`__LINE__, dpii_count(3), 1); + check (`__LINE__, dpii_count(4), 1); + check (`__LINE__, dpii_count(5), 1); + check (`__LINE__, dpii_count(6), 1); + check (`__LINE__, dpii_count(7), 1); + check (`__LINE__, dpii_count(8), 1); + check (`__LINE__, dpii_count(9), 1); + // + // Something a lot more complicated + dpii_clear(); + for (i=0; i<64; i++) begin + b = ( ((dpii_incx(0,i[0]) + && (dpii_incx(1,i[1]) + || dpii_incx(2,i[2]) + | dpii_incx(3,i[3]))) // | not || + || dpii_incx(4,i[4])) + -> dpii_incx(5,i[5])); + end + check (`__LINE__, dpii_count(0), 64); + check (`__LINE__, dpii_count(1), 32); + check (`__LINE__, dpii_count(2), 16); + check (`__LINE__, dpii_count(3), 16); + check (`__LINE__, dpii_count(4), 36); + check (`__LINE__, dpii_count(5), 46); + + if (|errors) $stop; + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule diff --git a/test_regress/t/t_dpi_shortcircuit_c.cpp b/test_regress/t/t_dpi_shortcircuit_c.cpp new file mode 100644 index 000000000..0090188a1 --- /dev/null +++ b/test_regress/t/t_dpi_shortcircuit_c.cpp @@ -0,0 +1,59 @@ +// -*- C++ -*- +//************************************************************************* +// +// Copyright 2011-2011 by Wilson Snyder. 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. +// +// Verilator 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. +// +//************************************************************************* + +#include +#include +#include "svdpi.h" + +//====================================================================== + +#if defined(VERILATOR) +# include "Vt_dpi_shortcircuit__Dpi.h" +#elif defined(VCS) +# include "../vc_hdrs.h" +#elif defined(CADENCE) +# define NEED_EXTERNS +#else +# error "Unknown simulator for DPI test" +#endif + +#ifdef NEED_EXTERNS +extern "C" { + extern int dpii_clear (); + extern int dpii_count (int idx); + extern unsigned char dpii_inc0 (int idx); + extern unsigned char dpii_inc1 (int idx); + extern unsigned char dpii_incx (int idx, unsigned char value); +} +#endif + +//====================================================================== + +#define COUNTERS 16 +static int global_count[COUNTERS]; + +int dpii_clear () { + for (int i=0; i= 0 && idx= 0 && idx